LuaFunctions.cpp 417 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646
  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 = ((Player*)player)->GetClient();
  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_PlayFlavorID(lua_State* state) {
  179. if (!lua_interface)
  180. return 0;
  181. Spawn* spawn = lua_interface->GetSpawn(state);
  182. int8 type = lua_interface->GetInt8Value(state, 2);
  183. int32 id = lua_interface->GetInt32Value(state, 3);
  184. int16 index = lua_interface->GetInt16Value(state, 4);
  185. Spawn* player = lua_interface->GetSpawn(state, 5);
  186. int8 language = lua_interface->GetInt8Value(state, 6);
  187. lua_interface->ResetFunctionStack(state);
  188. if (spawn) {
  189. Client* client = 0;
  190. if (player && player->IsPlayer())
  191. client = ((Player*)player)->GetClient();
  192. if (client) {
  193. VoiceOverStruct non_garble, garble;
  194. bool garble_success = false;
  195. bool success = world.FindVoiceOver(type, id, index, &non_garble, &garble_success, &garble);
  196. client->SendPlayFlavor(spawn, language, &non_garble, &garble, success, garble_success);
  197. }
  198. else
  199. spawn->GetZone()->PlayFlavorID(spawn, type, id, index, language);
  200. }
  201. return 0;
  202. }
  203. int EQ2Emu_lua_PlaySound(lua_State* state) {
  204. if (!lua_interface)
  205. return 0;
  206. Spawn* spawn = lua_interface->GetSpawn(state);
  207. string sound_string = lua_interface->GetStringValue(state, 2);
  208. float x = lua_interface->GetFloatValue(state, 3);
  209. float y = lua_interface->GetFloatValue(state, 4);
  210. float z = lua_interface->GetFloatValue(state, 5);
  211. Spawn* player = lua_interface->GetSpawn(state, 6);
  212. lua_interface->ResetFunctionStack(state);
  213. if (spawn && sound_string.length() > 0) {
  214. Client* client = 0;
  215. if (player && player->IsPlayer())
  216. client = ((Player*)player)->GetClient();
  217. if (client)
  218. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  219. else
  220. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  221. }
  222. return 0;
  223. }
  224. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  225. if (!lua_interface)
  226. return 0;
  227. Spawn* spawn = lua_interface->GetSpawn(state);
  228. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  229. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  230. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  231. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  232. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  233. lua_interface->ResetFunctionStack(state);
  234. if (!spawn) {
  235. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  236. return 0;
  237. }
  238. if (quest_id > 0) {
  239. //Add this quest to the list of required quests for this spawn
  240. spawn->SetQuestsRequired(quest_id, quest_step);
  241. //If private spawn value set
  242. if (private_spawn) {
  243. //Set the spawn to be private when not granted access through this quest
  244. spawn->AddAllowAccessSpawn(spawn);
  245. spawn->SetPrivateQuestSpawn(true);
  246. }
  247. //This value allows access after a quest step, or the whole quest has been completed
  248. if (continued_access)
  249. spawn->SetQuestsRequiredContinuedAccess(true);
  250. //This value will override vis_flags in the vis packet
  251. if (flag_override > 0)
  252. spawn->SetQuestsRequiredOverride(flag_override);
  253. }
  254. return 0;
  255. }
  256. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  257. if (!lua_interface)
  258. return 0;
  259. Spawn* spawn = lua_interface->GetSpawn(state);
  260. float max_distance = lua_interface->GetFloatValue(state, 2);
  261. string variable = lua_interface->GetStringValue(state, 3);
  262. string value = lua_interface->GetStringValue(state, 4);
  263. lua_interface->ResetFunctionStack(state);
  264. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  265. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  266. return 0;
  267. }
  268. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  269. if (!lua_interface)
  270. return 0;
  271. Client* client = 0;
  272. Spawn* player = lua_interface->GetSpawn(state);
  273. float intensity = lua_interface->GetFloatValue(state, 2);
  274. int8 direction = lua_interface->GetInt8Value(state, 3);
  275. lua_interface->ResetFunctionStack(state);
  276. if (!player) {
  277. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  278. return 0;
  279. }
  280. if (!player->IsPlayer()) {
  281. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  282. return 0;
  283. }
  284. if (player->GetZone())
  285. client = ((Player*)player)->GetClient();
  286. if (!client) {
  287. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  288. return 0;
  289. }
  290. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  291. if (packet) {
  292. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  293. v1 = *(float *)(a1 + 4);
  294. if ( v1 > 0.0 )
  295. v2 = fminf(v1, 1.0);
  296. else
  297. v2 = 0.1;
  298. */
  299. packet->setDataByName("intensity", intensity);
  300. if ( client->GetVersion() > 546 )
  301. packet->setDataByName("direction", direction);
  302. client->QueuePacket(packet->serialize());
  303. safe_delete(packet);
  304. }
  305. return 0;
  306. }
  307. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* dead = lua_interface->GetSpawn(state);
  311. Spawn* killer = lua_interface->GetSpawn(state, 2);
  312. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  313. lua_interface->ResetFunctionStack(state);
  314. if (dead && dead->Alive() && dead->GetZone())
  315. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  316. return 0;
  317. }
  318. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  319. if (!lua_interface)
  320. return 0;
  321. Spawn* spawn = lua_interface->GetSpawn(state);
  322. float max_distance = lua_interface->GetFloatValue(state, 2);
  323. bool include_players = lua_interface->GetInt8Value(state, 3);
  324. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  325. lua_interface->ResetFunctionStack(state);
  326. if (max_distance > 0 && spawn && spawn->GetZone())
  327. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  328. return 0;
  329. }
  330. int EQ2Emu_lua_Despawn(lua_State* state) {
  331. if (!lua_interface)
  332. return 0;
  333. Spawn* spawn = lua_interface->GetSpawn(state);
  334. int32 delay = lua_interface->GetInt32Value(state, 2);
  335. lua_interface->ResetFunctionStack(state);
  336. if (spawn && spawn->GetZone())
  337. spawn->GetZone()->Despawn(spawn, delay);
  338. return 0;
  339. }
  340. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  341. if (!lua_interface)
  342. return 0;
  343. Spawn* spawn = lua_interface->GetSpawn(state);
  344. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  345. lua_interface->ResetFunctionStack(state);
  346. if (spawn) {
  347. spawn->info_changed = true;
  348. spawn->SetShowHandIcon(displayHandIcon);
  349. }
  350. return 0;
  351. }
  352. //this function is used to force an update packet to be sent.
  353. //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
  354. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  355. if (!lua_interface)
  356. return 0;
  357. Spawn* spawn = lua_interface->GetSpawn(state);
  358. lua_interface->ResetFunctionStack(state);
  359. if (spawn) {
  360. spawn->vis_changed = true;
  361. spawn->GetZone()->AddChangedSpawn(spawn);
  362. }
  363. return 0;
  364. }
  365. //this function is used to force an update packet to be sent.
  366. //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
  367. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  368. if (!lua_interface)
  369. return 0;
  370. Spawn* spawn = lua_interface->GetSpawn(state);
  371. lua_interface->ResetFunctionStack(state);
  372. if (spawn) {
  373. spawn->info_changed = true;
  374. spawn->GetZone()->AddChangedSpawn(spawn);
  375. }
  376. return 0;
  377. }
  378. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  379. if (!lua_interface)
  380. return 0;
  381. Spawn* spawn = lua_interface->GetSpawn(state);
  382. int32 new_state = lua_interface->GetInt32Value(state, 2);
  383. Spawn* player = lua_interface->GetSpawn(state, 3);
  384. lua_interface->ResetFunctionStack(state);
  385. if (spawn) {
  386. if(player)
  387. {
  388. if(player->IsPlayer())
  389. {
  390. Client* client = ((Player*)player)->GetClient();
  391. if(client)
  392. {
  393. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  394. lua_interface->SetBooleanValue(state, true);
  395. return 1;
  396. }
  397. else
  398. 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());
  399. }
  400. else
  401. 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());
  402. }
  403. else
  404. {
  405. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  406. lua_interface->SetBooleanValue(state, true);
  407. return 1;
  408. }
  409. }
  410. lua_interface->SetBooleanValue(state, false);
  411. return 1;
  412. }
  413. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  414. if (!lua_interface)
  415. return 0;
  416. Spawn* spawn = lua_interface->GetSpawn(state);
  417. string variable = lua_interface->GetStringValue(state, 2);
  418. string value = lua_interface->GetStringValue(state, 3);
  419. 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.
  420. bool temporary_flag = true;
  421. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  422. int8 index = 0;
  423. if(num_args >= 5)
  424. {
  425. 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
  426. index = lua_interface->GetInt8Value(state, 6);
  427. }
  428. lua_interface->ResetFunctionStack(state);
  429. int32 type = commands.GetSpawnSetType(variable);
  430. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  431. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  432. return 0;
  433. }
  434. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  435. if (!lua_interface)
  436. return 0;
  437. Spawn* spawn = lua_interface->GetSpawn(state);
  438. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  439. lua_interface->ResetFunctionStack(state);
  440. if (spawn && spawn_id > 0) {
  441. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  442. if (closest_spawn) {
  443. lua_interface->SetSpawnValue(state, closest_spawn);
  444. return 1;
  445. }
  446. }
  447. return 0;
  448. }
  449. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  450. if (!lua_interface)
  451. return 0;
  452. vector<Spawn*> spawns;
  453. int32 position = 0;
  454. if(lua_istable(state, 1)) {
  455. size_t len = lua_rawlen(state, 1);
  456. for(int i=1;i <= len; i++)
  457. {
  458. // get the entry to stack
  459. lua_rawgeti(state, 1, i);
  460. int Top = lua_gettop(state);
  461. if(lua_islightuserdata(state,Top)) {
  462. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  463. if(data->IsSpawn()) {
  464. spawns.push_back(data->spawn);
  465. }
  466. }
  467. // remove entry from stack
  468. lua_pop(state,1);
  469. }
  470. }
  471. position = lua_interface->GetInt32Value(state, 2);
  472. lua_interface->ResetFunctionStack(state);
  473. Spawn* spawn = 0;
  474. if(position < spawns.size()) {
  475. spawn = spawns.at(position);
  476. }
  477. if(spawn) {
  478. lua_interface->SetSpawnValue(state, spawn);
  479. return 1;
  480. }
  481. return 0;
  482. }
  483. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  484. if (!lua_interface)
  485. return 0;
  486. vector<Spawn*> spawns;
  487. if(lua_istable(state, 1)) {
  488. size_t len = lua_rawlen(state, 1);
  489. for(int i=1;i <= len; i++)
  490. {
  491. // get the entry to stack
  492. lua_rawgeti(state, 1, i);
  493. int Top = lua_gettop(state);
  494. if(lua_islightuserdata(state,Top)) {
  495. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  496. if(data->IsSpawn()) {
  497. spawns.push_back(data->spawn);
  498. }
  499. }
  500. // remove entry from stack
  501. lua_pop(state,1);
  502. }
  503. }
  504. lua_interface->ResetFunctionStack(state);
  505. lua_interface->SetInt32Value(state, spawns.size());
  506. return 1;
  507. }
  508. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  509. if (!lua_interface)
  510. return 0;
  511. Spawn* spawn = lua_interface->GetSpawn(state);
  512. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  513. lua_interface->ResetFunctionStack(state);
  514. if (spawn) {
  515. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  516. if (spawns.size() > 0) {
  517. lua_createtable(state, spawns.size(), 0);
  518. int newTable = lua_gettop(state);
  519. for (int32 i = 0; i < spawns.size(); i++) {
  520. lua_interface->SetSpawnValue(state, spawns.at(i));
  521. lua_rawseti(state, newTable, i + 1);
  522. }
  523. return 1;
  524. }
  525. }
  526. return 0;
  527. }
  528. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  529. if (!lua_interface)
  530. return 0;
  531. Spawn* spawn = lua_interface->GetSpawn(state);
  532. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  533. lua_interface->ResetFunctionStack(state);
  534. if (spawn) {
  535. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  536. if (spawns.size() > 0) {
  537. lua_createtable(state, spawns.size(), 0);
  538. int newTable = lua_gettop(state);
  539. for (int32 i = 0; i < spawns.size(); i++) {
  540. lua_interface->SetSpawnValue(state, spawns.at(i));
  541. lua_rawseti(state, newTable, i + 1);
  542. }
  543. return 1;
  544. }
  545. }
  546. return 0;
  547. }
  548. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  549. if (!lua_interface)
  550. return 0;
  551. Spawn* spawn = lua_interface->GetSpawn(state);
  552. lua_interface->ResetFunctionStack(state);
  553. if (spawn) {
  554. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  555. if (spawns.size() > 0) {
  556. lua_createtable(state, spawns.size(), 0);
  557. int newTable = lua_gettop(state);
  558. for (int32 i = 0; i < spawns.size(); i++) {
  559. lua_interface->SetSpawnValue(state, spawns.at(i));
  560. lua_rawseti(state, newTable, i + 1);
  561. }
  562. return 1;
  563. }
  564. }
  565. return 0;
  566. }
  567. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  568. if (!lua_interface)
  569. return 0;
  570. string variable_name = lua_interface->GetStringValue(state);
  571. lua_interface->ResetFunctionStack(state);
  572. Variable* var = variables.FindVariable(variable_name);
  573. if (var) {
  574. lua_interface->SetStringValue(state, var->GetValue());
  575. return 1;
  576. }
  577. return 0;
  578. }
  579. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  580. if (!lua_interface)
  581. return 0;
  582. int32 total_coins = lua_interface->GetInt32Value(state);
  583. lua_interface->ResetFunctionStack(state);
  584. if (total_coins == 0) {
  585. lua_interface->SetStringValue(state, "0 copper");
  586. return 1;
  587. }
  588. char tmp[64] = { 0 };
  589. string message = "";
  590. int32 val = 0;
  591. if (total_coins >= 1000000) {
  592. val = total_coins / 1000000;
  593. total_coins -= 1000000 * val;
  594. sprintf(tmp, " %u Platinum", val);
  595. message.append(tmp);
  596. memset(tmp, 0, 64);
  597. }
  598. if (total_coins >= 10000) {
  599. val = total_coins / 10000;
  600. total_coins -= 10000 * val;
  601. sprintf(tmp, " %u Gold", val);
  602. message.append(tmp);
  603. memset(tmp, 0, 64);
  604. }
  605. if (total_coins >= 100) {
  606. val = total_coins / 100;
  607. total_coins -= 100 * val;
  608. sprintf(tmp, " %u Silver", val);
  609. message.append(tmp);
  610. memset(tmp, 0, 64);
  611. }
  612. if (total_coins > 0) {
  613. sprintf(tmp, " %u Copper", (int32)total_coins);
  614. message.append(tmp);
  615. }
  616. lua_interface->SetStringValue(state, message.c_str());
  617. return 1;
  618. }
  619. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  620. ZoneServer* zone = lua_interface->GetZone(state);
  621. int32 group_id = lua_interface->GetInt32Value(state, 2);
  622. lua_interface->ResetFunctionStack(state);
  623. if (zone) {
  624. Spawn* spawn = zone->GetSpawnGroup(group_id);
  625. if (spawn) {
  626. lua_interface->SetSpawnValue(state, spawn);
  627. return 1;
  628. }
  629. }
  630. return 0;
  631. }
  632. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  633. ZoneServer* zone = lua_interface->GetZone(state);
  634. int32 location_id = lua_interface->GetInt32Value(state, 2);
  635. lua_interface->ResetFunctionStack(state);
  636. if (zone) {
  637. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  638. if (spawn) {
  639. lua_interface->SetSpawnValue(state, spawn);
  640. return 1;
  641. }
  642. }
  643. return 0;
  644. }
  645. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  646. Spawn* spawn = lua_interface->GetSpawn(state);
  647. lua_interface->ResetFunctionStack(state);
  648. if (spawn) {
  649. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  650. return 1;
  651. }
  652. return 0;
  653. }
  654. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  655. Spawn* spawn = lua_interface->GetSpawn(state);
  656. lua_interface->ResetFunctionStack(state);
  657. if (spawn) {
  658. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  659. return 1;
  660. }
  661. return 0;
  662. }
  663. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  664. if (!lua_interface)
  665. return 0;
  666. Spawn* spawn = lua_interface->GetSpawn(state);
  667. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  668. lua_interface->ResetFunctionStack(state);
  669. if (spawn) {
  670. spawn->SetSpawnGroupID(new_group_id);
  671. lua_interface->SetBooleanValue(state, true);
  672. return 1;
  673. }
  674. lua_interface->SetBooleanValue(state, false);
  675. return 1;
  676. }
  677. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  678. if (!lua_interface)
  679. return 0;
  680. Spawn* spawn = lua_interface->GetSpawn(state);
  681. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  682. lua_interface->ResetFunctionStack(state);
  683. if (spawn) {
  684. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  685. lua_interface->SetBooleanValue(state, true);
  686. return 1;
  687. }
  688. lua_interface->SetBooleanValue(state, false);
  689. return 1;
  690. }
  691. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  692. Spawn* spawn = lua_interface->GetSpawn(state);
  693. lua_interface->ResetFunctionStack(state);
  694. if (spawn) {
  695. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  696. return 1;
  697. }
  698. return 0;
  699. }
  700. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  701. Spawn* spawn = lua_interface->GetSpawn(state);
  702. lua_interface->ResetFunctionStack(state);
  703. if (spawn) {
  704. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  705. return 1;
  706. }
  707. return 0;
  708. }
  709. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  710. Player* player = (Player*)lua_interface->GetSpawn(state);
  711. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  712. lua_interface->ResetFunctionStack(state);
  713. if (player && player->IsPlayer() && faction_id > 0) {
  714. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  715. return 1;
  716. }
  717. return 0;
  718. }
  719. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  720. if (!lua_interface)
  721. return 0;
  722. Spawn* spawn = lua_interface->GetSpawn(state);
  723. int32 value = lua_interface->GetInt32Value(state, 2);
  724. lua_interface->ResetFunctionStack(state);
  725. if (spawn) {
  726. spawn->SetFactionID(value);
  727. }
  728. return 0;
  729. }
  730. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  731. Spawn* spawn = lua_interface->GetSpawn(state);
  732. lua_interface->ResetFunctionStack(state);
  733. if (spawn) {
  734. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  735. return 1;
  736. }
  737. return 0;
  738. }
  739. int EQ2Emu_lua_GetGender(lua_State* state) {
  740. Spawn* spawn = lua_interface->GetSpawn(state);
  741. lua_interface->ResetFunctionStack(state);
  742. if (spawn) {
  743. lua_interface->SetInt32Value(state, spawn->GetGender());
  744. return 1;
  745. }
  746. return 0;
  747. }
  748. int EQ2Emu_lua_GetTarget(lua_State* state) {
  749. Spawn* spawn = lua_interface->GetSpawn(state);
  750. lua_interface->ResetFunctionStack(state);
  751. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  752. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  753. return 1;
  754. }
  755. return 0;
  756. }
  757. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  758. if (!lua_interface)
  759. return 0;
  760. Spawn* spawn = lua_interface->GetSpawn(state);
  761. string mp3_string = lua_interface->GetStringValue(state, 2);
  762. int32 key1 = lua_interface->GetInt32Value(state, 3);
  763. int32 key2 = lua_interface->GetInt32Value(state, 4);
  764. Spawn* player = lua_interface->GetSpawn(state, 5);
  765. lua_interface->ResetFunctionStack(state);
  766. if (spawn && mp3_string.length() > 0) {
  767. Client* client = 0;
  768. if (player && player->IsPlayer())
  769. client = ((Player*)player)->GetClient();
  770. if (client) {
  771. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  772. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  773. }
  774. else
  775. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  776. }
  777. return 0;
  778. }
  779. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  780. if (!lua_interface)
  781. return 0;
  782. Spawn* spawn = lua_interface->GetSpawn(state);
  783. lua_interface->ResetFunctionStack(state);
  784. if (spawn) {
  785. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  786. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  787. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  788. return 3;
  789. }
  790. return 0;
  791. }
  792. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  793. if (!lua_interface)
  794. return 0;
  795. Spawn* spawn = lua_interface->GetSpawn(state);
  796. if (spawn) {
  797. int32 item_id = lua_interface->GetInt32Value(state, 2);
  798. lua_interface->ResetFunctionStack(state);
  799. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  800. return 1;
  801. }
  802. lua_interface->ResetFunctionStack(state);
  803. return 0;
  804. }
  805. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  806. if (!lua_interface)
  807. return 0;
  808. Spawn* spawn = lua_interface->GetSpawn(state);
  809. if (spawn && spawn->IsEntity()) {
  810. int32 item_id = lua_interface->GetInt32Value(state, 2);
  811. int16 charges = lua_interface->GetInt16Value(state, 3);
  812. if (charges == 0)
  813. charges = 1;
  814. ((Entity*)spawn)->AddLootItem(item_id, charges);
  815. }
  816. lua_interface->ResetFunctionStack(state);
  817. return 0;
  818. }
  819. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  820. if (!lua_interface)
  821. return 0;
  822. Spawn* spawn = lua_interface->GetSpawn(state);
  823. if (spawn && spawn->IsEntity()) {
  824. int32 item_id = lua_interface->GetInt32Value(state, 2);
  825. Item* item = spawn->LootItem(item_id);
  826. lua_interface->SetLuaUserDataStale(item);
  827. safe_delete(item);
  828. }
  829. lua_interface->ResetFunctionStack(state);
  830. return 0;
  831. }
  832. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  833. if (!lua_interface)
  834. return 0;
  835. Spawn* spawn = lua_interface->GetSpawn(state);
  836. if (spawn) {
  837. int32 val = lua_interface->GetInt32Value(state, 2);
  838. spawn->AddLootCoins(val);
  839. }
  840. lua_interface->ResetFunctionStack(state);
  841. return 0;
  842. }
  843. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  844. if (!lua_interface)
  845. return 0;
  846. Spawn* entity = lua_interface->GetSpawn(state);
  847. Spawn* player = lua_interface->GetSpawn(state, 2);
  848. if (entity && player && player->IsPlayer()) {
  849. int32 coins = lua_interface->GetInt32Value(state, 3);
  850. vector<Item*>* items = 0;
  851. int i = 0;
  852. int32 item_id = 0;
  853. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  854. if (items == 0)
  855. items = new vector<Item*>;
  856. if (master_item_list.GetItem(item_id))
  857. items->push_back(master_item_list.GetItem(item_id));
  858. i++;
  859. }
  860. Client* client = 0;
  861. client = ((Player*)player)->GetClient();
  862. if (client)
  863. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  864. if(coins > 0)
  865. entity->AddLootCoins(coins);
  866. safe_delete(items);
  867. }
  868. lua_interface->ResetFunctionStack(state);
  869. return 0;
  870. }
  871. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  872. if (!lua_interface)
  873. return 0;
  874. Spawn* entity = lua_interface->GetSpawn(state);
  875. Spawn* player = lua_interface->GetSpawn(state, 2);
  876. int32 item_id = lua_interface->GetInt32Value(state, 3);
  877. lua_interface->ResetFunctionStack(state);
  878. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  879. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  880. return 1;
  881. }
  882. return 0;
  883. }
  884. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  885. if (!lua_interface)
  886. return 0;
  887. Spawn* entity = lua_interface->GetSpawn(state);
  888. Spawn* player = lua_interface->GetSpawn(state, 2);
  889. lua_interface->ResetFunctionStack(state);
  890. if (entity && player && player->IsPlayer()) {
  891. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  892. return 1;
  893. }
  894. return 0;
  895. }
  896. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  897. if (!lua_interface)
  898. return 0;
  899. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  900. lua_interface->SetLuaUserDataStale(conversation);
  901. safe_delete(conversation);
  902. lua_interface->ResetFunctionStack(state);
  903. conversation = new vector<ConversationOption>();
  904. lua_interface->SetConversationValue(state, conversation);
  905. return 1;
  906. }
  907. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  908. if (!lua_interface)
  909. return 0;
  910. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  911. if (conversation) {
  912. ConversationOption conv_option;
  913. conv_option.option = lua_interface->GetStringValue(state, 2);
  914. conv_option.function = lua_interface->GetStringValue(state, 3);
  915. if (conv_option.option.length() > 0)
  916. conversation->push_back(conv_option);
  917. }
  918. lua_interface->ResetFunctionStack(state);
  919. return 0;
  920. }
  921. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  922. if (!lua_interface)
  923. return 0;
  924. Spawn* npc = lua_interface->GetSpawn(state);
  925. Spawn* player = lua_interface->GetSpawn(state, 2);
  926. lua_interface->ResetFunctionStack(state);
  927. if (npc && player && player->IsPlayer() && player->GetZone()) {
  928. Client* client = ((Player*)player)->GetClient();
  929. if (client) {
  930. int32 conversation_id = client->GetConversationID(npc, 0);
  931. client->CloseDialog(conversation_id);
  932. }
  933. }
  934. return 0;
  935. }
  936. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  937. if (!lua_interface)
  938. return 0;
  939. Item* item = lua_interface->GetItem(state);
  940. Spawn* player = lua_interface->GetSpawn(state, 2);
  941. lua_interface->ResetFunctionStack(state);
  942. if (item && player && player->IsPlayer() && player->GetZone()) {
  943. Client* client = ((Player*)player)->GetClient();
  944. if (client) {
  945. int32 conversation_id = client->GetConversationID(0, item);
  946. client->CloseDialog(conversation_id);
  947. }
  948. }
  949. return 0;
  950. }
  951. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  952. if (!lua_interface)
  953. return 0;
  954. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  955. Spawn* spawn = 0;
  956. Item* item = 0;
  957. int8 type = lua_interface->GetInt8Value(state, 2);
  958. if (type == 1 || type == 3)
  959. spawn = lua_interface->GetSpawn(state, 3);
  960. else if (type == 2 || type == 4)
  961. item = lua_interface->GetItem(state, 3);
  962. Spawn* player = lua_interface->GetSpawn(state, 4);
  963. string text = lua_interface->GetStringValue(state, 5);
  964. string mp3 = lua_interface->GetStringValue(state, 6);
  965. int32 key1 = lua_interface->GetInt32Value(state, 7);
  966. int32 key2 = lua_interface->GetInt32Value(state, 8);
  967. int8 language = lua_interface->GetInt8Value(state, 9);
  968. int numargs = lua_interface->GetNumberOfArgs(state);
  969. int8 can_close = 1;
  970. if(numargs > 9)
  971. can_close = lua_interface->GetInt32Value(state, 10);
  972. lua_interface->ResetFunctionStack(state);
  973. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  974. Client* client = ((Player*)player)->GetClient();
  975. if (client) {
  976. if (spawn) {
  977. // Need to do this so the function works the same as it did before
  978. if (type == 1)
  979. type++;
  980. if (mp3.length() > 0)
  981. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2, language, can_close);
  982. else
  983. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), nullptr, 0, 0, language, can_close);
  984. }
  985. else {
  986. if (mp3.length() > 0)
  987. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2, language, can_close);
  988. else
  989. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, nullptr, 0, 0, language, can_close);
  990. }
  991. }
  992. }
  993. lua_interface->SetLuaUserDataStale(conversation);
  994. safe_delete(conversation);
  995. return 0;
  996. }
  997. int EQ2Emu_lua_StartConversation(lua_State* state) {
  998. if (!lua_interface)
  999. return 0;
  1000. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  1001. Spawn* source = lua_interface->GetSpawn(state, 2);
  1002. Spawn* player = lua_interface->GetSpawn(state, 3);
  1003. string text = lua_interface->GetStringValue(state, 4);
  1004. string mp3 = lua_interface->GetStringValue(state, 5);
  1005. int32 key1 = lua_interface->GetInt32Value(state, 6);
  1006. int32 key2 = lua_interface->GetInt32Value(state, 7);
  1007. int8 language = lua_interface->GetInt32Value(state, 8);
  1008. int numargs = lua_interface->GetNumberOfArgs(state);
  1009. int8 can_close = 1;
  1010. if(numargs > 8)
  1011. can_close = lua_interface->GetInt32Value(state, 9);
  1012. lua_interface->ResetFunctionStack(state);
  1013. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1014. Client* client = ((Player*)player)->GetClient();
  1015. if (mp3.length() > 0)
  1016. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2, language, can_close);
  1017. else
  1018. client->DisplayConversation(source, 1, conversation, text.c_str(), nullptr, 0, 0, language, can_close);
  1019. lua_interface->SetLuaUserDataStale(conversation);
  1020. safe_delete(conversation);
  1021. }
  1022. else
  1023. 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);
  1024. return 0;
  1025. }
  1026. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1027. if (!lua_interface)
  1028. return 0;
  1029. Spawn* spawn = lua_interface->GetSpawn(state);
  1030. float distance = lua_interface->GetFloatValue(state, 2);
  1031. string in_range_function = lua_interface->GetStringValue(state, 3);
  1032. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1033. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1034. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1035. return 0;
  1036. }
  1037. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1038. ZoneServer* zone = lua_interface->GetZone(state);
  1039. float x = lua_interface->GetFloatValue(state, 2);
  1040. float y = lua_interface->GetFloatValue(state, 3);
  1041. float z = lua_interface->GetFloatValue(state, 4);
  1042. float max_variation = lua_interface->GetFloatValue(state, 5);
  1043. string in_range_function = lua_interface->GetStringValue(state, 6);
  1044. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1045. lua_interface->ResetFunctionStack(state);
  1046. if (zone && in_range_function.length() > 0)
  1047. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1048. return 0;
  1049. }
  1050. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1051. if (!lua_interface)
  1052. return 0;
  1053. Spawn* spawn = lua_interface->GetSpawn(state);
  1054. if (spawn && spawn->IsEntity()) {
  1055. int32 val = lua_interface->GetInt32Value(state, 2);
  1056. ((Entity*)spawn)->SetLootCoins(val);
  1057. }
  1058. lua_interface->ResetFunctionStack(state);
  1059. return 0;
  1060. }
  1061. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1062. if (!lua_interface)
  1063. return 0;
  1064. Spawn* spawn = lua_interface->GetSpawn(state);
  1065. lua_interface->ResetFunctionStack(state);
  1066. if (spawn && spawn->IsEntity()) {
  1067. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1068. return 1;
  1069. }
  1070. return 0;
  1071. }
  1072. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1073. if (!lua_interface)
  1074. return 0;
  1075. Spawn* spawn = lua_interface->GetSpawn(state);
  1076. float x = lua_interface->GetFloatValue(state, 2);
  1077. float y = lua_interface->GetFloatValue(state, 3);
  1078. float z = lua_interface->GetFloatValue(state, 4);
  1079. float speed = lua_interface->GetFloatValue(state, 5);
  1080. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1081. string function = lua_interface->GetStringValue(state, 7);
  1082. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1083. float heading = lua_interface->GetFloatValue(state, 8);
  1084. if (spawn) {
  1085. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1086. spawn->GetZone()->AddMovementNPC(spawn);
  1087. }
  1088. lua_interface->ResetFunctionStack(state);
  1089. return 0;
  1090. }
  1091. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1092. if (!lua_interface)
  1093. return 0;
  1094. Spawn* spawn = lua_interface->GetSpawn(state);
  1095. lua_interface->ResetFunctionStack(state);
  1096. if (spawn) {
  1097. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1098. return 1;
  1099. }
  1100. return 0;
  1101. }
  1102. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1103. if (!lua_interface)
  1104. return 0;
  1105. Spawn* spawn = lua_interface->GetSpawn(state);
  1106. lua_interface->ResetFunctionStack(state);
  1107. if (spawn && spawn->IsPlayer()) {
  1108. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1109. return 1;
  1110. }
  1111. lua_interface->SetInt32Value(state, 0);
  1112. return 1;
  1113. }
  1114. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1115. if (!lua_interface)
  1116. return 0;
  1117. Spawn* spawn = lua_interface->GetSpawn(state);
  1118. Spawn* target = lua_interface->GetSpawn(state, 2);
  1119. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1120. bool reset_action_state = true;
  1121. if(num_args > 2)
  1122. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1123. if (spawn && target) {
  1124. if (spawn->IsEntity())
  1125. // ((Entity*)spawn)->FaceTarget(target);
  1126. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1127. }
  1128. lua_interface->ResetFunctionStack(state);
  1129. return 0;
  1130. }
  1131. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1132. if (!lua_interface)
  1133. return 0;
  1134. Spawn* spawn = lua_interface->GetSpawn(state);
  1135. float x = lua_interface->GetFloatValue(state, 2);
  1136. float y = lua_interface->GetFloatValue(state, 3);
  1137. float z = lua_interface->GetFloatValue(state, 4);
  1138. float speed = lua_interface->GetFloatValue(state, 5);
  1139. string lua_function = lua_interface->GetStringValue(state, 6);
  1140. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1141. if (spawn) {
  1142. if (speed == 0)
  1143. speed = spawn->GetSpeed();
  1144. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1145. }
  1146. lua_interface->ResetFunctionStack(state);
  1147. return 0;
  1148. }
  1149. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1150. if (!lua_interface)
  1151. return 0;
  1152. Spawn* spawn = lua_interface->GetSpawn(state);
  1153. lua_interface->ResetFunctionStack(state);
  1154. if (spawn) {
  1155. spawn->ClearRunningLocations();
  1156. }
  1157. return 0;
  1158. }
  1159. int EQ2Emu_lua_Say(lua_State* state) {
  1160. if (!lua_interface)
  1161. return 0;
  1162. Spawn* spawn = lua_interface->GetSpawn(state);
  1163. string message = lua_interface->GetStringValue(state, 2);
  1164. Spawn* player = lua_interface->GetSpawn(state, 3);
  1165. float dist = lua_interface->GetFloatValue(state, 4);
  1166. int32 language = lua_interface->GetInt32Value(state, 5);
  1167. if (spawn && message.length() > 0) {
  1168. Client* client = 0;
  1169. if (player && player->IsPlayer())
  1170. client = ((Player*)player)->GetClient();
  1171. if (client)
  1172. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1173. else
  1174. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1175. }
  1176. lua_interface->ResetFunctionStack(state);
  1177. return 0;
  1178. }
  1179. int EQ2Emu_lua_Shout(lua_State* state) {
  1180. if (!lua_interface)
  1181. return 0;
  1182. Spawn* spawn = lua_interface->GetSpawn(state);
  1183. string message = lua_interface->GetStringValue(state, 2);
  1184. Spawn* player = lua_interface->GetSpawn(state, 3);
  1185. float dist = lua_interface->GetFloatValue(state, 4);
  1186. int32 language = lua_interface->GetInt32Value(state, 5);
  1187. if (spawn && message.length() > 0) {
  1188. Client* client = 0;
  1189. if (player && player->IsPlayer())
  1190. client = ((Player*)player)->GetClient();
  1191. if (client)
  1192. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1193. else
  1194. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1195. }
  1196. lua_interface->ResetFunctionStack(state);
  1197. return 0;
  1198. }
  1199. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1200. if (!lua_interface)
  1201. return 0;
  1202. Spawn* spawn = lua_interface->GetSpawn(state);
  1203. string message = lua_interface->GetStringValue(state, 2);
  1204. Spawn* player = lua_interface->GetSpawn(state, 3);
  1205. float dist = lua_interface->GetFloatValue(state, 4);
  1206. int32 language = lua_interface->GetInt32Value(state, 5);
  1207. if (spawn && message.length() > 0) {
  1208. Client* client = 0;
  1209. if (player && player->IsPlayer())
  1210. client = ((Player*)player)->GetClient();
  1211. if (client)
  1212. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1213. else
  1214. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1215. }
  1216. lua_interface->ResetFunctionStack(state);
  1217. return 0;
  1218. }
  1219. int EQ2Emu_lua_Emote(lua_State* state) {
  1220. if (!lua_interface)
  1221. return 0;
  1222. Spawn* spawn = lua_interface->GetSpawn(state);
  1223. string message = lua_interface->GetStringValue(state, 2);
  1224. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1225. Spawn* player = lua_interface->GetSpawn(state, 4);
  1226. char* to = 0;
  1227. if (spawn2)
  1228. to = spawn2->GetName();
  1229. if (spawn && message.length() > 0) {
  1230. Client* client = 0;
  1231. if (player && player->IsPlayer())
  1232. client = ((Player*)player)->GetClient();
  1233. if (client)
  1234. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1235. else
  1236. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1237. }
  1238. lua_interface->ResetFunctionStack(state);
  1239. return 0;
  1240. }
  1241. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1242. if (!lua_interface)
  1243. return 0;
  1244. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1245. if(!luaspell || luaspell->resisted) {
  1246. lua_interface->ResetFunctionStack(state);
  1247. return 0;
  1248. }
  1249. Spawn* caster = luaspell->caster;
  1250. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1251. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1252. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1253. Spawn* target = lua_interface->GetSpawn(state, 4);
  1254. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1255. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1256. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1257. lua_interface->ResetFunctionStack(state);
  1258. boost::to_lower(heal_type);
  1259. if (caster && caster->IsEntity()) {
  1260. bool success = false;
  1261. luaspell->resisted = false;
  1262. if (target) {
  1263. float distance = caster->GetDistance(target, true);
  1264. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1265. success = true;
  1266. }
  1267. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1268. Spawn* target = 0;
  1269. ZoneServer* zone = luaspell->caster->GetZone();
  1270. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1271. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1272. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1273. float distance = caster->GetDistance(target, true);
  1274. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1275. }
  1276. }
  1277. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1278. success = true;
  1279. }
  1280. if (success) {
  1281. if (caster->GetZone())
  1282. caster->GetZone()->TriggerCharSheetTimer();
  1283. }
  1284. }
  1285. return 0;
  1286. }
  1287. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1288. if (!lua_interface)
  1289. return 0;
  1290. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1291. if(!luaspell || luaspell->resisted) {
  1292. lua_interface->ResetFunctionStack(state);
  1293. return 0;
  1294. }
  1295. Spawn* caster = luaspell->caster;
  1296. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1297. float percentage = lua_interface->GetFloatValue(state, 2);
  1298. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1299. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1300. Spawn* target = lua_interface->GetSpawn(state, 5);
  1301. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1302. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1303. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1304. lua_interface->ResetFunctionStack(state);
  1305. boost::to_lower(heal_type);
  1306. int32 min_heal = 0, max_heal = 0;
  1307. if (caster && caster->IsEntity() && target) {
  1308. if(percentage <= 0.0f)
  1309. {
  1310. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1311. return 0;
  1312. }
  1313. if(heal_type == "power")
  1314. {
  1315. if(current_value)
  1316. {
  1317. if(caster_value)
  1318. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1319. else
  1320. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1321. }
  1322. else
  1323. {
  1324. if(caster_value)
  1325. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1326. else
  1327. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1328. }
  1329. }
  1330. else
  1331. {
  1332. if(current_value)
  1333. {
  1334. if(caster_value)
  1335. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1336. else
  1337. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1338. }
  1339. else
  1340. {
  1341. if(caster_value)
  1342. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1343. else
  1344. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1345. }
  1346. }
  1347. bool success = false;
  1348. luaspell->resisted = false;
  1349. if (target) {
  1350. float distance = caster->GetDistance(target, true);
  1351. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1352. success = true;
  1353. }
  1354. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1355. Spawn* target = 0;
  1356. ZoneServer* zone = luaspell->caster->GetZone();
  1357. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1358. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1359. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1360. float distance = caster->GetDistance(target, true);
  1361. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1362. }
  1363. }
  1364. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1365. success = true;
  1366. }
  1367. if (success) {
  1368. if (caster->GetZone())
  1369. caster->GetZone()->TriggerCharSheetTimer();
  1370. }
  1371. }
  1372. return 0;
  1373. }
  1374. int EQ2Emu_lua_AddItem(lua_State* state) {
  1375. if (!lua_interface)
  1376. return 0;
  1377. Spawn* spawn = lua_interface->GetSpawn(state);
  1378. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1379. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1380. lua_interface->ResetFunctionStack(state);
  1381. // default of 1 quantity to add
  1382. if (quantity == 0)
  1383. quantity = 1;
  1384. if (spawn && spawn->IsPlayer()) {
  1385. Client* client = ((Player*)spawn)->GetClient();
  1386. if (client && item_id > 0) {
  1387. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1388. return 1;
  1389. }
  1390. }
  1391. lua_interface->SetBooleanValue(state, false);
  1392. return 1;
  1393. }
  1394. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1395. if (!lua_interface)
  1396. return 0;
  1397. Spawn* spawn = lua_interface->GetSpawn(state);
  1398. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1399. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1400. string location = lua_interface->GetStringValue(state, 4);
  1401. int16 item_count = lua_interface->GetInt16Value(state,5);
  1402. //devn00b: if we dont have a count, assume 1 item.
  1403. if(!item_count) {
  1404. item_count = 1;
  1405. }
  1406. lua_interface->ResetFunctionStack(state);
  1407. if (spawn && spawn->IsPlayer()) {
  1408. Client* client = ((Player*)spawn)->GetClient();
  1409. if (client && item_id > 0) {
  1410. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1411. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1412. else
  1413. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1414. if (send_messages) {
  1415. Item* item = master_item_list.GetItem(item_id);
  1416. if (item) {
  1417. if(item_count > 1) {
  1418. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1419. string popup_text1 = "You receive "+ item_count;
  1420. string popup_text2 = " " + item->name;
  1421. string popup_text = popup_text1 + popup_text2;
  1422. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1423. // return 1;
  1424. } else {
  1425. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1426. string popup_text = "You receive " + item->name;
  1427. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1428. }
  1429. }
  1430. }
  1431. return 1;
  1432. }
  1433. }
  1434. lua_interface->SetBooleanValue(state, false);
  1435. return 1;
  1436. }
  1437. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1438. Spawn* spawn = lua_interface->GetSpawn(state);
  1439. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1440. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1441. lua_interface->ResetFunctionStack(state);
  1442. // default of 1 to remove
  1443. if (quantity == 0)
  1444. quantity = 1;
  1445. Client* client;
  1446. Item* item;
  1447. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1448. if ((client = ((Player*)spawn)->GetClient())) {
  1449. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1450. if (client->RemoveItem(item, quantity)) {
  1451. lua_interface->SetBooleanValue(state, true);
  1452. return 1;
  1453. }
  1454. }
  1455. }
  1456. }
  1457. lua_interface->SetBooleanValue(state, false);
  1458. return 1;
  1459. }
  1460. int EQ2Emu_lua_HasItem(lua_State* state) {
  1461. Spawn* player = lua_interface->GetSpawn(state);
  1462. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1463. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1464. lua_interface->ResetFunctionStack(state);
  1465. if (player && player->IsPlayer()) {
  1466. bool hasItem = false;
  1467. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1468. if (!hasItem)
  1469. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1470. lua_interface->SetBooleanValue(state, hasItem);
  1471. return 1;
  1472. }
  1473. lua_interface->SetBooleanValue(state, false);
  1474. return 1;
  1475. }
  1476. int EQ2Emu_lua_Spawn(lua_State* state) {
  1477. if (!lua_interface)
  1478. return 0;
  1479. ZoneServer* zone = lua_interface->GetZone(state);
  1480. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1481. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1482. float x = lua_interface->GetFloatValue(state, 4);
  1483. float y = lua_interface->GetFloatValue(state, 5);
  1484. float z = lua_interface->GetFloatValue(state, 6);
  1485. float heading = lua_interface->GetFloatValue(state, 7);
  1486. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1487. Spawn* spawn = zone->GetSpawn(spawn_id);
  1488. if (!spawn)
  1489. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1490. else {
  1491. spawn->SetX(x);
  1492. spawn->SetZ(z);
  1493. spawn->SetY(y,true,true);
  1494. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1495. spawn->SetHeading(heading);
  1496. if (restricted_npc)
  1497. spawn->AddAllowAccessSpawn(spawn);
  1498. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1499. bool scriptActive = false;
  1500. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1501. scriptActive = true;
  1502. spawn->SetSpawnScript(string(spawn_script));
  1503. }
  1504. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1505. zone->AddSpawn(spawn);
  1506. if (scriptActive) {
  1507. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1508. }
  1509. lua_interface->ResetFunctionStack(state);
  1510. lua_interface->SetSpawnValue(state, spawn);
  1511. return 1;
  1512. }
  1513. }
  1514. else {
  1515. string output = "Invalid paramaters to LUA Spawn command: \n";
  1516. if (!zone)
  1517. output = output.append("\t").append("Missing zone reference. \n");
  1518. if (spawn_id == 0)
  1519. output = output.append("\t").append("Missing spawn_id.");
  1520. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1521. }
  1522. lua_interface->ResetFunctionStack(state);
  1523. return 0;
  1524. }
  1525. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1526. if (!lua_interface)
  1527. return 0;
  1528. ZoneServer* zone = lua_interface->GetZone(state);
  1529. lua_interface->ResetFunctionStack(state);
  1530. if (zone) {
  1531. lua_interface->SetStringValue(state, zone->GetZoneName());
  1532. return 1;
  1533. }
  1534. return 0;
  1535. }
  1536. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1537. if (!lua_interface)
  1538. return 0;
  1539. ZoneServer* zone = lua_interface->GetZone(state);
  1540. lua_interface->ResetFunctionStack(state);
  1541. if (zone) {
  1542. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1543. return 1;
  1544. }
  1545. return 0;
  1546. }
  1547. int EQ2Emu_lua_GetZone(lua_State* state) {
  1548. if (!lua_interface)
  1549. return 0;
  1550. int32 zone_id = lua_interface->GetInt32Value(state);
  1551. ZoneServer* zone = 0;
  1552. if (zone_id > 0)
  1553. zone = zone_list.Get(zone_id);
  1554. else {
  1555. string zone_name = lua_interface->GetStringValue(state);
  1556. if (zone_name.length() > 0) {
  1557. zone = zone_list.Get(zone_name.c_str());
  1558. }
  1559. else {
  1560. Spawn* spawn = lua_interface->GetSpawn(state);
  1561. if (spawn)
  1562. zone = spawn->GetZone();
  1563. }
  1564. }
  1565. lua_interface->ResetFunctionStack(state);
  1566. if (zone) {
  1567. lua_interface->SetZoneValue(state, zone);
  1568. return 1;
  1569. }
  1570. return 0;
  1571. }
  1572. int EQ2Emu_lua_AddHate(lua_State* state) {
  1573. Spawn* entity = lua_interface->GetSpawn(state);
  1574. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1575. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1576. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1577. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1578. if(luaspell && luaspell->resisted) {
  1579. lua_interface->ResetFunctionStack(state);
  1580. return 0;
  1581. }
  1582. if (entity && entity->IsEntity() && amount != 0) {
  1583. if (luaspell) {
  1584. ZoneServer* zone = luaspell->caster->GetZone();
  1585. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1586. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1587. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1588. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1589. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1590. if (send_packet)
  1591. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1592. }
  1593. }
  1594. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1595. }
  1596. else if (npc && npc->IsNPC() && npc->GetZone())
  1597. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1598. }
  1599. lua_interface->ResetFunctionStack(state);
  1600. return 0;
  1601. }
  1602. int EQ2Emu_lua_Zone(lua_State* state) {
  1603. if (!lua_interface)
  1604. return 0;
  1605. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1606. ZoneServer* zone = lua_interface->GetZone(state);
  1607. Spawn* player = lua_interface->GetSpawn(state, 2);
  1608. Client* client = 0;
  1609. if (player && player->IsPlayer())
  1610. client = ((Player*)player)->GetClient();
  1611. float x = lua_interface->GetFloatValue(state, 3);
  1612. float y = lua_interface->GetFloatValue(state, 4);
  1613. float z = lua_interface->GetFloatValue(state, 5);
  1614. float heading = lua_interface->GetFloatValue(state, 6);
  1615. if (zone && client) {
  1616. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1617. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1618. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1619. {
  1620. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1621. return 0;
  1622. }
  1623. if (x != 0 || y != 0 || z != 0) {
  1624. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1625. player->SetX(x);
  1626. player->SetY(y);
  1627. player->SetZ(z);
  1628. player->SetHeading(heading);
  1629. client->Zone(zone->GetZoneName(), false);
  1630. }
  1631. else
  1632. client->Zone(zone->GetZoneName());
  1633. }
  1634. else
  1635. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1636. lua_interface->ResetFunctionStack(state);
  1637. return 0;
  1638. }
  1639. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1640. if (!lua_interface)
  1641. return 0;
  1642. Spawn* spawn = lua_interface->GetSpawn(state);
  1643. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1644. if (spawn && spawn2)
  1645. spawn->AddAllowAccessSpawn(spawn2);
  1646. lua_interface->ResetFunctionStack(state);
  1647. return 0;
  1648. }
  1649. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1650. if (!lua_interface)
  1651. return 0;
  1652. Spawn* target = lua_interface->GetSpawn(state);
  1653. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1654. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1655. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1656. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1657. lua_interface->ResetFunctionStack(state);
  1658. if (!target) {
  1659. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1660. return 0;
  1661. }
  1662. if (!target->IsEntity()) {
  1663. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1664. return 0;
  1665. }
  1666. if (spell_id <= 0) {
  1667. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1668. return 0;
  1669. }
  1670. if (caster && !caster->IsEntity()) {
  1671. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1672. return 0;
  1673. }
  1674. if (spell_tier == 0)
  1675. spell_tier = 1;
  1676. if (!caster)
  1677. caster = target;
  1678. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1679. return 0;
  1680. }
  1681. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1682. if (!lua_interface)
  1683. return 0;
  1684. Spawn* target = lua_interface->GetSpawn(state);
  1685. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1686. if(!luaspell || luaspell->resisted) {
  1687. lua_interface->ResetFunctionStack(state);
  1688. return 0;
  1689. }
  1690. Spawn* caster = luaspell->caster;
  1691. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1692. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1693. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1694. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1695. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1696. //lua_interface->ResetFunctionStack(state);
  1697. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1698. vector<int16> faction_req;
  1699. vector<int16> race_req;
  1700. int32 class_req = 0;
  1701. int32 i = 0;
  1702. int8 f = 0;
  1703. int8 r = 0;
  1704. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1705. if (class_id < 100) {
  1706. class_req += pow(2.0, double(class_id - 1));
  1707. }
  1708. else if (class_id > 100 && class_id < 1000) {
  1709. race_req.push_back(class_id);
  1710. r++;
  1711. }
  1712. else {
  1713. faction_req.push_back(class_id);
  1714. f++;
  1715. }
  1716. i++;
  1717. }
  1718. lua_interface->ResetFunctionStack(state);
  1719. if (caster && caster->IsEntity()) {
  1720. bool race_match = false;
  1721. bool success = false;
  1722. luaspell->resisted = false;
  1723. if (luaspell->targets.size() > 0) {
  1724. ZoneServer* zone = luaspell->caster->GetZone();
  1725. Spawn* target = 0;
  1726. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1727. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1728. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1729. if (race_req.size() > 0) {
  1730. for (int8 i = 0; i < race_req.size(); i++) {
  1731. if(race_req[i] == target->GetRace() ||
  1732. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1733. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1734. race_match = true;
  1735. }
  1736. }
  1737. }
  1738. else
  1739. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1740. if (race_match == true) {
  1741. float distance = caster->GetDistance(target, true);
  1742. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1743. }
  1744. }
  1745. }
  1746. success = true;
  1747. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1748. }
  1749. else if (target) {
  1750. //check class and race/faction here
  1751. if (race_req.size() > 0) {
  1752. for (int8 i = 0; i < race_req.size(); i++) {
  1753. if(race_req[i] == target->GetRace() ||
  1754. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1755. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1756. race_match = true;
  1757. }
  1758. }
  1759. }
  1760. else
  1761. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1762. if (race_match == true) {
  1763. float distance = caster->GetDistance(target, true);
  1764. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1765. success = true;
  1766. }
  1767. }
  1768. if (success) {
  1769. Spell* spell = luaspell->spell;
  1770. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1771. ((Player*)caster)->InCombat(true);
  1772. if (caster->GetZone())
  1773. caster->GetZone()->TriggerCharSheetTimer();
  1774. }
  1775. }
  1776. }
  1777. return 0;
  1778. }
  1779. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1780. if (!lua_interface)
  1781. return 0;
  1782. Spawn* spawn = lua_interface->GetSpawn(state);
  1783. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1784. lua_interface->ResetFunctionStack(state);
  1785. if (spawn && value != 0) {
  1786. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1787. spawn->SetPower(spawn->GetTotalPower());
  1788. else
  1789. spawn->SetPower(spawn->GetPower() + value);
  1790. }
  1791. return 0;
  1792. }
  1793. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1794. if (!lua_interface)
  1795. return 0;
  1796. Spawn* spawn = lua_interface->GetSpawn(state);
  1797. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1798. lua_interface->ResetFunctionStack(state);
  1799. if (spawn && value != 0) {
  1800. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1801. spawn->SetHP(spawn->GetTotalHP());
  1802. else
  1803. spawn->SetHP(spawn->GetHP() + value);
  1804. }
  1805. return 0;
  1806. }
  1807. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1808. if (!lua_interface)
  1809. return 0;
  1810. Spawn* spawn = lua_interface->GetSpawn(state);
  1811. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1812. lua_interface->ResetFunctionStack(state);
  1813. if (spawn && value != 0) {
  1814. spawn->SetPower(spawn->GetPower() + value);
  1815. if (value > spawn->GetTotalHPBase())
  1816. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1817. }
  1818. return 0;
  1819. }
  1820. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1821. if (!lua_interface)
  1822. return 0;
  1823. Spawn* spawn = lua_interface->GetSpawn(state);
  1824. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1825. lua_interface->ResetFunctionStack(state);
  1826. if (spawn && value != 0) {
  1827. spawn->SetHP(spawn->GetHP() + value);
  1828. if (value > spawn->GetTotalHPBase())
  1829. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1830. }
  1831. return 0;
  1832. }
  1833. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1834. if (!lua_interface)
  1835. return 0;
  1836. Spawn* spawn = lua_interface->GetSpawn(state);
  1837. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1838. lua_interface->ResetFunctionStack(state);
  1839. if (spawn) {
  1840. spawn->SetHP(value);
  1841. if (value > spawn->GetTotalHPBase())
  1842. spawn->SetTotalHP(value);
  1843. }
  1844. return 0;
  1845. }
  1846. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1847. if (!lua_interface)
  1848. return 0;
  1849. Spawn* spawn = lua_interface->GetSpawn(state);
  1850. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1851. float value = lua_interface->GetFloatValue(state, 2);
  1852. lua_interface->ResetFunctionStack(state);
  1853. if (spawn && spawn->IsEntity() && value > 0)
  1854. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1855. if (spawn && spawn->IsPlayer())
  1856. ((Player*)spawn)->SetCharSheetChanged(true);
  1857. return 0;
  1858. }
  1859. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1860. if (!lua_interface)
  1861. return 0;
  1862. Spawn* spawn = lua_interface->GetSpawn(state);
  1863. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1864. lua_interface->ResetFunctionStack(state);
  1865. if (spawn && spawn->IsEntity() && value > 0)
  1866. ((Entity*)spawn)->SetTotalHPBase(value);
  1867. return 0;
  1868. }
  1869. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1870. if (!lua_interface)
  1871. return 0;
  1872. Spawn* spawn = lua_interface->GetSpawn(state);
  1873. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1874. lua_interface->ResetFunctionStack(state);
  1875. if (spawn && value > 0) {
  1876. spawn->SetPower(value);
  1877. if (value > spawn->GetTotalPowerBase())
  1878. spawn->SetTotalPower(value);
  1879. }
  1880. return 0;
  1881. }
  1882. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1883. if (!lua_interface)
  1884. return 0;
  1885. Spawn* spawn = lua_interface->GetSpawn(state);
  1886. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1887. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1888. lua_interface->ResetFunctionStack(state);
  1889. if (spawn && spawn->IsEntity() && value > 0)
  1890. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1891. return 0;
  1892. }
  1893. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1894. if (!lua_interface)
  1895. return 0;
  1896. Spawn* spawn = lua_interface->GetSpawn(state);
  1897. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1898. lua_interface->ResetFunctionStack(state);
  1899. if (spawn && spawn->IsEntity() && value > 0)
  1900. ((Entity*)spawn)->SetTotalPowerBase(value);
  1901. return 0;
  1902. }
  1903. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1904. if (!lua_interface)
  1905. return 0;
  1906. Spawn* spawn = lua_interface->GetSpawn(state);
  1907. float x = lua_interface->GetFloatValue(state, 2);
  1908. float y = lua_interface->GetFloatValue(state, 3);
  1909. float z = lua_interface->GetFloatValue(state, 4);
  1910. float heading = lua_interface->GetFloatValue(state, 5);
  1911. lua_interface->ResetFunctionStack(state);
  1912. if (spawn) {
  1913. spawn->SetX(x);
  1914. spawn->SetY(y);
  1915. spawn->SetZ(z);
  1916. if (heading != 0)
  1917. spawn->SetHeading(heading);
  1918. spawn->SetSpawnOrigX(spawn->GetX());
  1919. spawn->SetSpawnOrigY(spawn->GetY());
  1920. spawn->SetSpawnOrigZ(spawn->GetZ());
  1921. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1922. if (spawn->IsPlayer()) {
  1923. Client* client = ((Player*)spawn)->GetClient();
  1924. if (client) {
  1925. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1926. client->QueuePacket(packet);
  1927. }
  1928. }
  1929. }
  1930. return 0;
  1931. }
  1932. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1933. if (!lua_interface)
  1934. return 0;
  1935. Spawn* spawn = lua_interface->GetSpawn(state);
  1936. float value = lua_interface->GetFloatValue(state, 2);
  1937. lua_interface->ResetFunctionStack(state);
  1938. if (spawn) {
  1939. spawn->SetHeading(value);
  1940. if (spawn->IsPlayer()) {
  1941. Client* client = ((Player*)spawn)->GetClient();
  1942. if (client) {
  1943. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1944. client->QueuePacket(packet);
  1945. }
  1946. }
  1947. }
  1948. return 0;
  1949. }
  1950. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1951. if (!lua_interface)
  1952. return 0;
  1953. Spawn* spawn = lua_interface->GetSpawn(state);
  1954. int16 value = lua_interface->GetInt16Value(state, 2);
  1955. lua_interface->ResetFunctionStack(state);
  1956. if (spawn)
  1957. spawn->SetModelType(value);
  1958. return 0;
  1959. }
  1960. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1961. if (!lua_interface)
  1962. return 0;
  1963. Spawn* spawn = lua_interface->GetSpawn(state);
  1964. int8 value = lua_interface->GetInt8Value(state, 2);
  1965. lua_interface->ResetFunctionStack(state);
  1966. if (spawn) {
  1967. if (spawn->IsPlayer())
  1968. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1969. else
  1970. spawn->SetAdventureClass(value);
  1971. }
  1972. return 0;
  1973. }
  1974. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1975. if (!lua_interface)
  1976. return 0;
  1977. Spawn* spawn = lua_interface->GetSpawn(state);
  1978. int8 value = lua_interface->GetInt8Value(state, 2);
  1979. lua_interface->ResetFunctionStack(state);
  1980. if (spawn) {
  1981. spawn->SetTradeskillClass(value);
  1982. if (spawn->IsEntity()) {
  1983. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1984. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1985. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1986. }
  1987. if (spawn->IsPlayer())
  1988. ((Player*)spawn)->SetCharSheetChanged(true);
  1989. }
  1990. return 0;
  1991. }
  1992. int EQ2Emu_lua_SetMount(lua_State* state) {
  1993. if (!lua_interface)
  1994. return 0;
  1995. Spawn* spawn = lua_interface->GetSpawn(state);
  1996. int16 value = lua_interface->GetInt16Value(state, 2);
  1997. if (spawn && spawn->IsEntity()) {
  1998. ((Entity*)spawn)->SetMount(value);
  1999. EQ2_Color color;
  2000. color.red = 255;
  2001. color.green = 255;
  2002. color.blue = 255;
  2003. ((Entity*)spawn)->SetMountColor(&color);
  2004. ((Entity*)spawn)->SetMountSaddleColor(&color);
  2005. }
  2006. return 0;
  2007. }
  2008. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  2009. if (!lua_interface)
  2010. return 0;
  2011. Spawn* spawn = lua_interface->GetSpawn(state);
  2012. EQ2_Color mount_color;
  2013. EQ2_Color saddle_color;
  2014. mount_color.red = lua_interface->GetInt8Value(state, 2);
  2015. mount_color.green = lua_interface->GetInt8Value(state, 3);
  2016. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  2017. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  2018. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  2019. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  2020. if (spawn && spawn->IsEntity()) {
  2021. ((Entity*)spawn)->SetMountColor(&mount_color);
  2022. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  2023. }
  2024. return 0;
  2025. }
  2026. int EQ2Emu_lua_GetMount(lua_State* state) {
  2027. if (!lua_interface)
  2028. return 0;
  2029. Spawn* spawn = lua_interface->GetSpawn(state);
  2030. if (spawn && spawn->IsEntity()) {
  2031. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2032. return 1;
  2033. }
  2034. return 0;
  2035. }
  2036. int EQ2Emu_lua_GetRace(lua_State* state) {
  2037. if (!lua_interface)
  2038. return 0;
  2039. Spawn* spawn = lua_interface->GetSpawn(state);
  2040. if (spawn)
  2041. {
  2042. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2043. lua_interface->SetInt32Value(state, spawn->GetRace());
  2044. return 1;
  2045. }
  2046. return 0;
  2047. }
  2048. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2049. if (!lua_interface)
  2050. return 0;
  2051. Spawn* spawn = lua_interface->GetSpawn(state);
  2052. if (spawn) {
  2053. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2054. return 1;
  2055. }
  2056. return 0;
  2057. }
  2058. int EQ2Emu_lua_GetClass(lua_State* state) {
  2059. Spawn* spawn = lua_interface->GetSpawn(state);
  2060. if (spawn) {
  2061. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2062. return 1;
  2063. }
  2064. return 0;
  2065. }
  2066. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2067. Spawn* spawn = lua_interface->GetSpawn(state);
  2068. if (spawn) {
  2069. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2070. return 1;
  2071. }
  2072. return 0;
  2073. }
  2074. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2075. if (!lua_interface)
  2076. return 0;
  2077. Spawn* spawn = lua_interface->GetSpawn(state);
  2078. float value = lua_interface->GetFloatValue(state, 2);
  2079. lua_interface->ResetFunctionStack(state);
  2080. if (spawn) {
  2081. spawn->SetSpeed(value);
  2082. if(spawn->IsEntity())
  2083. ((Entity*)spawn)->SetSpeed(value);
  2084. if (spawn->IsPlayer()) {
  2085. Client* client = ((Player*)spawn)->GetClient();
  2086. if (client) {
  2087. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2088. if (packet) {
  2089. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2090. packet->setDataByName("speed", value);
  2091. packet->setDataByName("size", 0.51);
  2092. EQ2Packet* app = packet->serialize();
  2093. client->QueuePacket(app);
  2094. safe_delete(packet);
  2095. }
  2096. }
  2097. }
  2098. }
  2099. return 0;
  2100. }
  2101. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2102. if (!lua_interface)
  2103. return 0;
  2104. Spawn* spawn = lua_interface->GetSpawn(state);
  2105. const int16 type = lua_interface->GetInt16Value(state, 2);
  2106. const float value = lua_interface->GetFloatValue(state, 3);
  2107. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2108. if(!luaspell || luaspell->resisted) {
  2109. lua_interface->ResetFunctionStack(state);
  2110. return 0;
  2111. }
  2112. int64 class_req = 0;
  2113. int32 class_id = 0;
  2114. vector<int16> faction_req;
  2115. vector<int16> race_req;
  2116. int32 i = 0;
  2117. int8 f = 0;
  2118. int8 r = 0;
  2119. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2120. if (class_id < 100) {
  2121. class_req += pow(2.0, double(class_id - 1));
  2122. }
  2123. else if (class_id > 100 && class_id < 1000) {
  2124. race_req.push_back(class_id);
  2125. r++;
  2126. }
  2127. else {
  2128. faction_req.push_back(class_id);
  2129. f++;
  2130. }
  2131. i++;
  2132. }
  2133. if (value != 0 && type >= 0) {
  2134. if (luaspell && luaspell->spell && luaspell->caster) {
  2135. ZoneServer* zone = luaspell->caster->GetZone();
  2136. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2137. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2138. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2139. if (target) {
  2140. if (target->IsPlayer()) {
  2141. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2142. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2143. if (((Player*)target)->GetGroupMemberInfo())
  2144. ((Player*)target)->UpdateGroupMemberInfo();
  2145. ((Player*)target)->SetCharSheetChanged(true);
  2146. }
  2147. else if (target->IsNPC())
  2148. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2149. else
  2150. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2151. }
  2152. }
  2153. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2154. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2155. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2156. }
  2157. else if (spawn && spawn->IsEntity()) {
  2158. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2159. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2160. if (spawn->IsPlayer())
  2161. ((Player*)spawn)->SetCharSheetChanged(true);
  2162. }
  2163. else
  2164. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2165. }
  2166. else
  2167. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2168. return 0;
  2169. }
  2170. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2171. if (!lua_interface)
  2172. return 0;
  2173. Spawn* spawn = lua_interface->GetSpawn(state);
  2174. int16 type = lua_interface->GetInt16Value(state, 2);
  2175. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2176. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2177. if (!spawn) {
  2178. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2179. return 0;
  2180. }
  2181. if (!spawn->IsEntity()) {
  2182. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2183. return 0;
  2184. }
  2185. if (value == 0) {
  2186. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2187. return 0;
  2188. }
  2189. if (!luaspell || !luaspell->spell) {
  2190. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2191. return 0;
  2192. }
  2193. if(luaspell->resisted) {
  2194. lua_interface->ResetFunctionStack(state);
  2195. return 0;
  2196. }
  2197. int32 class_req = 0;
  2198. vector<int16> faction_req;
  2199. vector<int16> race_req;
  2200. int32 class_id = 0;
  2201. int32 i = 0;
  2202. int8 f = 0;
  2203. int8 r = 0;
  2204. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2205. if (class_id < 100) {
  2206. class_req += pow(2.0, double(class_id - 1));
  2207. }
  2208. else if (class_id > 100 && class_id < 1000) {
  2209. race_req.push_back(class_id);
  2210. r++;
  2211. }
  2212. else {
  2213. faction_req.push_back(class_id);
  2214. f++;
  2215. }
  2216. i++;
  2217. }
  2218. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2219. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2220. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2221. if (spawn->IsPlayer())
  2222. ((Player*)spawn)->SetCharSheetChanged(true);
  2223. return 0;
  2224. }
  2225. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2226. if (!lua_interface)
  2227. return 0;
  2228. Spawn* spawn = lua_interface->GetSpawn(state);
  2229. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2230. if (!spawn) {
  2231. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2232. return 0;
  2233. }
  2234. if (!spawn->IsEntity()) {
  2235. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2236. return 0;
  2237. }
  2238. if (!luaspell || !luaspell->spell) {
  2239. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2240. return 0;
  2241. }
  2242. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2243. if (spawn->IsPlayer())
  2244. ((Player*)spawn)->SetCharSheetChanged(true);
  2245. return 0;
  2246. }
  2247. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2248. if (!lua_interface)
  2249. return 0;
  2250. Spawn* spawn = lua_interface->GetSpawn(state);
  2251. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2252. if (luaspell && luaspell->spell) {
  2253. ZoneServer* zone = luaspell->caster->GetZone();
  2254. Spawn* target = 0;
  2255. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2256. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2257. target = zone->GetSpawnByID(luaspell->targets[i]);
  2258. if (target && target->IsEntity()) {
  2259. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2260. if (target->IsPlayer())
  2261. ((Player*)target)->SetCharSheetChanged(true);
  2262. }
  2263. }
  2264. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2265. }
  2266. else if (spawn && spawn->IsEntity()) {
  2267. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2268. if (spawn->IsPlayer())
  2269. ((Player*)spawn)->SetCharSheetChanged(true);
  2270. }
  2271. return 0;
  2272. }
  2273. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2274. if (!lua_interface)
  2275. return 0;
  2276. Spawn* spawn = lua_interface->GetSpawn(state);
  2277. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2278. float value = lua_interface->GetFloatValue(state, 3);
  2279. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2280. if (value != 0) {
  2281. int32 spell_id = 0;
  2282. if (luaspell && luaspell->spell && luaspell->caster) {
  2283. if(luaspell->resisted) {
  2284. lua_interface->ResetFunctionStack(state);
  2285. return 0;
  2286. }
  2287. spell_id = luaspell->spell->GetSpellID();
  2288. ZoneServer* zone = luaspell->caster->GetZone();
  2289. Spawn* target = 0;
  2290. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2291. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2292. target = zone->GetSpawnByID(luaspell->targets[i]);
  2293. if (target && target->Alive()) {
  2294. if (target->IsPlayer()) {
  2295. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2296. Client* client = ((Player*)target)->GetClient();
  2297. if (client) {
  2298. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2299. if (packet)
  2300. client->QueuePacket(packet);
  2301. }
  2302. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2303. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2304. }
  2305. else if (target->IsNPC()) {
  2306. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2307. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2308. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2309. }
  2310. else
  2311. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2312. }
  2313. }
  2314. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2315. }
  2316. else if (spawn) {
  2317. if (spawn->IsPlayer()) {
  2318. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2319. Client* client = ((Player*)spawn)->GetClient();
  2320. if (client) {
  2321. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2322. if (packet)
  2323. client->QueuePacket(packet);
  2324. }
  2325. }
  2326. else if (spawn->IsNPC())
  2327. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2328. else
  2329. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2330. }
  2331. }
  2332. else
  2333. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2334. return 0;
  2335. }
  2336. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2337. if (!lua_interface)
  2338. return 0;
  2339. Spawn* spawn = lua_interface->GetSpawn(state);
  2340. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2341. if (spawn && spawn->IsPlayer()) {
  2342. int32 spell_id = 0;
  2343. if (luaspell && luaspell->spell) {
  2344. if(luaspell->resisted) {
  2345. lua_interface->ResetFunctionStack(state);
  2346. return 0;
  2347. }
  2348. spell_id = luaspell->spell->GetSpellID();
  2349. ZoneServer* zone = luaspell->caster->GetZone();
  2350. Spawn* target = 0;
  2351. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2352. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2353. target = zone->GetSpawnByID(luaspell->targets[i]);
  2354. if (target) {
  2355. if (target->IsPlayer()) {
  2356. ((Player*)target)->RemoveSkillBonus(spell_id);
  2357. Client* client = ((Player*)target)->GetClient();
  2358. if (client) {
  2359. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2360. if (packet)
  2361. client->QueuePacket(packet);
  2362. }
  2363. }
  2364. else if (target->IsNPC())
  2365. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2366. else
  2367. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2368. }
  2369. }
  2370. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2371. }
  2372. else if (spawn) {
  2373. if (spawn->IsPlayer()) {
  2374. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2375. Client* client = ((Player*)spawn)->GetClient();
  2376. if (client) {
  2377. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2378. if (packet)
  2379. client->QueuePacket(packet);
  2380. }
  2381. }
  2382. else if (spawn->IsNPC())
  2383. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2384. else
  2385. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2386. }
  2387. }
  2388. return 0;
  2389. }
  2390. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2391. if (!lua_interface)
  2392. return 0;
  2393. Spawn* spawn = lua_interface->GetSpawn(state);
  2394. int8 type = lua_interface->GetInt32Value(state, 2);
  2395. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2396. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2397. if(luaspell && luaspell->resisted) {
  2398. lua_interface->ResetFunctionStack(state);
  2399. return 0;
  2400. }
  2401. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2402. ZoneServer* zone = luaspell->caster->GetZone();
  2403. Spawn* target = 0;
  2404. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2405. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2406. target = zone->GetSpawnByID(luaspell->targets[i]);
  2407. if (target && target->IsEntity()) {
  2408. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2409. ((Entity*)target)->AddMezSpell(luaspell);
  2410. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2411. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2412. if (target->IsNPC())
  2413. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2414. }
  2415. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2416. ((Entity*)target)->AddStifleSpell(luaspell);
  2417. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2418. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2419. if (target->IsNPC())
  2420. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2421. }
  2422. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2423. ((Entity*)target)->AddDazeSpell(luaspell);
  2424. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2425. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2426. if (target->IsNPC())
  2427. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2428. }
  2429. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2430. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2431. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2432. ((Entity*)target)->AddStunSpell(luaspell);
  2433. if (target->IsNPC())
  2434. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2435. }
  2436. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2437. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2438. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2439. ((Entity*)target)->AddRootSpell(luaspell);
  2440. if (target->IsNPC())
  2441. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2442. }
  2443. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2444. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2445. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2446. ((Entity*)target)->AddFearSpell(luaspell);
  2447. if (target->IsNPC())
  2448. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2449. }
  2450. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2451. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2452. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2453. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2454. }
  2455. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2456. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2457. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2458. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2459. }
  2460. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2461. ((Entity*)target)->AddSnareSpell(luaspell);
  2462. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2463. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2464. if (target->IsNPC())
  2465. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2466. }
  2467. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2468. ((Entity*)target)->AddFlightSpell(luaspell);
  2469. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2470. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2471. }
  2472. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2473. ((Entity*)target)->AddGlideSpell(luaspell);
  2474. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2475. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2476. }
  2477. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2478. ((Entity*)target)->AddSafefallSpell(luaspell);
  2479. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2480. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2481. }
  2482. else
  2483. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2484. }
  2485. else
  2486. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2487. }
  2488. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2489. }
  2490. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2491. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2492. ((Entity*)spawn)->AddMezSpell(luaspell);
  2493. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2494. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2495. }
  2496. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2497. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2498. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2499. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2500. }
  2501. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2502. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2503. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2504. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2505. }
  2506. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2507. ((Entity*)spawn)->AddStunSpell(luaspell);
  2508. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2509. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2510. }
  2511. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2512. ((Entity*)spawn)->AddRootSpell(luaspell);
  2513. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2514. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2515. }
  2516. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2517. ((Entity*)spawn)->AddFearSpell(luaspell);
  2518. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2519. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2520. }
  2521. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2522. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2523. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2524. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2525. }
  2526. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2527. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2528. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2529. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2530. }
  2531. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2532. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2533. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2534. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2535. }
  2536. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2537. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2538. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2539. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2540. }
  2541. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2542. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2543. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2544. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2545. }
  2546. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2547. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2548. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2549. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2550. }
  2551. else
  2552. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2553. }
  2554. else
  2555. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2556. return 0;
  2557. }
  2558. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2559. if (!lua_interface)
  2560. return 0;
  2561. Spawn* spawn = lua_interface->GetSpawn(state);
  2562. int8 type = lua_interface->GetInt8Value(state, 2);
  2563. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2564. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2565. if (spawn && spawn->IsEntity()) {
  2566. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2567. ZoneServer* zone = luaspell->caster->GetZone();
  2568. Spawn* target = 0;
  2569. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2570. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2571. target = zone->GetSpawnByID(luaspell->targets[i]);
  2572. if (target) {
  2573. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2574. ((Entity*)target)->RemoveMezSpell(luaspell);
  2575. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2576. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2577. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2578. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2579. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2580. ((Entity*)target)->RemoveStunSpell(luaspell);
  2581. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2582. ((Entity*)target)->RemoveRootSpell(luaspell);
  2583. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2584. ((Entity*)target)->RemoveFearSpell(luaspell);
  2585. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2586. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2587. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2588. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2589. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2590. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2591. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2592. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2593. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2594. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2595. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2596. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2597. else
  2598. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2599. }
  2600. }
  2601. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2602. }
  2603. else if (only_remove_spawn) {
  2604. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2605. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2606. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2607. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2608. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2609. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2610. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2611. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2612. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2613. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2614. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2615. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2616. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2617. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2618. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2619. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2620. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2621. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2622. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2623. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2624. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2625. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2626. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2627. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2628. else
  2629. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2630. }
  2631. }
  2632. return 0;
  2633. }
  2634. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2635. if (!lua_interface)
  2636. return 0;
  2637. Spawn* spawn = lua_interface->GetSpawn(state);
  2638. int8 type = lua_interface->GetInt8Value(state, 2);
  2639. bool hasEffect = false;
  2640. if (!spawn)
  2641. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2642. else if (!spawn->IsEntity())
  2643. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2644. else if (type < CONTROL_MAX_EFFECTS)
  2645. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2646. else
  2647. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2648. lua_interface->SetBooleanValue(state, hasEffect);
  2649. return 1;
  2650. }
  2651. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2652. if (!lua_interface)
  2653. return 0;
  2654. Spawn* spawn = lua_interface->GetSpawn(state);
  2655. float distance = 0.0f;
  2656. if (!spawn)
  2657. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2658. else if (!spawn->IsNPC())
  2659. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2660. else
  2661. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2662. lua_interface->SetFloatValue(state, distance);
  2663. return 1;
  2664. }
  2665. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2666. if (!lua_interface)
  2667. return 0;
  2668. Spawn* spawn = lua_interface->GetSpawn(state);
  2669. float distance = 0.0f;
  2670. if (!spawn)
  2671. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2672. else if (!spawn->IsNPC())
  2673. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2674. else
  2675. distance = ((NPC*)spawn)->GetAggroRadius();
  2676. lua_interface->SetFloatValue(state, distance);
  2677. return 1;
  2678. }
  2679. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2680. if (!lua_interface)
  2681. return 0;
  2682. Spawn* spawn = lua_interface->GetSpawn(state);
  2683. float distance = lua_interface->GetFloatValue(state, 2);
  2684. bool override = lua_interface->GetBooleanValue(state, 3);
  2685. bool result = false;
  2686. lua_interface->ResetFunctionStack(state);
  2687. if (!spawn)
  2688. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2689. else if (!spawn->IsNPC())
  2690. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2691. else
  2692. {
  2693. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2694. result = true;
  2695. }
  2696. lua_interface->SetBooleanValue(state, result);
  2697. return 1;
  2698. }
  2699. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2700. if (!lua_interface)
  2701. return 0;
  2702. Spawn* spawn = lua_interface->GetSpawn(state);
  2703. int16 value = lua_interface->GetInt16Value(state, 2);
  2704. if (spawn && spawn->IsEntity()) {
  2705. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2706. if (spawn->IsPlayer())
  2707. ((Player*)spawn)->SetCharSheetChanged(true);
  2708. }
  2709. return 0;
  2710. }
  2711. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2712. if (!lua_interface)
  2713. return 0;
  2714. Spawn* spawn = lua_interface->GetSpawn(state);
  2715. int16 value = lua_interface->GetInt16Value(state, 2);
  2716. if (spawn && spawn->IsEntity()) {
  2717. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2718. if (spawn->IsPlayer())
  2719. ((Player*)spawn)->SetCharSheetChanged(true);
  2720. }
  2721. return 0;
  2722. }
  2723. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2724. if (!lua_interface)
  2725. return 0;
  2726. Spawn* spawn = lua_interface->GetSpawn(state);
  2727. int16 value = lua_interface->GetInt16Value(state, 2);
  2728. if (spawn && spawn->IsEntity()) {
  2729. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2730. if (spawn->IsPlayer())
  2731. ((Player*)spawn)->SetCharSheetChanged(true);
  2732. }
  2733. return 0;
  2734. }
  2735. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2736. if (!lua_interface)
  2737. return 0;
  2738. Spawn* spawn = lua_interface->GetSpawn(state);
  2739. int16 value = lua_interface->GetInt16Value(state, 2);
  2740. if (spawn && spawn->IsEntity()) {
  2741. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2742. if (spawn->IsPlayer())
  2743. ((Player*)spawn)->SetCharSheetChanged(true);
  2744. }
  2745. return 0;
  2746. }
  2747. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2748. if (!lua_interface)
  2749. return 0;
  2750. Spawn* spawn = lua_interface->GetSpawn(state);
  2751. int16 value = lua_interface->GetInt16Value(state, 2);
  2752. if (spawn && spawn->IsEntity()) {
  2753. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2754. if (spawn->IsPlayer())
  2755. ((Player*)spawn)->SetCharSheetChanged(true);
  2756. }
  2757. return 0;
  2758. }
  2759. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2760. if (!lua_interface)
  2761. return 0;
  2762. Spawn* spawn = lua_interface->GetSpawn(state);
  2763. int8 value = lua_interface->GetInt8Value(state, 2);
  2764. if (spawn && spawn->IsEntity()) {
  2765. ((Entity*)spawn)->SetDeity(value);
  2766. if (spawn->IsPlayer())
  2767. ((Player*)spawn)->SetCharSheetChanged(true);
  2768. }
  2769. lua_interface->ResetFunctionStack(state);
  2770. return 0;
  2771. }
  2772. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2773. if (!lua_interface)
  2774. return 0;
  2775. Spawn* spawn = lua_interface->GetSpawn(state);
  2776. if (spawn && spawn->IsEntity()) {
  2777. int8 deity = ((Entity*)spawn)->GetDeity();
  2778. lua_interface->SetInt32Value(state, deity);
  2779. return 1;
  2780. }
  2781. return 0;
  2782. }
  2783. int EQ2Emu_lua_SetInt(lua_State* state) {
  2784. if (!lua_interface)
  2785. return 0;
  2786. Spawn* spawn = lua_interface->GetSpawn(state);
  2787. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2788. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2789. if (spawn && spawn->IsEntity()) {
  2790. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_INT, value);
  2791. if (spawn->IsPlayer())
  2792. ((Player*)spawn)->SetCharSheetChanged(true);
  2793. }
  2794. return 0;
  2795. }
  2796. int EQ2Emu_lua_SetWis(lua_State* state) {
  2797. if (!lua_interface)
  2798. return 0;
  2799. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2800. Spawn* spawn = lua_interface->GetSpawn(state);
  2801. float value = lua_interface->GetFloatValue(state, 2);
  2802. if (spawn && spawn->IsEntity()) {
  2803. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_WIS, value);
  2804. if (spawn->IsPlayer())
  2805. ((Player*)spawn)->SetCharSheetChanged(true);
  2806. }
  2807. return 0;
  2808. }
  2809. int EQ2Emu_lua_SetSta(lua_State* state) {
  2810. if (!lua_interface)
  2811. return 0;
  2812. Spawn* spawn = lua_interface->GetSpawn(state);
  2813. float value = lua_interface->GetFloatValue(state, 2);
  2814. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2815. if (spawn && spawn->IsEntity()) {
  2816. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STA, value);
  2817. if (spawn->IsPlayer())
  2818. ((Player*)spawn)->SetCharSheetChanged(true);
  2819. }
  2820. return 0;
  2821. }
  2822. int EQ2Emu_lua_SetStr(lua_State* state) {
  2823. if (!lua_interface)
  2824. return 0;
  2825. Spawn* spawn = lua_interface->GetSpawn(state);
  2826. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2827. float value = lua_interface->GetFloatValue(state, 2);
  2828. if (spawn && spawn->IsEntity()) {
  2829. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STR, value);
  2830. if (spawn->IsPlayer())
  2831. ((Player*)spawn)->SetCharSheetChanged(true);
  2832. }
  2833. return 0;
  2834. }
  2835. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2836. if (!lua_interface)
  2837. return 0;
  2838. Spawn* spawn = lua_interface->GetSpawn(state);
  2839. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2840. float value = lua_interface->GetFloatValue(state, 2);
  2841. if (spawn && spawn->IsEntity()) {
  2842. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_AGI, value);
  2843. if (spawn->IsPlayer())
  2844. ((Player*)spawn)->SetCharSheetChanged(true);
  2845. }
  2846. return 0;
  2847. }
  2848. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2849. if (!lua_interface)
  2850. return 0;
  2851. Spawn* spawn = lua_interface->GetSpawn(state);
  2852. if (spawn) {
  2853. lua_interface->SetInt32Value(state, spawn->GetHP());
  2854. return 1;
  2855. }
  2856. return 0;
  2857. }
  2858. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2859. if (!lua_interface)
  2860. return 0;
  2861. Spawn* spawn = lua_interface->GetSpawn(state);
  2862. if (spawn) {
  2863. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2864. return 1;
  2865. }
  2866. return 0;
  2867. }
  2868. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2869. if (!lua_interface)
  2870. return 0;
  2871. Spawn* spawn = lua_interface->GetSpawn(state);
  2872. if (spawn) {
  2873. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2874. return 1;
  2875. }
  2876. return 0;
  2877. }
  2878. int EQ2Emu_lua_GetName(lua_State* state) {
  2879. if (!lua_interface)
  2880. return 0;
  2881. Spawn* spawn = lua_interface->GetSpawn(state);
  2882. if (spawn) {
  2883. lua_interface->SetStringValue(state, spawn->GetName());
  2884. return 1;
  2885. }
  2886. return 0;
  2887. }
  2888. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2889. Spawn* spawn = lua_interface->GetSpawn(state);
  2890. if (spawn) {
  2891. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2892. return 1;
  2893. }
  2894. return 0;
  2895. }
  2896. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2897. if (!lua_interface)
  2898. return 0;
  2899. Spawn* spawn = lua_interface->GetSpawn(state);
  2900. if (spawn) {
  2901. lua_interface->SetInt32Value(state, spawn->GetPower());
  2902. return 1;
  2903. }
  2904. return 0;
  2905. }
  2906. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2907. if (!lua_interface)
  2908. return 0;
  2909. Spawn* spawn = lua_interface->GetSpawn(state);
  2910. if (spawn) {
  2911. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2912. return 1;
  2913. }
  2914. return 0;
  2915. }
  2916. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2917. if (!lua_interface)
  2918. return 0;
  2919. Spawn* spawn = lua_interface->GetSpawn(state);
  2920. if (spawn) {
  2921. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2922. return 1;
  2923. }
  2924. return 0;
  2925. }
  2926. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2927. if (!lua_interface)
  2928. return 0;
  2929. Spawn* spawn = lua_interface->GetSpawn(state);
  2930. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2931. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2932. if (spawn && spawn2) {
  2933. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2934. lua_interface->SetFloatValue(state, distance);
  2935. return 1;
  2936. }
  2937. return 0;
  2938. }
  2939. int EQ2Emu_lua_GetX(lua_State* state) {
  2940. if (!lua_interface)
  2941. return 0;
  2942. Spawn* spawn = lua_interface->GetSpawn(state);
  2943. if (spawn) {
  2944. lua_interface->SetFloatValue(state, spawn->GetX());
  2945. return 1;
  2946. }
  2947. return 0;
  2948. }
  2949. int EQ2Emu_lua_GetY(lua_State* state) {
  2950. if (!lua_interface)
  2951. return 0;
  2952. Spawn* spawn = lua_interface->GetSpawn(state);
  2953. if (spawn) {
  2954. lua_interface->SetFloatValue(state, spawn->GetY());
  2955. return 1;
  2956. }
  2957. return 0;
  2958. }
  2959. int EQ2Emu_lua_GetZ(lua_State* state) {
  2960. if (!lua_interface)
  2961. return 0;
  2962. Spawn* spawn = lua_interface->GetSpawn(state);
  2963. if (spawn) {
  2964. lua_interface->SetFloatValue(state, spawn->GetZ());
  2965. return 1;
  2966. }
  2967. return 0;
  2968. }
  2969. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2970. if (!lua_interface)
  2971. return 0;
  2972. Spawn* spawn = lua_interface->GetSpawn(state);
  2973. if (spawn) {
  2974. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2975. return 1;
  2976. }
  2977. return 0;
  2978. }
  2979. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2980. if (!lua_interface)
  2981. return 0;
  2982. Spawn* spawn = lua_interface->GetSpawn(state);
  2983. if (spawn) {
  2984. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2985. return 1;
  2986. }
  2987. return 0;
  2988. }
  2989. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2990. if (!lua_interface)
  2991. return 0;
  2992. Spawn* spawn = lua_interface->GetSpawn(state);
  2993. if (spawn) {
  2994. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2995. return 1;
  2996. }
  2997. return 0;
  2998. }
  2999. int EQ2Emu_lua_HasMoved(lua_State* state) {
  3000. if (!lua_interface)
  3001. return 0;
  3002. Spawn* spawn = lua_interface->GetSpawn(state);
  3003. if (spawn && spawn->IsEntity()) {
  3004. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  3005. return 1;
  3006. }
  3007. return 0;
  3008. }
  3009. int EQ2Emu_lua_GetInt(lua_State* state) {
  3010. if (!lua_interface)
  3011. return 0;
  3012. Spawn* spawn = lua_interface->GetSpawn(state);
  3013. if (spawn && spawn->IsEntity()) {
  3014. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  3015. return 1;
  3016. }
  3017. return 0;
  3018. }
  3019. int EQ2Emu_lua_GetWis(lua_State* state) {
  3020. if (!lua_interface)
  3021. return 0;
  3022. Spawn* spawn = lua_interface->GetSpawn(state);
  3023. if (spawn && spawn->IsEntity()) {
  3024. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  3025. return 1;
  3026. }
  3027. return 0;
  3028. }
  3029. int EQ2Emu_lua_GetSta(lua_State* state) {
  3030. if (!lua_interface)
  3031. return 0;
  3032. Spawn* spawn = lua_interface->GetSpawn(state);
  3033. if (spawn && spawn->IsEntity()) {
  3034. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  3035. return 1;
  3036. }
  3037. return 0;
  3038. }
  3039. int EQ2Emu_lua_GetStr(lua_State* state) {
  3040. if (!lua_interface)
  3041. return 0;
  3042. Spawn* spawn = lua_interface->GetSpawn(state);
  3043. if (spawn && spawn->IsEntity()) {
  3044. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3045. return 1;
  3046. }
  3047. return 0;
  3048. }
  3049. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3050. if (!lua_interface)
  3051. return 0;
  3052. Spawn* spawn = lua_interface->GetSpawn(state);
  3053. if (spawn && spawn->IsEntity()) {
  3054. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3055. return 1;
  3056. }
  3057. return 0;
  3058. }
  3059. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3060. if (!lua_interface)
  3061. return 0;
  3062. Spawn* spawn = lua_interface->GetSpawn(state);
  3063. if (spawn && spawn->IsEntity()) {
  3064. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3065. return 1;
  3066. }
  3067. return 0;
  3068. }
  3069. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3070. if (!lua_interface)
  3071. return 0;
  3072. Spawn* spawn = lua_interface->GetSpawn(state);
  3073. if (spawn && spawn->IsEntity()) {
  3074. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3075. return 1;
  3076. }
  3077. return 0;
  3078. }
  3079. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3080. if (!lua_interface)
  3081. return 0;
  3082. Spawn* spawn = lua_interface->GetSpawn(state);
  3083. if (spawn && spawn->IsEntity()) {
  3084. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3085. return 1;
  3086. }
  3087. return 0;
  3088. }
  3089. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3090. if (!lua_interface)
  3091. return 0;
  3092. Spawn* spawn = lua_interface->GetSpawn(state);
  3093. if (spawn && spawn->IsEntity()) {
  3094. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3095. return 1;
  3096. }
  3097. return 0;
  3098. }
  3099. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3100. if (!lua_interface)
  3101. return 0;
  3102. Spawn* spawn = lua_interface->GetSpawn(state);
  3103. if (spawn && spawn->IsEntity()) {
  3104. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3105. return 1;
  3106. }
  3107. return 0;
  3108. }
  3109. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3110. if (!lua_interface)
  3111. return 0;
  3112. Spawn* player = lua_interface->GetSpawn(state);
  3113. if (!player || !player->IsPlayer()) {
  3114. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3115. return 0;
  3116. }
  3117. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3118. if (quest_id <= 0) {
  3119. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3120. return 0;
  3121. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3122. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3123. return 0;
  3124. }
  3125. int32 step = lua_interface->GetInt32Value(state, 3);
  3126. if (step > 0) {
  3127. Client* client = ((Player*)player)->GetClient();
  3128. if (client)
  3129. client->AddPendingQuestUpdate(quest_id, step);
  3130. } else {
  3131. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3132. }
  3133. return 0;
  3134. }
  3135. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3136. Spawn* player = lua_interface->GetSpawn(state);
  3137. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3138. int32 step = lua_interface->GetInt32Value(state, 3);
  3139. int32 progress = lua_interface->GetInt32Value(state, 4);
  3140. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3141. Client* client = ((Player*)player)->GetClient();
  3142. if (client)
  3143. client->AddPendingQuestUpdate(quest_id, step, progress);
  3144. }
  3145. return 0;
  3146. }
  3147. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3148. if (!lua_interface)
  3149. return 0;
  3150. Spawn* player = lua_interface->GetSpawn(state);
  3151. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3152. if (player && player->IsPlayer() && quest_id > 0) {
  3153. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3154. return 1;
  3155. }
  3156. return 0;
  3157. }
  3158. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3159. if (!lua_interface)
  3160. return 0;
  3161. Spawn* player = lua_interface->GetSpawn(state);
  3162. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3163. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3164. if (player && player->IsPlayer() && quest_id > 0) {
  3165. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3166. return 1;
  3167. }
  3168. return 0;
  3169. }
  3170. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3171. if (!lua_interface)
  3172. return 0;
  3173. Spawn* player = lua_interface->GetSpawn(state);
  3174. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3175. if (player && player->IsPlayer() && quest_id > 0) {
  3176. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3177. return 1;
  3178. }
  3179. return 0;
  3180. }
  3181. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3182. if (!lua_interface)
  3183. return 0;
  3184. Quest* quest = lua_interface->GetQuest(state);
  3185. string name = lua_interface->GetStringValue(state, 2);
  3186. string type = lua_interface->GetStringValue(state, 3);
  3187. string zone = lua_interface->GetStringValue(state, 4);
  3188. int16 level = lua_interface->GetInt16Value(state, 5);
  3189. string description = lua_interface->GetStringValue(state, 6);
  3190. bool load = true;
  3191. if (!quest) {
  3192. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3193. load = false;
  3194. }
  3195. if (load && name.length() == 0) {
  3196. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3197. load = false;
  3198. }
  3199. if (load && type.length() == 0) {
  3200. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3201. load = false;
  3202. }
  3203. if (load && zone.length() == 0) {
  3204. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3205. load = false;
  3206. }
  3207. if (load && description.length() == 0) {
  3208. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3209. load = false;
  3210. }
  3211. if (load && level == 0) {
  3212. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3213. load = false;
  3214. }
  3215. if (load)
  3216. quest->RegisterQuest(name, type, zone, level, description);
  3217. return 0;
  3218. }
  3219. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3220. if (!lua_interface)
  3221. return 0;
  3222. Quest* quest = lua_interface->GetQuest(state);
  3223. if (quest) {
  3224. int8 level = lua_interface->GetInt16Value(state, 2);
  3225. quest->SetPrereqLevel(level);
  3226. }
  3227. return 0;
  3228. }
  3229. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3230. if (!lua_interface)
  3231. return 0;
  3232. Quest* quest = lua_interface->GetQuest(state);
  3233. if (quest) {
  3234. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3235. quest->AddPrereqQuest(quest_id);
  3236. }
  3237. return 0;
  3238. }
  3239. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3240. if (!lua_interface)
  3241. return 0;
  3242. Quest* quest = lua_interface->GetQuest(state);
  3243. if (quest) {
  3244. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3245. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3246. if (quantity == 0)
  3247. quantity = 1;
  3248. Item* master_item = master_item_list.GetItem(item_id);
  3249. if (master_item) {
  3250. Item* item = new Item(master_item);
  3251. item->details.count = quantity;
  3252. quest->AddPrereqItem(item);
  3253. }
  3254. }
  3255. return 0;
  3256. }
  3257. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3258. if (!lua_interface)
  3259. return 0;
  3260. Spawn* player = lua_interface->GetSpawn(state);
  3261. if(!player || !player->IsPlayer()) {
  3262. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3263. return 0;
  3264. }
  3265. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3266. if (quest_id > 0) {
  3267. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3268. return 1;
  3269. } else {
  3270. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3271. }
  3272. return 0;
  3273. }
  3274. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3275. if (!lua_interface)
  3276. return 0;
  3277. Quest* quest = lua_interface->GetQuest(state);
  3278. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3279. lua_interface->ResetFunctionStack(state);
  3280. if (quest && spawn_id > 0)
  3281. quest->SetQuestReturnNPC(spawn_id);
  3282. return 0;
  3283. }
  3284. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3285. if (!lua_interface)
  3286. return 0;
  3287. Spawn* spawn = lua_interface->GetSpawn(state);
  3288. int32 time = lua_interface->GetInt32Value(state, 2);
  3289. string function = lua_interface->GetStringValue(state, 3);
  3290. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3291. Spawn* player = lua_interface->GetSpawn(state, 5);
  3292. lua_interface->ResetFunctionStack(state);
  3293. if (!spawn) {
  3294. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3295. return 0;
  3296. }
  3297. if (time <= 0) {
  3298. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3299. return 0;
  3300. }
  3301. if (function.length() == 0) {
  3302. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3303. return 0;
  3304. }
  3305. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3306. if ( time < 10)
  3307. time = 10;
  3308. timer->timer = Timer::GetCurrentTime2() + time;
  3309. timer->function = function;
  3310. timer->spawn = spawn->GetID();
  3311. timer->player = player ? player->GetID() : 0;
  3312. if (max_count == 0)
  3313. max_count = 1;
  3314. timer->max_count = max_count;
  3315. timer->current_count = 0;
  3316. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3317. return 0;
  3318. }
  3319. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3320. if (!lua_interface)
  3321. return 0;
  3322. Spawn* spawn = lua_interface->GetSpawn(state);
  3323. string function = lua_interface->GetStringValue(state, 2);
  3324. lua_interface->ResetFunctionStack(state);
  3325. if (!spawn) {
  3326. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3327. return 0;
  3328. }
  3329. if(!spawn->GetZone()) {
  3330. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3331. return 0;
  3332. }
  3333. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3334. return 0;
  3335. }
  3336. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3337. if (!lua_interface)
  3338. return 0;
  3339. Spawn* player = lua_interface->GetSpawn(state);
  3340. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3341. lua_interface->ResetFunctionStack(state);
  3342. if (player && player->IsPlayer() && quest_id > 0) {
  3343. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3344. return 1;
  3345. }
  3346. return 0;
  3347. }
  3348. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3349. if (!lua_interface)
  3350. return 0;
  3351. Spawn* player = lua_interface->GetSpawn(state);
  3352. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3353. lua_interface->ResetFunctionStack(state);
  3354. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3355. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3356. if (quest)
  3357. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3358. return 1;
  3359. }
  3360. return 0;
  3361. }
  3362. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3363. if (!lua_interface)
  3364. return 0;
  3365. Spawn* player = lua_interface->GetSpawn(state);
  3366. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3367. lua_interface->ResetFunctionStack(state);
  3368. if (player && player->IsPlayer() && quest_id > 0) {
  3369. lua_interface->SetBooleanValue(state, (((Player*)player)->HasQuestBeenCompleted(quest_id) != 0));
  3370. return 1;
  3371. }
  3372. return 0;
  3373. }
  3374. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3375. if (!lua_interface)
  3376. return 0;
  3377. Spawn* npc = lua_interface->GetSpawn(state);
  3378. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3379. lua_interface->ResetFunctionStack(state);
  3380. if (npc && !npc->IsPlayer() && quest_id > 0)
  3381. npc->AddProvidedQuest(quest_id);
  3382. return 0;
  3383. }
  3384. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3385. if (!lua_interface)
  3386. return 0;
  3387. Spawn* npc = lua_interface->GetSpawn(state);
  3388. Spawn* player = lua_interface->GetSpawn(state, 2);
  3389. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3390. bool forced = lua_interface->GetBooleanValue(state, 4);
  3391. bool override_receive_quest_check = lua_interface->GetBooleanValue(state, 5);
  3392. lua_interface->ResetFunctionStack(state);
  3393. /* NPC is allowed to be null */
  3394. if (player && player->IsPlayer() && quest_id > 0) {
  3395. if(!((Player*)player)->CanReceiveQuest(quest_id)) {
  3396. if(override_receive_quest_check || player->GetClient() && player->GetClient()->GetAdminStatus() >= 200) {
  3397. if(override_receive_quest_check) {
  3398. lua_interface->LogError("%s: LUA OfferQuest player %s should not be able to receive quest %u, override as OfferQuest has override_receive_quest_check = true.", lua_interface->GetScriptName(state), player->GetName(), quest_id);
  3399. }
  3400. else {
  3401. lua_interface->LogError("%s: LUA OfferQuest player %s should not be able to receive quest %u, override as player is admin (status >= 200).", lua_interface->GetScriptName(state), player->GetName(), quest_id);
  3402. }
  3403. }
  3404. else {
  3405. lua_interface->LogError("%s: LUA OfferQuest player %s cannot receive the quest %u, failed CanReceiveQuest.", lua_interface->GetScriptName(state), player->GetName(), quest_id);
  3406. return 0;
  3407. }
  3408. }
  3409. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3410. if (master_quest) {
  3411. Client* client = ((Player*)player)->GetClient();
  3412. if (!client) {
  3413. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3414. }
  3415. Quest* quest = new Quest(master_quest);
  3416. if (!quest) {
  3417. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3418. }
  3419. if (client && quest) {
  3420. if (npc)
  3421. quest->SetQuestGiver(npc->GetDatabaseID());
  3422. else
  3423. quest->SetQuestGiver(0);
  3424. client->AddPendingQuest(quest, forced);
  3425. }
  3426. }
  3427. else {
  3428. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3429. }
  3430. }
  3431. else {
  3432. 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);
  3433. }
  3434. return 0;
  3435. }
  3436. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3437. if (!lua_interface)
  3438. return 0;
  3439. Quest* quest = lua_interface->GetQuest(state);
  3440. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3441. lua_interface->ResetFunctionStack(state);
  3442. if (quest) {
  3443. quest->AddPrereqClass(class_id);
  3444. }
  3445. return 0;
  3446. }
  3447. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3448. if (!lua_interface)
  3449. return 0;
  3450. Quest* quest = lua_interface->GetQuest(state);
  3451. int8 race = lua_interface->GetInt8Value(state, 2);
  3452. lua_interface->ResetFunctionStack(state);
  3453. if (quest) {
  3454. quest->AddPrereqRace(race);
  3455. }
  3456. return 0;
  3457. }
  3458. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3459. if (!lua_interface)
  3460. return 0;
  3461. Quest* quest = lua_interface->GetQuest(state);
  3462. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3463. lua_interface->ResetFunctionStack(state);
  3464. if (quest) {
  3465. quest->AddPrereqModelType(model_type);
  3466. }
  3467. return 0;
  3468. }
  3469. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3470. if (!lua_interface)
  3471. return 0;
  3472. Quest* quest = lua_interface->GetQuest(state);
  3473. int8 level = lua_interface->GetInt8Value(state, 2);
  3474. lua_interface->ResetFunctionStack(state);
  3475. if (!quest) {
  3476. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3477. return 0;
  3478. }
  3479. quest->SetPrereqTSLevel(level);
  3480. return 0;
  3481. }
  3482. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3483. if (!lua_interface)
  3484. return 0;
  3485. Quest* quest = lua_interface->GetQuest(state);
  3486. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3487. lua_interface->ResetFunctionStack(state);
  3488. if (!quest) {
  3489. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3490. return 0;
  3491. }
  3492. quest->AddPrereqTradeskillClass(class_id);
  3493. return 0;
  3494. }
  3495. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3496. if (!lua_interface)
  3497. return 0;
  3498. Quest* quest = lua_interface->GetQuest(state);
  3499. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3500. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3501. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3502. lua_interface->ResetFunctionStack(state);
  3503. if (quest) {
  3504. quest->AddPrereqFaction(faction_id, min, max);
  3505. }
  3506. return 0;
  3507. }
  3508. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3509. if (!lua_interface)
  3510. return 0;
  3511. Quest* quest = lua_interface->GetQuest(state);
  3512. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3513. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3514. lua_interface->ResetFunctionStack(state);
  3515. if (quest) {
  3516. if (quantity == 0)
  3517. quantity = 1;
  3518. Item* master_item = master_item_list.GetItem(item_id);
  3519. if (master_item) {
  3520. Item* item = new Item(master_item);
  3521. item->details.count = quantity;
  3522. quest->AddSelectableRewardItem(item);
  3523. }
  3524. }
  3525. return 0;
  3526. }
  3527. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3528. if (!lua_interface)
  3529. return 0;
  3530. Quest* quest = lua_interface->GetQuest(state);
  3531. if (quest) {
  3532. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3533. vector<Item*>* items = quest->GetRewardItems();
  3534. if (items) {
  3535. vector<Item*>::iterator itr;
  3536. for (itr = items->begin(); itr != items->end(); itr++) {
  3537. if (*itr && (*itr)->details.item_id == item_id) {
  3538. lua_interface->SetBooleanValue(state, true);
  3539. return 1;
  3540. }
  3541. }
  3542. }
  3543. }
  3544. lua_interface->SetBooleanValue(state, false);
  3545. return 1;
  3546. }
  3547. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3548. if (!lua_interface)
  3549. return 0;
  3550. Quest* quest = lua_interface->GetQuest(state);
  3551. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3552. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3553. lua_interface->ResetFunctionStack(state);
  3554. if (quest) {
  3555. if (quantity == 0)
  3556. quantity = 1;
  3557. Item* master_item = master_item_list.GetItem(item_id);
  3558. if (master_item) {
  3559. Item* item = new Item(master_item);
  3560. item->details.count = quantity;
  3561. quest->AddRewardItem(item);
  3562. }
  3563. }
  3564. return 0;
  3565. }
  3566. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3567. if (!lua_interface)
  3568. return 0;
  3569. Quest* quest = lua_interface->GetQuest(state);
  3570. int32 copper = lua_interface->GetInt32Value(state, 2);
  3571. int32 silver = lua_interface->GetInt32Value(state, 3);
  3572. int32 gold = lua_interface->GetInt32Value(state, 4);
  3573. int32 plat = lua_interface->GetInt32Value(state, 5);
  3574. lua_interface->ResetFunctionStack(state);
  3575. if (quest) {
  3576. quest->AddRewardCoins(copper, silver, gold, plat);
  3577. }
  3578. return 0;
  3579. }
  3580. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3581. if (!lua_interface)
  3582. return 0;
  3583. Quest* quest = lua_interface->GetQuest(state);
  3584. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3585. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3586. lua_interface->ResetFunctionStack(state);
  3587. if (quest && faction_id > 0 && amount != 0)
  3588. quest->AddRewardFaction(faction_id, amount);
  3589. return 0;
  3590. }
  3591. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3592. if (!lua_interface)
  3593. return 0;
  3594. Quest* quest = lua_interface->GetQuest(state);
  3595. int32 status = lua_interface->GetInt32Value(state, 2);
  3596. lua_interface->ResetFunctionStack(state);
  3597. if (quest) {
  3598. quest->SetRewardStatus(status);
  3599. }
  3600. return 0;
  3601. }
  3602. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3603. if (!lua_interface)
  3604. return 0;
  3605. Quest* quest = lua_interface->GetQuest(state);
  3606. int32 status = lua_interface->GetInt32Value(state, 2);
  3607. lua_interface->ResetFunctionStack(state);
  3608. if (quest) {
  3609. quest->SetStatusTmpReward(status);
  3610. }
  3611. return 0;
  3612. }
  3613. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3614. if (!lua_interface)
  3615. return 0;
  3616. Quest* quest = lua_interface->GetQuest(state);
  3617. int64 coins = lua_interface->GetInt64Value(state, 2);
  3618. lua_interface->ResetFunctionStack(state);
  3619. if (quest) {
  3620. quest->SetCoinTmpReward(coins);
  3621. }
  3622. return 0;
  3623. }
  3624. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3625. if (!lua_interface)
  3626. return 0;
  3627. Quest* quest = lua_interface->GetQuest(state);
  3628. string comment = lua_interface->GetStringValue(state, 2);
  3629. lua_interface->ResetFunctionStack(state);
  3630. if (quest) {
  3631. quest->SetRewardComment(comment);
  3632. }
  3633. return 0;
  3634. }
  3635. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3636. if (!lua_interface)
  3637. return 0;
  3638. Quest* quest = lua_interface->GetQuest(state);
  3639. int32 exp = lua_interface->GetInt32Value(state, 2);
  3640. lua_interface->ResetFunctionStack(state);
  3641. if (quest) {
  3642. quest->SetRewardXP(exp);
  3643. }
  3644. return 0;
  3645. }
  3646. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3647. Quest* quest = lua_interface->GetQuest(state);
  3648. int32 step = lua_interface->GetInt32Value(state, 2);
  3649. string description = lua_interface->GetStringValue(state, 3);
  3650. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3651. float percentage = lua_interface->GetFloatValue(state, 5);
  3652. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3653. int16 icon = lua_interface->GetInt16Value(state, 7);
  3654. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3655. if (quest) {
  3656. const char* taskgroup = 0;
  3657. if (str_taskgroup.length() > 0)
  3658. taskgroup = str_taskgroup.c_str();
  3659. int32 id = 0;
  3660. vector<int32>* ids = 0;
  3661. int i = 0;
  3662. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3663. if (ids == 0)
  3664. ids = new vector<int32>;
  3665. ids->push_back(id);
  3666. i++;
  3667. }
  3668. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3669. if (quest_step && icon && quantity > 0)
  3670. quest_step->SetIcon(icon);
  3671. if (quest->GetPlayer()) {
  3672. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3673. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3674. }
  3675. }
  3676. lua_interface->ResetFunctionStack(state);
  3677. return 0;
  3678. }
  3679. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3680. {
  3681. if (!lua_interface)
  3682. return 0;
  3683. Quest* quest = lua_interface->GetQuest(state);
  3684. int32 step = lua_interface->GetInt32Value(state, 2);
  3685. string description = lua_interface->GetStringValue(state, 3);
  3686. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3687. float percentage = lua_interface->GetFloatValue(state, 5);
  3688. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3689. int16 icon = lua_interface->GetInt16Value(state, 7);
  3690. if (quest) {
  3691. const char* taskgroup = 0;
  3692. if (str_taskgroup.length() > 0)
  3693. taskgroup = str_taskgroup.c_str();
  3694. int32 id = 0;
  3695. vector<int32>* ids = 0;
  3696. int i = 0;
  3697. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3698. if (ids == 0)
  3699. ids = new vector<int32>;
  3700. ids->push_back(id);
  3701. i++;
  3702. }
  3703. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3704. if (quest_step && icon > 0 && quantity > 0)
  3705. quest_step->SetIcon(icon);
  3706. if (quest->GetPlayer()) {
  3707. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3708. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3709. }
  3710. safe_delete(ids);
  3711. }
  3712. lua_interface->ResetFunctionStack(state);
  3713. return 0;
  3714. }
  3715. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3716. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3717. }
  3718. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3719. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3720. }
  3721. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3722. if (!lua_interface)
  3723. return 0;
  3724. Quest* quest = lua_interface->GetQuest(state);
  3725. int32 step = lua_interface->GetInt32Value(state, 2);
  3726. string description = lua_interface->GetStringValue(state, 3);
  3727. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3728. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3729. int16 icon = lua_interface->GetInt16Value(state, 6);
  3730. if (quest) {
  3731. const char* taskgroup = 0;
  3732. if (str_taskgroup.length() > 0)
  3733. taskgroup = str_taskgroup.c_str();
  3734. int32 npc_id = 0;
  3735. vector<int32>* ids = 0;
  3736. int i = 0;
  3737. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3738. if (ids == 0)
  3739. ids = new vector<int32>;
  3740. ids->push_back(npc_id);
  3741. i++;
  3742. }
  3743. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3744. if (quest_step && icon > 0)
  3745. quest_step->SetIcon(icon);
  3746. if (quest->GetPlayer()) {
  3747. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3748. if(client)
  3749. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3750. }
  3751. safe_delete(ids);
  3752. }
  3753. lua_interface->ResetFunctionStack(state);
  3754. return 0;
  3755. }
  3756. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3757. if (!lua_interface)
  3758. return 0;
  3759. Quest* quest = lua_interface->GetQuest(state);
  3760. int32 step = lua_interface->GetInt32Value(state, 2);
  3761. string description = lua_interface->GetStringValue(state, 3);
  3762. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3763. float percentage = lua_interface->GetFloatValue(state, 5);
  3764. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3765. int16 icon = lua_interface->GetInt16Value(state, 7);
  3766. if (quest) {
  3767. const char* taskgroup = 0;
  3768. if (str_taskgroup.length() > 0)
  3769. taskgroup = str_taskgroup.c_str();
  3770. int32 item_id = 0;
  3771. vector<int32>* ids = 0;
  3772. int i = 0;
  3773. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3774. if (ids == 0)
  3775. ids = new vector<int32>;
  3776. ids->push_back(item_id);
  3777. i++;
  3778. }
  3779. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3780. if (quest_step && icon > 0 && quantity > 0)
  3781. quest_step->SetIcon(icon);
  3782. if (quest->GetPlayer()) {
  3783. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3784. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3785. }
  3786. safe_delete(ids);
  3787. }
  3788. lua_interface->ResetFunctionStack(state);
  3789. return 0;
  3790. }
  3791. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3792. if (!lua_interface)
  3793. return 0;
  3794. Quest* quest = lua_interface->GetQuest(state);
  3795. int32 step = lua_interface->GetInt32Value(state, 2);
  3796. string description = lua_interface->GetStringValue(state, 3);
  3797. float max_variation = lua_interface->GetFloatValue(state, 4);
  3798. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3799. int16 icon = lua_interface->GetInt16Value(state, 6);
  3800. if (quest) {
  3801. const char* taskgroup = 0;
  3802. if (str_taskgroup.length() > 0)
  3803. taskgroup = str_taskgroup.c_str();
  3804. vector<Location>* locations = 0;
  3805. int8 i = 7;
  3806. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3807. while (true) {
  3808. Location loc;
  3809. loc.x = lua_interface->GetFloatValue(state, i);
  3810. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3811. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3812. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3813. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3814. break;
  3815. if (locations == 0)
  3816. locations = new vector<Location>;
  3817. locations->push_back(loc);
  3818. i += 4;
  3819. }
  3820. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3821. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3822. if (quest_step && icon > 0)
  3823. quest_step->SetIcon(icon);
  3824. if (quest->GetPlayer()) {
  3825. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3826. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3827. }
  3828. }
  3829. lua_interface->ResetFunctionStack(state);
  3830. return 0;
  3831. }
  3832. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3833. if (!lua_interface)
  3834. return 0;
  3835. Quest* quest = lua_interface->GetQuest(state);
  3836. int32 step = lua_interface->GetInt32Value(state, 2);
  3837. string description = lua_interface->GetStringValue(state, 3);
  3838. float max_variation = lua_interface->GetFloatValue(state, 4);
  3839. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3840. int16 icon = lua_interface->GetInt16Value(state, 6);
  3841. if (quest) {
  3842. const char* taskgroup = 0;
  3843. if (str_taskgroup.length() > 0)
  3844. taskgroup = str_taskgroup.c_str();
  3845. vector<Location>* locations = 0;
  3846. int8 i = 7;
  3847. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3848. while (true) {
  3849. Location loc;
  3850. loc.x = lua_interface->GetFloatValue(state, i);
  3851. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3852. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3853. loc.zone_id = 0;
  3854. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3855. break;
  3856. if (locations == 0)
  3857. locations = new vector<Location>;
  3858. locations->push_back(loc);
  3859. i += 3;
  3860. }
  3861. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3862. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3863. if (quest_step && icon > 0)
  3864. quest_step->SetIcon(icon);
  3865. if (quest->GetPlayer()) {
  3866. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3867. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3868. }
  3869. }
  3870. lua_interface->ResetFunctionStack(state);
  3871. return 0;
  3872. }
  3873. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3874. if (!lua_interface)
  3875. return 0;
  3876. Quest* quest = lua_interface->GetQuest(state);
  3877. int32 step = lua_interface->GetInt32Value(state, 2);
  3878. string description = lua_interface->GetStringValue(state, 3);
  3879. float max_variation = lua_interface->GetFloatValue(state, 4);
  3880. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3881. int16 icon = lua_interface->GetInt16Value(state, 6);
  3882. if (quest) {
  3883. const char* taskgroup = 0;
  3884. if (str_taskgroup.length() > 0)
  3885. taskgroup = str_taskgroup.c_str();
  3886. vector<Location>* locations = 0;
  3887. int i = 7;
  3888. while (true) {
  3889. Location loc;
  3890. loc.x = lua_interface->GetFloatValue(state, i);
  3891. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3892. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3893. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3894. break;
  3895. if (locations == 0)
  3896. locations = new vector<Location>;
  3897. locations->push_back(loc);
  3898. i += 3;
  3899. }
  3900. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3901. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3902. if (quest_step && icon > 0)
  3903. quest_step->SetIcon(icon);
  3904. if (quest->GetPlayer()) {
  3905. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3906. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3907. }
  3908. }
  3909. lua_interface->ResetFunctionStack(state);
  3910. return 0;
  3911. }
  3912. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3913. Quest* quest = lua_interface->GetQuest(state);
  3914. int32 step = lua_interface->GetInt32Value(state, 2);
  3915. string description = lua_interface->GetStringValue(state, 3);
  3916. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3917. float percentage = lua_interface->GetFloatValue(state, 5);
  3918. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3919. int16 icon = lua_interface->GetInt16Value(state, 7);
  3920. if (quest) {
  3921. const char* taskgroup = 0;
  3922. if (str_taskgroup.length() > 0)
  3923. taskgroup = str_taskgroup.c_str();
  3924. int32 spell_id = 0;
  3925. vector<int32>* ids = 0;
  3926. int i = 0;
  3927. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3928. if (ids == 0)
  3929. ids = new vector<int32>;
  3930. ids->push_back(spell_id);
  3931. i++;
  3932. }
  3933. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3934. if (quest_step && icon > 0 && quantity > 0)
  3935. quest_step->SetIcon(icon);
  3936. if (quest->GetPlayer()) {
  3937. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3938. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3939. }
  3940. safe_delete(ids);
  3941. }
  3942. lua_interface->ResetFunctionStack(state);
  3943. return 0;
  3944. }
  3945. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3946. if (!lua_interface)
  3947. return 0;
  3948. Quest* quest = lua_interface->GetQuest(state);
  3949. int32 step = lua_interface->GetInt32Value(state, 2);
  3950. string description = lua_interface->GetStringValue(state, 3);
  3951. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3952. float percentage = lua_interface->GetFloatValue(state, 5);
  3953. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3954. int16 icon = lua_interface->GetInt16Value(state, 7);
  3955. if (quest) {
  3956. const char* taskgroup = 0;
  3957. if (str_taskgroup.length() > 0)
  3958. taskgroup = str_taskgroup.c_str();
  3959. int32 item_id = 0;
  3960. vector<int32>* ids = 0;
  3961. int i = 0;
  3962. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3963. if (ids == 0)
  3964. ids = new vector<int32>;
  3965. ids->push_back(item_id);
  3966. i++;
  3967. }
  3968. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3969. if (quest_step && icon > 0 && quantity > 0)
  3970. quest_step->SetIcon(icon);
  3971. if (quest->GetPlayer()) {
  3972. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3973. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3974. }
  3975. safe_delete(ids);
  3976. }
  3977. lua_interface->ResetFunctionStack(state);
  3978. return 0;
  3979. }
  3980. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3981. if (!lua_interface)
  3982. return 0;
  3983. Quest* quest = lua_interface->GetQuest(state);
  3984. int32 step = lua_interface->GetInt32Value(state, 2);
  3985. string description = lua_interface->GetStringValue(state, 3);
  3986. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3987. float percentage = lua_interface->GetFloatValue(state, 5);
  3988. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3989. int16 icon = lua_interface->GetInt16Value(state, 7);
  3990. if (quest) {
  3991. const char* taskgroup = 0;
  3992. if (str_taskgroup.length() > 0)
  3993. taskgroup = str_taskgroup.c_str();
  3994. int32 item_id = 0;
  3995. vector<int32>* ids = 0;
  3996. int i = 0;
  3997. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3998. if (ids == 0)
  3999. ids = new vector<int32>;
  4000. ids->push_back(item_id);
  4001. i++;
  4002. }
  4003. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4004. if (quest_step && icon > 0 && quantity > 0)
  4005. quest_step->SetIcon(icon);
  4006. if (quest->GetPlayer()) {
  4007. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4008. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4009. }
  4010. safe_delete(ids);
  4011. }
  4012. lua_interface->ResetFunctionStack(state);
  4013. return 0;
  4014. }
  4015. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  4016. if (!lua_interface)
  4017. return 0;
  4018. Quest* quest = lua_interface->GetQuest(state);
  4019. string action = lua_interface->GetStringValue(state, 2);
  4020. lua_interface->ResetFunctionStack(state);
  4021. if (quest) {
  4022. if (action.length() > 0)
  4023. quest->SetCompleteAction(action);
  4024. }
  4025. return 0;
  4026. }
  4027. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  4028. if (!lua_interface)
  4029. return 0;
  4030. Quest* quest = lua_interface->GetQuest(state);
  4031. int32 step = lua_interface->GetInt32Value(state, 2);
  4032. string action = lua_interface->GetStringValue(state, 3);
  4033. lua_interface->ResetFunctionStack(state);
  4034. if (quest) {
  4035. if (step > 0 && action.length() > 0)
  4036. quest->AddCompleteAction(step, action);
  4037. }
  4038. return 0;
  4039. }
  4040. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  4041. if (!lua_interface)
  4042. return 0;
  4043. Quest* quest = lua_interface->GetQuest(state);
  4044. int32 step = lua_interface->GetInt32Value(state, 2);
  4045. string action = lua_interface->GetStringValue(state, 3);
  4046. lua_interface->ResetFunctionStack(state);
  4047. if (quest) {
  4048. if (step > 0 && action.length() > 0)
  4049. quest->AddProgressAction(step, action);
  4050. }
  4051. return 0;
  4052. }
  4053. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  4054. if (!lua_interface)
  4055. return 0;
  4056. Quest* quest = lua_interface->GetQuest(state);
  4057. string description = lua_interface->GetStringValue(state, 2);
  4058. lua_interface->ResetFunctionStack(state);
  4059. if (quest && description.length() > 0)
  4060. quest->SetDescription(description);
  4061. return 0;
  4062. }
  4063. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4064. if (!lua_interface)
  4065. return 0;
  4066. Quest* quest = lua_interface->GetQuest(state);
  4067. string description = lua_interface->GetStringValue(state, 2);
  4068. lua_interface->ResetFunctionStack(state);
  4069. if (quest && description.length() > 0)
  4070. quest->SetCompletedDescription(description);
  4071. return 0;
  4072. }
  4073. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4074. if (!lua_interface)
  4075. return 0;
  4076. Quest* quest = lua_interface->GetQuest(state);
  4077. int32 step = lua_interface->GetInt32Value(state, 2);
  4078. string description = lua_interface->GetStringValue(state, 3);
  4079. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4080. lua_interface->ResetFunctionStack(state);
  4081. if (quest && step > 0 && description.length() > 0) {
  4082. quest->SetTaskGroupDescription(step, description, display_bullets);
  4083. /* if (quest->GetPlayer()) {
  4084. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4085. if (client)
  4086. client->SendQuestUpdateStep(quest, step, false);
  4087. }*/
  4088. }
  4089. return 0;
  4090. }
  4091. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4092. if (!lua_interface)
  4093. return 0;
  4094. Quest* quest = lua_interface->GetQuest(state);
  4095. int32 step = lua_interface->GetInt32Value(state, 2);
  4096. string description = lua_interface->GetStringValue(state, 3);
  4097. lua_interface->ResetFunctionStack(state);
  4098. if (quest && step > 0 && description.length() > 0) {
  4099. quest->SetStepDescription(step, description);
  4100. /*if (quest->GetPlayer()) {
  4101. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4102. if (client)
  4103. client->SendQuestUpdateStepImmediately(quest, step);
  4104. }*/
  4105. }
  4106. return 0;
  4107. }
  4108. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4109. Quest* quest = lua_interface->GetQuest(state);
  4110. string zone = lua_interface->GetStringValue(state, 2);
  4111. lua_interface->ResetFunctionStack(state);
  4112. if (quest && zone.length() > 0)
  4113. quest->SetZone(zone);
  4114. return 0;
  4115. }
  4116. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4117. if (!lua_interface)
  4118. return 0;
  4119. Quest* quest = lua_interface->GetQuest(state);
  4120. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4121. lua_interface->ResetFunctionStack(state);
  4122. if (quest && spawn) {
  4123. if (spawn->IsPlayer()) {
  4124. Client* client = ((Player*)spawn)->GetClient();
  4125. if (client) {
  4126. client->AddPendingQuestReward(quest);
  4127. }
  4128. }
  4129. }
  4130. return 0;
  4131. }
  4132. int EQ2Emu_lua_Harvest(lua_State* state) {
  4133. if (!lua_interface)
  4134. return 0;
  4135. Spawn* player = lua_interface->GetSpawn(state);
  4136. Spawn* node = lua_interface->GetSpawn(state, 2);
  4137. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4138. Client* client = ((Player*)player)->GetClient();
  4139. if (client) {
  4140. ((GroundSpawn*)node)->ProcessHarvest(client);
  4141. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4142. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4143. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4144. }
  4145. }
  4146. }
  4147. else if (player && player->IsPlayer()) {
  4148. Client* client = ((Player*)player)->GetClient();
  4149. if (client)
  4150. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4151. }
  4152. lua_interface->ResetFunctionStack(state);
  4153. return 0;
  4154. }
  4155. int EQ2Emu_lua_Bind(lua_State* state) {
  4156. if (!lua_interface)
  4157. return 0;
  4158. Spawn* spawn = lua_interface->GetSpawn(state);
  4159. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4160. float x = lua_interface->GetFloatValue(state, 3);
  4161. float y = lua_interface->GetFloatValue(state, 4);
  4162. float z = lua_interface->GetFloatValue(state, 5);
  4163. float h = lua_interface->GetFloatValue(state, 6);
  4164. lua_interface->ResetFunctionStack(state);
  4165. if (!spawn) {
  4166. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4167. return 0;
  4168. }
  4169. if (!spawn->IsPlayer()) {
  4170. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4171. return 0;
  4172. }
  4173. if (zone_id == 0) {
  4174. Client* client = ((Player*)spawn)->GetClient();
  4175. if (!client) {
  4176. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4177. return 0;
  4178. }
  4179. if (!client->Bind())
  4180. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4181. }
  4182. else {
  4183. Player* player = (Player*)spawn;
  4184. player->GetPlayerInfo()->SetBindZone(zone_id);
  4185. player->GetPlayerInfo()->SetBindX(x);
  4186. player->GetPlayerInfo()->SetBindY(y);
  4187. player->GetPlayerInfo()->SetBindZ(z);
  4188. player->GetPlayerInfo()->SetBindHeading(h);
  4189. }
  4190. return 0;
  4191. }
  4192. int EQ2Emu_lua_Gate(lua_State* state) {
  4193. if (!lua_interface)
  4194. return 0;
  4195. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4196. Spawn* spawn = lua_interface->GetSpawn(state);
  4197. lua_interface->ResetFunctionStack(state);
  4198. if (spawn) {
  4199. if (spawn->IsPlayer()) {
  4200. Client* client = ((Player*)spawn)->GetClient();
  4201. if (client) {
  4202. if (!client->Gate((spell != nullptr) ? true : false))
  4203. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4204. }
  4205. }
  4206. }
  4207. return 0;
  4208. }
  4209. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4210. if (!lua_interface)
  4211. return 0;
  4212. bool ret = false;
  4213. Spawn* spawn = lua_interface->GetSpawn(state);
  4214. lua_interface->ResetFunctionStack(state);
  4215. if (spawn) {
  4216. if (spawn->IsPlayer()) {
  4217. Client* client = ((Player*)spawn)->GetClient();
  4218. if (client)
  4219. ret = client->BindAllowed();
  4220. }
  4221. }
  4222. lua_interface->SetBooleanValue(state, ret);
  4223. return 1;
  4224. }
  4225. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4226. if (!lua_interface)
  4227. return 0;
  4228. bool ret = false;
  4229. Spawn* spawn = lua_interface->GetSpawn(state);
  4230. lua_interface->ResetFunctionStack(state);
  4231. if (spawn) {
  4232. if (spawn->IsPlayer()) {
  4233. Client* client = ((Player*)spawn)->GetClient();
  4234. ZoneServer* zone = lua_interface->GetZone(state);
  4235. if (client && zone){
  4236. ret = zone->GetCanGate();
  4237. }
  4238. }
  4239. }
  4240. lua_interface->SetBooleanValue(state, ret);
  4241. return 1;
  4242. }
  4243. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4244. Spawn* spawn = lua_interface->GetSpawn(state);
  4245. lua_interface->ResetFunctionStack(state);
  4246. if (spawn) {
  4247. lua_interface->SetBooleanValue(state, spawn->Alive());
  4248. return 1;
  4249. }
  4250. return 0;
  4251. }
  4252. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4253. if (!lua_interface)
  4254. return 0;
  4255. Spawn* spawn = lua_interface->GetSpawn(state);
  4256. lua_interface->ResetFunctionStack(state);
  4257. if (spawn && spawn->IsEntity()) {
  4258. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4259. return 1;
  4260. }
  4261. return 0;
  4262. }
  4263. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4264. Spawn* spawn = lua_interface->GetSpawn(state);
  4265. string message = lua_interface->GetStringValue(state, 2);
  4266. string color_str = lua_interface->GetStringValue(state, 3);
  4267. lua_interface->ResetFunctionStack(state);
  4268. int8 color = CHANNEL_NARRATIVE;
  4269. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4270. Client* client = ((Player*)spawn)->GetClient();
  4271. if (client) {
  4272. if (color_str.length() > 0) {
  4273. // leave for backwards compat, but all future should just use the number
  4274. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4275. color = CHANNEL_COLOR_RED;
  4276. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4277. color = CHANNEL_COLOR_YELLOW;
  4278. else
  4279. {
  4280. // use a number to specify the channel as per Commands/Commands.h defines
  4281. color = (int8)atoul(color_str.c_str());
  4282. }
  4283. }
  4284. client->SimpleMessage(color, message.c_str());
  4285. }
  4286. }
  4287. return 0;
  4288. }
  4289. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4290. Spawn* spawn = lua_interface->GetSpawn(state);
  4291. string message = lua_interface->GetStringValue(state, 2);
  4292. int8 red = lua_interface->GetInt8Value(state, 3);
  4293. int8 green = lua_interface->GetInt8Value(state, 4);
  4294. int8 blue = lua_interface->GetInt8Value(state, 5);
  4295. lua_interface->ResetFunctionStack(state);
  4296. if (!spawn) {
  4297. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4298. return 0;
  4299. }
  4300. if (!spawn->IsPlayer()) {
  4301. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not a player.", lua_interface->GetScriptName(state));
  4302. return 0;
  4303. }
  4304. int32 words = ::CountWordsInString(message.c_str());
  4305. if (words < 5)
  4306. words = 5;
  4307. Client* client = ((Player*)spawn)->GetClient();
  4308. if (client)
  4309. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4310. return 0;
  4311. }
  4312. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4313. Spawn* spawn = lua_interface->GetSpawn(state);
  4314. int8 param = lua_interface->GetInt8Value(state, 2);
  4315. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4316. int8 value = lua_interface->GetInt8Value(state, 4);
  4317. lua_interface->ResetFunctionStack(state);
  4318. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4319. Client* client = ((Player*)spawn)->GetClient();
  4320. if (client) {
  4321. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4322. switch (param) {
  4323. case 1: {
  4324. packet->setDataByName("parameter1", param_value);
  4325. break;
  4326. }
  4327. case 2: {
  4328. packet->setDataByName("parameter2", param_value);
  4329. break;
  4330. }
  4331. case 3: {
  4332. packet->setDataByName("parameter3", param_value);
  4333. break;
  4334. }
  4335. case 4: {
  4336. packet->setDataByName("parameter4", param_value);
  4337. break;
  4338. }
  4339. case 5: {
  4340. packet->setDataByName("parameter5", param_value);
  4341. break;
  4342. }
  4343. }
  4344. packet->setDataByName("value", value);
  4345. client->QueuePacket(packet->serialize());
  4346. safe_delete(packet);
  4347. }
  4348. }
  4349. return 0;
  4350. }
  4351. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4352. Spawn* spawn = lua_interface->GetSpawn(state);
  4353. lua_interface->ResetFunctionStack(state);
  4354. if (spawn && spawn->IsPlayer()) {
  4355. if (((Player*)spawn)->GetIsTracking())
  4356. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4357. else
  4358. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4359. }
  4360. return 0;
  4361. }
  4362. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4363. Spawn* player = lua_interface->GetSpawn(state);
  4364. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4365. string name = lua_interface->GetStringValue(state, 3);
  4366. float distance = lua_interface->GetFloatValue(state, 4);
  4367. string command = lua_interface->GetStringValue(state, 5);
  4368. string error_text = lua_interface->GetStringValue(state, 6);
  4369. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4370. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4371. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4372. lua_interface->ResetFunctionStack(state);
  4373. if (spawn) {
  4374. if (distance == 0)
  4375. distance = 10.0f;
  4376. if (command.length() == 0)
  4377. command = name;
  4378. if (command.length() < 1 && name.length() < 1)
  4379. {
  4380. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4381. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4382. spawn->RemovePrimaryCommands();
  4383. }
  4384. else
  4385. {
  4386. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4387. }
  4388. }
  4389. return 0;
  4390. }
  4391. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4392. if (!lua_interface)
  4393. return 0;
  4394. Spawn* player = lua_interface->GetSpawn(state);
  4395. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4396. int16 tier = lua_interface->GetInt16Value(state, 3);
  4397. lua_interface->ResetFunctionStack(state);
  4398. if (player && player->IsPlayer()) {
  4399. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4400. return 1;
  4401. }
  4402. return 0;
  4403. }
  4404. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4405. if (!lua_interface)
  4406. return 0;
  4407. Spawn* player = lua_interface->GetSpawn(state);
  4408. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4409. int16 tier = lua_interface->GetInt16Value(state, 3);
  4410. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4411. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4412. bool add_to_hotbar = true;
  4413. if (num_args > 4) {
  4414. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4415. }
  4416. lua_interface->ResetFunctionStack(state);
  4417. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4418. if (player && spell && player->IsPlayer()) {
  4419. Client* client = player->GetClient();
  4420. if (client) {
  4421. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4422. {
  4423. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4424. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4425. client->GetPlayer()->UnlockSpell(spell);
  4426. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4427. }
  4428. else
  4429. {
  4430. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4431. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4432. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4433. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4434. client->GetPlayer()->UnlockSpell(spell);
  4435. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4436. }
  4437. //if (client ) {
  4438. // ((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);
  4439. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4440. if (outapp)
  4441. client->QueuePacket(outapp);
  4442. }
  4443. }
  4444. return 0;
  4445. }
  4446. int EQ2Emu_lua_DeleteSpellBook(lua_State* state) {
  4447. if (!lua_interface)
  4448. return 0;
  4449. Spawn* player = lua_interface->GetSpawn(state);
  4450. int8 type_selection = lua_interface->GetInt8Value(state, 2);
  4451. lua_interface->ResetFunctionStack(state);
  4452. if (player && player->IsPlayer()) {
  4453. Client* client = player->GetClient();
  4454. if (client) {
  4455. ((Player*)player)->DeleteSpellBook(type_selection);
  4456. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4457. if (outapp)
  4458. client->QueuePacket(outapp);
  4459. }
  4460. }
  4461. return 0;
  4462. }
  4463. int EQ2Emu_lua_SendNewAdventureSpells(lua_State* state) {
  4464. if (!lua_interface)
  4465. return 0;
  4466. Spawn* player = lua_interface->GetSpawn(state);
  4467. lua_interface->ResetFunctionStack(state);
  4468. if (player && player->IsPlayer()) {
  4469. Client* client = player->GetClient();
  4470. if (client) {
  4471. client->SendNewAdventureSpells();
  4472. }
  4473. }
  4474. return 0;
  4475. }
  4476. int EQ2Emu_lua_SendNewTradeskillSpells(lua_State* state) {
  4477. if (!lua_interface)
  4478. return 0;
  4479. Spawn* player = lua_interface->GetSpawn(state);
  4480. lua_interface->ResetFunctionStack(state);
  4481. if (player && player->IsPlayer()) {
  4482. Client* client = player->GetClient();
  4483. if (client) {
  4484. client->SendNewTradeskillSpells();
  4485. }
  4486. }
  4487. return 0;
  4488. }
  4489. int EQ2Emu_lua_RemoveSpellBookEntry(lua_State* state) {
  4490. if (!lua_interface)
  4491. return 0;
  4492. Spawn* player = lua_interface->GetSpawn(state);
  4493. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4494. lua_interface->ResetFunctionStack(state);
  4495. if (player && player->IsPlayer()) {
  4496. SpellBookEntry* sbe = ((Player*)player)->GetSpellBookSpell(spellid);
  4497. Client* client = player->GetClient();
  4498. if (sbe && client) {
  4499. ((Player*)player)->RemoveSpellBookEntry(spellid);
  4500. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4501. if (outapp)
  4502. client->QueuePacket(outapp);
  4503. }
  4504. }
  4505. return 0;
  4506. }
  4507. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4508. if (!lua_interface)
  4509. return 0;
  4510. Spawn* player = lua_interface->GetSpawn(state);
  4511. lua_interface->ResetFunctionStack(state);
  4512. if (player && player->IsPlayer()) {
  4513. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4514. return 1;
  4515. }
  4516. return 0;
  4517. }
  4518. int EQ2Emu_lua_Attack(lua_State* state) {
  4519. if (lua_interface) {
  4520. Spawn* npc = lua_interface->GetSpawn(state);
  4521. Spawn* player = lua_interface->GetSpawn(state, 2);
  4522. lua_interface->ResetFunctionStack(state);
  4523. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4524. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4525. }
  4526. return 0;
  4527. }
  4528. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4529. if (lua_interface) {
  4530. Spawn* target = lua_interface->GetSpawn(state);
  4531. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4532. lua_interface->ResetFunctionStack(state);
  4533. if (target && target->GetZone())
  4534. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4535. }
  4536. return 0;
  4537. }
  4538. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4539. Spawn* player;
  4540. if (lua_interface) {
  4541. player = lua_interface->GetSpawn(state);
  4542. lua_interface->ResetFunctionStack(state);
  4543. if (player && player->IsPlayer()) {
  4544. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4545. return 1;
  4546. }
  4547. }
  4548. return 0;
  4549. }
  4550. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4551. Spawn* player;
  4552. Client* client;
  4553. if (lua_interface) {
  4554. player = lua_interface->GetSpawn(state);
  4555. lua_interface->ResetFunctionStack(state);
  4556. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4557. if ((client = ((Player*)player)->GetClient()))
  4558. client->HandInCollections();
  4559. }
  4560. return 0;
  4561. }
  4562. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4563. Spawn* widget;
  4564. if (lua_interface) {
  4565. widget = lua_interface->GetSpawn(state);
  4566. lua_interface->ResetFunctionStack(state);
  4567. if (widget && widget->IsWidget())
  4568. ((Widget*)widget)->HandleUse(nullptr, "");
  4569. }
  4570. return 0;
  4571. }
  4572. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4573. Spawn* spawn = 0;
  4574. int32 primary_list = 0;
  4575. int32 secondary_list = 0;
  4576. if (lua_interface) {
  4577. spawn = lua_interface->GetSpawn(state);
  4578. primary_list = lua_interface->GetInt32Value(state, 2);
  4579. secondary_list = lua_interface->GetInt32Value(state, 3);
  4580. lua_interface->ResetFunctionStack(state);
  4581. if (!spawn->IsNPC()) {
  4582. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4583. return 0;
  4584. }
  4585. NPC* npc = (NPC*)spawn;
  4586. npc->SetPrimarySpellList(primary_list);
  4587. npc->SetSecondarySpellList(secondary_list);
  4588. npc->SetSpells(world.GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4589. }
  4590. return 0;
  4591. }
  4592. int EQ2Emu_lua_GetPet(lua_State* state) {
  4593. if (!lua_interface)
  4594. return 0;
  4595. Spawn* spawn = lua_interface->GetSpawn(state);
  4596. lua_interface->ResetFunctionStack(state);
  4597. if (spawn) {
  4598. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4599. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4600. return 1;
  4601. }
  4602. }
  4603. return 0;
  4604. }
  4605. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4606. if (!lua_interface)
  4607. return 0;
  4608. Spawn* spawn = lua_interface->GetSpawn(state);
  4609. lua_interface->ResetFunctionStack(state);
  4610. if (spawn) {
  4611. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4612. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4613. return 1;
  4614. }
  4615. }
  4616. return 0;
  4617. }
  4618. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4619. if (!lua_interface)
  4620. return 0;
  4621. Spawn* spawn = lua_interface->GetSpawn(state);
  4622. lua_interface->ResetFunctionStack(state);
  4623. if (spawn) {
  4624. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4625. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4626. return 1;
  4627. }
  4628. }
  4629. return 0;
  4630. }
  4631. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4632. if (!lua_interface)
  4633. return 0;
  4634. Spawn* spawn = lua_interface->GetSpawn(state);
  4635. lua_interface->ResetFunctionStack(state);
  4636. if (spawn) {
  4637. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4638. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4639. return 1;
  4640. }
  4641. }
  4642. return 0;
  4643. }
  4644. int EQ2Emu_lua_Charm(lua_State* state) {
  4645. if (!lua_interface)
  4646. return 0;
  4647. Spawn* owner = lua_interface->GetSpawn(state);
  4648. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4649. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4650. lua_interface->ResetFunctionStack(state);
  4651. if (!luaspell) {
  4652. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4653. return 0;
  4654. }
  4655. if(luaspell->resisted) {
  4656. return 0;
  4657. }
  4658. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4659. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4660. pet->SetPet(true);
  4661. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4662. ((NPC*)pet)->SetOwner((Entity*)owner);
  4663. // If owner is player and player does not have a summoned pet set the players charsheet
  4664. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4665. Player* player = (Player*)owner;
  4666. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4667. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4668. player->GetInfoStruct()->set_pet_movement(2);
  4669. player->GetInfoStruct()->set_pet_behavior(3);
  4670. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4671. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4672. // Make sure the values get sent to the client
  4673. player->SetCharSheetChanged(true);
  4674. }
  4675. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4676. pet->SetSpawnScript("");
  4677. // Set faction to the same as the owner
  4678. pet->SetFactionID(owner->GetFactionID());
  4679. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4680. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4681. // Clear hate list
  4682. ((NPC*)pet)->Brain()->ClearHate();
  4683. // Set the brain to a pet brain
  4684. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4685. }
  4686. return 0;
  4687. }
  4688. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4689. if (!lua_interface)
  4690. return 0;
  4691. Spawn* spawn = lua_interface->GetSpawn(state);
  4692. lua_interface->ResetFunctionStack(state);
  4693. if (!spawn) {
  4694. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4695. return 0;
  4696. }
  4697. vector<Spawn*> groupMembers;
  4698. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4699. groupMembers = *spawn->GetSpawnGroup();
  4700. }
  4701. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4702. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4703. deque<GroupMemberInfo*>::iterator itr;
  4704. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4705. if (group)
  4706. {
  4707. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4708. deque<GroupMemberInfo*>* members = group->GetMembers();
  4709. GroupMemberInfo* info = 0;
  4710. for (itr = members->begin(); itr != members->end(); itr++) {
  4711. info = *itr;
  4712. if (info->client)
  4713. groupMembers.push_back(info->client->GetPlayer());
  4714. }
  4715. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4716. }
  4717. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4718. }
  4719. else
  4720. return 0;
  4721. lua_createtable(state, groupMembers.size(), 0);
  4722. int newTable = lua_gettop(state);
  4723. for (int32 i = 0; i < groupMembers.size(); i++) {
  4724. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4725. lua_rawseti(state, newTable, i + 1);
  4726. }
  4727. return 1;
  4728. }
  4729. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4730. if (!lua_interface)
  4731. return 0;
  4732. lua_interface->ResetFunctionStack(state);
  4733. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4734. lua_interface->SetOptionWindowValue(state, option_window);
  4735. return 1;
  4736. }
  4737. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4738. if (!lua_interface)
  4739. return 0;
  4740. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4741. if (option_window) {
  4742. OptionWindowOption option_window_option;
  4743. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4744. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4745. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4746. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4747. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4748. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4749. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4750. option_window->push_back(option_window_option);
  4751. }
  4752. lua_interface->ResetFunctionStack(state);
  4753. return 0;
  4754. }
  4755. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4756. if (!lua_interface)
  4757. return 0;
  4758. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4759. Spawn* player = lua_interface->GetSpawn(state, 2);
  4760. string window_title = lua_interface->GetStringValue(state, 3);
  4761. string cancel_command = lua_interface->GetStringValue(state, 4);
  4762. lua_interface->ResetFunctionStack(state);
  4763. if (!player->IsPlayer()) {
  4764. lua_interface->LogError("%s: LUA SendOptionWindow command error: spawn is not a player", lua_interface->GetScriptName(state));
  4765. return 0;
  4766. }
  4767. Client* client = ((Player*)player)->GetClient();
  4768. if (option_window && window_title.length() > 0 && client) {
  4769. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4770. if (!packet)
  4771. return 0;
  4772. packet->setDataByName("title_text", window_title.c_str());
  4773. if (cancel_command.length() > 0)
  4774. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4775. packet->setArrayLengthByName("num_selections", option_window->size());
  4776. vector<OptionWindowOption>::iterator itr;
  4777. int8 i = 0;
  4778. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4779. OptionWindowOption opt = *itr;
  4780. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4781. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4782. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4783. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4784. if (opt.optionCommand.length() > 0)
  4785. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4786. if (opt.optionConfirmTitle.length() > 0)
  4787. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4788. i++;
  4789. }
  4790. client->QueuePacket(packet->serialize());
  4791. lua_interface->SetLuaUserDataStale(option_window);
  4792. safe_delete(option_window);
  4793. safe_delete(packet);
  4794. }
  4795. return 0;
  4796. }
  4797. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4798. if (!lua_interface)
  4799. return 0;
  4800. Spawn* spawn = lua_interface->GetSpawn(state);
  4801. lua_interface->ResetFunctionStack(state);
  4802. if (spawn) {
  4803. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4804. return 1;
  4805. }
  4806. else
  4807. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4808. return 0;
  4809. }
  4810. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4811. if (!lua_interface)
  4812. return 0;
  4813. Spawn* spawn = lua_interface->GetSpawn(state);
  4814. lua_interface->ResetFunctionStack(state);
  4815. if (spawn) {
  4816. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4817. return 1;
  4818. }
  4819. else
  4820. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4821. return 0;
  4822. }
  4823. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4824. if (!lua_interface)
  4825. return 0;
  4826. Spawn* spawn = lua_interface->GetSpawn(state);
  4827. lua_interface->ResetFunctionStack(state);
  4828. if (spawn) {
  4829. int8 class_id = spawn->GetTradeskillClass();
  4830. // Need to add 42 for the offset in the array
  4831. class_id += 44;
  4832. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4833. return 1;
  4834. }
  4835. else
  4836. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4837. return 0;
  4838. }
  4839. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4840. if (!lua_interface)
  4841. return 0;
  4842. Spawn* spawn = lua_interface->GetSpawn(state);
  4843. int16 level = lua_interface->GetInt8Value(state, 2);
  4844. lua_interface->ResetFunctionStack(state);
  4845. if (spawn) {
  4846. if (spawn->IsPlayer() && ((Player*)spawn)->GetClient())
  4847. ((Player*)spawn)->GetClient()->ChangeTSLevel(spawn->GetTSLevel(), level);
  4848. else
  4849. spawn->SetTSLevel(level);
  4850. }
  4851. else
  4852. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4853. return 0;
  4854. }
  4855. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4856. if (!lua_interface)
  4857. return 0;
  4858. Spawn* spawn = lua_interface->GetSpawn(state);
  4859. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4860. lua_interface->ResetFunctionStack(state);
  4861. if (spawn) {
  4862. spawn->SetAttackable(attackable);
  4863. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4864. }
  4865. return 0;
  4866. }
  4867. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4868. // Check to see if we have a valid lua_interface
  4869. if (!lua_interface)
  4870. return 0;
  4871. // Get the spawn that is getting the pet
  4872. Spawn* spawn = lua_interface->GetSpawn(state);
  4873. // Get the DB ID of the pet
  4874. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4875. // The max level the pet can gain
  4876. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4877. // Get the spell that this command was called from
  4878. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4879. lua_interface->ResetFunctionStack(state);
  4880. // Check to make sure the spawn pointer is valid
  4881. if (!spawn) {
  4882. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4883. return 0;
  4884. }
  4885. // Check to make sure the spawn is an entity
  4886. if (!spawn->IsEntity()) {
  4887. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4888. return 0;
  4889. }
  4890. // Check to make sure the spawn doesn't already have a pet of this type
  4891. if (((Entity*)spawn)->GetPet()) {
  4892. if (spawn->IsPlayer()) {
  4893. Client* client = ((Player*)spawn)->GetClient();
  4894. if (client)
  4895. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4896. }
  4897. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4898. return 0;
  4899. }
  4900. // Check to see if the DB ID for the pet is set
  4901. if (pet_id == 0) {
  4902. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4903. return 0;
  4904. }
  4905. // Check to see if the pointer to the spell is valid
  4906. if (!luaspell) {
  4907. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4908. return 0;
  4909. }
  4910. if(luaspell->resisted) {
  4911. return 0;
  4912. }
  4913. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4914. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4915. if (!pet) {
  4916. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4917. return 0;
  4918. }
  4919. // Check to make sure the pet is an npc
  4920. if (!pet->IsNPC()) {
  4921. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4922. return 0;
  4923. }
  4924. // Spawn the pet at the same location as the owner
  4925. pet->SetX(spawn->GetX());
  4926. pet->SetY(spawn->GetY());
  4927. pet->SetZ(spawn->GetZ());
  4928. pet->SetLocation(spawn->GetLocation());
  4929. pet->SetHeading(spawn->GetHeading());
  4930. std::string petName = std::string("");
  4931. if(spawn->IsEntity()) {
  4932. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  4933. }
  4934. if(petName.size() < 1) {
  4935. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4936. petName = spawn->GetZone()->pet_names.at(rand_index);
  4937. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  4938. }
  4939. // If player set various values for the char sheet (pet window)
  4940. if (spawn->IsPlayer()) {
  4941. Player* player = (Player*)spawn;
  4942. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4943. player->GetInfoStruct()->set_pet_name(petName);
  4944. player->GetInfoStruct()->set_pet_movement(2);
  4945. player->GetInfoStruct()->set_pet_behavior(3);
  4946. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4947. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4948. // Make sure the values get sent to the client
  4949. player->SetCharSheetChanged(true);
  4950. }
  4951. // Set the pets name
  4952. pet->SetName(petName.c_str());
  4953. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4954. if (max_level > 0)
  4955. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4956. else
  4957. pet->SetLevel(spawn->GetLevel());
  4958. // Set the max level this pet can reach
  4959. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4960. ((NPC*)pet)->UpdateWeapons();
  4961. // Set the faction of the pet to the same faction as the owner
  4962. pet->SetFactionID(spawn->GetFactionID());
  4963. // Set the spawn as a pet
  4964. pet->SetPet(true);
  4965. // Give a pointer of the owner to the pet
  4966. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4967. // Give a pointer of the pet to the owner
  4968. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4969. // Set the pet type
  4970. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4971. // Set the spell id used to create this pet
  4972. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4973. // Set the spell tier used to create this pet
  4974. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4975. // Set the pets spawn type to 6
  4976. pet->SetSpawnType(6);
  4977. // Set the pets brain
  4978. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4979. // Check to see if the pet has a subtitle
  4980. if (strlen(pet->GetSubTitle()) > 0) {
  4981. // Add the players name to the front of the sub title
  4982. string pet_subtitle;
  4983. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4984. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4985. // Set the pets subtitle to the new one
  4986. pet->SetSubTitle(pet_subtitle.c_str());
  4987. }
  4988. // Add the "Pet Options" entity command to the pet
  4989. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4990. const char* spawn_script = world.GetSpawnScript(pet_id);
  4991. bool runScript = false;
  4992. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4993. runScript = true;
  4994. pet->SetSpawnScript(string(spawn_script));
  4995. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_PRESPAWN);
  4996. }
  4997. spawn->GetZone()->AddSpawn(pet);
  4998. if(runScript){
  4999. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_SPAWN);
  5000. }
  5001. // Set the pet as the return value for this function
  5002. lua_interface->SetSpawnValue(state, pet);
  5003. return 1;
  5004. }
  5005. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  5006. if (!lua_interface)
  5007. return 0;
  5008. Spawn* spawn = lua_interface->GetSpawn(state);
  5009. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5010. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5011. lua_interface->ResetFunctionStack(state);
  5012. if (!spawn) {
  5013. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5014. return 0;
  5015. }
  5016. if (!spawn->IsEntity()) {
  5017. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5018. return 0;
  5019. }
  5020. if (((Entity*)spawn)->GetDeityPet()) {
  5021. if (spawn->IsPlayer()) {
  5022. Client* client = ((Player*)spawn)->GetClient();
  5023. if (client)
  5024. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  5025. }
  5026. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5027. return 0;
  5028. }
  5029. if (pet_id == 0) {
  5030. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5031. return 0;
  5032. }
  5033. if (!luaspell) {
  5034. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5035. return 0;
  5036. }
  5037. if(luaspell->resisted) {
  5038. return 0;
  5039. }
  5040. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5041. if (!pet) {
  5042. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5043. return 0;
  5044. }
  5045. if (!pet->IsNPC()) {
  5046. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5047. return 0;
  5048. }
  5049. pet->SetX(spawn->GetX());
  5050. pet->SetY(spawn->GetY());
  5051. pet->SetZ(spawn->GetZ());
  5052. pet->SetLocation(spawn->GetLocation());
  5053. pet->SetHeading(spawn->GetHeading());
  5054. spawn->GetZone()->AddSpawn(pet);
  5055. string random_pet_name;
  5056. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5057. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5058. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5059. pet->SetName(random_pet_name.c_str());
  5060. pet->SetLevel(spawn->GetLevel());
  5061. pet->SetFactionID(spawn->GetFactionID());
  5062. pet->SetPet(true);
  5063. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  5064. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5065. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  5066. pet->SetSpawnType(6);
  5067. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5068. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5069. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5070. if (strlen(pet->GetSubTitle()) > 0) {
  5071. string pet_subtitle;
  5072. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5073. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5074. pet->SetSubTitle(pet_subtitle.c_str());
  5075. }
  5076. // deity and cosmetic pets are not attackable
  5077. pet->SetAttackable(false);
  5078. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5079. lua_interface->SetSpawnValue(state, pet);
  5080. return 1;
  5081. }
  5082. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  5083. if (!lua_interface)
  5084. return 0;
  5085. Spawn* spawn = lua_interface->GetSpawn(state);
  5086. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5087. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5088. lua_interface->ResetFunctionStack(state);
  5089. if (!spawn) {
  5090. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5091. return 0;
  5092. }
  5093. if (!spawn->IsEntity()) {
  5094. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5095. return 0;
  5096. }
  5097. if (((Entity*)spawn)->GetCosmeticPet()) {
  5098. if (spawn->IsPlayer()) {
  5099. Client* client = ((Player*)spawn)->GetClient();
  5100. if (client)
  5101. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  5102. }
  5103. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5104. return 0;
  5105. }
  5106. if (pet_id == 0) {
  5107. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5108. return 0;
  5109. }
  5110. if (!luaspell) {
  5111. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5112. return 0;
  5113. }
  5114. if(luaspell->resisted) {
  5115. return 0;
  5116. }
  5117. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5118. if (!pet) {
  5119. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5120. return 0;
  5121. }
  5122. if (!pet->IsNPC()) {
  5123. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5124. return 0;
  5125. }
  5126. pet->SetX(spawn->GetX());
  5127. pet->SetY(spawn->GetY());
  5128. pet->SetZ(spawn->GetZ());
  5129. pet->SetLocation(spawn->GetLocation());
  5130. pet->SetHeading(spawn->GetHeading());
  5131. spawn->GetZone()->AddSpawn(pet);
  5132. string random_pet_name;
  5133. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5134. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5135. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5136. pet->SetName(random_pet_name.c_str());
  5137. pet->SetLevel(spawn->GetLevel());
  5138. pet->SetFactionID(spawn->GetFactionID());
  5139. pet->SetPet(true);
  5140. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  5141. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5142. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5143. pet->SetSpawnType(6);
  5144. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5145. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5146. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5147. if (strlen(pet->GetSubTitle()) > 0) {
  5148. string pet_subtitle;
  5149. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5150. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5151. pet->SetSubTitle(pet_subtitle.c_str());
  5152. }
  5153. pet->SetAttackable(false);
  5154. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5155. lua_interface->SetSpawnValue(state, pet);
  5156. return 1;
  5157. }
  5158. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5159. if (!lua_interface)
  5160. return 0;
  5161. Spawn* spawn = lua_interface->GetSpawn(state);
  5162. lua_interface->ResetFunctionStack(state);
  5163. if (!spawn) {
  5164. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5165. return 0;
  5166. }
  5167. if (!spawn->IsPet()) {
  5168. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5169. return 0;
  5170. }
  5171. if (!((NPC*)spawn)->IsDismissing() && ((NPC*)spawn)->GetOwner())
  5172. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5173. return 0;
  5174. }
  5175. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5176. if (!lua_interface)
  5177. return 0;
  5178. Quest* quest = lua_interface->GetQuest(state);
  5179. if (!quest) {
  5180. 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));
  5181. lua_interface->ResetFunctionStack(state);
  5182. return 0;
  5183. }
  5184. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5185. lua_interface->ResetFunctionStack(state);
  5186. if (feather_color > 0)
  5187. quest->SetFeatherColor(feather_color);
  5188. return 0;
  5189. }
  5190. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5191. if (!lua_interface)
  5192. return 0;
  5193. Spawn* spawn = lua_interface->GetSpawn(state);
  5194. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5195. lua_interface->ResetFunctionStack(state);
  5196. if (!spawn) {
  5197. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5198. return 0;
  5199. }
  5200. if (!spawn2) {
  5201. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5202. return 0;
  5203. }
  5204. spawn->RemoveSpawnAccess(spawn2);
  5205. return 0;
  5206. }
  5207. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5208. if (!lua_interface)
  5209. return 0;
  5210. ZoneServer* zone = lua_interface->GetZone(state);
  5211. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5212. lua_interface->ResetFunctionStack(state);
  5213. if (!zone) {
  5214. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5215. return 0;
  5216. }
  5217. if (location_id == 0) {
  5218. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5219. return 0;
  5220. }
  5221. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5222. if (!location) {
  5223. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5224. return 0;
  5225. }
  5226. Spawn* spawn = 0;
  5227. if (location->entities[0]) {
  5228. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5229. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5230. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5231. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5232. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5233. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5234. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5235. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5236. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5237. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5238. if(spawn && spawn->IsOmittedByDBFlag())
  5239. {
  5240. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5241. safe_delete(spawn);
  5242. spawn = 0;
  5243. return 0;
  5244. }
  5245. if (spawn) {
  5246. const char* script = 0;
  5247. for (int x = 0; x < 3; x++) {
  5248. switch (x) {
  5249. case 0:
  5250. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5251. break;
  5252. case 1:
  5253. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5254. break;
  5255. case 2:
  5256. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5257. break;
  5258. }
  5259. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5260. spawn->SetSpawnScript(string(script));
  5261. break;
  5262. }
  5263. }
  5264. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5265. lua_interface->SetSpawnValue(state, spawn);
  5266. return 1;
  5267. }
  5268. else {
  5269. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5270. safe_delete(spawn);
  5271. }
  5272. }
  5273. return 0;
  5274. }
  5275. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5276. if (!lua_interface)
  5277. return 0;
  5278. Spawn* caster = lua_interface->GetSpawn(state);
  5279. Spawn* target = lua_interface->GetSpawn(state, 2);
  5280. int32 id = lua_interface->GetInt32Value(state, 3);
  5281. string command = lua_interface->GetStringValue(state, 4);
  5282. lua_interface->ResetFunctionStack(state);
  5283. if (!caster) {
  5284. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5285. return 0;
  5286. }
  5287. if (!target) {
  5288. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5289. return 0;
  5290. }
  5291. if (!caster->IsPlayer()) {
  5292. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5293. return 0;
  5294. }
  5295. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5296. if (!entity_command) {
  5297. 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());
  5298. return 0;
  5299. }
  5300. Client* client = ((Player*)caster)->GetClient();
  5301. if (!client) {
  5302. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5303. return 0;
  5304. }
  5305. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5306. return 0;
  5307. }
  5308. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5309. if (!lua_interface)
  5310. return 0;
  5311. Spawn* spawn = lua_interface->GetSpawn(state);
  5312. lua_interface->ResetFunctionStack(state);
  5313. if (!spawn) {
  5314. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5315. return 0;
  5316. }
  5317. if (!spawn->IsNPC()) {
  5318. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5319. return 0;
  5320. }
  5321. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5322. return 0;
  5323. }
  5324. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5325. if (!lua_interface)
  5326. return 0;
  5327. Spawn* spawn = lua_interface->GetSpawn(state);
  5328. int16 tick = lua_interface->GetInt16Value(state, 2);
  5329. lua_interface->ResetFunctionStack(state);
  5330. if (!spawn) {
  5331. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5332. return 0;
  5333. }
  5334. if (!spawn->IsNPC()) {
  5335. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5336. return 0;
  5337. }
  5338. if (tick < 20) {
  5339. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5340. return 0;
  5341. }
  5342. ((NPC*)spawn)->Brain()->SetTick(tick);
  5343. return 0;
  5344. }
  5345. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5346. if (!lua_interface)
  5347. return 0;
  5348. Spawn* spawn = lua_interface->GetSpawn(state);
  5349. Spawn* target = lua_interface->GetSpawn(state, 2);
  5350. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5351. lua_interface->ResetFunctionStack(state);
  5352. if (!spawn) {
  5353. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5354. return 0;
  5355. }
  5356. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5357. spawn->SetFollowTarget(target, follow_distance);
  5358. return 0;
  5359. }
  5360. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5361. if (!lua_interface)
  5362. return 0;
  5363. Spawn* spawn = lua_interface->GetSpawn(state);
  5364. lua_interface->ResetFunctionStack(state);
  5365. if (!spawn) {
  5366. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5367. return 0;
  5368. }
  5369. Spawn* target = spawn->GetFollowTarget();
  5370. if (target) {
  5371. lua_interface->SetSpawnValue(state, target);
  5372. return 1;
  5373. }
  5374. return 0;
  5375. }
  5376. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5377. if (!lua_interface)
  5378. return 0;
  5379. Spawn* spawn = lua_interface->GetSpawn(state);
  5380. lua_interface->ResetFunctionStack(state);
  5381. if (!spawn) {
  5382. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5383. return 0;
  5384. }
  5385. if (spawn->following)
  5386. spawn->following = false;
  5387. else
  5388. spawn->following = true;
  5389. return 0;
  5390. }
  5391. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5392. if (!lua_interface)
  5393. return 0;
  5394. Spawn* spawn = lua_interface->GetSpawn(state);
  5395. lua_interface->ResetFunctionStack(state);
  5396. if (!spawn) {
  5397. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5398. return 0;
  5399. }
  5400. lua_interface->SetBooleanValue(state, spawn->following);
  5401. return 1;
  5402. }
  5403. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5404. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5405. // I will attempt to explain how this function works for future refrence
  5406. // Fist lets make sure lua_interface is valid, if not return out
  5407. if (!lua_interface)
  5408. return 0;
  5409. // Next we grab the first 2 params same as we usually would
  5410. Spawn* spawn = lua_interface->GetSpawn(state);
  5411. string var = lua_interface->GetStringValue(state, 2);
  5412. // 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
  5413. // 1 = Spawn
  5414. // 2 = Zone
  5415. // 3 = Item
  5416. // 4 = Quest
  5417. // 5 = String
  5418. // 6 = nil (null)
  5419. int8 dataType = 0;
  5420. // Define pointers for each potential type
  5421. Spawn* spawnVal = 0;
  5422. ZoneServer* zone = 0;
  5423. Item* item = 0;
  5424. Quest* quest = 0;
  5425. string val;
  5426. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5427. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5428. // options window are also light user data be we do not handle those.
  5429. // We check with lua_islightuserdata(lua_State*, index)
  5430. if (lua_islightuserdata(state, 3)) {
  5431. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5432. // and convert it to LUAUserData*
  5433. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5434. // Check to make sure the data we got is valid, if not give an error
  5435. if (!data || !data->IsCorrectlyInitialized()) {
  5436. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5437. }
  5438. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5439. else if (data->IsSpawn()) {
  5440. spawnVal = data->spawn;
  5441. dataType = 1;
  5442. }
  5443. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5444. else if (data->IsZone()) {
  5445. zone = data->zone;
  5446. dataType = 2;
  5447. }
  5448. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5449. else if (data->IsItem()) {
  5450. item = data->item;
  5451. dataType = 3;
  5452. }
  5453. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5454. else if (data->IsQuest()) {
  5455. quest = data->quest;
  5456. dataType = 4;
  5457. }
  5458. }
  5459. // Wasn't light user data, check if it is nil(null)
  5460. else if (lua_isnil(state, 3)) {
  5461. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5462. dataType = 6;
  5463. }
  5464. // Wasn't light user data or nil (null), must be a string
  5465. else {
  5466. // Set the string and dataType variable
  5467. val = lua_interface->GetStringValue(state, 3);
  5468. dataType = 5;
  5469. }
  5470. lua_interface->ResetFunctionStack(state);
  5471. // We now have all the params, lets check to make sure they are valid
  5472. if (!spawn) {
  5473. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5474. return 0;
  5475. }
  5476. if (var.length() == 0) {
  5477. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5478. return 0;
  5479. }
  5480. if (dataType == 0) {
  5481. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5482. return 0;
  5483. }
  5484. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5485. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5486. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5487. switch (dataType) {
  5488. case 1:
  5489. // 1 = Spawn
  5490. spawn->AddTempVariable(var, spawnVal);
  5491. break;
  5492. case 2:
  5493. // 2 = Zone
  5494. spawn->AddTempVariable(var, zone);
  5495. break;
  5496. case 3:
  5497. // 3 = Item
  5498. spawn->AddTempVariable(var, item);
  5499. break;
  5500. case 4:
  5501. // 4 = Quest
  5502. spawn->AddTempVariable(var, quest);
  5503. break;
  5504. case 5:
  5505. // 5 = String
  5506. spawn->AddTempVariable(var, val);
  5507. break;
  5508. case 6:
  5509. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5510. spawn->DeleteTempVariable(var);
  5511. break;
  5512. }
  5513. // And we are done so return out
  5514. return 0;
  5515. }
  5516. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5517. if (!lua_interface)
  5518. return 0;
  5519. Spawn* spawn = lua_interface->GetSpawn(state);
  5520. string var = lua_interface->GetStringValue(state, 2);
  5521. lua_interface->ResetFunctionStack(state);
  5522. if (!spawn) {
  5523. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5524. return 0;
  5525. }
  5526. if (var.length() == 0) {
  5527. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5528. return 0;
  5529. }
  5530. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5531. int8 type = spawn->GetTempVariableType(var);
  5532. Spawn* spawn2 = 0;
  5533. ZoneServer* zone = 0;
  5534. Item* item = 0;
  5535. Quest* quest = 0;
  5536. // Set the lua function return value based on the type of data the variable contains
  5537. switch (type) {
  5538. case 1:
  5539. spawn2 = spawn->GetTempVariableSpawn(var);
  5540. if (!spawn2)
  5541. return 0;
  5542. lua_interface->SetSpawnValue(state, spawn2);
  5543. break;
  5544. case 2:
  5545. zone = spawn->GetTempVariableZone(var);
  5546. if (!zone)
  5547. return 0;
  5548. lua_interface->SetZoneValue(state, zone);
  5549. break;
  5550. case 3:
  5551. item = spawn->GetTempVariableItem(var);
  5552. if (!item)
  5553. return 0;
  5554. lua_interface->SetItemValue(state, item);
  5555. break;
  5556. case 4:
  5557. quest = spawn->GetTempVariableQuest(var);
  5558. if (!quest)
  5559. return 0;
  5560. lua_interface->SetQuestValue(state, quest);
  5561. break;
  5562. case 5:
  5563. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5564. break;
  5565. default:
  5566. // Not a valid type then the variable was not set so return out
  5567. return 0;
  5568. }
  5569. // Return value was set so return out
  5570. return 1;
  5571. }
  5572. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5573. {
  5574. if (!lua_interface)
  5575. return 0;
  5576. Quest* quest = lua_interface->GetQuest(state);
  5577. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5578. string description = lua_interface->GetStringValue(state, 3);
  5579. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5580. if (!quest) {
  5581. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5582. lua_interface->ResetFunctionStack(state);
  5583. lua_interface->SetBooleanValue(state, false);
  5584. return 1;
  5585. }
  5586. if (!spawn) {
  5587. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5588. lua_interface->ResetFunctionStack(state);
  5589. lua_interface->SetBooleanValue(state, false);
  5590. return 1;
  5591. }
  5592. if (!spawn->IsPlayer()) {
  5593. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5594. lua_interface->ResetFunctionStack(state);
  5595. lua_interface->SetBooleanValue(state, false);
  5596. return 1;
  5597. }
  5598. if (item_id == 0) {
  5599. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5600. lua_interface->ResetFunctionStack(state);
  5601. lua_interface->SetBooleanValue(state, false);
  5602. return 1;
  5603. }
  5604. Client* client = ((Player*)spawn)->GetClient();
  5605. if (!client) {
  5606. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given player spawn", lua_interface->GetScriptName(state));
  5607. lua_interface->ResetFunctionStack(state);
  5608. lua_interface->SetBooleanValue(state, false);
  5609. return 1;
  5610. }
  5611. Item* item = master_item_list.GetItem(item_id);
  5612. if (!item) {
  5613. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5614. lua_interface->ResetFunctionStack(state);
  5615. lua_interface->SetBooleanValue(state, false);
  5616. return 1;
  5617. }
  5618. Item* firstItem = new Item(item);
  5619. quest->AddTmpRewardItem(firstItem);
  5620. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5621. bool itemsAddedSuccessfully = true;
  5622. if(num_args > 4)
  5623. {
  5624. for(int8 n=5;n<num_args+1;n++)
  5625. {
  5626. int32 new_item = lua_interface->GetInt32Value(state, n);
  5627. Item* tmpItem = master_item_list.GetItem(new_item);
  5628. if(tmpItem)
  5629. {
  5630. Item* newTmpItem = new Item(tmpItem);
  5631. quest->AddTmpRewardItem(newTmpItem);
  5632. }
  5633. else
  5634. itemsAddedSuccessfully = false;
  5635. }
  5636. }
  5637. client->AddPendingQuestReward(quest, true, true, description); // queue for display
  5638. lua_interface->ResetFunctionStack(state);
  5639. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5640. return 1;
  5641. }
  5642. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5643. if (!lua_interface)
  5644. return 0;
  5645. Quest* quest = lua_interface->GetQuest(state);
  5646. lua_interface->ResetFunctionStack(state);
  5647. if (!quest) {
  5648. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5649. return 0;
  5650. }
  5651. quest->SetRepeatable(true);
  5652. return 0;
  5653. }
  5654. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5655. if (!lua_interface)
  5656. return 0;
  5657. Spawn* spawn = lua_interface->GetSpawn(state);
  5658. lua_interface->ResetFunctionStack(state);
  5659. if (!spawn) {
  5660. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5661. return 0;
  5662. }
  5663. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5664. string ret = classes.GetClassNameCase(base_class);
  5665. if (ret.length() > 0) {
  5666. lua_interface->SetStringValue(state, ret.c_str());
  5667. return 1;
  5668. }
  5669. return 0;
  5670. }
  5671. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5672. if (!lua_interface)
  5673. return 0;
  5674. Spawn* player = lua_interface->GetSpawn(state);
  5675. lua_interface->ResetFunctionStack(state);
  5676. if (player && player->IsPlayer()) {
  5677. Client* client = player->GetClient();
  5678. if (client)
  5679. client->SendWaypoints();
  5680. }
  5681. return 0;
  5682. }
  5683. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5684. if (!lua_interface)
  5685. return 0;
  5686. Spawn* player = lua_interface->GetSpawn(state);
  5687. string name = lua_interface->GetStringValue(state, 2);
  5688. int32 type = lua_interface->GetInt32Value(state, 3);
  5689. lua_interface->ResetFunctionStack(state);
  5690. if (type == 0)
  5691. type = 2;
  5692. if (name.length() > 0) {
  5693. if (player && player->IsPlayer()) {
  5694. Client* client = player->GetClient();
  5695. if (client)
  5696. client->AddWaypoint(name, type);
  5697. }
  5698. }
  5699. return 0;
  5700. }
  5701. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5702. if (!lua_interface)
  5703. return 0;
  5704. Spawn* player = lua_interface->GetSpawn(state);
  5705. string name = lua_interface->GetStringValue(state, 2);
  5706. lua_interface->ResetFunctionStack(state);
  5707. if (name.length() > 0) {
  5708. if (player && player->IsPlayer()) {
  5709. Client* client = player->GetClient();
  5710. if (client)
  5711. client->RemoveWaypoint(name);
  5712. }
  5713. }
  5714. return 0;
  5715. }
  5716. int EQ2Emu_lua_AddWard(lua_State* state) {
  5717. if (!lua_interface)
  5718. return 0;
  5719. int32 damage = lua_interface->GetInt32Value(state);
  5720. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5721. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5722. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5723. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5724. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5725. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5726. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5727. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5728. lua_interface->ResetFunctionStack(state);
  5729. if(!spell || spell->resisted) {
  5730. return 0;
  5731. }
  5732. bool ward_was_added = false;
  5733. ZoneServer* zone = spell->caster->GetZone();
  5734. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5735. for (int32 i = 0; i < spell->targets.size(); i++) {
  5736. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5737. if (!target)
  5738. continue;
  5739. if (target->IsEntity()) {
  5740. // If the ward is already active remove it
  5741. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5742. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5743. // Create new ward info
  5744. WardInfo* ward = new WardInfo;
  5745. ward->Spell = spell;
  5746. ward->BaseDamage = damage;
  5747. ward->DamageLeft = damage;
  5748. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5749. ward->keepWard = keepWard;
  5750. ward->WardType = wardType;
  5751. if (damageAbsorptionPercent > 100)
  5752. damageAbsorptionPercent = 100;
  5753. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5754. if (damageAbsorptionMaxHealthPercent > 100)
  5755. damageAbsorptionMaxHealthPercent = 100;
  5756. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5757. ward->RedirectDamagePercent = redirectDamagePercent;
  5758. ward->LastRedirectDamage = 0;
  5759. ward->LastAbsorbedDamage = 0;
  5760. ward->HitCount = 0;
  5761. spell->num_triggers = maxHitCount;
  5762. spell->had_triggers = true;
  5763. spell->cancel_after_all_triggers = false;
  5764. ward->MaxHitCount = maxHitCount;
  5765. ward->RoundTriggered = false;
  5766. if (wardType == WARD_TYPE_MAGICAL)
  5767. ward->DamageType = damageTypes;
  5768. // Add the ward to the entity
  5769. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5770. ward_was_added = true;
  5771. }
  5772. }
  5773. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5774. if (ward_was_added && spell->caster->IsPlayer()) {
  5775. spell->had_dmg_remaining = true;
  5776. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, damage, 1);
  5777. }
  5778. return 0;
  5779. }
  5780. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5781. if (!lua_interface)
  5782. return 0;
  5783. int32 amount = lua_interface->GetInt32Value(state);
  5784. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5785. lua_interface->ResetFunctionStack(state);
  5786. WardInfo* ward = 0;
  5787. if(!spell || spell->resisted) {
  5788. return 0;
  5789. }
  5790. ZoneServer* zone = spell->caster->GetZone();
  5791. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5792. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5793. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5794. ward = target->GetWard(spell->spell->GetSpellID());
  5795. if (target && ward) {
  5796. ward->DamageLeft += amount;
  5797. if (ward->DamageLeft > ward->BaseDamage)
  5798. ward->DamageLeft = ward->BaseDamage;
  5799. for (int32 i = 0; i < spell->targets.size(); i++) {
  5800. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5801. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5802. }
  5803. }
  5804. }
  5805. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5806. if (ward && spell->caster->IsPlayer())
  5807. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
  5808. return 0;
  5809. }
  5810. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5811. if (!lua_interface)
  5812. return 0;
  5813. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5814. lua_interface->ResetFunctionStack(state);
  5815. if (!spell) {
  5816. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5817. return 0;
  5818. }
  5819. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5820. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5821. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5822. if (ward) {
  5823. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5824. return 1;
  5825. }
  5826. }
  5827. return 0;
  5828. }
  5829. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5830. if (!lua_interface)
  5831. return 0;
  5832. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5833. if (!spell) {
  5834. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5835. lua_interface->ResetFunctionStack(state);
  5836. return 0;
  5837. }
  5838. string type = lua_interface->GetStringValue(state, 2);
  5839. lua_interface->ResetFunctionStack(state);
  5840. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5841. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5842. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5843. if (ward) {
  5844. if (boost::iequals(type, "damageleft"))
  5845. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5846. else if (boost::iequals(type, "basedamage"))
  5847. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5848. else if (boost::iequals(type, "keepward"))
  5849. lua_interface->SetBooleanValue(state, ward->keepWard);
  5850. else if (boost::iequals(type, "wardtype"))
  5851. lua_interface->SetInt32Value(state, ward->WardType);
  5852. else if (boost::iequals(type, "dmgabsorptionpct"))
  5853. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5854. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5855. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5856. else if (boost::iequals(type, "redirectdamagepercent"))
  5857. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5858. else if (boost::iequals(type, "lastredirectdamage"))
  5859. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5860. else if (boost::iequals(type, "lastabsorbeddamage"))
  5861. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5862. else if (boost::iequals(type, "hitcount"))
  5863. lua_interface->SetInt32Value(state, ward->HitCount);
  5864. else if (boost::iequals(type, "maxhitcount"))
  5865. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5866. else
  5867. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5868. return 1;
  5869. }
  5870. }
  5871. return 0;
  5872. }
  5873. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5874. if (!lua_interface)
  5875. return 0;
  5876. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5877. lua_interface->ResetFunctionStack(state);
  5878. if(!spell) {
  5879. return 0;
  5880. }
  5881. ZoneServer* zone = spell->caster->GetZone();
  5882. Spawn* target = 0;
  5883. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5884. for (int32 i = 0; i < spell->targets.size(); i++) {
  5885. target = zone->GetSpawnByID(spell->targets.at(i));
  5886. if (target && target->IsEntity()) {
  5887. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5888. }
  5889. }
  5890. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5891. return 0;
  5892. }
  5893. int EQ2Emu_lua_Interrupt(lua_State* state)
  5894. {
  5895. if (!lua_interface)
  5896. return 0;
  5897. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5898. Spawn* target = lua_interface->GetSpawn(state, 2);
  5899. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5900. lua_interface->ResetFunctionStack(state);
  5901. if (!caster)
  5902. {
  5903. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5904. return 0;
  5905. }
  5906. if (!target)
  5907. {
  5908. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5909. return 0;
  5910. }
  5911. if (!spell) {
  5912. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5913. return 0;
  5914. }
  5915. if (!target->IsEntity() && !spell)
  5916. {
  5917. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5918. return 0;
  5919. }
  5920. if (!target && spell) {
  5921. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5922. for (int8 i = 0; i < spell->targets.size(); i++) {
  5923. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5924. if (!target || !target->IsEntity())
  5925. continue;
  5926. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5927. }
  5928. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5929. }
  5930. else
  5931. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5932. return 0;
  5933. }
  5934. int EQ2Emu_lua_Stealth(lua_State* state) {
  5935. if (!lua_interface)
  5936. return 0;
  5937. int8 type = lua_interface->GetInt8Value(state);
  5938. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5939. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5940. lua_interface->ResetFunctionStack(state);
  5941. if (!spell) {
  5942. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5943. return 0;
  5944. }
  5945. ZoneServer* zone = spell->caster->GetZone();
  5946. if (spawn) {
  5947. if (spawn->IsEntity()) {
  5948. if (type == 1) {
  5949. ((Entity*)spawn)->AddStealthSpell(spell);
  5950. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5951. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5952. }
  5953. else if (type == 2) {
  5954. ((Entity*)spawn)->AddInvisSpell(spell);
  5955. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5956. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5957. }
  5958. return 0;
  5959. }
  5960. else {
  5961. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5962. return 0;
  5963. }
  5964. }
  5965. else {
  5966. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5967. for (int32 i = 0; i < spell->targets.size(); i++) {
  5968. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5969. if (!spawn || !spawn->IsEntity())
  5970. continue;
  5971. if (type == 1) {
  5972. ((Entity*)spawn)->AddStealthSpell(spell);
  5973. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5974. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5975. }
  5976. else if (type == 2) {
  5977. ((Entity*)spawn)->AddInvisSpell(spell);
  5978. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5979. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5980. }
  5981. else {
  5982. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5983. break;
  5984. }
  5985. }
  5986. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5987. }
  5988. return 0;
  5989. }
  5990. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5991. if (!lua_interface)
  5992. return 0;
  5993. Spawn* spawn = lua_interface->GetSpawn(state);
  5994. lua_interface->ResetFunctionStack(state);
  5995. if (!spawn) {
  5996. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5997. return 0;
  5998. }
  5999. if (spawn->IsEntity()) {
  6000. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  6001. return 1;
  6002. }
  6003. else
  6004. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  6005. return 0;
  6006. }
  6007. int EQ2Emu_lua_IsInvis(lua_State* state) {
  6008. if (!lua_interface)
  6009. return 0;
  6010. Spawn* spawn = lua_interface->GetSpawn(state);
  6011. lua_interface->ResetFunctionStack(state);
  6012. if (!spawn) {
  6013. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  6014. return 0;
  6015. }
  6016. if (spawn->IsEntity()) {
  6017. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  6018. return 1;
  6019. }
  6020. else
  6021. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  6022. return 0;
  6023. }
  6024. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  6025. if (!lua_interface)
  6026. return 0;
  6027. Spawn* player = lua_interface->GetSpawn(state);
  6028. int32 item_id = lua_interface->GetInt32Value(state, 2);
  6029. lua_interface->ResetFunctionStack(state);
  6030. if (!player->IsPlayer()) {
  6031. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  6032. return 0;
  6033. }
  6034. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  6035. return 1;
  6036. }
  6037. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  6038. if (!lua_interface)
  6039. return 0;
  6040. Spawn* spawn = lua_interface->GetSpawn(state);
  6041. int8 slot = lua_interface->GetInt8Value(state, 2);
  6042. lua_interface->ResetFunctionStack(state);
  6043. if (!spawn) {
  6044. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6045. return 0;
  6046. }
  6047. if (!spawn->IsEntity()) {
  6048. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6049. return 0;
  6050. }
  6051. Item* item = ((Entity*)spawn)->GetEquipmentList()->GetItem(slot);
  6052. if (!item) {
  6053. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  6054. return 0;
  6055. }
  6056. lua_interface->SetItemValue(state, item);
  6057. return 1;
  6058. }
  6059. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  6060. if (!lua_interface)
  6061. return 0;
  6062. Spawn* player = lua_interface->GetSpawn(state);
  6063. int32 id = lua_interface->GetInt32Value(state, 2);
  6064. lua_interface->ResetFunctionStack(state);
  6065. if (!player) {
  6066. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6067. return 0;
  6068. }
  6069. if (!player->IsPlayer()) {
  6070. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6071. return 0;
  6072. }
  6073. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  6074. if (!item) {
  6075. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  6076. return 0;
  6077. }
  6078. lua_interface->SetItemValue(state, item);
  6079. return 1;
  6080. }
  6081. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  6082. if (!lua_interface)
  6083. return 0;
  6084. Spawn* spawn = lua_interface->GetSpawn(state);
  6085. int8 slot = lua_interface->GetInt8Value(state, 2);
  6086. int32 item_id = lua_interface->GetInt32Value(state, 3);
  6087. lua_interface->ResetFunctionStack(state);
  6088. if (!spawn) {
  6089. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6090. return 0;
  6091. }
  6092. if (!spawn->IsEntity()) {
  6093. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6094. return 0;
  6095. }
  6096. Item* item = master_item_list.GetItem(item_id);
  6097. if (!item) {
  6098. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  6099. return 0;
  6100. }
  6101. Item* copy = new Item(item);
  6102. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  6103. if(result)
  6104. {
  6105. ((Entity*)spawn)->SetEquipment(copy, slot);
  6106. spawn->vis_changed = true;
  6107. if(spawn->IsPlayer())
  6108. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6109. }
  6110. else
  6111. {
  6112. safe_delete(copy);
  6113. }
  6114. lua_interface->SetBooleanValue(state, result);
  6115. return 1;
  6116. }
  6117. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  6118. if (!lua_interface)
  6119. return 0;
  6120. Spawn* spawn = lua_interface->GetSpawn(state);
  6121. int8 slot = lua_interface->GetInt8Value(state, 2);
  6122. Item* item = lua_interface->GetItem(state, 3);
  6123. lua_interface->ResetFunctionStack(state);
  6124. if (!spawn) {
  6125. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  6126. return 0;
  6127. }
  6128. if (!spawn->IsEntity()) {
  6129. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6130. return 0;
  6131. }
  6132. if (!item) {
  6133. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  6134. return 0;
  6135. }
  6136. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  6137. if(result)
  6138. {
  6139. ((Entity*)spawn)->SetEquipment(item, slot);
  6140. spawn->vis_changed = true;
  6141. if(spawn->IsPlayer())
  6142. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6143. }
  6144. lua_interface->SetBooleanValue(state, result);
  6145. return 1;
  6146. }
  6147. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  6148. if (!lua_interface)
  6149. return 0;
  6150. Spawn* spawn = lua_interface->GetSpawn(state);
  6151. int8 slot = lua_interface->GetInt8Value(state, 2);
  6152. bool no_delete_item = (lua_interface->GetBooleanValue(state, 3) == false); // if not set then we default to deleting it, otherwise if set to true we don't delete
  6153. lua_interface->ResetFunctionStack(state);
  6154. if (!spawn) {
  6155. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6156. return 0;
  6157. }
  6158. if (!spawn->IsEntity()) {
  6159. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6160. return 0;
  6161. }
  6162. if(slot >= NUM_SLOTS) {
  6163. lua_interface->LogError("%s: LUA UnequipSlot command error: wrong slot id given %u, max %u", lua_interface->GetScriptName(state), slot, NUM_SLOTS);
  6164. return 0;
  6165. }
  6166. if(spawn->IsPlayer() && ((Player*)spawn)->GetClient()) {
  6167. Item* item = ((Player*)spawn)->GetEquipmentList()->GetItem(slot);
  6168. if(item) {
  6169. item->save_needed = true;
  6170. if(no_delete_item) {
  6171. database.DeleteItem(((Player*)spawn)->GetClient()->GetCharacterID(), item, 0);
  6172. ((Player*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6173. }
  6174. else{
  6175. Client* client = ((Player*)spawn)->GetClient();
  6176. client->UnequipItem(item->details.index);
  6177. }
  6178. }
  6179. }
  6180. else
  6181. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6182. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  6183. spawn->vis_changed = true;
  6184. if(spawn->IsPlayer())
  6185. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6186. lua_interface->SetBooleanValue(state, true);
  6187. return 1;
  6188. }
  6189. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  6190. if (!lua_interface)
  6191. return 0;
  6192. Spawn* spawn = lua_interface->GetSpawn(state);
  6193. int8 slot = lua_interface->GetInt8Value(state, 2);
  6194. int16 type = lua_interface->GetInt16Value(state, 3);
  6195. int8 r = lua_interface->GetInt8Value(state, 4);
  6196. int8 g = lua_interface->GetInt8Value(state, 5);
  6197. int8 b = lua_interface->GetInt8Value(state, 6);
  6198. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6199. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6200. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6201. lua_interface->ResetFunctionStack(state);
  6202. if (!spawn) {
  6203. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6204. return 0;
  6205. }
  6206. if (!spawn->IsEntity()) {
  6207. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6208. return 0;
  6209. }
  6210. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6211. spawn->vis_changed = true;
  6212. lua_interface->SetBooleanValue(state, true);
  6213. return 1;
  6214. }
  6215. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6216. if (!lua_interface)
  6217. return 0;
  6218. Spawn* player = lua_interface->GetSpawn(state);
  6219. int32 id = lua_interface->GetInt32Value(state, 2);
  6220. int8 count = lua_interface->GetInt8Value(state, 3);
  6221. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6222. lua_interface->ResetFunctionStack(state);
  6223. if (!player) {
  6224. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6225. return 0;
  6226. }
  6227. if (!player->IsPlayer()) {
  6228. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6229. return 0;
  6230. }
  6231. if (!count)
  6232. count = 1;
  6233. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6234. if (!item) {
  6235. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6236. return 0;
  6237. }
  6238. lua_interface->SetItemValue(state, item);
  6239. return 1;
  6240. }
  6241. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6242. if (!lua_interface)
  6243. return 0;
  6244. Spawn* spawn = lua_interface->GetSpawn(state);
  6245. int32 anim = lua_interface->GetInt32Value(state, 2);
  6246. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6247. int8 type = lua_interface->GetInt8Value(state, 4);
  6248. lua_interface->ResetFunctionStack(state);
  6249. if (!spawn) {
  6250. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6251. return 0;
  6252. }
  6253. if (spawn2) {
  6254. if (spawn2->IsPlayer()) {
  6255. if (type != 1 && type != 2)
  6256. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6257. else
  6258. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6259. return 0;
  6260. }
  6261. else {
  6262. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6263. return 0;
  6264. }
  6265. }
  6266. else
  6267. spawn->GetZone()->PlayAnimation(spawn, anim);
  6268. return 0;
  6269. }
  6270. int EQ2Emu_lua_IsPet(lua_State* state) {
  6271. if (!lua_interface)
  6272. return 0;
  6273. Spawn* spawn = lua_interface->GetSpawn(state);
  6274. lua_interface->ResetFunctionStack(state);
  6275. if (!spawn) {
  6276. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6277. return 0;
  6278. }
  6279. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6280. return 1;
  6281. }
  6282. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6283. if (!lua_interface)
  6284. return 0;
  6285. Spawn* spawn = lua_interface->GetSpawn(state);
  6286. lua_interface->ResetFunctionStack(state);
  6287. if (!spawn) {
  6288. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6289. return 0;
  6290. }
  6291. if (!spawn->IsNPC()) {
  6292. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6293. return 0;
  6294. }
  6295. if (((NPC*)spawn)->GetOwner()) {
  6296. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6297. return 1;
  6298. }
  6299. return 0;
  6300. }
  6301. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6302. if (!lua_interface)
  6303. return 0;
  6304. Spawn* spawn = lua_interface->GetSpawn(state);
  6305. Spawn* target = lua_interface->GetSpawn(state, 2);
  6306. lua_interface->ResetFunctionStack(state);
  6307. if (!spawn) {
  6308. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6309. return 0;
  6310. }
  6311. if (!spawn) {
  6312. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6313. return 0;
  6314. }
  6315. spawn->SetTarget(target);
  6316. return 0;
  6317. }
  6318. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6319. if (!lua_interface)
  6320. return 0;
  6321. Spawn* spawn = lua_interface->GetSpawn(state);
  6322. bool val = lua_interface->GetBooleanValue(state, 2);
  6323. lua_interface->ResetFunctionStack(state);
  6324. if (!spawn) {
  6325. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6326. return 0;
  6327. }
  6328. if (!spawn->IsEntity()) {
  6329. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6330. return 0;
  6331. }
  6332. ((Entity*)spawn)->InCombat(val);
  6333. if (val) {
  6334. spawn->ClearRunningLocations();
  6335. spawn->CalculateRunningLocation(true);
  6336. }
  6337. return 0;
  6338. }
  6339. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6340. if (!lua_interface)
  6341. return 0;
  6342. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6343. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6344. lua_interface->ResetFunctionStack(state);
  6345. if (!spawn1) {
  6346. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6347. return 0;
  6348. }
  6349. if (!spawn2) {
  6350. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6351. return 0;
  6352. }
  6353. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6354. return 1;
  6355. }
  6356. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6357. if (!lua_interface)
  6358. return 0;
  6359. Spawn* spawn = lua_interface->GetSpawn(state);
  6360. lua_interface->ResetFunctionStack(state);
  6361. if (!spawn) {
  6362. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6363. return 0;
  6364. }
  6365. if (!spawn->IsNPC()) {
  6366. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6367. return 0;
  6368. }
  6369. ((NPC*)spawn)->ClearRunback();
  6370. return 0;
  6371. }
  6372. int EQ2Emu_lua_Runback(lua_State* state) {
  6373. if (!lua_interface)
  6374. return 0;
  6375. Spawn* spawn = lua_interface->GetSpawn(state);
  6376. lua_interface->ResetFunctionStack(state);
  6377. if (!spawn) {
  6378. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6379. return 0;
  6380. }
  6381. if (!spawn->IsNPC()) {
  6382. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6383. return 0;
  6384. }
  6385. ((NPC*)spawn)->Runback();
  6386. return 0;
  6387. }
  6388. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6389. if (!lua_interface)
  6390. return 0;
  6391. Spawn* spawn = lua_interface->GetSpawn(state);
  6392. lua_interface->ResetFunctionStack(state);
  6393. if (!spawn) {
  6394. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6395. return 0;
  6396. }
  6397. if (!spawn->IsNPC()) {
  6398. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6399. return 0;
  6400. }
  6401. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6402. return 1;
  6403. }
  6404. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6405. if (!lua_interface)
  6406. return 0;
  6407. Spawn* spawn = lua_interface->GetSpawn(state);
  6408. lua_interface->ResetFunctionStack(state);
  6409. if (!spawn) {
  6410. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6411. return 0;
  6412. }
  6413. if (!spawn->IsEntity()) {
  6414. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6415. return 0;
  6416. }
  6417. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6418. return 1;
  6419. }
  6420. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6421. if (!lua_interface)
  6422. return 0;
  6423. Spawn* spawn = lua_interface->GetSpawn(state);
  6424. lua_interface->ResetFunctionStack(state);
  6425. if (!spawn) {
  6426. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6427. return 0;
  6428. }
  6429. if (!spawn->IsEntity()) {
  6430. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6431. return 0;
  6432. }
  6433. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6434. return 1;
  6435. }
  6436. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6437. if (!lua_interface)
  6438. return 0;
  6439. Spawn* spawn = lua_interface->GetSpawn(state);
  6440. lua_interface->ResetFunctionStack(state);
  6441. if (!spawn) {
  6442. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6443. return 0;
  6444. }
  6445. if (!spawn->IsEntity()) {
  6446. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6447. return 0;
  6448. }
  6449. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6450. return 1;
  6451. }
  6452. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6453. if (!lua_interface)
  6454. return 0;
  6455. Spawn* spawn = lua_interface->GetSpawn(state);
  6456. lua_interface->ResetFunctionStack(state);
  6457. if (!spawn) {
  6458. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6459. return 0;
  6460. }
  6461. if (!spawn->IsEntity()) {
  6462. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6463. return 0;
  6464. }
  6465. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6466. return 1;
  6467. }
  6468. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6469. if (!lua_interface)
  6470. return 0;
  6471. Spawn* spawn = lua_interface->GetSpawn(state);
  6472. Spawn* target = lua_interface->GetSpawn(state, 2);
  6473. float distance = lua_interface->GetFloatValue(state, 3);
  6474. lua_interface->ResetFunctionStack(state);
  6475. if (!spawn) {
  6476. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6477. return 0;
  6478. }
  6479. if (!target) {
  6480. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6481. return 0;
  6482. }
  6483. if (!spawn->IsNPC()) {
  6484. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6485. return 0;
  6486. }
  6487. if (!target->IsEntity()) {
  6488. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6489. return 0;
  6490. }
  6491. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6492. return 1;
  6493. }
  6494. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6495. if (!lua_interface)
  6496. return 0;
  6497. Spawn* spawn = lua_interface->GetSpawn(state);
  6498. Spawn* target = lua_interface->GetSpawn(state, 2);
  6499. float distance = lua_interface->GetFloatValue(state, 3);
  6500. lua_interface->ResetFunctionStack(state);
  6501. if (!spawn) {
  6502. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6503. return 0;
  6504. }
  6505. if (!target) {
  6506. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6507. return 0;
  6508. }
  6509. if (!spawn->IsNPC()) {
  6510. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6511. return 0;
  6512. }
  6513. if (!target->IsEntity()) {
  6514. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6515. return 0;
  6516. }
  6517. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6518. return 0;
  6519. }
  6520. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6521. if (!lua_interface)
  6522. return 0;
  6523. Spawn* spawn = lua_interface->GetSpawn(state);
  6524. lua_interface->ResetFunctionStack(state);
  6525. if (!spawn) {
  6526. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6527. return 0;
  6528. }
  6529. if (!spawn->IsNPC()) {
  6530. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6531. return 0;
  6532. }
  6533. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6534. return 1;
  6535. }
  6536. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6537. if (!lua_interface)
  6538. return 0;
  6539. Spawn* spawn = lua_interface->GetSpawn(state);
  6540. lua_interface->ResetFunctionStack(state);
  6541. if (!spawn) {
  6542. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6543. return 0;
  6544. }
  6545. if (!spawn->IsNPC()) {
  6546. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6547. return 0;
  6548. }
  6549. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6550. return 1;
  6551. }
  6552. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6553. if (!lua_interface)
  6554. return 0;
  6555. Spawn* spawn = lua_interface->GetSpawn(state);
  6556. lua_interface->ResetFunctionStack(state);
  6557. if (!spawn) {
  6558. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6559. return 0;
  6560. }
  6561. if (!spawn->IsNPC()) {
  6562. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6563. return 0;
  6564. }
  6565. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6566. if (hated) {
  6567. lua_interface->SetSpawnValue(state, hated);
  6568. return 1;
  6569. }
  6570. return 0;
  6571. }
  6572. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6573. if (!lua_interface)
  6574. return 0;
  6575. Spawn* spawn = lua_interface->GetSpawn(state);
  6576. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6577. lua_interface->ResetFunctionStack(state);
  6578. if (!spawn) {
  6579. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6580. return 0;
  6581. }
  6582. if (!spawn->IsNPC()) {
  6583. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6584. return 0;
  6585. }
  6586. if (!hated) {
  6587. ((NPC*)spawn)->Brain()->ClearHate();
  6588. return 0;
  6589. }
  6590. else
  6591. {
  6592. if (!hated->IsEntity()) {
  6593. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6594. return 0;
  6595. }
  6596. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6597. return 0;
  6598. }
  6599. return 0;
  6600. }
  6601. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6602. if (!lua_interface)
  6603. return 0;
  6604. Spawn* spawn = lua_interface->GetSpawn(state);
  6605. lua_interface->ResetFunctionStack(state);
  6606. if (!spawn) {
  6607. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6608. return 0;
  6609. }
  6610. if (!spawn->IsNPC()) {
  6611. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6612. return 0;
  6613. }
  6614. ((NPC*)spawn)->Brain()->ClearEncounter();
  6615. return 0;
  6616. }
  6617. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6618. if (!lua_interface)
  6619. return 0;
  6620. Spawn* spawn = lua_interface->GetSpawn(state);
  6621. lua_interface->ResetFunctionStack(state);
  6622. if (!spawn) {
  6623. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6624. return 0;
  6625. }
  6626. if (!spawn->IsNPC()) {
  6627. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6628. return 0;
  6629. }
  6630. // Temp list to store hate list
  6631. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6632. if (encounterList->size() == 0) {
  6633. safe_delete(encounterList);
  6634. return 0;
  6635. }
  6636. lua_createtable(state, encounterList->size(), 0);
  6637. int newTable = lua_gettop(state);
  6638. for (int32 i = 0; i < encounterList->size(); i++) {
  6639. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6640. if (temp)
  6641. lua_interface->SetSpawnValue(state, temp);
  6642. lua_rawseti(state, newTable, i + 1);
  6643. }
  6644. safe_delete(encounterList);
  6645. return 1;
  6646. }
  6647. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6648. if (!lua_interface)
  6649. return 0;
  6650. Spawn* spawn = lua_interface->GetSpawn(state);
  6651. lua_interface->ResetFunctionStack(state);
  6652. if (!spawn) {
  6653. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6654. return 0;
  6655. }
  6656. if (!spawn->IsNPC()) {
  6657. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6658. return 0;
  6659. }
  6660. // Temp list to store hate list
  6661. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6662. if (hateList->size() == 0) {
  6663. safe_delete(hateList);
  6664. return 0;
  6665. }
  6666. lua_createtable(state, hateList->size(), 0);
  6667. int newTable = lua_gettop(state);
  6668. for (int32 i = 0; i < hateList->size(); i++) {
  6669. lua_interface->SetSpawnValue(state, hateList->at(i));
  6670. lua_rawseti(state, newTable, i + 1);
  6671. }
  6672. safe_delete(hateList);
  6673. return 1;
  6674. }
  6675. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6676. if (!lua_interface)
  6677. return 0;
  6678. Spawn* spawn = lua_interface->GetSpawn(state);
  6679. lua_interface->ResetFunctionStack(state);
  6680. if (!spawn) {
  6681. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6682. return 0;
  6683. }
  6684. if (spawn->IsPlayer()) {
  6685. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6686. lua_interface->SetBooleanValue(state, true);
  6687. else
  6688. lua_interface->SetBooleanValue(state, false);
  6689. return 1;
  6690. }
  6691. else {
  6692. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6693. return 1;
  6694. }
  6695. }
  6696. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6697. if (!lua_interface)
  6698. return 0;
  6699. Quest* quest = lua_interface->GetQuest(state);
  6700. lua_interface->ResetFunctionStack(state);
  6701. if (!quest) {
  6702. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6703. return 0;
  6704. }
  6705. quest->SetCompletedFlag(true);
  6706. return 0;
  6707. }
  6708. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6709. if (!lua_interface)
  6710. return 0;
  6711. Spawn* spawn = lua_interface->GetSpawn(state);
  6712. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6713. int8 tier = lua_interface->GetInt8Value(state, 3);
  6714. lua_interface->ResetFunctionStack(state);
  6715. if (!spawn) {
  6716. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6717. return 0;
  6718. }
  6719. if (!spawn->IsEntity()) {
  6720. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6721. return 0;
  6722. }
  6723. if (spellID == 0) {
  6724. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6725. return 0;
  6726. }
  6727. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6728. if (effect) {
  6729. if (tier > 0) {
  6730. // If a tier was passed chec to see if it is the same as the effect
  6731. if (tier == effect->tier)
  6732. lua_interface->SetBooleanValue(state, true);
  6733. else
  6734. lua_interface->SetBooleanValue(state, false);
  6735. return 1;
  6736. }
  6737. else {
  6738. // Have an effect but no tier was passed so return true
  6739. lua_interface->SetBooleanValue(state, true);
  6740. }
  6741. return 1;
  6742. }
  6743. // no effect so return false
  6744. lua_interface->SetBooleanValue(state, false);
  6745. return 1;
  6746. }
  6747. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6748. if (!lua_interface)
  6749. return 0;
  6750. Spawn* spawn = lua_interface->GetSpawn(state);
  6751. int32 id = lua_interface->GetInt32Value(state, 2);
  6752. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6753. lua_interface->ResetFunctionStack(state);
  6754. Spawn* spawn2 = 0;
  6755. vector<Spawn*> list;
  6756. if (!spawn) {
  6757. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6758. return 0;
  6759. }
  6760. //If zone not provided, use spawn's zone
  6761. if (!zone)
  6762. zone = spawn->GetZone();
  6763. list = zone->GetSpawnsByID(id);
  6764. if (list.size() == 0) {
  6765. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6766. return 0;
  6767. }
  6768. vector<Spawn*>::iterator itr = list.begin();
  6769. for (int8 i = 0; i < list.size(); i++) {
  6770. spawn2 = itr[i];
  6771. if (spawn2)
  6772. spawn2->AddAllowAccessSpawn(spawn);
  6773. }
  6774. return 0;
  6775. }
  6776. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6777. if (!lua_interface)
  6778. return 0;
  6779. Spawn* spawn = lua_interface->GetSpawn(state);
  6780. int32 id = lua_interface->GetInt32Value(state, 2);
  6781. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6782. lua_interface->ResetFunctionStack(state);
  6783. Spawn* spawn2 = 0;
  6784. if (!spawn) {
  6785. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6786. return 0;
  6787. }
  6788. //If zone not provided, use spawn's zone
  6789. if (!zone)
  6790. zone = spawn->GetZone();
  6791. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6792. vector<Spawn*>::iterator itr = list.begin();
  6793. if (list.size() == 0) {
  6794. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6795. return 0;
  6796. }
  6797. for (int8 i = 0; i < list.size(); i++) {
  6798. spawn2 = itr[i];
  6799. if (spawn2)
  6800. spawn2->RemoveSpawnAccess(spawn);
  6801. }
  6802. return 0;
  6803. }
  6804. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6805. if (!lua_interface)
  6806. return 0;
  6807. Quest* quest = lua_interface->GetQuest(state);
  6808. lua_interface->ResetFunctionStack(state);
  6809. if (!quest) {
  6810. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6811. return 0;
  6812. }
  6813. quest->SetYellowName(true);
  6814. return 0;
  6815. }
  6816. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6817. if (!lua_interface)
  6818. return 0;
  6819. Spawn* spawn = lua_interface->GetSpawn(state);
  6820. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6821. lua_interface->ResetFunctionStack(state);
  6822. if (!spawn) {
  6823. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6824. return 0;
  6825. }
  6826. if (!spawn->IsPlayer()) {
  6827. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6828. return 0;
  6829. }
  6830. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6831. return 1;
  6832. }
  6833. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6834. if (!lua_interface)
  6835. return 0;
  6836. Spawn* spawn = lua_interface->GetSpawn(state);
  6837. lua_interface->ResetFunctionStack(state);
  6838. if (!spawn) {
  6839. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6840. return 0;
  6841. }
  6842. if (!spawn->IsPlayer()) {
  6843. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6844. return 0;
  6845. }
  6846. ZoneServer* zone = spawn->GetZone();
  6847. if (!zone) {
  6848. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6849. return 0;
  6850. }
  6851. Instance_Type iType = zone->GetInstanceType();
  6852. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6853. iType == GROUP_LOCKOUT_INSTANCE ||
  6854. iType == RAID_LOCKOUT_INSTANCE ||
  6855. iType == SOLO_PERSIST_INSTANCE ||
  6856. iType == GROUP_PERSIST_INSTANCE ||
  6857. iType == RAID_PERSIST_INSTANCE) {
  6858. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6859. if (data) {
  6860. // Check to see if the timer has already been set, if it has return out.
  6861. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6862. return 0;
  6863. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6864. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6865. if(spawn->IsPlayer()) {
  6866. Client* client = ((Player*)spawn)->GetClient();
  6867. if (client) {
  6868. string time_msg = "";
  6869. int32 time = data->success_lockout_time;
  6870. int16 hour;
  6871. int8 min;
  6872. int8 sec;
  6873. hour = time / 3600;
  6874. time = time % 3600;
  6875. min = time / 60;
  6876. time = time % 60;
  6877. sec = time;
  6878. if (hour > 0) {
  6879. char temp[10];
  6880. sprintf(temp, " %i", hour);
  6881. time_msg.append(temp);
  6882. time_msg.append(" hour");
  6883. time_msg.append((hour > 1) ? "s" : "");
  6884. }
  6885. if (min > 0) {
  6886. char temp[5];
  6887. sprintf(temp, " %i", min);
  6888. time_msg.append(temp);
  6889. time_msg.append(" minute");
  6890. time_msg.append((min > 1) ? "s" : "");
  6891. }
  6892. // Only add seconds if minutes and hours are 0
  6893. if (hour == 0 && min == 0 && sec > 0) {
  6894. char temp[5];
  6895. sprintf(temp, " %i", sec);
  6896. time_msg.append(temp);
  6897. time_msg.append(" second");
  6898. time_msg.append((sec > 1) ? "s" : "");
  6899. }
  6900. 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());
  6901. }
  6902. else {
  6903. lua_interface->LogError("LUA SetSuccessTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6904. }
  6905. }
  6906. }
  6907. else
  6908. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6909. }
  6910. else
  6911. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6912. return 0;
  6913. }
  6914. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6915. if (!lua_interface)
  6916. return 0;
  6917. Spawn* spawn = lua_interface->GetSpawn(state);
  6918. lua_interface->ResetFunctionStack(state);
  6919. if (!spawn) {
  6920. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6921. return 0;
  6922. }
  6923. if (!spawn->IsPlayer()) {
  6924. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6925. return 0;
  6926. }
  6927. ZoneServer* zone = spawn->GetZone();
  6928. if (!zone) {
  6929. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6930. return 0;
  6931. }
  6932. Instance_Type iType = zone->GetInstanceType();
  6933. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6934. iType == GROUP_LOCKOUT_INSTANCE ||
  6935. iType == RAID_LOCKOUT_INSTANCE ||
  6936. iType == SOLO_PERSIST_INSTANCE ||
  6937. iType == GROUP_PERSIST_INSTANCE ||
  6938. iType == RAID_PERSIST_INSTANCE) {
  6939. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6940. if (data) {
  6941. // Check to see if the timer has already been set, if it has return out.
  6942. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6943. return 0;
  6944. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6945. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6946. if(spawn->IsPlayer()) {
  6947. Client* client = ((Player*)spawn)->GetClient();
  6948. if (client) {
  6949. string time_msg = "";
  6950. int32 time = data->failure_lockout_time;
  6951. int16 hour;
  6952. int8 min;
  6953. int8 sec;
  6954. hour = time / 3600;
  6955. time = time % 3600;
  6956. min = time / 60;
  6957. time = time % 60;
  6958. sec = time;
  6959. if (hour > 0) {
  6960. char temp[10];
  6961. sprintf(temp, " %i", hour);
  6962. time_msg.append(temp);
  6963. time_msg.append(" hour");
  6964. time_msg.append((hour > 1) ? "s" : "");
  6965. }
  6966. if (min > 0) {
  6967. char temp[5];
  6968. sprintf(temp, " %i", min);
  6969. time_msg.append(temp);
  6970. time_msg.append(" minute");
  6971. time_msg.append((min > 1) ? "s" : "");
  6972. }
  6973. // Only add seconds if minutes and hours are 0
  6974. if (hour == 0 && min == 0 && sec > 0) {
  6975. char temp[5];
  6976. sprintf(temp, " %i", sec);
  6977. time_msg.append(temp);
  6978. time_msg.append(" second");
  6979. time_msg.append((sec > 1) ? "s" : "");
  6980. }
  6981. 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());
  6982. }
  6983. }
  6984. else {
  6985. lua_interface->LogError("LUA SetFailureTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6986. }
  6987. }
  6988. else
  6989. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6990. }
  6991. else
  6992. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6993. return 0;
  6994. }
  6995. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6996. if (!lua_interface)
  6997. return 0;
  6998. Spawn* spawn = lua_interface->GetSpawn(state);
  6999. lua_interface->ResetFunctionStack(state);
  7000. if (!spawn) {
  7001. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  7002. return 0;
  7003. }
  7004. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  7005. return 1;
  7006. }
  7007. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  7008. if (!lua_interface)
  7009. return 0;
  7010. Spawn* player = lua_interface->GetSpawn(state);
  7011. Spawn* ground = lua_interface->GetSpawn(state, 2);
  7012. if (!player) {
  7013. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7014. lua_interface->ResetFunctionStack(state);
  7015. return 0;
  7016. }
  7017. if (!player->IsPlayer()) {
  7018. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  7019. lua_interface->ResetFunctionStack(state);
  7020. return 0;
  7021. }
  7022. if (!ground) {
  7023. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7024. lua_interface->ResetFunctionStack(state);
  7025. return 0;
  7026. }
  7027. if (!ground->IsGroundSpawn()) {
  7028. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  7029. lua_interface->ResetFunctionStack(state);
  7030. return 0;
  7031. }
  7032. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7033. if (!groundspawn_entries) {
  7034. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7035. lua_interface->ResetFunctionStack(state);
  7036. return 0;
  7037. }
  7038. Skill* skill = 0;
  7039. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  7040. if (collection_skill == "Collecting")
  7041. skill = ((Player*)player)->GetSkillByName("Gathering");
  7042. else
  7043. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  7044. if (!skill) {
  7045. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  7046. lua_interface->ResetFunctionStack(state);
  7047. return 0;
  7048. }
  7049. vector<GroundSpawnEntry*>::iterator itr;
  7050. GroundSpawnEntry* entry = 0;
  7051. bool can_harvest = false;
  7052. sint32 min_skill = -1;
  7053. int16 totalSkill = skill->current_val;
  7054. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  7055. if(skillID != 0xFFFFFFFF)
  7056. {
  7057. ((Entity*)player)->MStats.lock();
  7058. totalSkill += ((Entity*)player)->stats[skillID];
  7059. ((Entity*)player)->MStats.unlock();
  7060. }
  7061. // first, iterate through groundspawn_entries, discard tables player cannot use
  7062. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  7063. {
  7064. entry = *itr;
  7065. if (min_skill == -1 || entry->min_skill_level < min_skill)
  7066. min_skill = entry->min_skill_level;
  7067. // if player lacks skill, skip table
  7068. if (entry->min_skill_level > totalSkill)
  7069. continue;
  7070. // if bonus, but player lacks level, skip table
  7071. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  7072. continue;
  7073. can_harvest = true;
  7074. break;
  7075. }
  7076. lua_interface->SetBooleanValue(state, can_harvest);
  7077. // If false, send the message to the client
  7078. if (!can_harvest) {
  7079. Client* client = ((Player*)player)->GetClient();
  7080. if (client) {
  7081. string msg = "You do not have enough skill to ";
  7082. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  7083. msg.append("gather");
  7084. else if (collection_skill == "Mining")
  7085. msg.append("mine");
  7086. else if (collection_skill == "Trapping")
  7087. msg.append("trap");
  7088. else if (collection_skill == "Foresting")
  7089. msg.append("forest");
  7090. else if (collection_skill == "Fishing")
  7091. msg.append("catch");
  7092. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  7093. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  7094. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  7095. }
  7096. }
  7097. lua_interface->ResetFunctionStack(state);
  7098. return 1;
  7099. }
  7100. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  7101. if (!lua_interface)
  7102. return 0;
  7103. Spawn* player = lua_interface->GetSpawn(state);
  7104. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  7105. lua_interface->ResetFunctionStack(state);
  7106. if (!player) {
  7107. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  7108. return 0;
  7109. }
  7110. if (!player->IsPlayer()) {
  7111. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  7112. return 0;
  7113. }
  7114. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  7115. lua_interface->SetBooleanValue(state, ret);
  7116. return 1;
  7117. }
  7118. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  7119. // Check to see if we have a valid lua_interface
  7120. if (!lua_interface)
  7121. return 0;
  7122. // Get the spawn that is getting the pet
  7123. Spawn* spawn = lua_interface->GetSpawn(state);
  7124. Spawn* target = lua_interface->GetSpawn(state, 2);
  7125. // Get the DB ID of the pet
  7126. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  7127. float x = lua_interface->GetFloatValue(state, 4);
  7128. float y = lua_interface->GetFloatValue(state, 5);
  7129. float z = lua_interface->GetFloatValue(state, 6);
  7130. // Get the spell that this command was called from
  7131. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7132. lua_interface->ResetFunctionStack(state);
  7133. // Check to make sure the spawn pointer is valid
  7134. if (!spawn) {
  7135. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  7136. return 0;
  7137. }
  7138. // Check to make sure the spawn is an entity
  7139. if (!spawn->IsEntity()) {
  7140. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  7141. return 0;
  7142. }
  7143. if (!target) {
  7144. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  7145. return 0;
  7146. }
  7147. if (!target->IsEntity()) {
  7148. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  7149. return 0;
  7150. }
  7151. // Check to see if the DB ID for the pet is set
  7152. if (pet_id == 0) {
  7153. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  7154. return 0;
  7155. }
  7156. // Check to see if the pointer to the spell is valid
  7157. if (!luaspell) {
  7158. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  7159. return 0;
  7160. }
  7161. if(luaspell->resisted) {
  7162. return 0;
  7163. }
  7164. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  7165. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  7166. if (!pet) {
  7167. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  7168. return 0;
  7169. }
  7170. // Check to make sure the pet is an npc
  7171. if (!pet->IsNPC()) {
  7172. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  7173. return 0;
  7174. }
  7175. if (x == 0)
  7176. x = spawn->GetX();
  7177. if (y == 0)
  7178. y = spawn->GetY();
  7179. if (z == 0)
  7180. z = spawn->GetZ();
  7181. // Spawn the pet at the same location as the owner
  7182. pet->SetX(x);
  7183. pet->SetY(y);
  7184. pet->SetZ(z);
  7185. pet->SetLocation(spawn->GetLocation());
  7186. pet->SetHeading(spawn->GetHeading());
  7187. spawn->GetZone()->AddSpawn(pet);
  7188. const char* spawn_script = world.GetSpawnScript(pet_id);
  7189. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  7190. spawn->SetSpawnScript(string(spawn_script));
  7191. spawn->GetZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7192. }
  7193. std::string petName = std::string("");
  7194. if(spawn->IsEntity()) {
  7195. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  7196. }
  7197. if(petName.size() < 1) {
  7198. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  7199. petName = spawn->GetZone()->pet_names.at(rand_index);
  7200. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  7201. }
  7202. // Set the pets name
  7203. pet->SetName(petName.c_str());
  7204. // Set the level of the pet to the owners level
  7205. pet->SetLevel(spawn->GetLevel());
  7206. // Set the faction of the pet to the same faction as the owner
  7207. pet->SetFactionID(spawn->GetFactionID());
  7208. // Set the spawn as a pet
  7209. pet->SetPet(true);
  7210. // Give a pointer of the owner to the pet
  7211. ((NPC*)pet)->SetOwner((Entity*)spawn);
  7212. // Set the pet type
  7213. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  7214. // Set the spell id used to create this pet
  7215. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  7216. // Set the spell tier used to create this pet
  7217. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  7218. // Set the pets spawn type to 6
  7219. pet->SetSpawnType(6);
  7220. // Set the pets brain
  7221. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  7222. // Check to see if the pet has a subtitle
  7223. if (strlen(pet->GetSubTitle()) > 0) {
  7224. // Add the players name to the front of the sub title
  7225. string pet_subtitle;
  7226. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  7227. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  7228. // Set the pets subtitle to the new one
  7229. pet->SetSubTitle(pet_subtitle.c_str());
  7230. }
  7231. // Set the pet as the return value for this function
  7232. lua_interface->SetSpawnValue(state, pet);
  7233. return 1;
  7234. }
  7235. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  7236. if (!lua_interface)
  7237. return 0;
  7238. Spawn* spawn = lua_interface->GetSpawn(state);
  7239. Spawn* player = lua_interface->GetSpawn(state, 2);
  7240. float max_distance = lua_interface->GetFloatValue(state, 3);
  7241. string type = lua_interface->GetStringValue(state, 4);
  7242. lua_interface->ResetFunctionStack(state);
  7243. if (!spawn || (spawn && spawn->IsPlayer())) {
  7244. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  7245. return 0;
  7246. }
  7247. if (!player || !player->IsPlayer()) {
  7248. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  7249. return 0;
  7250. }
  7251. Client* client = ((Player*)player)->GetClient();
  7252. if (!client) {
  7253. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7254. return 0;
  7255. }
  7256. //Set max_distance to default if not set or not proper value
  7257. if (max_distance <= 0)
  7258. max_distance = 500;
  7259. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7260. if (packet) {
  7261. float unknown2_3 = 0;
  7262. int8 placement_mode = 0;
  7263. if (type == "wall") {
  7264. placement_mode = 2;
  7265. unknown2_3 = 150;
  7266. }
  7267. else if (type == "ceiling")
  7268. placement_mode = 1;
  7269. packet->setDataByName("placement_mode", placement_mode);
  7270. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7271. packet->setDataByName("model_type", spawn->GetModelType());
  7272. packet->setDataByName("unknown", 1); //size
  7273. packet->setDataByName("unknown2", 1); //size 2
  7274. packet->setDataByName("unknown2", .5, 1); //size 3
  7275. packet->setDataByName("unknown2", 3, 2);
  7276. packet->setDataByName("unknown2", unknown2_3, 3);
  7277. packet->setDataByName("max_distance", max_distance);
  7278. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7279. client->QueuePacket(packet->serialize());
  7280. safe_delete(packet);
  7281. }
  7282. return 0;
  7283. }
  7284. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7285. if (!lua_interface)
  7286. return 0;
  7287. Item* item = lua_interface->GetItem(state);
  7288. lua_interface->ResetFunctionStack(state);
  7289. if (!item) {
  7290. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7291. return 0;
  7292. }
  7293. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7294. return 1;
  7295. }
  7296. int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
  7297. if (!lua_interface)
  7298. return 0;
  7299. Item* item = lua_interface->GetItem(state);
  7300. lua_interface->ResetFunctionStack(state);
  7301. if (!item) {
  7302. lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7303. return 0;
  7304. }
  7305. lua_interface->SetInt32Value(state, item->effect_type);
  7306. return 1;
  7307. }
  7308. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7309. if (!lua_interface)
  7310. return 0;
  7311. Spawn* spawn = lua_interface->GetSpawn(state);
  7312. lua_interface->ResetFunctionStack(state);
  7313. if (!spawn) {
  7314. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7315. return 0;
  7316. }
  7317. if (spawn->GetZone())
  7318. spawn->GetZone()->AddTransportSpawn(spawn);
  7319. return 0;
  7320. }
  7321. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7322. if (!lua_interface)
  7323. return 0;
  7324. Spawn* spawn = lua_interface->GetSpawn(state);
  7325. lua_interface->ResetFunctionStack(state);
  7326. if (!spawn) {
  7327. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7328. return 0;
  7329. }
  7330. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7331. return 1;
  7332. }
  7333. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7334. if (!lua_interface)
  7335. return 0;
  7336. Skill* skill = lua_interface->GetSkill(state);
  7337. lua_interface->ResetFunctionStack(state);
  7338. if (!skill) {
  7339. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7340. return 0;
  7341. }
  7342. lua_interface->SetInt32Value(state, skill->current_val);
  7343. return 1;
  7344. }
  7345. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7346. if (!lua_interface)
  7347. return 0;
  7348. Skill* skill = lua_interface->GetSkill(state);
  7349. lua_interface->ResetFunctionStack(state);
  7350. if (!skill) {
  7351. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7352. return 0;
  7353. }
  7354. lua_interface->SetInt32Value(state, skill->max_val);
  7355. return 1;
  7356. }
  7357. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7358. if (!lua_interface)
  7359. return 0;
  7360. Skill* skill = lua_interface->GetSkill(state);
  7361. lua_interface->ResetFunctionStack(state);
  7362. if (!skill) {
  7363. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7364. return 0;
  7365. }
  7366. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7367. return 1;
  7368. }
  7369. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7370. if (!lua_interface)
  7371. return 0;
  7372. Skill* skill = lua_interface->GetSkill(state);
  7373. int16 value = lua_interface->GetInt16Value(state, 2);
  7374. lua_interface->ResetFunctionStack(state);
  7375. if (!skill) {
  7376. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7377. return 0;
  7378. }
  7379. skill->max_val = value;
  7380. if (skill->max_val < skill->current_val)
  7381. skill->current_val = skill->max_val;
  7382. return 0;
  7383. }
  7384. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7385. if (!lua_interface)
  7386. return 0;
  7387. Skill* skill = lua_interface->GetSkill(state);
  7388. int16 value = lua_interface->GetInt16Value(state, 2);
  7389. lua_interface->ResetFunctionStack(state);
  7390. if (!skill) {
  7391. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7392. return 0;
  7393. }
  7394. if (value > skill->max_val)
  7395. skill->current_val = skill->max_val;
  7396. else
  7397. skill->current_val = value;
  7398. return 0;
  7399. }
  7400. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7401. if (!lua_interface)
  7402. return 0;
  7403. Spawn* player = lua_interface->GetSpawn(state);
  7404. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7405. lua_interface->ResetFunctionStack(state);
  7406. if (skill_id > 0 && player && player->IsPlayer()) {
  7407. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7408. return 1;
  7409. }
  7410. return 0;
  7411. }
  7412. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7413. if (!lua_interface)
  7414. return 0;
  7415. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7416. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7417. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7418. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7419. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7420. lua_interface->ResetFunctionStack(state);
  7421. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7422. if (player_spawn && player_spawn->IsPlayer()) {
  7423. Player* player = (Player*)player_spawn;
  7424. bool added = false;
  7425. if (!player->skill_list.HasSkill(skill_id)) {
  7426. player->AddSkill(skill_id, current_val, max_val, true);
  7427. added = true;
  7428. }
  7429. 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
  7430. Client* client = player->GetClient();
  7431. if (client) {
  7432. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7433. if (packet)
  7434. client->QueuePacket(packet);
  7435. }
  7436. }
  7437. if (added) {
  7438. lua_interface->SetBooleanValue(state, true);
  7439. return 1;
  7440. }
  7441. }
  7442. else {
  7443. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7444. }
  7445. }
  7446. else {
  7447. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7448. }
  7449. lua_interface->SetBooleanValue(state, false);
  7450. return 1;
  7451. }
  7452. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7453. if (!lua_interface)
  7454. return 0;
  7455. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7456. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7457. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7458. lua_interface->ResetFunctionStack(state);
  7459. if (skill_id > 0) {
  7460. if (player_spawn && player_spawn->IsPlayer()) {
  7461. Player* player = (Player*)player_spawn;
  7462. if (player->skill_list.HasSkill(skill_id)) {
  7463. player->RemovePlayerSkill(skill_id);
  7464. if (!more_to_remove) {
  7465. Client* client = player->GetClient();
  7466. if (client) {
  7467. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7468. if (packet)
  7469. client->QueuePacket(packet);
  7470. }
  7471. }
  7472. }
  7473. }
  7474. else {
  7475. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7476. }
  7477. }
  7478. else {
  7479. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7480. }
  7481. return 0;
  7482. }
  7483. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7484. if (!lua_interface)
  7485. return 0;
  7486. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7487. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7488. int16 amount = lua_interface->GetInt8Value(state, 3);
  7489. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7490. lua_interface->ResetFunctionStack(state);
  7491. if (amount > 0 && skill_type < 100) {
  7492. if (player_spawn && player_spawn->IsPlayer()) {
  7493. Player* player = (Player*)player_spawn;
  7494. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7495. if (!more_to_increase) {
  7496. Client* client = player->GetClient();
  7497. if (client) {
  7498. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7499. if (packet)
  7500. client->QueuePacket(packet);
  7501. }
  7502. }
  7503. }
  7504. else {
  7505. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7506. }
  7507. }
  7508. else {
  7509. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7510. }
  7511. return 0;
  7512. }
  7513. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7514. if (!lua_interface)
  7515. return 0;
  7516. Spawn* spawn = lua_interface->GetSpawn(state);
  7517. string name = lua_interface->GetStringValue(state, 2);
  7518. lua_interface->ResetFunctionStack(state);
  7519. if (!spawn) {
  7520. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7521. return 0;
  7522. }
  7523. if (!spawn->IsEntity()) {
  7524. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7525. return 0;
  7526. }
  7527. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7528. if (skill) {
  7529. lua_interface->SetSkillValue(state, skill);
  7530. return 1;
  7531. }
  7532. return 0;
  7533. }
  7534. int EQ2Emu_lua_AddProc(lua_State* state) {
  7535. if (!lua_interface)
  7536. return 0;
  7537. Spawn* spawn = lua_interface->GetSpawn(state);
  7538. int8 type = lua_interface->GetInt8Value(state, 2);
  7539. float chance = lua_interface->GetFloatValue(state, 3);
  7540. Item* item = lua_interface->GetItem(state, 4);
  7541. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7542. LuaSpell* spell = 0;
  7543. if (!spawn && (!spell || !use_all_spelltargets)) {
  7544. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7545. return 0;
  7546. }
  7547. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7548. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7549. return 0;
  7550. }
  7551. if (!item)
  7552. spell = lua_interface->GetCurrentSpell(state);
  7553. if (!item && !spell) {
  7554. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7555. return 0;
  7556. }
  7557. if(spell && spell->resisted) {
  7558. return 0;
  7559. }
  7560. if (spell && use_all_spelltargets) {
  7561. Spawn* target;
  7562. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7563. for (int8 i = 0; i < spell->targets.size(); i++) {
  7564. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7565. if (!target || !target->IsEntity())
  7566. continue;
  7567. ((Entity*)target)->AddProc(type, chance, item, spell);
  7568. }
  7569. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7570. }
  7571. else
  7572. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7573. return 0;
  7574. }
  7575. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7576. if (!lua_interface)
  7577. return 0;
  7578. Spawn* spawn = lua_interface->GetSpawn(state);
  7579. Item* item = lua_interface->GetItem(state, 2);
  7580. LuaSpell* spell = 0;
  7581. if (!spawn) {
  7582. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7583. lua_interface->ResetFunctionStack(state);
  7584. return 0;
  7585. }
  7586. if (!spawn->IsEntity()) {
  7587. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7588. lua_interface->ResetFunctionStack(state);
  7589. return 0;
  7590. }
  7591. if (!item)
  7592. spell = lua_interface->GetCurrentSpell(state);
  7593. lua_interface->ResetFunctionStack(state);
  7594. if (!item && !spell) {
  7595. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7596. return 0;
  7597. }
  7598. if (spell) {
  7599. Spawn* target;
  7600. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7601. for (int8 i = 0; i < spell->targets.size(); i++) {
  7602. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7603. if (!target || !target->IsEntity())
  7604. continue;
  7605. ((Entity*)target)->RemoveProc(item, spell);
  7606. }
  7607. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7608. spell->caster->RemoveProc(item, spell);
  7609. }
  7610. else
  7611. ((Entity*)spawn)->RemoveProc(item, spell);
  7612. return 0;
  7613. }
  7614. int EQ2Emu_lua_Knockback(lua_State* state) {
  7615. if (!lua_interface)
  7616. return 0;
  7617. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7618. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7619. int32 duration = lua_interface->GetInt32Value(state, 3);
  7620. float vertical = lua_interface->GetFloatValue(state, 4);
  7621. float horizontal = lua_interface->GetFloatValue(state, 5);
  7622. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7623. lua_interface->ResetFunctionStack(state);
  7624. if (!target_spawn) {
  7625. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7626. return 0;
  7627. }
  7628. if (!spawn) {
  7629. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7630. return 0;
  7631. }
  7632. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7633. Client* client = ((Player*)spawn)->GetClient();
  7634. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7635. if (packet) {
  7636. packet->setDataByName("target_x", target_spawn->GetX());
  7637. packet->setDataByName("target_y", target_spawn->GetY());
  7638. packet->setDataByName("target_z", target_spawn->GetZ());
  7639. packet->setDataByName("vertical_movement", vertical);
  7640. packet->setDataByName("horizontal_movement", horizontal);
  7641. if (use_heading)
  7642. packet->setDataByName("use_player_heading", 1);
  7643. client->QueuePacket(packet->serialize());
  7644. }
  7645. safe_delete(packet);
  7646. }
  7647. return 0;
  7648. }
  7649. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7650. if (!lua_interface)
  7651. return 0;
  7652. Spawn* spawn = lua_interface->GetSpawn(state);
  7653. lua_interface->ResetFunctionStack(state);
  7654. if (!spawn) {
  7655. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7656. return 0;
  7657. }
  7658. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7659. return 1;
  7660. }
  7661. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7662. if (!lua_interface)
  7663. return 0;
  7664. Spawn* caster = lua_interface->GetSpawn(state);
  7665. Spawn* target = lua_interface->GetSpawn(state, 2);
  7666. string name = lua_interface->GetStringValue(state, 3);
  7667. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7668. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7669. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7670. string success_msg = lua_interface->GetStringValue(state, 7);
  7671. string effect_msg = lua_interface->GetStringValue(state, 8);
  7672. lua_interface->ResetFunctionStack(state);
  7673. if (!caster) {
  7674. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7675. return 0;
  7676. }
  7677. if (!caster->IsEntity()) {
  7678. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7679. return 0;
  7680. }
  7681. if (!target) {
  7682. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7683. return 0;
  7684. }
  7685. if (!target->IsEntity()) {
  7686. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7687. return 0;
  7688. }
  7689. if (name.length() == 0) {
  7690. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7691. return 0;
  7692. }
  7693. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7694. return 0;
  7695. }
  7696. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7697. if (!lua_interface)
  7698. return 0;
  7699. string name = lua_interface->GetStringValue(state);
  7700. lua_interface->ResetFunctionStack(state);
  7701. if (name.length() == 0) {
  7702. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7703. return 0;
  7704. }
  7705. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7706. if (!skill) {
  7707. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7708. return 0;
  7709. }
  7710. lua_interface->SetInt32Value(state, skill->skill_id);
  7711. return 1;
  7712. }
  7713. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7714. if (!lua_interface)
  7715. return 0;
  7716. Spawn* spawn = lua_interface->GetSpawn(state);
  7717. lua_interface->ResetFunctionStack(state);
  7718. if (!spawn) {
  7719. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7720. return 0;
  7721. }
  7722. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7723. return 1;
  7724. }
  7725. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7726. if (!lua_interface)
  7727. return 0;
  7728. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7729. lua_interface->ResetFunctionStack(state);
  7730. if (!luaspell) {
  7731. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7732. return 0;
  7733. }
  7734. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7735. return 1;
  7736. }
  7737. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7738. if (!lua_interface)
  7739. return 0;
  7740. Spawn* spawn = lua_interface->GetSpawn(state);
  7741. Spawn* target = lua_interface->GetSpawn(state, 2);
  7742. lua_interface->ResetFunctionStack(state);
  7743. if (!spawn) {
  7744. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7745. return 0;
  7746. }
  7747. if (!spawn->IsEntity()) {
  7748. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7749. return 0;
  7750. }
  7751. if (!target) {
  7752. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7753. return 0;
  7754. }
  7755. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7756. return 1;
  7757. }
  7758. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7759. if (!lua_interface)
  7760. return 0;
  7761. Spawn* spawn = lua_interface->GetSpawn(state);
  7762. Spawn* target = lua_interface->GetSpawn(state, 2);
  7763. lua_interface->ResetFunctionStack(state);
  7764. if (!spawn) {
  7765. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7766. return 0;
  7767. }
  7768. if (!spawn->IsEntity()) {
  7769. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7770. return 0;
  7771. }
  7772. if (!target) {
  7773. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7774. return 0;
  7775. }
  7776. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7777. return 1;
  7778. }
  7779. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7780. if (!lua_interface)
  7781. return 0;
  7782. Item* item = lua_interface->GetItem(state);
  7783. lua_interface->ResetFunctionStack(state);
  7784. if (!item) {
  7785. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7786. return 0;
  7787. }
  7788. lua_interface->SetInt32Value(state, item->details.count);
  7789. return 1;
  7790. }
  7791. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7792. if (!lua_interface)
  7793. return 0;
  7794. Item* item = lua_interface->GetItem(state);
  7795. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7796. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7797. lua_interface->ResetFunctionStack(state);
  7798. if (!item) {
  7799. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7800. return 0;
  7801. }
  7802. if (!owner) {
  7803. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7804. return 0;
  7805. }
  7806. if (!owner->IsPlayer()) {
  7807. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7808. return 0;
  7809. }
  7810. if (item->stack_count < new_count) {
  7811. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7812. return 0;
  7813. }
  7814. if (new_count > 0) {
  7815. item->details.count = new_count;
  7816. item->save_needed = true;
  7817. }
  7818. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7819. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7820. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7821. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7822. else
  7823. {
  7824. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7825. return 0;
  7826. }
  7827. Client* client = ((Player*)owner)->GetClient();
  7828. if (!client)
  7829. return 0;
  7830. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7831. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7832. if (app)
  7833. client->QueuePacket(app);
  7834. return 0;
  7835. }
  7836. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7837. if (!lua_interface)
  7838. return 0;
  7839. int32 time = lua_interface->GetInt32Value(state);
  7840. string function = lua_interface->GetStringValue(state, 2);
  7841. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7842. Spawn* target = lua_interface->GetSpawn(state, 4);
  7843. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7844. lua_interface->ResetFunctionStack(state);
  7845. if (time == 0) {
  7846. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7847. return 0;
  7848. }
  7849. if (function.length() == 0) {
  7850. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7851. return 0;
  7852. }
  7853. if (!spell) {
  7854. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7855. return 0;
  7856. }
  7857. SpellScriptTimer* timer = new SpellScriptTimer;
  7858. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7859. #ifdef WIN32
  7860. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7861. #else
  7862. bzero(timer, sizeof(SpellScriptTimer));
  7863. #endif*/
  7864. timer->caster = 0;
  7865. timer->deleteWhenDone = false;
  7866. timer->target = 0;
  7867. timer->time = Timer::GetCurrentTime2() + time;
  7868. timer->customFunction = function;
  7869. timer->spell = spell;
  7870. if (caster)
  7871. timer->caster = caster->GetID();
  7872. if (target)
  7873. timer->target = target->GetID();
  7874. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7875. return 0;
  7876. }
  7877. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7878. if (!lua_interface)
  7879. return 0;
  7880. float hp_perc = lua_interface->GetFloatValue(state);
  7881. float power_perc = lua_interface->GetFloatValue(state, 2);
  7882. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7883. Spawn* target = lua_interface->GetSpawn(state, 4);
  7884. string heal_name = lua_interface->GetStringValue(state, 5);
  7885. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7886. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7887. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7888. lua_interface->ResetFunctionStack(state);
  7889. if (!spell) {
  7890. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7891. return 0;
  7892. }
  7893. Entity* caster = spell->caster;
  7894. if (!caster) {
  7895. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7896. return 0;
  7897. }
  7898. Client* client = 0;
  7899. PendingResurrection* rez = 0;
  7900. ZoneServer* zone = spell->caster->GetZone();
  7901. if (!target) {
  7902. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7903. if (spell->targets.size() > 0) {
  7904. vector<int32> spell_targets = spell->targets;
  7905. for (int8 i = 0; i < spell_targets.size(); i++) {
  7906. target = zone->GetSpawnByID(spell_targets.at(i));
  7907. if (!target)
  7908. continue;
  7909. if (!target->IsPlayer())
  7910. continue;
  7911. client = ((Player*)target)->GetClient();
  7912. if (!client)
  7913. continue;
  7914. rez = client->GetCurrentRez();
  7915. if (rez->active)
  7916. continue;
  7917. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7918. rez->active = true;
  7919. rez->caster = caster;
  7920. rez->expire_timer = new Timer;
  7921. int32 duration = spell->spell->GetSpellDuration();
  7922. rez->expire_timer->Start(duration * 100);
  7923. rez->hp_perc = hp_perc;
  7924. rez->mp_perc = power_perc;
  7925. rez->range = spell->spell->GetSpellData()->range;
  7926. rez->spell_name = spell->spell->GetName();
  7927. if (heal_name.length() > 0)
  7928. rez->heal_name = heal_name;
  7929. else
  7930. rez->heal_name = rez->spell_name;
  7931. rez->no_calcs = no_calcs;
  7932. rez->crit_mod = crit_mod;
  7933. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7934. if (send_window)
  7935. client->SendResurrectionWindow();
  7936. else {
  7937. target->GetZone()->ResurrectSpawn(target, client);
  7938. rez->should_delete = true;
  7939. }
  7940. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7941. }
  7942. }
  7943. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7944. }
  7945. else {
  7946. if(!target->IsPlayer())
  7947. return 0;
  7948. client = ((Player*)target)->GetClient();
  7949. if (!client)
  7950. return 0;
  7951. rez = client->GetCurrentRez();
  7952. if (rez->active)
  7953. return 0;
  7954. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7955. rez->active = true;
  7956. rez->caster = caster;
  7957. rez->expire_timer = new Timer;
  7958. int32 duration = spell->spell->GetSpellDuration();
  7959. rez->expire_timer->Start(duration * 100);
  7960. rez->hp_perc = hp_perc;
  7961. rez->mp_perc = power_perc;
  7962. rez->range = spell->spell->GetSpellData()->range;
  7963. rez->spell_name = spell->spell->GetName();
  7964. if (heal_name.length() > 0)
  7965. rez->heal_name = heal_name;
  7966. else
  7967. rez->heal_name = rez->spell_name;
  7968. rez->no_calcs = no_calcs;
  7969. rez->crit_mod = crit_mod;
  7970. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7971. if (send_window)
  7972. client->SendResurrectionWindow();
  7973. else {
  7974. target->GetZone()->ResurrectSpawn(target, client);
  7975. rez->should_delete = true;
  7976. }
  7977. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7978. }
  7979. return 0;
  7980. }
  7981. int EQ2Emu_lua_SetVision(lua_State* state) {
  7982. if (!lua_interface)
  7983. return 0;
  7984. Spawn* spawn = lua_interface->GetSpawn(state);
  7985. int32 vision = lua_interface->GetInt32Value(state, 2);
  7986. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7987. lua_interface->ResetFunctionStack(state);
  7988. if (!spawn) {
  7989. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7990. return 0;
  7991. }
  7992. if (!spawn->IsEntity()) {
  7993. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7994. return 0;
  7995. }
  7996. if (spell && spell->targets.size() > 0) {
  7997. ZoneServer* zone = spell->caster->GetZone();
  7998. for (int8 i = 0; i < spell->targets.size(); i++) {
  7999. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8000. if (target && target->IsEntity()) {
  8001. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  8002. if (target->IsPlayer())
  8003. ((Player*)target)->SetCharSheetChanged(true);
  8004. }
  8005. }
  8006. }
  8007. else {
  8008. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  8009. if (spawn->IsPlayer())
  8010. ((Player*)spawn)->SetCharSheetChanged(true);
  8011. }
  8012. return 0;
  8013. }
  8014. int EQ2Emu_lua_BlurVision(lua_State* state) {
  8015. if (!lua_interface)
  8016. return 0;
  8017. Spawn* spawn = lua_interface->GetSpawn(state);
  8018. float intensity = lua_interface->GetFloatValue(state, 2);
  8019. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8020. lua_interface->ResetFunctionStack(state);
  8021. if (!spawn) {
  8022. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8023. return 0;
  8024. }
  8025. if (!spawn->IsEntity()) {
  8026. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8027. return 0;
  8028. }
  8029. if (spell && spell->targets.size() > 0) {
  8030. ZoneServer* zone = spell->caster->GetZone();
  8031. for (int8 i = 0; i < spell->targets.size(); i++) {
  8032. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8033. if (target && target->IsEntity()) {
  8034. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  8035. if (target->IsPlayer())
  8036. ((Player*)target)->SetCharSheetChanged(true);
  8037. }
  8038. }
  8039. }
  8040. else {
  8041. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  8042. if (spawn->IsPlayer())
  8043. ((Player*)spawn)->SetCharSheetChanged(true);
  8044. }
  8045. return 0;
  8046. }
  8047. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  8048. if (!lua_interface)
  8049. return 0;
  8050. Spawn* spawn = lua_interface->GetSpawn(state);
  8051. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  8052. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8053. lua_interface->ResetFunctionStack(state);
  8054. if (!spawn) {
  8055. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  8056. return 0;
  8057. }
  8058. if (!spawn->IsEntity()) {
  8059. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  8060. return 0;
  8061. }
  8062. if (spell && spell->targets.size() > 0) {
  8063. ZoneServer* zone = spell->caster->GetZone();
  8064. for (int8 i = 0; i < spell->targets.size(); i++) {
  8065. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8066. if (target && target->IsEntity()) {
  8067. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8068. if (target->IsPlayer())
  8069. ((Player*)target)->SetCharSheetChanged(true);
  8070. }
  8071. }
  8072. }
  8073. else {
  8074. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8075. if (spawn->IsPlayer())
  8076. ((Player*)spawn)->SetCharSheetChanged(true);
  8077. }
  8078. return 0;
  8079. }
  8080. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  8081. if (!lua_interface)
  8082. return 0;
  8083. Item* item = lua_interface->GetItem(state);
  8084. int8 type = lua_interface->GetInt32Value(state, 2);
  8085. lua_interface->ResetFunctionStack(state);
  8086. if (!item) {
  8087. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  8088. return 0;
  8089. }
  8090. if (type == 1)
  8091. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  8092. else if (type == 2)
  8093. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  8094. return 1;
  8095. }
  8096. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  8097. if (!lua_interface)
  8098. return 0;
  8099. Spawn* target = lua_interface->GetSpawn(state);
  8100. float val = lua_interface->GetFloatValue(state, 2);
  8101. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8102. lua_interface->ResetFunctionStack(state);
  8103. // Added from Gangrenous post
  8104. if (spell && spell->resisted)
  8105. return 0;
  8106. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  8107. if (val > 1.0f)
  8108. val = 1.0f - (val / 100.0f);
  8109. if (spell && spell->spell && spell->targets.size() > 0) {
  8110. ZoneServer* zone = spell->caster->GetZone();
  8111. for (int32 i = 0; i != spell->targets.size(); i++) {
  8112. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  8113. if (spawn && spawn->IsEntity()) {
  8114. ((Entity*)spawn)->SetSpeedMultiplier(val);
  8115. if (spawn->IsPlayer())
  8116. ((Player*)spawn)->SetCharSheetChanged(true);
  8117. }
  8118. }
  8119. }
  8120. else {
  8121. if (target && target->IsEntity()) {
  8122. ((Entity*)target)->SetSpeedMultiplier(val);
  8123. if (target->IsPlayer())
  8124. ((Player*)target)->SetCharSheetChanged(true);
  8125. }
  8126. }
  8127. return 0;
  8128. }
  8129. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  8130. if (!lua_interface)
  8131. return 0;
  8132. Spawn* spawn = lua_interface->GetSpawn(state);
  8133. int16 model = lua_interface->GetInt16Value(state, 2);
  8134. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8135. lua_interface->ResetFunctionStack(state);
  8136. if (spell && spell->spell && spell->targets.size() > 0) {
  8137. ZoneServer* zone = spell->caster->GetZone();
  8138. for (int32 i = 0; i < spell->targets.size(); i++) {
  8139. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8140. if (target)
  8141. target->SetIllusionModel(model);
  8142. }
  8143. }
  8144. else {
  8145. if (!spawn) {
  8146. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8147. return 0;
  8148. }
  8149. spawn->SetIllusionModel(model);
  8150. }
  8151. return 0;
  8152. }
  8153. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  8154. if (!lua_interface)
  8155. return 0;
  8156. Spawn* spawn = lua_interface->GetSpawn(state);
  8157. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8158. lua_interface->ResetFunctionStack(state);
  8159. if (spell && spell->spell && spell->targets.size() > 0) {
  8160. ZoneServer* zone = spell->caster->GetZone();
  8161. for (int32 i = 0; i < spell->targets.size(); i++) {
  8162. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8163. if (target)
  8164. target->SetIllusionModel(0);
  8165. }
  8166. }
  8167. else {
  8168. if (!spawn) {
  8169. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8170. return 0;
  8171. }
  8172. spawn->SetIllusionModel(0);
  8173. }
  8174. return 0;
  8175. }
  8176. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  8177. if (!lua_interface)
  8178. return 0;
  8179. Spawn* caster = lua_interface->GetSpawn(state);
  8180. Spawn* target = lua_interface->GetSpawn(state, 2);
  8181. float chance = lua_interface->GetFloatValue(state, 3);
  8182. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8183. lua_interface->ResetFunctionStack(state);
  8184. if (!caster) {
  8185. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8186. return 0;
  8187. }
  8188. if (!caster->IsEntity()) {
  8189. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  8190. return 0;
  8191. }
  8192. if (!target) {
  8193. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8194. return 0;
  8195. }
  8196. if (!target->IsEntity()) {
  8197. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  8198. return 0;
  8199. }
  8200. if (chance <= 0) {
  8201. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  8202. return 0;
  8203. }
  8204. if (!spell) {
  8205. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8206. return 0;
  8207. }
  8208. if(spell->resisted) {
  8209. return 0;
  8210. }
  8211. if (((Entity*)caster)->GetThreatTransfer()) {
  8212. return 0;
  8213. }
  8214. ThreatTransfer* transfer = new ThreatTransfer;
  8215. transfer->Target = target->GetID();
  8216. transfer->Amount = chance;
  8217. transfer->Spell = spell;
  8218. ((Entity*)caster)->SetThreatTransfer(transfer);
  8219. return 0;
  8220. }
  8221. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  8222. if (!lua_interface)
  8223. return 0;
  8224. Spawn* spawn = lua_interface->GetSpawn(state);
  8225. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8226. lua_interface->ResetFunctionStack(state);
  8227. if (!spawn) {
  8228. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  8229. return 0;
  8230. }
  8231. if (!spell) {
  8232. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8233. return 0;
  8234. }
  8235. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  8236. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  8237. if(transfer && transfer->Spell != spell) {
  8238. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  8239. return 0;
  8240. }
  8241. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  8242. }
  8243. return 0;
  8244. }
  8245. int EQ2Emu_lua_CureByType(lua_State* state) {
  8246. if (!lua_interface)
  8247. return 0;
  8248. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8249. int8 cure_count = lua_interface->GetInt8Value(state);
  8250. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8251. string cure_name = lua_interface->GetStringValue(state, 3);
  8252. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8253. Spawn* target = lua_interface->GetSpawn(state, 5);
  8254. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  8255. lua_interface->ResetFunctionStack(state);
  8256. if(spell && spell->resisted) {
  8257. return 0;
  8258. }
  8259. if (target) {
  8260. if (!target->IsEntity()) {
  8261. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8262. return 0;
  8263. }
  8264. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8265. std::string alternate_name = "item";
  8266. if(spell)
  8267. alternate_name = std::string(spell->spell->GetName());
  8268. if(!caster && spell)
  8269. caster = (Spawn*)spell->caster;
  8270. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  8271. }
  8272. }
  8273. else {
  8274. ZoneServer* zone = spell->caster->GetZone();
  8275. vector<int32> targets = spell->targets;
  8276. vector<Entity*> targets_to_cure;
  8277. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8278. for (int8 i = 0; i < targets.size(); i++) {
  8279. target = zone->GetSpawnByID(targets.at(i));
  8280. if (!target || !target->IsEntity())
  8281. continue;
  8282. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8283. targets_to_cure.push_back((Entity*)target);
  8284. }
  8285. }
  8286. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8287. vector<Entity*>::iterator itr;
  8288. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  8289. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8290. }
  8291. }
  8292. return 0;
  8293. }
  8294. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  8295. if (!lua_interface)
  8296. return 0;
  8297. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8298. if (!spell) {
  8299. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8300. lua_interface->ResetFunctionStack(state);
  8301. return 0;
  8302. }
  8303. if(spell->resisted) {
  8304. lua_interface->ResetFunctionStack(state);
  8305. return 0;
  8306. }
  8307. int8 cure_count = lua_interface->GetInt8Value(state);
  8308. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8309. string cure_name = lua_interface->GetStringValue(state, 3);
  8310. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8311. Spawn* target = lua_interface->GetSpawn(state, 5);
  8312. lua_interface->ResetFunctionStack(state);
  8313. if (target) {
  8314. if (!target->IsEntity()) {
  8315. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8316. return 0;
  8317. }
  8318. if (((Entity*)target)->GetDetCount() > 0)
  8319. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8320. }
  8321. else {
  8322. ZoneServer* zone = spell->caster->GetZone();
  8323. vector<int32> targets = spell->targets;
  8324. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8325. for (int8 i = 0; i < targets.size(); i++) {
  8326. target = zone->GetSpawnByID(targets.at(i));
  8327. if (!target || !target->IsEntity())
  8328. continue;
  8329. if (((Entity*)target)->GetDetCount() > 0)
  8330. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8331. }
  8332. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8333. }
  8334. return 0;
  8335. }
  8336. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8337. if (!lua_interface)
  8338. return 0;
  8339. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8340. lua_interface->ResetFunctionStack(state);
  8341. if (!spell) {
  8342. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8343. return 0;
  8344. }
  8345. if (!spell->caster) {
  8346. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8347. return 0;
  8348. }
  8349. if (!spell->caster->GetZone()) {
  8350. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8351. return 0;
  8352. }
  8353. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8354. return 0;
  8355. }
  8356. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8357. if (!lua_interface)
  8358. return 0;
  8359. Spawn* spawn = lua_interface->GetSpawn(state);
  8360. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8361. lua_interface->ResetFunctionStack(state);
  8362. if (!spell) {
  8363. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8364. return 0;
  8365. }
  8366. if (spawn && spawn->IsEntity())
  8367. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8368. else {
  8369. ZoneServer* zone = spell->caster->GetZone();
  8370. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8371. for (int32 i = 0; i < spell->targets.size(); i++) {
  8372. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8373. if (!spawn || !spawn->IsEntity())
  8374. continue;
  8375. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8376. }
  8377. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8378. }
  8379. return 0;
  8380. }
  8381. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8382. if (!lua_interface)
  8383. return 0;
  8384. Spawn* spawn = lua_interface->GetSpawn(state);
  8385. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8386. lua_interface->ResetFunctionStack(state);
  8387. if (!spell) {
  8388. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8389. return 0;
  8390. }
  8391. if (spawn && spawn->IsEntity())
  8392. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8393. else {
  8394. ZoneServer* zone = spell->caster->GetZone();
  8395. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8396. for (int32 i = 0; i < spell->targets.size(); i++) {
  8397. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8398. if (!spawn || !spawn->IsEntity())
  8399. continue;
  8400. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8401. }
  8402. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8403. }
  8404. return 0;
  8405. }
  8406. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8407. if (!lua_interface)
  8408. return 0;
  8409. Spawn* caster = lua_interface->GetSpawn(state);
  8410. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8411. lua_interface->ResetFunctionStack(state);
  8412. if (!caster) {
  8413. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8414. return 0;
  8415. }
  8416. if (!caster->IsPlayer()) {
  8417. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8418. return 0;
  8419. }
  8420. Spawn* target = caster->GetTarget();
  8421. if (!target) {
  8422. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8423. return 0;
  8424. }
  8425. Client* client = ((Player*)caster)->GetClient();
  8426. if (!client) {
  8427. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8428. return 0;
  8429. }
  8430. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8431. if (ho) {
  8432. ho->SetTarget(target->GetID());
  8433. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8434. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8435. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8436. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8437. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8438. deque<GroupMemberInfo*>::iterator itr;
  8439. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8440. if (group)
  8441. {
  8442. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8443. deque<GroupMemberInfo*>* members = group->GetMembers();
  8444. for (itr = members->begin(); itr != members->end(); itr++) {
  8445. if ((*itr)->client)
  8446. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8447. }
  8448. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8449. }
  8450. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8451. }
  8452. else
  8453. safe_delete(ho);
  8454. }
  8455. else {
  8456. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8457. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8458. }
  8459. else
  8460. safe_delete(ho);
  8461. }
  8462. }
  8463. return 0;
  8464. }
  8465. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8466. if (!lua_interface)
  8467. return 0;
  8468. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8469. if (!spell) {
  8470. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8471. return 0;
  8472. }
  8473. int16 triggerCount = lua_interface->GetInt16Value(state);
  8474. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8475. if (!triggerCount) {
  8476. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8477. return 0;
  8478. }
  8479. spell->num_triggers = triggerCount;
  8480. spell->had_triggers = true;
  8481. spell->cancel_after_all_triggers = cancel_after_triggers;
  8482. return 0;
  8483. }
  8484. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8485. if (!lua_interface)
  8486. return 0;
  8487. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8488. lua_interface->ResetFunctionStack(state);
  8489. if (!spell) {
  8490. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8491. return 0;
  8492. }
  8493. lua_interface->SetInt32Value(state, spell->num_triggers);
  8494. return 1;
  8495. }
  8496. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8497. if (!lua_interface)
  8498. return 0;
  8499. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8500. if (!spell) {
  8501. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8502. lua_interface->ResetFunctionStack(state);
  8503. return 0;
  8504. }
  8505. int16 remove_count = lua_interface->GetInt16Value(state);
  8506. lua_interface->ResetFunctionStack(state);
  8507. if (!remove_count)
  8508. remove_count = 1;
  8509. if (remove_count >= spell->num_triggers) {
  8510. spell->num_triggers = 0;
  8511. if (spell->cancel_after_all_triggers)
  8512. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8513. }
  8514. else {
  8515. spell->num_triggers -= remove_count;
  8516. Client* client = spell->caster->IsPlayer() ? ((Player*)spell->caster)->GetClient() : nullptr;
  8517. ClientPacketFunctions::SendMaintainedExamineUpdate(client, spell->slot_pos, spell->num_triggers, 0);
  8518. }
  8519. return 0;
  8520. }
  8521. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8522. if (!lua_interface)
  8523. return 0;
  8524. Spawn* spawn = lua_interface->GetSpawn(state);
  8525. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8526. lua_interface->ResetFunctionStack(state);
  8527. if (!spawn) {
  8528. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8529. return 0;
  8530. }
  8531. if (!copy_spawn) {
  8532. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8533. return 0;
  8534. }
  8535. spawn->CopySpawnAppearance(copy_spawn);
  8536. return 0;
  8537. }
  8538. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8539. Spawn* spawn = lua_interface->GetSpawn(state);
  8540. int8 type = lua_interface->GetInt8Value(state, 2);
  8541. lua_interface->ResetFunctionStack(state);
  8542. if (!spawn) {
  8543. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8544. return 0;
  8545. }
  8546. else if (!spawn->IsEntity()) {
  8547. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8548. return 0;
  8549. }
  8550. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8551. return 1;
  8552. }
  8553. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8554. if (!lua_interface)
  8555. return 0;
  8556. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8557. int8 type = lua_interface->GetInt8Value(state);
  8558. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8559. lua_interface->ResetFunctionStack(state);
  8560. if (!spell) {
  8561. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8562. return 0;
  8563. }
  8564. if(spell->resisted) {
  8565. return 0;
  8566. }
  8567. if (spawn) {
  8568. if (!spawn->IsEntity()) {
  8569. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8570. return 0;
  8571. }
  8572. Entity* entity = ((Entity*)spawn);
  8573. entity->AddImmunity(spell, type);
  8574. }
  8575. else {
  8576. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8577. for (int8 i = 0; i < spell->targets.size(); i++) {
  8578. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8579. if (!spawn || !spawn->IsEntity())
  8580. continue;
  8581. Entity* entity = ((Entity*)spawn);
  8582. entity->AddImmunity(spell, type);
  8583. }
  8584. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8585. }
  8586. return 0;
  8587. }
  8588. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8589. if (!lua_interface)
  8590. return 0;
  8591. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8592. int8 type = lua_interface->GetInt8Value(state);
  8593. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8594. lua_interface->ResetFunctionStack(state);
  8595. if (!spell) {
  8596. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8597. return 0;
  8598. }
  8599. if (spawn) {
  8600. if (!spawn->IsEntity()) {
  8601. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8602. return 0;
  8603. }
  8604. Entity* entity = ((Entity*)spawn);
  8605. entity->RemoveImmunity(spell, type);
  8606. }
  8607. else {
  8608. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8609. for (int8 i = 0; i < spell->targets.size(); i++) {
  8610. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8611. if (!spawn || !spawn->IsEntity())
  8612. continue;
  8613. Entity* entity = ((Entity*)spawn);
  8614. entity->RemoveImmunity(spell, type);
  8615. }
  8616. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8617. }
  8618. return 0;
  8619. }
  8620. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8621. if (!lua_interface)
  8622. return 0;
  8623. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8624. if (!spell) {
  8625. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8626. lua_interface->ResetFunctionStack(state);
  8627. return 0;
  8628. }
  8629. if(spell->resisted) {
  8630. lua_interface->ResetFunctionStack(state);
  8631. return 0;
  8632. }
  8633. float snare = lua_interface->GetFloatValue(state);
  8634. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8635. lua_interface->ResetFunctionStack(state);
  8636. // convert the val to the speed multipler value (100 - val)
  8637. float val = 100.0 - snare;
  8638. val /= 100.0;
  8639. if (spawn) {
  8640. if (!spawn->IsEntity()) {
  8641. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8642. return 0;
  8643. }
  8644. ((Entity*)spawn)->SetSnareValue(spell, val);
  8645. }
  8646. else {
  8647. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8648. for (int8 i = 0; i < spell->targets.size(); i++) {
  8649. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8650. if (!spawn || !spawn->IsEntity())
  8651. continue;
  8652. ((Entity*)spawn)->SetSnareValue(spell, val);
  8653. }
  8654. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8655. }
  8656. return 0;
  8657. }
  8658. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8659. if (!lua_interface)
  8660. return 0;
  8661. Spawn* spawn = lua_interface->GetSpawn(state);
  8662. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8663. lua_interface->ResetFunctionStack(state);
  8664. if (!spawn) {
  8665. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8666. return 0;
  8667. }
  8668. if (race_id == 0) {
  8669. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8670. return 0;
  8671. }
  8672. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8673. return 1;
  8674. }
  8675. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8676. if (!lua_interface)
  8677. return 0;
  8678. Spawn* spawn = lua_interface->GetSpawn(state);
  8679. lua_interface->ResetFunctionStack(state);
  8680. if (!spawn) {
  8681. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8682. return 0;
  8683. }
  8684. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8685. return 1;
  8686. }
  8687. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8688. if (!lua_interface)
  8689. return 0;
  8690. Spawn* spawn = lua_interface->GetSpawn(state);
  8691. lua_interface->ResetFunctionStack(state);
  8692. if (!spawn) {
  8693. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8694. return 0;
  8695. }
  8696. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8697. return 1;
  8698. }
  8699. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8700. if (!lua_interface)
  8701. return 0;
  8702. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8703. lua_interface->ResetFunctionStack(state);
  8704. if (!spell) {
  8705. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8706. return 0;
  8707. }
  8708. lua_interface->SetStringValue(state, spell->spell->GetName());
  8709. return 1;
  8710. }
  8711. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8712. if (!lua_interface)
  8713. return 0;
  8714. Quest* quest = lua_interface->GetQuest(state);
  8715. lua_interface->ResetFunctionStack(state);
  8716. if (!quest) {
  8717. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8718. return 0;
  8719. }
  8720. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8721. return 1;
  8722. }
  8723. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8724. if (!lua_interface)
  8725. return 0;
  8726. Quest* quest = lua_interface->GetQuest(state);
  8727. int32 flags = lua_interface->GetInt32Value(state, 2);
  8728. lua_interface->ResetFunctionStack(state);
  8729. if (!quest) {
  8730. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8731. return 0;
  8732. }
  8733. quest->SetQuestFlags(flags);
  8734. return 0;
  8735. }
  8736. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8737. if (!lua_interface)
  8738. return 0;
  8739. Quest* quest = lua_interface->GetQuest(state);
  8740. Spawn* player = lua_interface->GetSpawn(state, 2);
  8741. int32 step = lua_interface->GetInt32Value(state, 3);
  8742. int32 duration = lua_interface->GetInt32Value(state, 4);
  8743. string action = lua_interface->GetStringValue(state, 5);
  8744. lua_interface->ResetFunctionStack(state);
  8745. if (!quest) {
  8746. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8747. return 0;
  8748. }
  8749. if (!player) {
  8750. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8751. return 0;
  8752. }
  8753. if (!player->IsPlayer()) {
  8754. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8755. return 0;
  8756. }
  8757. if (step == 0) {
  8758. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8759. return 0;
  8760. }
  8761. if (duration == 0) {
  8762. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8763. return 0;
  8764. }
  8765. if (action.length() == 0) {
  8766. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8767. return 0;
  8768. }
  8769. Client* client = ((Player*)player)->GetClient();
  8770. if (!client) {
  8771. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8772. return 0;
  8773. }
  8774. quest->SetTimerStep(step);
  8775. quest->AddFailedAction(step, action);
  8776. quest->SetStepTimer(duration);
  8777. client->AddQuestTimer(quest->GetQuestID());
  8778. return 0;
  8779. }
  8780. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8781. if (!lua_interface)
  8782. return 0;
  8783. Quest* quest = lua_interface->GetQuest(state);
  8784. Spawn* player = lua_interface->GetSpawn(state, 2);
  8785. lua_interface->ResetFunctionStack(state);
  8786. if (!quest) {
  8787. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8788. return 0;
  8789. }
  8790. if (!player) {
  8791. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8792. return 0;
  8793. }
  8794. if (!player->IsPlayer()) {
  8795. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8796. return 0;
  8797. }
  8798. Client* client = ((Player*)player)->GetClient();
  8799. if (!client) {
  8800. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8801. return 0;
  8802. }
  8803. quest->SetTimerStep(0);
  8804. quest->SetStepTimer(0);
  8805. client->RemoveQuestTimer(quest->GetQuestID());
  8806. return 0;
  8807. }
  8808. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8809. if (!lua_interface)
  8810. return 0;
  8811. Spawn* player = lua_interface->GetSpawn(state);
  8812. Quest* quest = lua_interface->GetQuest(state, 2);
  8813. int32 step = lua_interface->GetInt32Value(state, 3);
  8814. lua_interface->ResetFunctionStack(state);
  8815. if (!player) {
  8816. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8817. return 0;
  8818. }
  8819. if (!player->IsPlayer()) {
  8820. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8821. return 0;
  8822. }
  8823. if (!quest) {
  8824. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8825. return 0;
  8826. }
  8827. if (step == 0) {
  8828. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8829. return 0;
  8830. }
  8831. Client* client = ((Player*)player)->GetClient();
  8832. if (!client) {
  8833. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8834. return 0;
  8835. }
  8836. if (quest->RemoveQuestStep(step, client)) {
  8837. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8838. client->GetCurrentZone()->SendQuestUpdates(client);
  8839. }
  8840. else
  8841. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8842. return 0;
  8843. }
  8844. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8845. if (!lua_interface)
  8846. return 0;
  8847. Quest* quest = lua_interface->GetQuest(state, 1);
  8848. int32 step = lua_interface->GetInt32Value(state, 2);
  8849. string desc = lua_interface->GetStringValue(state, 3);
  8850. string task_group = lua_interface->GetStringValue(state, 4);
  8851. lua_interface->ResetFunctionStack(state);
  8852. if (!quest) {
  8853. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8854. return 0;
  8855. }
  8856. if (step == 0) {
  8857. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8858. return 0;
  8859. }
  8860. QuestStep* quest_step = quest->GetQuestStep(step);
  8861. if (!quest_step) {
  8862. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8863. return 0;
  8864. }
  8865. quest_step->SetStepProgress(0);
  8866. quest_step->SetTaskGroup(task_group);
  8867. quest_step->SetDescription(desc);
  8868. return 0;
  8869. }
  8870. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8871. if (!lua_interface)
  8872. return 0;
  8873. Quest* quest = lua_interface->GetQuest(state);
  8874. int32 step = lua_interface->GetInt32Value(state, 2);
  8875. string action = lua_interface->GetStringValue(state, 3);
  8876. lua_interface->ResetFunctionStack(state);
  8877. if (!quest) {
  8878. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8879. return 0;
  8880. }
  8881. if (step == 0) {
  8882. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8883. return 0;
  8884. }
  8885. if (action.length() == 0) {
  8886. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8887. return 0;
  8888. }
  8889. quest->AddFailedAction(step, action);
  8890. return 0;
  8891. }
  8892. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8893. if (!lua_interface)
  8894. return 0;
  8895. Spawn* player = lua_interface->GetSpawn(state);
  8896. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8897. int32 step = lua_interface->GetInt32Value(state, 3);
  8898. lua_interface->ResetFunctionStack(state);
  8899. if (!player) {
  8900. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8901. return 0;
  8902. }
  8903. if (!player->IsPlayer()) {
  8904. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8905. return 0;
  8906. }
  8907. if (quest_id == 0) {
  8908. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8909. return 0;
  8910. }
  8911. if (step == 0) {
  8912. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8913. return 0;
  8914. }
  8915. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8916. if (!quest) {
  8917. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8918. return 0;
  8919. }
  8920. quest->StepFailed(step);
  8921. return 0;
  8922. }
  8923. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8924. if (!lua_interface)
  8925. return 0;
  8926. Spawn* player = lua_interface->GetSpawn(state);
  8927. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8928. lua_interface->ResetFunctionStack(state);
  8929. if (!player) {
  8930. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8931. return 0;
  8932. }
  8933. if (!player->IsPlayer()) {
  8934. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8935. return 0;
  8936. }
  8937. if (quest_id == 0) {
  8938. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8939. return 0;
  8940. }
  8941. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestCompletedCount(quest_id));
  8942. return 1;
  8943. }
  8944. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8945. if (!lua_interface)
  8946. return 0;
  8947. string name = lua_interface->GetStringValue(state);
  8948. string value = lua_interface->GetStringValue(state, 2);
  8949. string comment = lua_interface->GetStringValue(state, 3);
  8950. lua_interface->ResetFunctionStack(state);
  8951. if (name.length() == 0) {
  8952. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8953. return 0;
  8954. }
  8955. if (value.length() == 0) {
  8956. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8957. return 0;
  8958. }
  8959. string varname = string("lua_").append(name);
  8960. Variable* var = variables.FindVariable(varname);
  8961. if (var)
  8962. var->SetValue(value.c_str());
  8963. else {
  8964. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8965. variables.AddVariable(var);
  8966. }
  8967. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8968. return 0;
  8969. }
  8970. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8971. if (!lua_interface)
  8972. return 0;
  8973. string name = lua_interface->GetStringValue(state);
  8974. lua_interface->ResetFunctionStack(state);
  8975. if (name.length() == 0) {
  8976. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8977. return 0;
  8978. }
  8979. string varname = string("lua_").append(name);
  8980. Variable* var = variables.FindVariable(varname);
  8981. if (var)
  8982. lua_interface->SetStringValue(state, var->GetValue());
  8983. else
  8984. lua_interface->SetStringValue(state, "NULL");
  8985. return 1;
  8986. }
  8987. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8988. if (!lua_interface)
  8989. return 0;
  8990. Spawn* player = lua_interface->GetSpawn(state);
  8991. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8992. lua_interface->ResetFunctionStack(state);
  8993. if (!player) {
  8994. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8995. return 0;
  8996. }
  8997. if (!player->IsPlayer()) {
  8998. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8999. return 0;
  9000. }
  9001. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  9002. return 1;
  9003. }
  9004. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  9005. if (!lua_interface)
  9006. return 0;
  9007. Spawn* player = lua_interface->GetSpawn(state);
  9008. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9009. lua_interface->ResetFunctionStack(state);
  9010. if (!player) {
  9011. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9012. return 0;
  9013. }
  9014. if (!player->IsPlayer()) {
  9015. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9016. return 0;
  9017. }
  9018. Language* language = master_languages_list.GetLanguage(language_id);
  9019. if (language)
  9020. {
  9021. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  9022. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID(), 0);
  9023. }
  9024. return 0;
  9025. }
  9026. int EQ2Emu_lua_IsNight(lua_State* state) {
  9027. if (!lua_interface)
  9028. return 0;
  9029. ZoneServer* zone = lua_interface->GetZone(state);
  9030. lua_interface->ResetFunctionStack(state);
  9031. if (!zone) {
  9032. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  9033. return 0;
  9034. }
  9035. lua_interface->SetBooleanValue(state, zone->IsDusk());
  9036. return 1;
  9037. }
  9038. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  9039. if (!lua_interface)
  9040. return 0;
  9041. Spawn* spawn = lua_interface->GetSpawn(state);
  9042. lua_interface->ResetFunctionStack(state);
  9043. if (!spawn) {
  9044. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  9045. return 0;
  9046. }
  9047. if (!spawn->IsWidget()) {
  9048. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  9049. return 0;
  9050. }
  9051. ((Widget*)spawn)->SetMultiFloorLift(true);
  9052. if (spawn->GetZone())
  9053. spawn->GetZone()->AddTransportSpawn(spawn);
  9054. return 0;
  9055. }
  9056. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  9057. if (!lua_interface)
  9058. return 0;
  9059. Spawn* player = lua_interface->GetSpawn(state);
  9060. int32 path = lua_interface->GetInt32Value(state, 2);
  9061. lua_interface->ResetFunctionStack(state);
  9062. if (!player) {
  9063. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9064. return 0;
  9065. }
  9066. if (!player->IsPlayer()) {
  9067. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9068. return 0;
  9069. }
  9070. if (path == 0) {
  9071. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  9072. return 0;
  9073. }
  9074. Client* client = ((Player*)player)->GetClient();
  9075. if (!client) {
  9076. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9077. return 0;
  9078. }
  9079. client->SendFlightAutoMount(path);
  9080. return 0;
  9081. }
  9082. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  9083. if (!lua_interface)
  9084. return 0;
  9085. Spawn* player = lua_interface->GetSpawn(state);
  9086. if (!player) {
  9087. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9088. return 0;
  9089. }
  9090. if (!player->IsPlayer()) {
  9091. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9092. return 0;
  9093. }
  9094. Client* client = ((Player*)player)->GetClient();
  9095. if (!client) {
  9096. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9097. return 0;
  9098. }
  9099. client->EndAutoMount();
  9100. return 0;
  9101. }
  9102. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  9103. if (!lua_interface)
  9104. return 0;
  9105. Spawn* player = lua_interface->GetSpawn(state);
  9106. lua_interface->ResetFunctionStack(state);
  9107. if (!player) {
  9108. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  9109. return 0;
  9110. }
  9111. if (!player->IsPlayer()) {
  9112. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9113. return 0;
  9114. }
  9115. Client* client = ((Player*)player)->GetClient();
  9116. if (!client) {
  9117. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9118. return 0;
  9119. }
  9120. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  9121. return 1;
  9122. }
  9123. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  9124. if (!lua_interface)
  9125. return 0;
  9126. Spawn* player = lua_interface->GetSpawn(state);
  9127. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9128. int32 value = lua_interface->GetInt32Value(state, 3);
  9129. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9130. lua_interface->ResetFunctionStack(state);
  9131. if (!player) {
  9132. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9133. return 0;
  9134. }
  9135. if (!player->IsPlayer()) {
  9136. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9137. return 0;
  9138. }
  9139. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  9140. return 0;
  9141. }
  9142. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  9143. if (!lua_interface)
  9144. return 0;
  9145. Spawn* player = lua_interface->GetSpawn(state);
  9146. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9147. lua_interface->ResetFunctionStack(state);
  9148. if (!player) {
  9149. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9150. return 0;
  9151. }
  9152. if (!player->IsPlayer()) {
  9153. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9154. return 0;
  9155. }
  9156. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  9157. if (!hd)
  9158. return 0;
  9159. lua_interface->SetInt32Value(state, hd->Value);
  9160. lua_interface->SetInt32Value(state, hd->Value2);
  9161. return 2;
  9162. }
  9163. int EQ2Emu_lua_SetGridID(lua_State* state) {
  9164. if (!lua_interface)
  9165. return 0;
  9166. Spawn* spawn = lua_interface->GetSpawn(state);
  9167. int32 grid = lua_interface->GetInt32Value(state, 2);
  9168. lua_interface->ResetFunctionStack(state);
  9169. if (!spawn) {
  9170. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9171. return 0;
  9172. }
  9173. if (grid == 0) {
  9174. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  9175. return 0;
  9176. }
  9177. spawn->SetLocation(grid);
  9178. return 0;
  9179. }
  9180. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  9181. if (!lua_interface)
  9182. return 0;
  9183. Spawn* spawn = lua_interface->GetSpawn(state);
  9184. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9185. int32 value1 = lua_interface->GetInt32Value(state, 3);
  9186. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9187. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  9188. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  9189. lua_interface->ResetFunctionStack(state);
  9190. if (!spawn) {
  9191. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9192. return 0;
  9193. }
  9194. //Add this quest to the list of required quests for this spawn
  9195. spawn->SetRequiredHistory(event_id, value1, value2);
  9196. //If private spawn value set
  9197. if (private_spawn) {
  9198. //Set the spawn to be private when not granted access via history
  9199. spawn->AddAllowAccessSpawn(spawn);
  9200. spawn->SetPrivateQuestSpawn(true);
  9201. }
  9202. //This value will override vis_flags in the vis packet
  9203. if (flag_override > 0)
  9204. spawn->SetQuestsRequiredOverride(flag_override);
  9205. return 0;
  9206. }
  9207. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  9208. if (!lua_interface)
  9209. return 0;
  9210. Spawn* player = lua_interface->GetSpawn(state);
  9211. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9212. int32 step_id = lua_interface->GetInt32Value(state, 3);
  9213. lua_interface->ResetFunctionStack(state);
  9214. if (!player) {
  9215. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  9216. return 0;
  9217. }
  9218. if (!player->IsPlayer()) {
  9219. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  9220. return 0;
  9221. }
  9222. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  9223. return 1;
  9224. }
  9225. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  9226. if (!lua_interface)
  9227. return 0;
  9228. Spawn* player = lua_interface->GetSpawn(state);
  9229. int8 level = lua_interface->GetInt8Value(state, 2);
  9230. lua_interface->ResetFunctionStack(state);
  9231. if (!player) {
  9232. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  9233. return 0;
  9234. }
  9235. if (!player->IsPlayer()) {
  9236. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  9237. return 0;
  9238. }
  9239. if (level == 0) {
  9240. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  9241. return 0;
  9242. }
  9243. Client* client = ((Player*)player)->GetClient();
  9244. if (!client) {
  9245. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  9246. return 0;
  9247. }
  9248. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  9249. return 0;
  9250. }
  9251. int EQ2Emu_lua_AddCoin(lua_State* state) {
  9252. if (!lua_interface)
  9253. return 0;
  9254. Spawn* player = lua_interface->GetSpawn(state);
  9255. int32 amount = lua_interface->GetInt32Value(state, 2);
  9256. lua_interface->ResetFunctionStack(state);
  9257. if (!player) {
  9258. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9259. return 0;
  9260. }
  9261. if (!player->IsPlayer()) {
  9262. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9263. return 0;
  9264. }
  9265. if (amount == 0) {
  9266. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9267. return 0;
  9268. }
  9269. ((Player*)player)->AddCoins(amount);
  9270. return 0;
  9271. }
  9272. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  9273. if (!lua_interface)
  9274. return 0;
  9275. Spawn* player = lua_interface->GetSpawn(state);
  9276. int32 amount = lua_interface->GetInt32Value(state, 2);
  9277. lua_interface->ResetFunctionStack(state);
  9278. if (!player) {
  9279. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9280. return 0;
  9281. }
  9282. if (!player->IsPlayer()) {
  9283. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9284. return 0;
  9285. }
  9286. if (amount == 0) {
  9287. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9288. return 0;
  9289. }
  9290. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  9291. return 1;
  9292. }
  9293. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  9294. if (!lua_interface)
  9295. return 0;
  9296. ZoneServer* zone = lua_interface->GetZone(state);
  9297. lua_interface->ResetFunctionStack(state);
  9298. if (!zone) {
  9299. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9300. return 0;
  9301. }
  9302. vector<Entity*> players = zone->GetPlayers();
  9303. if (players.size() == 0)
  9304. return 0;
  9305. lua_createtable(state, players.size(), 0);
  9306. int newTable = lua_gettop(state);
  9307. for (int32 i = 0; i < players.size(); i++) {
  9308. lua_interface->SetSpawnValue(state, players.at(i));
  9309. lua_rawseti(state, newTable, i + 1);
  9310. }
  9311. return 1;
  9312. }
  9313. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  9314. if (!lua_interface)
  9315. return 0;
  9316. ZoneServer* zone = lua_interface->GetZone(state, 1);
  9317. if (!zone) {
  9318. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9319. return 0;
  9320. }
  9321. int32 group_id = lua_interface->GetInt32Value(state, 2);
  9322. lua_interface->ResetFunctionStack(state);
  9323. //Map of <placement_id, location_id>
  9324. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  9325. map<int32, int32>::iterator itr;
  9326. vector<Spawn*> group;
  9327. for (itr = locs->begin(); itr != locs->end(); itr++) {
  9328. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  9329. if (!location) {
  9330. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  9331. return 0;
  9332. }
  9333. Spawn* spawn = 0;
  9334. if (location->entities[0]) {
  9335. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  9336. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  9337. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  9338. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  9339. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  9340. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  9341. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  9342. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  9343. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9344. spawn = zone->AddSignSpawn(location, location->entities[0]);
  9345. if(spawn && spawn->IsOmittedByDBFlag())
  9346. {
  9347. 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);
  9348. safe_delete(spawn);
  9349. continue;
  9350. }
  9351. if (spawn) {
  9352. const char* script = 0;
  9353. for (int x = 0; x < 3; x++) {
  9354. switch (x) {
  9355. case 0:
  9356. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  9357. break;
  9358. case 1:
  9359. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  9360. break;
  9361. case 2:
  9362. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  9363. break;
  9364. }
  9365. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9366. spawn->SetSpawnScript(string(script));
  9367. break;
  9368. }
  9369. }
  9370. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9371. lua_interface->SetSpawnValue(state, spawn);
  9372. group.push_back(spawn);
  9373. }
  9374. else {
  9375. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  9376. safe_delete(spawn);
  9377. }
  9378. }
  9379. }
  9380. if (!group.empty()) {
  9381. lua_createtable(state, group.size(), 0);
  9382. int newTable = lua_gettop(state);
  9383. for (int32 i = 0; i < group.size(); i++) {
  9384. lua_interface->SetSpawnValue(state, group[i]);
  9385. lua_rawseti(state, newTable, i + 1);
  9386. }
  9387. }
  9388. else
  9389. lua_pushnil(state);
  9390. return 1;
  9391. }
  9392. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9393. if (!lua_interface)
  9394. return 0;
  9395. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9396. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9397. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9398. lua_interface->ResetFunctionStack(state);
  9399. if (!spawn) {
  9400. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9401. return 0;
  9402. }
  9403. if (anim_id == 0) {
  9404. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9405. return 0;
  9406. }
  9407. if (leeway == 0)
  9408. leeway = 5000;
  9409. spawn->SetSpawnAnim(anim_id);
  9410. spawn->SetSpawnAnimLeeway(leeway);
  9411. return 0;
  9412. }
  9413. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9414. if (!lua_interface)
  9415. return 0;
  9416. Spawn* player = lua_interface->GetSpawn(state);
  9417. lua_interface->ResetFunctionStack(state);
  9418. if (!player || !player->IsPlayer()) {
  9419. return 0;
  9420. }
  9421. Client* client = ((Player*)player)->GetClient();
  9422. if (!client) {
  9423. return 0;
  9424. }
  9425. lua_interface->SetInt32Value(state, client->GetVersion());
  9426. return 1;
  9427. }
  9428. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9429. if (!lua_interface)
  9430. return 0;
  9431. Item* item = lua_interface->GetItem(state);
  9432. lua_interface->ResetFunctionStack(state);
  9433. if (!item) {
  9434. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9435. return 0;
  9436. }
  9437. lua_interface->SetInt32Value(state, item->details.item_id);
  9438. return 1;
  9439. }
  9440. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9441. if (!lua_interface)
  9442. return 0;
  9443. Spawn* spawn = lua_interface->GetSpawn(state);
  9444. lua_interface->ResetFunctionStack(state);
  9445. if (!spawn) {
  9446. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9447. return 0;
  9448. }
  9449. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9450. return 1;
  9451. }
  9452. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9453. if (!lua_interface)
  9454. return 0;
  9455. Spawn* spawn = lua_interface->GetSpawn(state);
  9456. lua_interface->ResetFunctionStack(state);
  9457. if (!spawn) {
  9458. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9459. return 0;
  9460. }
  9461. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9462. return 1;
  9463. }
  9464. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9465. if (!lua_interface)
  9466. return 0;
  9467. Spawn* spawn = lua_interface->GetSpawn(state);
  9468. lua_interface->ResetFunctionStack(state);
  9469. if (!spawn) {
  9470. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9471. return 0;
  9472. }
  9473. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9474. return 1;
  9475. }
  9476. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9477. if (!lua_interface)
  9478. return 0;
  9479. Spawn* spawn = lua_interface->GetSpawn(state);
  9480. lua_interface->ResetFunctionStack(state);
  9481. if (!spawn) {
  9482. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9483. return 0;
  9484. }
  9485. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9486. return 1;
  9487. }
  9488. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9489. if (!lua_interface)
  9490. return 0;
  9491. Spawn* spawn = lua_interface->GetSpawn(state);
  9492. float pct = lua_interface->GetFloatValue(state, 2);
  9493. lua_interface->ResetFunctionStack(state);
  9494. if (!spawn) {
  9495. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9496. return 0;
  9497. }
  9498. if (pct == 0) {
  9499. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9500. return 0;
  9501. }
  9502. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9503. lua_interface->SetInt32Value(state, amount);
  9504. return 1;
  9505. }
  9506. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9507. if (!lua_interface)
  9508. return 0;
  9509. Spawn* spawn = lua_interface->GetSpawn(state);
  9510. float pct = lua_interface->GetFloatValue(state, 2);
  9511. lua_interface->ResetFunctionStack(state);
  9512. if (!spawn) {
  9513. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9514. return 0;
  9515. }
  9516. if (pct == 0) {
  9517. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9518. return 0;
  9519. }
  9520. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9521. lua_interface->SetInt32Value(state, amount);
  9522. return 1;
  9523. }
  9524. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9525. if (!lua_interface)
  9526. return 0;
  9527. Spawn* spawn = lua_interface->GetSpawn(state);
  9528. lua_interface->ResetFunctionStack(state);
  9529. if (!spawn) {
  9530. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9531. return 0;
  9532. }
  9533. if (!spawn->IsPlayer()) {
  9534. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9535. return 0;
  9536. }
  9537. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9538. return 1;
  9539. }
  9540. int EQ2Emu_lua_Evac(lua_State* state) {
  9541. if (!lua_interface)
  9542. return 0;
  9543. Spawn* target = lua_interface->GetSpawn(state);
  9544. if (target) {
  9545. float x = target->GetZone()->GetSafeX();
  9546. float y = target->GetZone()->GetSafeY();
  9547. float z = target->GetZone()->GetSafeZ();
  9548. float h = target->GetZone()->GetSafeHeading();
  9549. target->SetX(x);
  9550. target->SetY(y);
  9551. target->SetZ(z);
  9552. target->SetHeading(h);
  9553. target->SetSpawnOrigX(x);
  9554. target->SetSpawnOrigY(y);
  9555. target->SetSpawnOrigZ(z);
  9556. target->SetSpawnOrigHeading(h);
  9557. if (target->IsPlayer()) {
  9558. Client* client = ((Player*)target)->GetClient();
  9559. if (client) {
  9560. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9561. int numargs = lua_interface->GetNumberOfArgs(state);
  9562. if(numargs == 4) {
  9563. x = lua_interface->GetFloatValue(state,1);
  9564. y = lua_interface->GetFloatValue(state,2);
  9565. z = lua_interface->GetFloatValue(state,3);
  9566. h = lua_interface->GetFloatValue(state,4);
  9567. }
  9568. client->SetReloadingZone(true);
  9569. target->SetX(x);
  9570. target->SetY(y);
  9571. target->SetZ(z);
  9572. target->SetHeading(h);
  9573. target->SetSpawnOrigX(x);
  9574. target->SetSpawnOrigY(y);
  9575. target->SetSpawnOrigZ(z);
  9576. target->SetSpawnOrigHeading(h);
  9577. target->SetAppearancePosition(x,y,z);
  9578. client->SetZoningCoords(x,y,z,h);
  9579. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9580. if (packet)
  9581. {
  9582. packet->setDataByName("x", x);
  9583. packet->setDataByName("y", y);
  9584. packet->setDataByName("z", z);
  9585. client->QueuePacket(packet->serialize());
  9586. safe_delete(packet);
  9587. }
  9588. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9589. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9590. }
  9591. }
  9592. lua_interface->ResetFunctionStack(state);
  9593. }
  9594. else {
  9595. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9596. if(!spell) {
  9597. lua_interface->ResetFunctionStack(state);
  9598. return 0;
  9599. }
  9600. ZoneServer* zone = spell->caster->GetZone();
  9601. float x = spell->caster->GetZone()->GetSafeX();
  9602. float y = spell->caster->GetZone()->GetSafeY();
  9603. float z = spell->caster->GetZone()->GetSafeZ();
  9604. float h = spell->caster->GetZone()->GetSafeHeading();
  9605. int numargs = lua_interface->GetNumberOfArgs(state);
  9606. if(numargs == 4) {
  9607. x = lua_interface->GetFloatValue(state,1);
  9608. y = lua_interface->GetFloatValue(state,2);
  9609. z = lua_interface->GetFloatValue(state,3);
  9610. h = lua_interface->GetFloatValue(state,4);
  9611. }
  9612. lua_interface->ResetFunctionStack(state);
  9613. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9614. for (int32 i = 0; i < spell->targets.size(); i++) {
  9615. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9616. if (!target2)
  9617. continue;
  9618. if (target2->IsPlayer()) {
  9619. Client* client = ((Player*)target2)->GetClient();
  9620. if (client) {
  9621. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9622. client->SetReloadingZone(true);
  9623. target2->SetX(x);
  9624. target2->SetY(y);
  9625. target2->SetZ(z);
  9626. target2->SetHeading(h);
  9627. target2->SetSpawnOrigX(x);
  9628. target2->SetSpawnOrigY(y);
  9629. target2->SetSpawnOrigZ(z);
  9630. target2->SetSpawnOrigHeading(h);
  9631. target2->SetAppearancePosition(x,y,z);
  9632. client->SetZoningCoords(x,y,z,h);
  9633. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9634. if (packet)
  9635. {
  9636. packet->setDataByName("x", x);
  9637. packet->setDataByName("y", y);
  9638. packet->setDataByName("z", z);
  9639. client->QueuePacket(packet->serialize());
  9640. safe_delete(packet);
  9641. }
  9642. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9643. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9644. }
  9645. }
  9646. }
  9647. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9648. }
  9649. return 0;
  9650. }
  9651. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9652. if (!lua_interface)
  9653. return 0;
  9654. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9655. lua_interface->ResetFunctionStack(state);
  9656. if (!luaspell) {
  9657. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9658. return 0;
  9659. }
  9660. int8 tier = luaspell->spell->GetSpellTier();
  9661. lua_interface->SetInt32Value(state, tier);
  9662. return 1;
  9663. }
  9664. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9665. if (!lua_interface)
  9666. return 0;
  9667. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9668. lua_interface->ResetFunctionStack(state);
  9669. if (!luaspell) {
  9670. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9671. return 0;
  9672. }
  9673. int32 spell_id = luaspell->spell->GetSpellID();
  9674. lua_interface->SetInt32Value(state, spell_id);
  9675. return 1;
  9676. }
  9677. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9678. if (!lua_interface)
  9679. return 0;
  9680. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9681. lua_interface->ResetFunctionStack(state);
  9682. if (!spawn) {
  9683. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9684. return 0;
  9685. }
  9686. if (!spawn->IsPlayer()) {
  9687. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9688. return 0;
  9689. }
  9690. ZoneServer* zone = spawn->GetZone();
  9691. if (!zone) {
  9692. return 0;
  9693. }
  9694. Client* client = ((Player*)spawn)->GetClient();
  9695. if (!client) {
  9696. return 0;
  9697. }
  9698. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9699. return 0;
  9700. }
  9701. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9702. if (!lua_interface)
  9703. return 0;
  9704. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9705. lua_interface->ResetFunctionStack(state);
  9706. if (!spawn) {
  9707. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9708. return 0;
  9709. }
  9710. if (!spawn->IsPlayer()) {
  9711. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9712. return 0;
  9713. }
  9714. ZoneServer* zone = spawn->GetZone();
  9715. if (!zone) {
  9716. return 0;
  9717. }
  9718. Client* client = ((Player*)spawn)->GetClient();
  9719. if (!client) {
  9720. return 0;
  9721. }
  9722. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9723. return 0;
  9724. }
  9725. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9726. if (!lua_interface)
  9727. return 0;
  9728. Spawn* caster = lua_interface->GetSpawn(state);
  9729. Spawn* target = lua_interface->GetSpawn(state, 2);
  9730. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9731. string spell_name = lua_interface->GetStringValue(state, 4);
  9732. lua_interface->ResetFunctionStack(state);
  9733. if (!caster) {
  9734. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9735. return 0;
  9736. }
  9737. if (!caster->IsEntity()) {
  9738. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9739. return 0;
  9740. }
  9741. if (!target) {
  9742. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9743. return 0;
  9744. }
  9745. if (!target->IsEntity()) {
  9746. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9747. return 0;
  9748. }
  9749. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9750. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9751. return 0;
  9752. }
  9753. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9754. if (!lua_interface)
  9755. return 0;
  9756. Spawn* player = lua_interface->GetSpawn(state);
  9757. int32 amount = lua_interface->GetInt32Value(state, 2);
  9758. lua_interface->ResetFunctionStack(state);
  9759. if (player && player->IsPlayer() && amount > 0) {
  9760. ((Player*)player)->AddXP(amount);
  9761. }
  9762. return 0;
  9763. }
  9764. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9765. if (!lua_interface)
  9766. return 0;
  9767. Spawn* player = lua_interface->GetSpawn(state);
  9768. int8 type = lua_interface->GetInt8Value(state, 2);
  9769. string text = lua_interface->GetStringValue(state, 3);
  9770. lua_interface->ResetFunctionStack(state);
  9771. Client* client = 0;
  9772. if (player && player->IsPlayer())
  9773. client = ((Player*)player)->GetClient();
  9774. if (!client || text.length() == 0) {
  9775. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9776. return 0;
  9777. }
  9778. client->SimpleMessage(type, text.c_str());
  9779. return 0;
  9780. }
  9781. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9782. if (!lua_interface)
  9783. return 0;
  9784. Spawn* player = lua_interface->GetSpawn(state);
  9785. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9786. lua_interface->ResetFunctionStack(state);
  9787. Client* client = 0;
  9788. if (player && player->IsPlayer())
  9789. client = ((Player*)player)->GetClient();
  9790. if (!client || !spawn) {
  9791. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9792. return 0;
  9793. }
  9794. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9795. if (!items) {
  9796. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9797. return 0;
  9798. }
  9799. client->Loot(spawn->GetLootCoins(), items, spawn);
  9800. return 0;
  9801. }
  9802. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9803. if (!lua_interface)
  9804. return 0;
  9805. Spawn* spawnref = lua_interface->GetSpawn(state);
  9806. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9807. lua_interface->ResetFunctionStack(state);
  9808. if (spawn_id > 0 && spawnref) {
  9809. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9810. if (spawns.size() == 0) {
  9811. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9812. return 0;
  9813. }
  9814. Spawn* spawn = 0;
  9815. int16 index = MakeRandomInt(0, spawns.size());
  9816. if (index >= spawns.size() || index < 0)
  9817. index = 0;
  9818. spawn = spawns[index];
  9819. lua_interface->SetSpawnValue(state, spawn);
  9820. return 1;
  9821. }
  9822. else {
  9823. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9824. }
  9825. return 0;
  9826. }
  9827. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9828. Spawn* player = lua_interface->GetSpawn(state);
  9829. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9830. string name = lua_interface->GetStringValue(state, 3);
  9831. float distance = lua_interface->GetFloatValue(state, 4);
  9832. string command = lua_interface->GetStringValue(state, 5);
  9833. string error_text = lua_interface->GetStringValue(state, 6);
  9834. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9835. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9836. lua_interface->ResetFunctionStack(state);
  9837. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9838. if (distance == 0)
  9839. distance = 10.0f;
  9840. if (command.length() == 0)
  9841. command = name;
  9842. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9843. if (spawns.size() == 0) {
  9844. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9845. return 0;
  9846. }
  9847. Spawn* spawn = 0;
  9848. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9849. spawn = *itr;
  9850. if (spawn) {
  9851. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9852. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9853. }
  9854. }
  9855. }
  9856. return 0;
  9857. }
  9858. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9859. if (!lua_interface)
  9860. return 0;
  9861. Client* client = 0;
  9862. Spawn* player = lua_interface->GetSpawn(state);
  9863. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9864. lua_interface->ResetFunctionStack(state);
  9865. if (player && player->IsPlayer() && player->GetZone())
  9866. client = ((Player*)player)->GetClient();
  9867. else{
  9868. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9869. return 0;
  9870. }
  9871. if (client) {
  9872. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9873. if (packet) {
  9874. packet->setDataByName("goal_num", goal_num);
  9875. client->QueuePacket(packet->serialize());
  9876. safe_delete(packet);
  9877. }
  9878. }
  9879. return 0;
  9880. }
  9881. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9882. if (!lua_interface)
  9883. return 0;
  9884. Client* client = 0;
  9885. Spawn* player = lua_interface->GetSpawn(state);
  9886. lua_interface->ResetFunctionStack(state);
  9887. if (player && player->IsPlayer() && player->GetZone())
  9888. client = ((Player*)player)->GetClient();
  9889. else {
  9890. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9891. return 0;
  9892. }
  9893. if (client) {
  9894. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9895. }
  9896. return 0;
  9897. }
  9898. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9899. if (!lua_interface)
  9900. return 0;
  9901. Client* client = 0;
  9902. Spawn* player = lua_interface->GetSpawn(state);
  9903. float duration = lua_interface->GetFloatValue(state, 2);
  9904. string text = lua_interface->GetStringValue(state, 3);
  9905. string voice = lua_interface->GetStringValue(state, 4);
  9906. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9907. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9908. string signal = lua_interface->GetStringValue(state, 7);
  9909. string goal1 = lua_interface->GetStringValue(state, 8);
  9910. string task1 = lua_interface->GetStringValue(state, 9);
  9911. string goal2 = lua_interface->GetStringValue(state, 10);
  9912. string task2 = lua_interface->GetStringValue(state, 11);
  9913. string goal3 = lua_interface->GetStringValue(state, 12);
  9914. string task3 = lua_interface->GetStringValue(state, 13);
  9915. string goal4 = lua_interface->GetStringValue(state, 14);
  9916. string task4 = lua_interface->GetStringValue(state, 15);
  9917. lua_interface->ResetFunctionStack(state);
  9918. if (!player) {
  9919. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9920. return 0;
  9921. }
  9922. if (!player->IsPlayer()) {
  9923. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9924. return 0;
  9925. }
  9926. else
  9927. client = ((Player*)player)->GetClient();
  9928. if (!client) {
  9929. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9930. return 0;
  9931. }
  9932. if (text.length() == 0) {
  9933. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9934. return 0;
  9935. }
  9936. if (duration >= 0 && duration < 2)
  9937. duration = 2;
  9938. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9939. if (packet) {
  9940. packet->setDataByName("open_seconds_max", duration);
  9941. packet->setDataByName("text", text.c_str());
  9942. packet->setDataByName("voice", voice.c_str());
  9943. int8 num_goals = 1;
  9944. if (task2.length() > 0)
  9945. num_goals++;
  9946. if (task3.length() > 0)
  9947. num_goals++;
  9948. if (task4.length() > 0)
  9949. num_goals++;
  9950. packet->setArrayLengthByName("num_goals", num_goals);
  9951. for (int8 i = 0; i < num_goals; i++) {
  9952. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9953. }
  9954. if (goal1.length() > 0)
  9955. packet->setArrayDataByName("goal_text", goal1.c_str());
  9956. if (goal2.length() > 0)
  9957. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9958. if (goal3.length() > 0)
  9959. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9960. if (goal4.length() > 0)
  9961. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9962. packet->setSubArrayDataByName("task_text", task1.c_str());
  9963. if (task2.length() > 0)
  9964. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9965. if (task3.length() > 0)
  9966. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9967. if (task4.length() > 0)
  9968. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9969. packet->setDataByName("complete_sound", "click");
  9970. packet->setDataByName("signal", signal.c_str());
  9971. packet->setDataByName("voice_key1", voice_key1);
  9972. packet->setDataByName("voice_key2", voice_key2);
  9973. client->QueuePacket(packet->serialize());
  9974. safe_delete(packet);
  9975. }
  9976. return 0;
  9977. }
  9978. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9979. if (!lua_interface)
  9980. return 0;
  9981. Client* client = 0;
  9982. Spawn* player = lua_interface->GetSpawn(state);
  9983. string window = lua_interface->GetStringValue(state, 2);
  9984. int8 show = lua_interface->GetInt8Value(state, 3);
  9985. lua_interface->ResetFunctionStack(state);
  9986. if (!player) {
  9987. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9988. return 0;
  9989. }
  9990. if (!player->IsPlayer()) {
  9991. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9992. return 0;
  9993. }
  9994. else
  9995. client = ((Player*)player)->GetClient();
  9996. if (!client) {
  9997. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9998. return 0;
  9999. }
  10000. if (window.length() == 0) {
  10001. lua_interface->LogError("LUA ShowWindow required parameters not given");
  10002. return 0;
  10003. }
  10004. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  10005. if (packet) {
  10006. packet->setDataByName("window", window.c_str());
  10007. packet->setDataByName("show", show);
  10008. client->QueuePacket(packet->serialize());
  10009. safe_delete(packet);
  10010. }
  10011. return 0;
  10012. }
  10013. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  10014. //See GameEvents.txt for options that can be used for this function
  10015. if (!lua_interface)
  10016. return 0;
  10017. Client* client = 0;
  10018. Spawn* player = lua_interface->GetSpawn(state);
  10019. string event_name = lua_interface->GetStringValue(state, 2);
  10020. int8 enabled = lua_interface->GetInt8Value(state, 3);
  10021. lua_interface->ResetFunctionStack(state);
  10022. if (!player || !player->IsPlayer()) {
  10023. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  10024. return 0;
  10025. }
  10026. client = ((Player*)player)->GetClient();
  10027. if (!client) {
  10028. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  10029. return 0;
  10030. }
  10031. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  10032. if (packet) {
  10033. packet->setDataByName("event_name", event_name.c_str());
  10034. packet->setDataByName("enabled", enabled);
  10035. client->QueuePacket(packet->serialize());
  10036. safe_delete(packet);
  10037. }
  10038. return 0;
  10039. }
  10040. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  10041. if (!lua_interface)
  10042. return 0;
  10043. Spawn* player = lua_interface->GetSpawn(state);
  10044. lua_interface->ResetFunctionStack(state);
  10045. if (player && player->IsPlayer()) {
  10046. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  10047. return 1;
  10048. }
  10049. return 0;
  10050. }
  10051. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  10052. if (!lua_interface)
  10053. return 0;
  10054. Spawn* player = lua_interface->GetSpawn(state);
  10055. int8 step = lua_interface->GetInt8Value(state, 2);
  10056. lua_interface->ResetFunctionStack(state);
  10057. if (player && player->IsPlayer() && step > 0) {
  10058. ((Player*)player)->SetTutorialStep(step);
  10059. }
  10060. return 0;
  10061. }
  10062. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  10063. if (!lua_interface)
  10064. return 0;
  10065. Client* client = 0;
  10066. Spawn* player = lua_interface->GetSpawn(state);
  10067. string window = lua_interface->GetStringValue(state, 2);
  10068. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  10069. lua_interface->ResetFunctionStack(state);
  10070. if (!player) {
  10071. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  10072. return 0;
  10073. }
  10074. if (!player->IsPlayer()) {
  10075. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  10076. return 0;
  10077. }
  10078. else
  10079. client = ((Player*)player)->GetClient();
  10080. if (!client) {
  10081. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  10082. return 0;
  10083. }
  10084. if (window.length() == 0) {
  10085. lua_interface->LogError("LUA FlashWindow required parameters not given");
  10086. return 0;
  10087. }
  10088. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  10089. if (packet) {
  10090. packet->setDataByName("window", window.c_str());
  10091. packet->setDataByName("flash_seconds", flash_seconds);
  10092. client->QueuePacket(packet->serialize());
  10093. safe_delete(packet);
  10094. }
  10095. return 0;
  10096. }
  10097. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  10098. if (!lua_interface)
  10099. return 0;
  10100. Spawn* spawn = lua_interface->GetSpawn(state);
  10101. Spawn* target = lua_interface->GetSpawn(state, 2);
  10102. lua_interface->ResetFunctionStack(state);
  10103. if (spawn && target)
  10104. return spawn->CheckLoS(target);
  10105. return 0;
  10106. }
  10107. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  10108. if (!lua_interface)
  10109. return 0;
  10110. Spawn* spawn = lua_interface->GetSpawn(state);
  10111. float x = lua_interface->GetFloatValue(state, 2);
  10112. float y = lua_interface->GetFloatValue(state, 3);
  10113. float z = lua_interface->GetFloatValue(state, 4);
  10114. lua_interface->ResetFunctionStack(state);
  10115. if (spawn)
  10116. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  10117. return 0;
  10118. }
  10119. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  10120. if (!lua_interface)
  10121. return 0;
  10122. ZoneServer* zone = lua_interface->GetZone(state);
  10123. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  10124. lua_interface->ResetFunctionStack(state);
  10125. if (zone)
  10126. zone->SetExpansionFlag(xpackFlag);
  10127. return 0;
  10128. }
  10129. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  10130. if (!lua_interface)
  10131. return 0;
  10132. ZoneServer* zone = lua_interface->GetZone(state);
  10133. lua_interface->ResetFunctionStack(state);
  10134. if (zone) {
  10135. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  10136. return 1;
  10137. }
  10138. return 0;
  10139. }
  10140. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  10141. if (!lua_interface)
  10142. return 0;
  10143. ZoneServer* zone = lua_interface->GetZone(state);
  10144. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  10145. lua_interface->ResetFunctionStack(state);
  10146. if (zone)
  10147. zone->SetHolidayFlag(holidayFlag);
  10148. return 0;
  10149. }
  10150. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  10151. if (!lua_interface)
  10152. return 0;
  10153. ZoneServer* zone = lua_interface->GetZone(state);
  10154. lua_interface->ResetFunctionStack(state);
  10155. if (zone) {
  10156. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  10157. return 1;
  10158. }
  10159. return 0;
  10160. }
  10161. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  10162. if (!lua_interface)
  10163. return 0;
  10164. Spawn* player = lua_interface->GetSpawn(state);
  10165. ZoneServer* zone = player->GetZone();
  10166. bool canbind = lua_interface->GetInt32Value(state, 2);
  10167. lua_interface->ResetFunctionStack(state);
  10168. if (zone)
  10169. zone->SetCanBind(canbind);
  10170. return 0;
  10171. }
  10172. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  10173. if (!lua_interface)
  10174. return 0;
  10175. Spawn* player = lua_interface->GetSpawn(state);
  10176. ZoneServer* zone = player->GetZone();
  10177. lua_interface->ResetFunctionStack(state);
  10178. if (zone) {
  10179. lua_interface->SetInt32Value(state, zone->GetCanBind());
  10180. return 1;
  10181. }
  10182. return 0;
  10183. }
  10184. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  10185. if (!lua_interface)
  10186. return 0;
  10187. Spawn* player = lua_interface->GetSpawn(state);
  10188. ZoneServer* zone = player->GetZone();
  10189. bool cangate = lua_interface->GetInt32Value(state, 2);
  10190. lua_interface->ResetFunctionStack(state);
  10191. if (zone)
  10192. zone->SetCanGate(cangate);
  10193. return 0;
  10194. }
  10195. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  10196. if (!lua_interface)
  10197. return 0;
  10198. Spawn* player = lua_interface->GetSpawn(state);
  10199. ZoneServer* zone = player->GetZone();
  10200. lua_interface->ResetFunctionStack(state);
  10201. if (zone) {
  10202. lua_interface->SetInt32Value(state, zone->GetCanGate());
  10203. return 1;
  10204. }
  10205. return 0;
  10206. }
  10207. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  10208. if (!lua_interface)
  10209. return 0;
  10210. Spawn* spawn = lua_interface->GetSpawn(state);
  10211. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  10212. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  10213. float distance = lua_interface->GetFloatValue(state, 4);
  10214. string in_range_function = lua_interface->GetStringValue(state, 5);
  10215. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  10216. lua_interface->ResetFunctionStack(state);
  10217. if (spawn && distance > 0 && in_range_function.length() > 0)
  10218. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  10219. return 0;
  10220. }
  10221. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  10222. if (!lua_interface)
  10223. return 0;
  10224. Spawn* spawn = lua_interface->GetSpawn(state);
  10225. Spawn* target = lua_interface->GetSpawn(state, 2);
  10226. lua_interface->ResetFunctionStack(state);
  10227. if (spawn && target)
  10228. {
  10229. if (spawn->IsPlayer() && target->IsEntity())
  10230. {
  10231. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  10232. return 1;
  10233. }
  10234. else if (spawn->IsEntity() && target->IsEntity())
  10235. {
  10236. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  10237. return 1;
  10238. }
  10239. }
  10240. return 0;
  10241. }
  10242. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  10243. if (!lua_interface)
  10244. return 0;
  10245. Spawn* spawn = lua_interface->GetSpawn(state);
  10246. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10247. lua_interface->ResetFunctionStack(state);
  10248. if (spawn && spawn->IsEntity())
  10249. {
  10250. ((Entity*)spawn)->SetSeeInvisSpell(val);
  10251. if (spawn->IsPlayer())
  10252. {
  10253. Client* client = ((Player*)spawn)->GetClient();
  10254. if (client)
  10255. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  10256. }
  10257. }
  10258. return 0;
  10259. }
  10260. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  10261. if (!lua_interface)
  10262. return 0;
  10263. Spawn* spawn = lua_interface->GetSpawn(state);
  10264. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10265. lua_interface->ResetFunctionStack(state);
  10266. if (spawn && spawn->IsEntity())
  10267. {
  10268. ((Entity*)spawn)->SetSeeHideSpell(val);
  10269. if (spawn->IsPlayer())
  10270. {
  10271. Client* client = ((Player*)spawn)->GetClient();
  10272. if (client)
  10273. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  10274. }
  10275. }
  10276. return 0;
  10277. }
  10278. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  10279. {
  10280. if (!lua_interface)
  10281. return 0;
  10282. Spawn* player = lua_interface->GetSpawn(state);
  10283. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10284. string command = lua_interface->GetStringValue(state, 3);
  10285. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10286. lua_interface->ResetFunctionStack(state);
  10287. if (spawn && player && player->IsPlayer())
  10288. {
  10289. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10290. bool res = false;
  10291. if (cmd)
  10292. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  10293. lua_interface->SetBooleanValue(state, res);
  10294. return 1;
  10295. }
  10296. return 0;
  10297. }
  10298. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  10299. {
  10300. if (!lua_interface)
  10301. return 0;
  10302. Spawn* spawn = lua_interface->GetSpawn(state);
  10303. int32 charID = lua_interface->GetInt32Value(state, 2);
  10304. string command = lua_interface->GetStringValue(state, 3);
  10305. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10306. lua_interface->ResetFunctionStack(state);
  10307. if (spawn && charID)
  10308. {
  10309. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10310. bool res = false;
  10311. if (cmd)
  10312. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  10313. lua_interface->SetBooleanValue(state, res);
  10314. return 1;
  10315. }
  10316. return 0;
  10317. }
  10318. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  10319. {
  10320. if (!lua_interface)
  10321. return 0;
  10322. Spawn* spawn = lua_interface->GetSpawn(state);
  10323. string command = lua_interface->GetStringValue(state, 2);
  10324. lua_interface->ResetFunctionStack(state);
  10325. if (spawn && command.length() > 0)
  10326. spawn->RemovePrimaryEntityCommand(command.c_str());
  10327. return 0;
  10328. }
  10329. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  10330. if (!lua_interface)
  10331. return 0;
  10332. Spawn* spawn = lua_interface->GetSpawn(state);
  10333. float distance = lua_interface->GetFloatValue(state, 2);
  10334. string command = lua_interface->GetStringValue(state, 3);
  10335. Spawn* player = lua_interface->GetSpawn(state, 4);
  10336. lua_interface->ResetFunctionStack(state);
  10337. if (spawn) {
  10338. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  10339. }
  10340. return 0;
  10341. }
  10342. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  10343. if (!lua_interface)
  10344. return 0;
  10345. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10346. Spawn* spawn = lua_interface->GetSpawn(state);
  10347. Spawn* player = lua_interface->GetSpawn(state, 2);
  10348. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  10349. lua_interface->ResetFunctionStack(state);
  10350. if (spawn && player && transport_id && player->IsPlayer()) {
  10351. Client* client = 0;
  10352. if (player && player->IsPlayer())
  10353. client = ((Player*)player)->GetClient();
  10354. if (!client)
  10355. return 0;
  10356. vector<TransportDestination*> destinations;
  10357. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  10358. if (destinations.size())
  10359. {
  10360. client->SetTemporaryTransportID(transport_id);
  10361. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  10362. }
  10363. else
  10364. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  10365. }
  10366. return 0;
  10367. }
  10368. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  10369. if (!lua_interface)
  10370. return 0;
  10371. Spawn* player = lua_interface->GetSpawn(state);
  10372. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  10373. lua_interface->ResetFunctionStack(state);
  10374. if (player && player->IsPlayer()) {
  10375. Client* client = 0;
  10376. if (player && player->IsPlayer())
  10377. client = ((Player*)player)->GetClient();
  10378. if (!client)
  10379. return 0;
  10380. client->SetTemporaryTransportID(transport_id);
  10381. }
  10382. return 0;
  10383. }
  10384. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10385. if (!lua_interface)
  10386. return 0;
  10387. Spawn* player = lua_interface->GetSpawn(state);
  10388. lua_interface->ResetFunctionStack(state);
  10389. if (player && player->IsPlayer()) {
  10390. Client* client = 0;
  10391. if (player && player->IsPlayer())
  10392. client = ((Player*)player)->GetClient();
  10393. if (!client)
  10394. return 0;
  10395. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10396. return 1;
  10397. }
  10398. return 0;
  10399. }
  10400. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10401. if (!lua_interface)
  10402. return 0;
  10403. Spawn* spawn = lua_interface->GetSpawn(state);
  10404. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10405. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10406. if (!spawn) {
  10407. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10408. return 0;
  10409. }
  10410. if (!spawn->IsEntity()) {
  10411. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10412. return 0;
  10413. }
  10414. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10415. {
  10416. 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);
  10417. return 0;
  10418. }
  10419. lua_interface->ResetFunctionStack(state);
  10420. if (spell && spell->targets.size() > 0) {
  10421. ZoneServer* zone = spell->caster->GetZone();
  10422. for (int8 i = 0; i < spell->targets.size(); i++) {
  10423. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10424. if (target && target->IsEntity()) {
  10425. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10426. if (target->IsPlayer())
  10427. ((Player*)target)->SetCharSheetChanged(true);
  10428. }
  10429. }
  10430. }
  10431. else {
  10432. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10433. if (spawn->IsPlayer())
  10434. ((Player*)spawn)->SetCharSheetChanged(true);
  10435. }
  10436. return 0;
  10437. }
  10438. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10439. if (!lua_interface)
  10440. return 0;
  10441. Spawn* spawn = lua_interface->GetSpawn(state);
  10442. lua_interface->ResetFunctionStack(state);
  10443. if (!spawn) {
  10444. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10445. return 0;
  10446. }
  10447. if (!spawn->IsEntity()) {
  10448. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10449. return 0;
  10450. }
  10451. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10452. return 1;
  10453. }
  10454. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10455. if (!lua_interface)
  10456. return 0;
  10457. int32 spell_id = lua_interface->GetInt32Value(state);
  10458. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10459. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10460. if (spell_id > 0) {
  10461. if (spell_tier == 0)
  10462. spell_tier = 1;
  10463. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10464. LuaSpell* lua_spell = 0;
  10465. if(custom_lua_script.size() > 0)
  10466. {
  10467. // attempt to load the custom script since it isn't already loaded
  10468. // we will re-obtain the lua_spell further below
  10469. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10470. {
  10471. 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());
  10472. lua_interface->LoadLuaSpell(custom_lua_script);
  10473. }
  10474. }
  10475. else
  10476. custom_lua_script = spell->GetSpellData()->lua_script;
  10477. if (!lua_spell && lua_interface)
  10478. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10479. if (!lua_spell)
  10480. {
  10481. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10482. return 0;
  10483. }
  10484. lua_spell->spell = new Spell(spell);
  10485. lua_interface->AddCustomSpell(lua_spell);
  10486. lua_interface->SetSpellValue(state, lua_spell);
  10487. return 1;
  10488. }
  10489. return 0;
  10490. }
  10491. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10492. if (!lua_interface)
  10493. return 0;
  10494. LuaSpell* spell = lua_interface->GetSpell(state);
  10495. string field = lua_interface->GetStringValue(state, 2);
  10496. if (!spell) {
  10497. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10498. return 0;
  10499. }
  10500. if (!spell->spell || !spell->spell->GetSpellData()) {
  10501. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10502. return 0;
  10503. }
  10504. boost::to_lower(field);
  10505. return spell->spell->GetSpellData(state, field);
  10506. }
  10507. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10508. if (!lua_interface)
  10509. return 0;
  10510. LuaSpell* spell = lua_interface->GetSpell(state);
  10511. string field = lua_interface->GetStringValue(state, 2);
  10512. int8 fieldArg = 3; // field value after the initial set
  10513. if (!spell) {
  10514. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10515. return 0;
  10516. }
  10517. if (!spell->spell || !spell->spell->GetSpellData()) {
  10518. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10519. return 0;
  10520. }
  10521. boost::to_lower(field);
  10522. bool valSet = false;
  10523. spell->spell->SetSpellData(state, field, fieldArg);
  10524. return valSet;
  10525. }
  10526. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10527. if (!lua_interface)
  10528. return 0;
  10529. LuaSpell* spell = lua_interface->GetSpell(state);
  10530. int8 idx = lua_interface->GetInt32Value(state, 2);
  10531. if (!spell) {
  10532. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10533. return 0;
  10534. }
  10535. if (!spell->spell || !spell->spell->GetSpellData()) {
  10536. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10537. return 0;
  10538. }
  10539. if (spell->spell->lua_data.size() <= idx)
  10540. {
  10541. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10542. return 0;
  10543. }
  10544. bool setVal = true;
  10545. LUAData* data = spell->spell->lua_data[idx];
  10546. switch (data->type)
  10547. {
  10548. case 0:
  10549. {
  10550. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10551. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10552. data->int_value = value;
  10553. data->int_value2 = value2;
  10554. break;
  10555. }
  10556. case 1:
  10557. {
  10558. float value = lua_interface->GetFloatValue(state, 3);
  10559. float value2 = lua_interface->GetFloatValue(state, 4);
  10560. data->float_value = value;
  10561. data->float_value2 = value2;
  10562. break;
  10563. }
  10564. case 2:
  10565. {
  10566. bool value = lua_interface->GetBooleanValue(state, 3);
  10567. data->bool_value = value;
  10568. break;
  10569. }
  10570. case 3:
  10571. {
  10572. string value = lua_interface->GetStringValue(state, 3);
  10573. string value2 = lua_interface->GetStringValue(state, 4);
  10574. data->string_value = value;
  10575. data->string_value2 = value2;
  10576. break;
  10577. }
  10578. default:
  10579. setVal = false;
  10580. }
  10581. return setVal;
  10582. }
  10583. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10584. if (!lua_interface)
  10585. return 0;
  10586. LuaSpell* spell = lua_interface->GetSpell(state);
  10587. int8 idx = lua_interface->GetInt32Value(state, 2);
  10588. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10589. if (!spell) {
  10590. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10591. return 0;
  10592. }
  10593. if (!spell->spell || !spell->spell->GetSpellData()) {
  10594. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10595. return 0;
  10596. }
  10597. if (spell->spell->lua_data.size() <= idx)
  10598. {
  10599. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10600. return 0;
  10601. }
  10602. bool setVal = true;
  10603. LUAData* data = spell->spell->lua_data[idx];
  10604. switch (data->type)
  10605. {
  10606. case 0:
  10607. {
  10608. if(!secondfield)
  10609. lua_interface->SetSInt32Value(state, data->int_value);
  10610. else
  10611. lua_interface->SetSInt32Value(state, data->int_value2);
  10612. break;
  10613. }
  10614. case 1:
  10615. {
  10616. if (!secondfield)
  10617. lua_interface->SetFloatValue(state, data->float_value);
  10618. else
  10619. lua_interface->SetFloatValue(state, data->float_value2);
  10620. break;
  10621. }
  10622. case 2:
  10623. {
  10624. lua_interface->SetBooleanValue(state, data->bool_value);
  10625. break;
  10626. }
  10627. case 3:
  10628. {
  10629. if (!secondfield)
  10630. lua_interface->SetStringValue(state, data->string_value.c_str());
  10631. else
  10632. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10633. break;
  10634. }
  10635. default:
  10636. setVal = false;
  10637. }
  10638. return setVal;
  10639. }
  10640. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10641. if (!lua_interface)
  10642. return 0;
  10643. LuaSpell* spell = lua_interface->GetSpell(state);
  10644. int8 idx = lua_interface->GetInt32Value(state, 2);
  10645. string field = lua_interface->GetStringValue(state, 3);
  10646. boost::to_lower(field);
  10647. if (!spell) {
  10648. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10649. return 0;
  10650. }
  10651. if (!spell->spell || !spell->spell->GetSpellData()) {
  10652. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10653. return 0;
  10654. }
  10655. if (spell->spell->effects.size() <= idx)
  10656. {
  10657. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10658. return 0;
  10659. }
  10660. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10661. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10662. if (field == "description")
  10663. effect->description = string(lua_interface->GetStringValue(state, 4));
  10664. else if (field == "bullet")
  10665. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10666. else if (field == "percentage")
  10667. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10668. else // no match
  10669. return 0;
  10670. return 1;
  10671. }
  10672. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10673. if (!lua_interface)
  10674. return 0;
  10675. LuaSpell* spell = lua_interface->GetSpell(state);
  10676. int8 idx = lua_interface->GetInt32Value(state, 2);
  10677. string field = lua_interface->GetStringValue(state, 3);
  10678. boost::to_lower(field);
  10679. if (!spell) {
  10680. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10681. return 0;
  10682. }
  10683. if (!spell->spell || !spell->spell->GetSpellData()) {
  10684. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10685. return 0;
  10686. }
  10687. if (spell->spell->effects.size() <= idx)
  10688. {
  10689. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10690. return 0;
  10691. }
  10692. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10693. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10694. if (field == "description")
  10695. lua_interface->SetStringValue(state, effect->description.c_str());
  10696. else if (field == "bullet")
  10697. lua_interface->SetInt32Value(state, effect->subbullet);
  10698. else if (field == "percentage")
  10699. lua_interface->SetInt32Value(state, effect->percentage);
  10700. else // no match
  10701. return 0;
  10702. return 1;
  10703. }
  10704. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10705. if (!lua_interface)
  10706. return 0;
  10707. LuaSpell* spell = lua_interface->GetSpell(state);
  10708. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10709. Spawn* target = lua_interface->GetSpawn(state, 3);
  10710. if (!target) {
  10711. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10712. return 0;
  10713. }
  10714. if (!target->IsEntity()) {
  10715. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10716. return 0;
  10717. }
  10718. if (!spell) {
  10719. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10720. return 0;
  10721. }
  10722. if (caster && !caster->IsEntity()) {
  10723. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10724. return 0;
  10725. }
  10726. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10727. return 0;
  10728. }
  10729. int EQ2Emu_lua_InWater(lua_State* state) {
  10730. if (!lua_interface)
  10731. return 0;
  10732. Spawn* spawn = lua_interface->GetSpawn(state);
  10733. lua_interface->ResetFunctionStack(state);
  10734. if (spawn) {
  10735. lua_interface->SetBooleanValue(state, spawn->InWater());
  10736. return 1;
  10737. }
  10738. return 0;
  10739. }
  10740. int EQ2Emu_lua_InLava(lua_State* state) {
  10741. if (!lua_interface)
  10742. return 0;
  10743. Spawn* spawn = lua_interface->GetSpawn(state);
  10744. lua_interface->ResetFunctionStack(state);
  10745. if (spawn) {
  10746. lua_interface->SetBooleanValue(state, spawn->InLava());
  10747. return 1;
  10748. }
  10749. return 0;
  10750. }
  10751. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10752. if (!lua_interface)
  10753. return 0;
  10754. Spawn* attacker = lua_interface->GetSpawn(state);
  10755. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10756. int8 type = lua_interface->GetInt8Value(state, 3);
  10757. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10758. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10759. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10760. string spell_name = lua_interface->GetStringValue(state, 7);
  10761. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10762. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10763. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10764. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10765. lua_interface->ResetFunctionStack(state);
  10766. if (!attacker) {
  10767. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10768. return 0;
  10769. }
  10770. if (!attacker->IsEntity()) {
  10771. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10772. return 0;
  10773. }
  10774. if (!victim) {
  10775. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10776. return 0;
  10777. }
  10778. if (!victim->IsEntity()) {
  10779. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10780. return 0;
  10781. }
  10782. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10783. return 0;
  10784. }
  10785. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10786. if (!lua_interface)
  10787. return 0;
  10788. Spawn* spawn = lua_interface->GetSpawn(state);
  10789. lua_interface->ResetFunctionStack(state);
  10790. if (spawn) {
  10791. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10792. return 1;
  10793. }
  10794. return 0;
  10795. }
  10796. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10797. if (!lua_interface)
  10798. return 0;
  10799. Spawn* spawn = lua_interface->GetSpawn(state);
  10800. bool invul = lua_interface->GetBooleanValue(state, 2);
  10801. lua_interface->ResetFunctionStack(state);
  10802. if (spawn) {
  10803. spawn->SetInvulnerable(invul);
  10804. }
  10805. return 0;
  10806. }
  10807. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10808. if (!lua_interface)
  10809. return 0;
  10810. string category = lua_interface->GetStringValue(state);
  10811. string name = lua_interface->GetStringValue(state, 2);
  10812. lua_interface->ResetFunctionStack(state);
  10813. Rule *ret = 0;
  10814. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10815. lua_interface->SetBooleanValue(state, ret->GetBool());
  10816. return 1;
  10817. }
  10818. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10819. return 0;
  10820. }
  10821. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10822. if (!lua_interface)
  10823. return 0;
  10824. string category = lua_interface->GetStringValue(state);
  10825. string name = lua_interface->GetStringValue(state, 2);
  10826. lua_interface->ResetFunctionStack(state);
  10827. Rule *ret = 0;
  10828. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10829. lua_interface->SetInt32Value(state, ret->GetInt32());
  10830. return 1;
  10831. }
  10832. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10833. return 0;
  10834. }
  10835. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10836. if (!lua_interface)
  10837. return 0;
  10838. string category = lua_interface->GetStringValue(state);
  10839. string name = lua_interface->GetStringValue(state, 2);
  10840. lua_interface->ResetFunctionStack(state);
  10841. Rule *ret = 0;
  10842. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10843. lua_interface->SetFloatValue(state, ret->GetFloat());
  10844. return 1;
  10845. }
  10846. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10847. return 0;
  10848. }
  10849. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10850. if (!lua_interface)
  10851. return 0;
  10852. Spawn* spawn = lua_interface->GetSpawn(state);
  10853. string type = lua_interface->GetStringValue(state, 2);
  10854. lua_interface->ResetFunctionStack(state);
  10855. if (spawn) {
  10856. int res = 1;
  10857. boost::to_lower(type);
  10858. if(type == "assigned_aa")
  10859. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10860. else if ( type == "unassigned_aa")
  10861. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10862. else if ( type == "assigned_tradeskill_aa")
  10863. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10864. else if ( type == "unassigned_tradeskill_aa")
  10865. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10866. else if ( type == "assigned_prestige_aa")
  10867. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10868. else if ( type == "unassigned_prestige_aa")
  10869. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10870. else if ( type == "assigned_tradeskill_prestige_aa")
  10871. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10872. else if ( type == "unassigned_tradeskill_prestige_aa")
  10873. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10874. else
  10875. res = 0;
  10876. return res;
  10877. }
  10878. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10879. return 0;
  10880. }
  10881. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10882. if (!lua_interface)
  10883. return 0;
  10884. Spawn* spawn = lua_interface->GetSpawn(state);
  10885. string type = lua_interface->GetStringValue(state, 2);
  10886. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10887. lua_interface->ResetFunctionStack(state);
  10888. if (spawn) {
  10889. boost::to_lower(type);
  10890. if(type == "assigned_aa")
  10891. spawn->SetAssignedAA((sint16)value);
  10892. else if ( type == "unassigned_aa")
  10893. spawn->SetUnassignedAA((sint16)value);
  10894. else if ( type == "assigned_tradeskill_aa")
  10895. spawn->SetTradeskillAA((sint16)value);
  10896. else if ( type == "unassigned_tradeskill_aa")
  10897. spawn->SetUnassignedTradeskillAA((sint16)value);
  10898. else if ( type == "assigned_prestige_aa")
  10899. spawn->SetPrestigeAA((sint16)value);
  10900. else if ( type == "unassigned_prestige_aa")
  10901. spawn->SetUnassignedPrestigeAA((sint16)value);
  10902. else if ( type == "assigned_tradeskill_prestige_aa")
  10903. spawn->SetTradeskillPrestigeAA((sint16)value);
  10904. else if ( type == "unassigned_tradeskill_prestige_aa")
  10905. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10906. if(spawn->IsPlayer())
  10907. ((Player*)spawn)->SetCharSheetChanged(true);
  10908. }
  10909. return 0;
  10910. }
  10911. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10912. if (!lua_interface)
  10913. return 0;
  10914. string titleName = lua_interface->GetStringValue(state);
  10915. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10916. lua_interface->ResetFunctionStack(state);
  10917. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10918. lua_interface->SetSInt32Value(state, index);
  10919. return 1;
  10920. }
  10921. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10922. if (!lua_interface)
  10923. return 0;
  10924. Spawn* spawn = lua_interface->GetSpawn(state);
  10925. string titleName = lua_interface->GetStringValue(state, 2);
  10926. lua_interface->ResetFunctionStack(state);
  10927. if(!spawn->IsPlayer())
  10928. {
  10929. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10930. lua_interface->SetSInt32Value(state, -1);
  10931. return 1;
  10932. }
  10933. Player* player = (Player*)spawn;
  10934. // check if player already has the title, don't need to add twice
  10935. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10936. if ( playerHasTitle)
  10937. {
  10938. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10939. return 1;
  10940. }
  10941. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10942. if(!title)
  10943. {
  10944. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10945. lua_interface->SetSInt32Value(state, -1);
  10946. return 1;
  10947. }
  10948. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10949. if(returnIdx < 0)
  10950. {
  10951. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10952. }
  10953. lua_interface->SetSInt32Value(state, returnIdx);
  10954. player->GetClient()->SendTitleUpdate();
  10955. return 1;
  10956. }
  10957. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10958. if (!lua_interface)
  10959. return 0;
  10960. Spawn* spawn = lua_interface->GetSpawn(state);
  10961. string titleName = lua_interface->GetStringValue(state, 2);
  10962. lua_interface->ResetFunctionStack(state);
  10963. if(!spawn->IsPlayer())
  10964. {
  10965. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10966. return 0;
  10967. }
  10968. Player* player = (Player*)spawn;
  10969. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10970. if(!title)
  10971. {
  10972. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10973. return 0;
  10974. }
  10975. if(title->GetPrefix())
  10976. {
  10977. 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());
  10978. return 0;
  10979. }
  10980. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10981. player->GetClient()->SendTitleUpdate();
  10982. return 1;
  10983. }
  10984. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10985. if (!lua_interface)
  10986. return 0;
  10987. Spawn* spawn = lua_interface->GetSpawn(state);
  10988. string titleName = lua_interface->GetStringValue(state, 2);
  10989. lua_interface->ResetFunctionStack(state);
  10990. if(!spawn->IsPlayer())
  10991. {
  10992. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10993. return 0;
  10994. }
  10995. Player* player = (Player*)spawn;
  10996. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10997. if(!title)
  10998. {
  10999. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11000. return 0;
  11001. }
  11002. if(!title->GetPrefix())
  11003. {
  11004. 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());
  11005. return 0;
  11006. }
  11007. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  11008. player->GetClient()->SendTitleUpdate();
  11009. return 1;
  11010. }
  11011. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  11012. if (!lua_interface)
  11013. return 0;
  11014. Spawn* spawn = lua_interface->GetSpawn(state);
  11015. lua_interface->ResetFunctionStack(state);
  11016. if(!spawn->IsPlayer())
  11017. {
  11018. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11019. return 0;
  11020. }
  11021. Player* player = (Player*)spawn;
  11022. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  11023. player->GetClient()->SendTitleUpdate();
  11024. return 1;
  11025. }
  11026. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  11027. if (!lua_interface)
  11028. return 0;
  11029. Spawn* spawn = lua_interface->GetSpawn(state);
  11030. lua_interface->ResetFunctionStack(state);
  11031. if(!spawn->IsPlayer())
  11032. {
  11033. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11034. return 0;
  11035. }
  11036. Player* player = (Player*)spawn;
  11037. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  11038. player->GetClient()->SendTitleUpdate();
  11039. return 1;
  11040. }
  11041. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  11042. if (!lua_interface)
  11043. return 0;
  11044. Spawn* spawn = lua_interface->GetSpawn(state);
  11045. string field = lua_interface->GetStringValue(state, 2);
  11046. lua_interface->ResetFunctionStack(state);
  11047. if(!spawn || !spawn->IsEntity())
  11048. {
  11049. 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));
  11050. return 0;
  11051. }
  11052. Entity* ent = (Entity*)spawn;
  11053. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  11054. return 1;
  11055. }
  11056. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  11057. if (!lua_interface)
  11058. return 0;
  11059. Spawn* spawn = lua_interface->GetSpawn(state);
  11060. string field = lua_interface->GetStringValue(state, 2);
  11061. lua_interface->ResetFunctionStack(state);
  11062. if(!spawn || !spawn->IsEntity())
  11063. {
  11064. 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));
  11065. return 0;
  11066. }
  11067. Entity* ent = (Entity*)spawn;
  11068. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  11069. return 1;
  11070. }
  11071. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  11072. if (!lua_interface)
  11073. return 0;
  11074. Spawn* spawn = lua_interface->GetSpawn(state);
  11075. string field = lua_interface->GetStringValue(state, 2);
  11076. lua_interface->ResetFunctionStack(state);
  11077. if(!spawn || !spawn->IsEntity())
  11078. {
  11079. 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));
  11080. return 0;
  11081. }
  11082. Entity* ent = (Entity*)spawn;
  11083. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  11084. return 1;
  11085. }
  11086. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  11087. if (!lua_interface)
  11088. return 0;
  11089. Spawn* spawn = lua_interface->GetSpawn(state);
  11090. string field = lua_interface->GetStringValue(state, 2);
  11091. lua_interface->ResetFunctionStack(state);
  11092. if(!spawn || !spawn->IsEntity())
  11093. {
  11094. 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));
  11095. return 0;
  11096. }
  11097. Entity* ent = (Entity*)spawn;
  11098. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  11099. return 1;
  11100. }
  11101. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  11102. if (!lua_interface)
  11103. return 0;
  11104. Spawn* spawn = lua_interface->GetSpawn(state);
  11105. string field = lua_interface->GetStringValue(state, 2);
  11106. string value = lua_interface->GetStringValue(state, 3);
  11107. lua_interface->ResetFunctionStack(state);
  11108. if(!spawn || !spawn->IsEntity())
  11109. {
  11110. 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));
  11111. return 0;
  11112. }
  11113. Entity* ent = (Entity*)spawn;
  11114. bool set_ = ent->SetInfoStructString(field, value);
  11115. lua_interface->SetBooleanValue(state, set_);
  11116. return 1;
  11117. }
  11118. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  11119. if (!lua_interface)
  11120. return 0;
  11121. Spawn* spawn = lua_interface->GetSpawn(state);
  11122. string field = lua_interface->GetStringValue(state, 2);
  11123. int64 value = lua_interface->GetInt64Value(state, 3);
  11124. lua_interface->ResetFunctionStack(state);
  11125. if(!spawn || !spawn->IsEntity())
  11126. {
  11127. 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));
  11128. return 0;
  11129. }
  11130. Entity* ent = (Entity*)spawn;
  11131. bool set_ = ent->SetInfoStructUInt(field, value);
  11132. lua_interface->SetBooleanValue(state, set_);
  11133. return 1;
  11134. }
  11135. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  11136. if (!lua_interface)
  11137. return 0;
  11138. Spawn* spawn = lua_interface->GetSpawn(state);
  11139. string field = lua_interface->GetStringValue(state, 2);
  11140. sint64 value = lua_interface->GetSInt64Value(state, 3);
  11141. lua_interface->ResetFunctionStack(state);
  11142. if(!spawn || !spawn->IsEntity())
  11143. {
  11144. 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));
  11145. return 0;
  11146. }
  11147. Entity* ent = (Entity*)spawn;
  11148. bool set_ = ent->SetInfoStructSInt(field, value);
  11149. lua_interface->SetBooleanValue(state, set_);
  11150. return 1;
  11151. }
  11152. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  11153. if (!lua_interface)
  11154. return 0;
  11155. Spawn* spawn = lua_interface->GetSpawn(state);
  11156. string field = lua_interface->GetStringValue(state, 2);
  11157. float value = lua_interface->GetFloatValue(state, 3);
  11158. lua_interface->ResetFunctionStack(state);
  11159. if(!spawn || !spawn->IsEntity())
  11160. {
  11161. 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));
  11162. return 0;
  11163. }
  11164. Entity* ent = (Entity*)spawn;
  11165. bool set_ = ent->SetInfoStructFloat(field, value);
  11166. lua_interface->SetBooleanValue(state, set_);
  11167. return 1;
  11168. }
  11169. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  11170. if (!lua_interface)
  11171. return 0;
  11172. Spawn* spawn = lua_interface->GetSpawn(state);
  11173. bool value = lua_interface->GetBooleanValue(state, 2);
  11174. lua_interface->ResetFunctionStack(state);
  11175. if(!spawn || !spawn->IsPlayer())
  11176. {
  11177. 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));
  11178. return 0;
  11179. }
  11180. ((Player*)spawn)->SetCharSheetChanged(value);
  11181. return 0;
  11182. }
  11183. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  11184. if (!lua_interface)
  11185. return 0;
  11186. Spawn* spawn = lua_interface->GetSpawn(state);
  11187. std::string fromName = lua_interface->GetStringValue(state, 2);
  11188. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11189. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11190. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11191. int32 copper = lua_interface->GetInt32Value(state, 6);
  11192. int32 silver = lua_interface->GetInt32Value(state, 7);
  11193. int32 gold = lua_interface->GetInt32Value(state, 8);
  11194. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11195. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11196. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11197. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11198. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11199. lua_interface->ResetFunctionStack(state);
  11200. if(!spawn || !spawn->IsPlayer())
  11201. {
  11202. 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));
  11203. lua_interface->SetBooleanValue(state, false);
  11204. return 1;
  11205. }
  11206. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11207. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11208. lua_interface->SetBooleanValue(state, true);
  11209. return 1;
  11210. }
  11211. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  11212. if (!lua_interface)
  11213. return 0;
  11214. int32 char_id = lua_interface->GetInt32Value(state);
  11215. std::string fromName = lua_interface->GetStringValue(state, 2);
  11216. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11217. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11218. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11219. int32 copper = lua_interface->GetInt32Value(state, 6);
  11220. int32 silver = lua_interface->GetInt32Value(state, 7);
  11221. int32 gold = lua_interface->GetInt32Value(state, 8);
  11222. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11223. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11224. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11225. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11226. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11227. lua_interface->ResetFunctionStack(state);
  11228. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11229. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11230. lua_interface->SetBooleanValue(state, true);
  11231. return 1;
  11232. }
  11233. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  11234. Spawn* widget;
  11235. if (lua_interface) {
  11236. widget = lua_interface->GetSpawn(state);
  11237. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  11238. lua_interface->ResetFunctionStack(state);
  11239. if (widget && widget->IsWidget())
  11240. {
  11241. ((Widget*)widget)->OpenDoor();
  11242. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  11243. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11244. }
  11245. else
  11246. 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));
  11247. }
  11248. return 0;
  11249. }
  11250. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  11251. Spawn* widget;
  11252. if (lua_interface) {
  11253. widget = lua_interface->GetSpawn(state);
  11254. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  11255. lua_interface->ResetFunctionStack(state);
  11256. if (widget && widget->IsWidget())
  11257. {
  11258. ((Widget*)widget)->CloseDoor();
  11259. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  11260. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11261. }
  11262. else
  11263. 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));
  11264. }
  11265. return 0;
  11266. }
  11267. int EQ2Emu_lua_IsOpen(lua_State* state) {
  11268. if (!lua_interface)
  11269. return 0;
  11270. Spawn* widget = lua_interface->GetSpawn(state);
  11271. lua_interface->ResetFunctionStack(state);
  11272. if (widget && widget->IsWidget())
  11273. {
  11274. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  11275. return 1;
  11276. }
  11277. return 0;
  11278. }
  11279. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  11280. if (!lua_interface)
  11281. return 0;
  11282. sint32 min = lua_interface->GetSInt32Value(state);
  11283. sint32 max = lua_interface->GetSInt32Value(state, 2);
  11284. lua_interface->ResetFunctionStack(state);
  11285. sint32 result = MakeRandomInt(min, max);
  11286. lua_interface->SetSInt32Value(state, result);
  11287. return 1;
  11288. }
  11289. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  11290. if (!lua_interface)
  11291. return 0;
  11292. float min = lua_interface->GetFloatValue(state);
  11293. float max = lua_interface->GetFloatValue(state, 2);
  11294. lua_interface->ResetFunctionStack(state);
  11295. float result = MakeRandomFloat(min, max);
  11296. lua_interface->SetFloatValue(state, result);
  11297. return 1;
  11298. }
  11299. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  11300. if (!lua_interface)
  11301. return 0;
  11302. Spawn* spawn = lua_interface->GetSpawn(state);
  11303. int32 value = lua_interface->GetInt32Value(state, 2);
  11304. lua_interface->ResetFunctionStack(state);
  11305. if(!spawn)
  11306. {
  11307. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11308. lua_interface->SetBooleanValue(state, false);
  11309. return 1;
  11310. }
  11311. spawn->AddIconValue(value);
  11312. lua_interface->SetBooleanValue(state, true);
  11313. return 1;
  11314. }
  11315. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  11316. if (!lua_interface)
  11317. return 0;
  11318. Spawn* spawn = lua_interface->GetSpawn(state);
  11319. int32 value = lua_interface->GetInt32Value(state, 2);
  11320. lua_interface->ResetFunctionStack(state);
  11321. if(!spawn)
  11322. {
  11323. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11324. lua_interface->SetBooleanValue(state, false);
  11325. return 1;
  11326. }
  11327. spawn->RemoveIconValue(value);
  11328. lua_interface->SetBooleanValue(state, true);
  11329. return 1;
  11330. }
  11331. int EQ2Emu_lua_GetShardID(lua_State* state) {
  11332. Spawn* npc = lua_interface->GetSpawn(state);
  11333. lua_interface->ResetFunctionStack(state);
  11334. if (npc && npc->IsNPC()) {
  11335. NPC* shard = (NPC*)npc;
  11336. int32 shardid = shard->GetShardID();
  11337. lua_interface->SetInt32Value(state, shardid);
  11338. return 1;
  11339. }
  11340. lua_interface->SetInt32Value(state, 0);
  11341. return 1;
  11342. }
  11343. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  11344. Spawn* npc = lua_interface->GetSpawn(state);
  11345. lua_interface->ResetFunctionStack(state);
  11346. if (npc && npc->IsNPC()) {
  11347. NPC* shard = (NPC*)npc;
  11348. int32 charid = shard->GetShardCharID();
  11349. lua_interface->SetInt32Value(state, charid);
  11350. return 1;
  11351. }
  11352. lua_interface->SetInt32Value(state, 0);
  11353. return 1;
  11354. }
  11355. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  11356. Spawn* npc = lua_interface->GetSpawn(state);
  11357. lua_interface->ResetFunctionStack(state);
  11358. if (npc && npc->IsNPC()) {
  11359. NPC* shard = (NPC*)npc;
  11360. int64 timestamp = shard->GetShardCreatedTimestamp();
  11361. lua_interface->SetSInt64Value(state, timestamp);
  11362. return 1;
  11363. }
  11364. lua_interface->SetSInt64Value(state, 0);
  11365. return 1;
  11366. }
  11367. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  11368. if (!lua_interface)
  11369. return 0;
  11370. int32 shardid = lua_interface->GetInt32Value(state);
  11371. lua_interface->ResetFunctionStack(state);
  11372. if(shardid < 1)
  11373. lua_interface->SetBooleanValue(state, false);
  11374. else
  11375. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  11376. return 1;
  11377. }
  11378. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  11379. if (!lua_interface)
  11380. return 0;
  11381. Spawn* spawn = lua_interface->GetSpawn(state);
  11382. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11383. if (spawn) {
  11384. spawn->PauseMovement(delay_in_ms);
  11385. }
  11386. lua_interface->ResetFunctionStack(state);
  11387. return 0;
  11388. }
  11389. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11390. if (!lua_interface)
  11391. return 0;
  11392. Spawn* spawn = lua_interface->GetSpawn(state);
  11393. if (spawn) {
  11394. spawn->StopMovement();
  11395. }
  11396. lua_interface->ResetFunctionStack(state);
  11397. return 0;
  11398. }
  11399. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11400. Player* player = (Player*)lua_interface->GetSpawn(state);
  11401. int8 level = lua_interface->GetInt8Value(state, 2);
  11402. lua_interface->ResetFunctionStack(state);
  11403. if (player && player->IsPlayer() && level > 0) {
  11404. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11405. return 1;
  11406. }
  11407. return 0;
  11408. }
  11409. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11410. Player* player = (Player*)lua_interface->GetSpawn(state);
  11411. int8 level = lua_interface->GetInt8Value(state, 2);
  11412. lua_interface->ResetFunctionStack(state);
  11413. if (player && player->IsPlayer() && level > 0) {
  11414. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11415. return 1;
  11416. }
  11417. return 0;
  11418. }
  11419. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11420. ZoneServer* zone = lua_interface->GetZone(state);
  11421. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11422. lua_interface->ResetFunctionStack(state);
  11423. if (zone) {
  11424. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11425. if (spawn) {
  11426. lua_interface->SetSpawnValue(state, spawn);
  11427. return 1;
  11428. }
  11429. }
  11430. return 0;
  11431. }
  11432. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11433. if (!lua_interface)
  11434. return 0;
  11435. Spawn* spawn = lua_interface->GetSpawn(state);
  11436. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11437. lua_interface->ResetFunctionStack(state);
  11438. bool res = false;
  11439. if(spawn && spawn->IsTransportSpawn())
  11440. {
  11441. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11442. spawn->SetRailID(rail_id);
  11443. res = true;
  11444. }
  11445. else if (!spawn) {
  11446. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11447. }
  11448. else if(!spawn->IsTransportSpawn()) {
  11449. 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());
  11450. }
  11451. lua_interface->SetBooleanValue(state, res);
  11452. return 1;
  11453. }
  11454. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11455. if (!lua_interface)
  11456. return 0;
  11457. ZoneServer* zone = lua_interface->GetZone(state);
  11458. lua_interface->ResetFunctionStack(state);
  11459. if (zone) {
  11460. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11461. return 1;
  11462. }
  11463. return 0;
  11464. }
  11465. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11466. if (!lua_interface)
  11467. return 0;
  11468. Spawn* spawn = lua_interface->GetSpawn(state);
  11469. lua_interface->ResetFunctionStack(state);
  11470. if (spawn) {
  11471. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11472. return 1;
  11473. }
  11474. return 0;
  11475. }
  11476. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11477. if (!lua_interface)
  11478. return 0;
  11479. Spawn* player = lua_interface->GetSpawn(state);
  11480. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11481. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11482. lua_interface->ResetFunctionStack(state);
  11483. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11484. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11485. }
  11486. else if(!zoneID) {
  11487. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11488. }
  11489. else
  11490. {
  11491. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11492. return 1;
  11493. }
  11494. return 0;
  11495. }
  11496. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11497. if (!lua_interface)
  11498. return 0;
  11499. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11500. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11501. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11502. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11503. lua_interface->ResetFunctionStack(state);
  11504. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11505. world.GetWorldTimeStruct()->year = newYear;
  11506. world.GetWorldTimeStruct()->month = newMonth;
  11507. world.GetWorldTimeStruct()->hour = newHour;
  11508. world.GetWorldTimeStruct()->minute = newMinute;
  11509. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11510. return 0;
  11511. }
  11512. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11513. if (!lua_interface)
  11514. return 0;
  11515. lua_interface->ResetFunctionStack(state);
  11516. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11517. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11518. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11519. return 1;
  11520. }
  11521. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11522. if (!lua_interface)
  11523. return 0;
  11524. lua_interface->ResetFunctionStack(state);
  11525. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11526. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11527. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11528. return 1;
  11529. }
  11530. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11531. if (!lua_interface)
  11532. return 0;
  11533. lua_interface->ResetFunctionStack(state);
  11534. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11535. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11536. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11537. return 1;
  11538. }
  11539. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11540. if (!lua_interface)
  11541. return 0;
  11542. lua_interface->ResetFunctionStack(state);
  11543. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11544. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11545. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11546. return 1;
  11547. }
  11548. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11549. if (!lua_interface)
  11550. return 0;
  11551. lua_interface->ResetFunctionStack(state);
  11552. world.SendTimeUpdate();
  11553. return 0;
  11554. }
  11555. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11556. bool update_result = false;
  11557. Faction* faction = 0;
  11558. Spawn* spawn = lua_interface->GetSpawn(state);
  11559. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11560. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11561. lua_interface->ResetFunctionStack(state);
  11562. if(!spawn || !spawn->IsPlayer()) {
  11563. lua_interface->LogError("LUA ChangeFaction command error: player is not valid");
  11564. return 0;
  11565. }
  11566. Player* player = (Player*)spawn;
  11567. Client* client = player->GetClient();
  11568. if (faction_id > 0) {
  11569. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11570. if(hasfaction == 0) {
  11571. //they do not have the faction. Lets get the default value and feed it in.
  11572. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11573. //add the default faction for the player.
  11574. player->SetFactionValue(faction_id, defaultfaction);
  11575. }
  11576. if(increase >= 0) {
  11577. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11578. faction = master_faction_list.GetFaction(faction_id);
  11579. if(faction && update_result)
  11580. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11581. else if(faction)
  11582. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11583. lua_interface->SetBooleanValue(state, true);
  11584. return 1;
  11585. }
  11586. if(increase < 0){
  11587. //change the negative to a positive, since thats how decreasefaction() likes it.
  11588. increase *= -1;
  11589. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11590. faction = master_faction_list.GetFaction(faction_id);
  11591. if(faction && update_result)
  11592. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11593. else if(faction)
  11594. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11595. lua_interface->SetBooleanValue(state, true);
  11596. return 1;
  11597. }
  11598. }
  11599. lua_interface->SetBooleanValue(state, false);
  11600. return 1;
  11601. }
  11602. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11603. bool hascoin = 0;
  11604. Player* player = (Player*)lua_interface->GetSpawn(state);
  11605. int32 coins = lua_interface->GetInt32Value(state, 2);
  11606. lua_interface->ResetFunctionStack(state);
  11607. if (player && player->IsPlayer()) {
  11608. hascoin = player->HasCoins(coins);
  11609. if(hascoin == 0) {
  11610. lua_interface->SetBooleanValue(state, false);
  11611. return 1;
  11612. }
  11613. if(hascoin == 1) {
  11614. lua_interface->SetBooleanValue(state, true);
  11615. return 1;
  11616. }
  11617. }
  11618. return 0;
  11619. }
  11620. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11621. int32 loot_tier = 0;
  11622. Spawn* spawn = lua_interface->GetSpawn(state);
  11623. lua_interface->ResetFunctionStack(state);
  11624. if (spawn) {
  11625. loot_tier = spawn->GetLootTier();
  11626. lua_interface->SetInt32Value(state, loot_tier);
  11627. return 1;
  11628. }
  11629. return 0;
  11630. }
  11631. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11632. if (!lua_interface)
  11633. return 0;
  11634. Spawn* spawn = lua_interface->GetSpawn(state);
  11635. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11636. lua_interface->ResetFunctionStack(state);
  11637. if (spawn) {
  11638. spawn->SetLootTier(loot_tier);
  11639. lua_interface->SetBooleanValue(state, true);
  11640. return 1;
  11641. }
  11642. lua_interface->SetBooleanValue(state, false);
  11643. return 1;
  11644. }
  11645. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11646. int32 loot_drop_type = 0;
  11647. Spawn* spawn = lua_interface->GetSpawn(state);
  11648. lua_interface->ResetFunctionStack(state);
  11649. if (spawn) {
  11650. loot_drop_type = spawn->GetLootDropType();
  11651. lua_interface->SetInt32Value(state, loot_drop_type);
  11652. return 1;
  11653. }
  11654. return 0;
  11655. }
  11656. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11657. if (!lua_interface)
  11658. return 0;
  11659. Spawn* spawn = lua_interface->GetSpawn(state);
  11660. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11661. lua_interface->ResetFunctionStack(state);
  11662. if (spawn) {
  11663. spawn->SetLootDropType(loot_drop_type);
  11664. lua_interface->SetBooleanValue(state, true);
  11665. return 1;
  11666. }
  11667. lua_interface->SetBooleanValue(state, false);
  11668. return 1;
  11669. }
  11670. int EQ2Emu_lua_DamageEquippedItems(lua_State* state) {
  11671. if (!lua_interface)
  11672. return 0;
  11673. Spawn* spawn = lua_interface->GetSpawn(state);
  11674. int8 damage_amount = lua_interface->GetInt32Value(state, 2);
  11675. if(damage_amount > 100) {
  11676. damage_amount = 100;
  11677. }
  11678. if (!spawn) {
  11679. lua_interface->LogError("%s: LUA DamageEquippedItems command error: spawn is not valid", lua_interface->GetScriptName(state));
  11680. lua_interface->ResetFunctionStack(state);
  11681. return 0;
  11682. }
  11683. lua_interface->ResetFunctionStack(state);
  11684. if (spawn->IsPlayer()) {
  11685. if (((Player*)spawn)->GetClient() && ((Player*)spawn)->DamageEquippedItems(damage_amount, ((Player*)spawn)->GetClient()))
  11686. lua_interface->SetBooleanValue(state, true);
  11687. else
  11688. lua_interface->SetBooleanValue(state, false);
  11689. }
  11690. else {
  11691. lua_interface->SetBooleanValue(state, false);
  11692. }
  11693. return 1;
  11694. }
  11695. int EQ2Emu_lua_CreateWidgetRegion(lua_State* state) {
  11696. ZoneServer* zone = lua_interface->GetZone(state);
  11697. int32 version = lua_interface->GetInt32Value(state, 2);
  11698. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11699. if(region_map == nullptr) {
  11700. lua_interface->LogError("%s: LUA CreateWidgetRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11701. lua_interface->ResetFunctionStack(state);
  11702. return 0;
  11703. }
  11704. string region_name = lua_interface->GetStringValue(state, 3);
  11705. string env_name = lua_interface->GetStringValue(state, 4);
  11706. int32 grid_id = lua_interface->GetInt32Value(state, 5);
  11707. int32 widget_id = lua_interface->GetInt32Value(state, 6);
  11708. float dist = lua_interface->GetFloatValue(state, 7);
  11709. region_map->InsertRegionNode(zone, version, region_name, env_name, grid_id, widget_id, dist);
  11710. lua_interface->ResetFunctionStack(state);
  11711. lua_interface->SetBooleanValue(state, true);
  11712. return 1;
  11713. }
  11714. int EQ2Emu_lua_RemoveRegion(lua_State* state) {
  11715. ZoneServer* zone = lua_interface->GetZone(state);
  11716. int32 version = lua_interface->GetInt32Value(state, 2);
  11717. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11718. if(region_map == nullptr) {
  11719. lua_interface->LogError("%s: LUA RemoveRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11720. lua_interface->ResetFunctionStack(state);
  11721. return 0;
  11722. }
  11723. string region_name = lua_interface->GetStringValue(state, 3);
  11724. region_map->RemoveRegionNode(region_name);
  11725. lua_interface->ResetFunctionStack(state);
  11726. lua_interface->SetBooleanValue(state, true);
  11727. return 1;
  11728. }
  11729. int EQ2Emu_lua_SetPlayerPOVGhost(lua_State* state) {
  11730. Client* client = nullptr;
  11731. Spawn* player = lua_interface->GetSpawn(state);
  11732. if (!player) {
  11733. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not valid");
  11734. lua_interface->SetBooleanValue(state, false);
  11735. lua_interface->ResetFunctionStack(state);
  11736. return 1;
  11737. }
  11738. if (!player->IsPlayer()) {
  11739. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
  11740. lua_interface->SetBooleanValue(state, false);
  11741. lua_interface->ResetFunctionStack(state);
  11742. return 1;
  11743. }
  11744. client = player->GetClient();
  11745. if (!client) {
  11746. lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
  11747. lua_interface->SetBooleanValue(state, false);
  11748. lua_interface->ResetFunctionStack(state);
  11749. return 1;
  11750. }
  11751. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  11752. bool success_sight = client->SetPlayerPOVGhost(spawn);
  11753. lua_interface->ResetFunctionStack(state);
  11754. lua_interface->SetBooleanValue(state, success_sight);
  11755. return 1;
  11756. }
  11757. int EQ2Emu_lua_SetCastOnAggroComplete(lua_State* state) {
  11758. if (!lua_interface)
  11759. return 0;
  11760. bool result = false;
  11761. Spawn* spawn = lua_interface->GetSpawn(state);
  11762. bool cast_completed = (lua_interface->GetInt8Value(state, 2) == 1);
  11763. lua_interface->ResetFunctionStack(state);
  11764. if (!spawn)
  11765. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11766. else if (!spawn->IsNPC())
  11767. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11768. else
  11769. {
  11770. ((NPC*)spawn)->cast_on_aggro_completed = cast_completed;
  11771. result = true;
  11772. }
  11773. lua_interface->SetBooleanValue(state, result);
  11774. return 1;
  11775. }
  11776. int EQ2Emu_lua_IsCastOnAggroComplete(lua_State* state) {
  11777. if (!lua_interface)
  11778. return 0;
  11779. bool result = false;
  11780. Spawn* spawn = lua_interface->GetSpawn(state);
  11781. lua_interface->ResetFunctionStack(state);
  11782. if (!spawn)
  11783. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11784. else if (!spawn->IsNPC())
  11785. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11786. else
  11787. {
  11788. if(((NPC*)spawn)->cast_on_aggro_completed)
  11789. result = true;
  11790. }
  11791. lua_interface->SetBooleanValue(state, result);
  11792. return 1;
  11793. }
  11794. int EQ2Emu_lua_AddRecipeBookToPlayer(lua_State* state) {
  11795. Client* client = nullptr;
  11796. Spawn* player = lua_interface->GetSpawn(state);
  11797. int32 recipe_book_id = lua_interface->GetInt32Value(state, 2);
  11798. lua_interface->ResetFunctionStack(state);
  11799. if (!player) {
  11800. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not valid");
  11801. lua_interface->SetBooleanValue(state, false);
  11802. return 1;
  11803. }
  11804. if (!player->IsPlayer()) {
  11805. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not a player");
  11806. lua_interface->SetBooleanValue(state, false);
  11807. return 1;
  11808. }
  11809. client = player->GetClient();
  11810. if (!client) {
  11811. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: could not find client");
  11812. lua_interface->SetBooleanValue(state, false);
  11813. return 1;
  11814. }
  11815. bool result = client->AddRecipeBookToPlayer(recipe_book_id);
  11816. lua_interface->SetBooleanValue(state, result);
  11817. return 1;
  11818. }
  11819. int EQ2Emu_lua_RemoveRecipeFromPlayer(lua_State* state) {
  11820. Client* client = nullptr;
  11821. Spawn* player = lua_interface->GetSpawn(state);
  11822. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  11823. lua_interface->ResetFunctionStack(state);
  11824. if (!player) {
  11825. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not valid");
  11826. lua_interface->SetBooleanValue(state, false);
  11827. return 1;
  11828. }
  11829. if (!player->IsPlayer()) {
  11830. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not a player");
  11831. lua_interface->SetBooleanValue(state, false);
  11832. return 1;
  11833. }
  11834. client = player->GetClient();
  11835. if (!client) {
  11836. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: could not find client");
  11837. lua_interface->SetBooleanValue(state, false);
  11838. return 1;
  11839. }
  11840. bool result = client->RemoveRecipeFromPlayer(recipe_id);
  11841. lua_interface->SetBooleanValue(state, result);
  11842. return 1;
  11843. }