LuaFunctions.cpp 417 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640
  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. entity->CheckEncounterState((Entity*)spawn);
  1590. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1591. if (send_packet)
  1592. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1593. }
  1594. }
  1595. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1596. }
  1597. else if (npc && npc->IsNPC() && npc->GetZone()) {
  1598. entity->CheckEncounterState((Entity*)npc);
  1599. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1600. }
  1601. }
  1602. lua_interface->ResetFunctionStack(state);
  1603. return 0;
  1604. }
  1605. int EQ2Emu_lua_Zone(lua_State* state) {
  1606. if (!lua_interface)
  1607. return 0;
  1608. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1609. ZoneServer* zone = lua_interface->GetZone(state);
  1610. Spawn* player = lua_interface->GetSpawn(state, 2);
  1611. Client* client = 0;
  1612. if (player && player->IsPlayer())
  1613. client = ((Player*)player)->GetClient();
  1614. float x = lua_interface->GetFloatValue(state, 3);
  1615. float y = lua_interface->GetFloatValue(state, 4);
  1616. float z = lua_interface->GetFloatValue(state, 5);
  1617. float heading = lua_interface->GetFloatValue(state, 6);
  1618. if (zone && client) {
  1619. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1620. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1621. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1622. {
  1623. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1624. return 0;
  1625. }
  1626. if (x != 0 || y != 0 || z != 0) {
  1627. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1628. player->SetX(x);
  1629. player->SetY(y);
  1630. player->SetZ(z);
  1631. player->SetHeading(heading);
  1632. client->Zone(zone->GetZoneName(), false);
  1633. }
  1634. else
  1635. client->Zone(zone->GetZoneName());
  1636. }
  1637. else
  1638. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1639. lua_interface->ResetFunctionStack(state);
  1640. return 0;
  1641. }
  1642. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1643. if (!lua_interface)
  1644. return 0;
  1645. Spawn* spawn = lua_interface->GetSpawn(state);
  1646. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1647. if (spawn && spawn2)
  1648. spawn->AddAllowAccessSpawn(spawn2);
  1649. lua_interface->ResetFunctionStack(state);
  1650. return 0;
  1651. }
  1652. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1653. if (!lua_interface)
  1654. return 0;
  1655. Spawn* target = lua_interface->GetSpawn(state);
  1656. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1657. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1658. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1659. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1660. lua_interface->ResetFunctionStack(state);
  1661. if (!target) {
  1662. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1663. return 0;
  1664. }
  1665. if (!target->IsEntity()) {
  1666. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1667. return 0;
  1668. }
  1669. if (spell_id <= 0) {
  1670. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1671. return 0;
  1672. }
  1673. if (caster && !caster->IsEntity()) {
  1674. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1675. return 0;
  1676. }
  1677. if (spell_tier == 0)
  1678. spell_tier = 1;
  1679. if (!caster)
  1680. caster = target;
  1681. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1682. return 0;
  1683. }
  1684. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1685. if (!lua_interface)
  1686. return 0;
  1687. Spawn* target = lua_interface->GetSpawn(state);
  1688. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1689. if(!luaspell || luaspell->resisted) {
  1690. lua_interface->ResetFunctionStack(state);
  1691. return 0;
  1692. }
  1693. Spawn* caster = luaspell->caster;
  1694. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1695. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1696. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1697. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1698. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1699. //lua_interface->ResetFunctionStack(state);
  1700. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1701. vector<int16> faction_req;
  1702. vector<int16> race_req;
  1703. int32 class_req = 0;
  1704. int32 i = 0;
  1705. int8 f = 0;
  1706. int8 r = 0;
  1707. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1708. if (class_id < 100) {
  1709. class_req += pow(2.0, double(class_id - 1));
  1710. }
  1711. else if (class_id > 100 && class_id < 1000) {
  1712. race_req.push_back(class_id);
  1713. r++;
  1714. }
  1715. else {
  1716. faction_req.push_back(class_id);
  1717. f++;
  1718. }
  1719. i++;
  1720. }
  1721. lua_interface->ResetFunctionStack(state);
  1722. if (caster && caster->IsEntity()) {
  1723. bool race_match = false;
  1724. bool success = false;
  1725. luaspell->resisted = false;
  1726. if (luaspell->targets.size() > 0) {
  1727. ZoneServer* zone = luaspell->caster->GetZone();
  1728. Spawn* target = 0;
  1729. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1730. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1731. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1732. if (race_req.size() > 0) {
  1733. for (int8 i = 0; i < race_req.size(); i++) {
  1734. if(race_req[i] == target->GetRace() ||
  1735. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1736. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1737. race_match = true;
  1738. }
  1739. }
  1740. }
  1741. else
  1742. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1743. if (race_match == true) {
  1744. float distance = caster->GetDistance(target, true);
  1745. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1746. }
  1747. }
  1748. }
  1749. success = true;
  1750. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1751. }
  1752. else if (target) {
  1753. //check class and race/faction here
  1754. if (race_req.size() > 0) {
  1755. for (int8 i = 0; i < race_req.size(); i++) {
  1756. if(race_req[i] == target->GetRace() ||
  1757. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1758. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1759. race_match = true;
  1760. }
  1761. }
  1762. }
  1763. else
  1764. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1765. if (race_match == true) {
  1766. float distance = caster->GetDistance(target, true);
  1767. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1768. success = true;
  1769. }
  1770. }
  1771. if (success) {
  1772. Spell* spell = luaspell->spell;
  1773. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1774. ((Player*)caster)->InCombat(true);
  1775. if (caster->GetZone())
  1776. caster->GetZone()->TriggerCharSheetTimer();
  1777. }
  1778. }
  1779. }
  1780. return 0;
  1781. }
  1782. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1783. if (!lua_interface)
  1784. return 0;
  1785. Spawn* spawn = lua_interface->GetSpawn(state);
  1786. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1787. lua_interface->ResetFunctionStack(state);
  1788. if (spawn && value != 0) {
  1789. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1790. spawn->SetPower(spawn->GetTotalPower());
  1791. else
  1792. spawn->SetPower(spawn->GetPower() + value);
  1793. }
  1794. return 0;
  1795. }
  1796. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1797. if (!lua_interface)
  1798. return 0;
  1799. Spawn* spawn = lua_interface->GetSpawn(state);
  1800. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1801. lua_interface->ResetFunctionStack(state);
  1802. if (spawn && value != 0) {
  1803. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1804. spawn->SetHP(spawn->GetTotalHP());
  1805. else
  1806. spawn->SetHP(spawn->GetHP() + value);
  1807. }
  1808. return 0;
  1809. }
  1810. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1811. if (!lua_interface)
  1812. return 0;
  1813. Spawn* spawn = lua_interface->GetSpawn(state);
  1814. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1815. lua_interface->ResetFunctionStack(state);
  1816. if (spawn && value != 0) {
  1817. spawn->SetPower(spawn->GetPower() + value);
  1818. if (value > spawn->GetTotalHPBase())
  1819. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1820. }
  1821. return 0;
  1822. }
  1823. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1824. if (!lua_interface)
  1825. return 0;
  1826. Spawn* spawn = lua_interface->GetSpawn(state);
  1827. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1828. lua_interface->ResetFunctionStack(state);
  1829. if (spawn && value != 0) {
  1830. spawn->SetHP(spawn->GetHP() + value);
  1831. if (value > spawn->GetTotalHPBase())
  1832. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1833. }
  1834. return 0;
  1835. }
  1836. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1837. if (!lua_interface)
  1838. return 0;
  1839. Spawn* spawn = lua_interface->GetSpawn(state);
  1840. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1841. lua_interface->ResetFunctionStack(state);
  1842. if (spawn) {
  1843. spawn->SetHP(value);
  1844. if (value > spawn->GetTotalHPBase())
  1845. spawn->SetTotalHP(value);
  1846. }
  1847. return 0;
  1848. }
  1849. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1850. if (!lua_interface)
  1851. return 0;
  1852. Spawn* spawn = lua_interface->GetSpawn(state);
  1853. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1854. float value = lua_interface->GetFloatValue(state, 2);
  1855. lua_interface->ResetFunctionStack(state);
  1856. if (spawn && spawn->IsEntity() && value > 0)
  1857. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1858. if (spawn && spawn->IsPlayer())
  1859. ((Player*)spawn)->SetCharSheetChanged(true);
  1860. return 0;
  1861. }
  1862. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1863. if (!lua_interface)
  1864. return 0;
  1865. Spawn* spawn = lua_interface->GetSpawn(state);
  1866. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1867. lua_interface->ResetFunctionStack(state);
  1868. if (spawn && spawn->IsEntity() && value > 0)
  1869. ((Entity*)spawn)->SetTotalHPBase(value);
  1870. return 0;
  1871. }
  1872. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1873. if (!lua_interface)
  1874. return 0;
  1875. Spawn* spawn = lua_interface->GetSpawn(state);
  1876. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1877. lua_interface->ResetFunctionStack(state);
  1878. if (spawn && value > 0) {
  1879. spawn->SetPower(value);
  1880. if (value > spawn->GetTotalPowerBase())
  1881. spawn->SetTotalPower(value);
  1882. }
  1883. return 0;
  1884. }
  1885. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1886. if (!lua_interface)
  1887. return 0;
  1888. Spawn* spawn = lua_interface->GetSpawn(state);
  1889. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1890. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1891. lua_interface->ResetFunctionStack(state);
  1892. if (spawn && spawn->IsEntity() && value > 0)
  1893. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1894. return 0;
  1895. }
  1896. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1897. if (!lua_interface)
  1898. return 0;
  1899. Spawn* spawn = lua_interface->GetSpawn(state);
  1900. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1901. lua_interface->ResetFunctionStack(state);
  1902. if (spawn && spawn->IsEntity() && value > 0)
  1903. ((Entity*)spawn)->SetTotalPowerBase(value);
  1904. return 0;
  1905. }
  1906. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1907. if (!lua_interface)
  1908. return 0;
  1909. Spawn* spawn = lua_interface->GetSpawn(state);
  1910. float x = lua_interface->GetFloatValue(state, 2);
  1911. float y = lua_interface->GetFloatValue(state, 3);
  1912. float z = lua_interface->GetFloatValue(state, 4);
  1913. float heading = lua_interface->GetFloatValue(state, 5);
  1914. lua_interface->ResetFunctionStack(state);
  1915. if (spawn) {
  1916. spawn->SetX(x);
  1917. spawn->SetY(y);
  1918. spawn->SetZ(z);
  1919. if (heading != 0)
  1920. spawn->SetHeading(heading);
  1921. spawn->SetSpawnOrigX(spawn->GetX());
  1922. spawn->SetSpawnOrigY(spawn->GetY());
  1923. spawn->SetSpawnOrigZ(spawn->GetZ());
  1924. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1925. if (spawn->IsPlayer()) {
  1926. Client* client = ((Player*)spawn)->GetClient();
  1927. if (client) {
  1928. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1929. client->QueuePacket(packet);
  1930. }
  1931. }
  1932. }
  1933. return 0;
  1934. }
  1935. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1936. if (!lua_interface)
  1937. return 0;
  1938. Spawn* spawn = lua_interface->GetSpawn(state);
  1939. float value = lua_interface->GetFloatValue(state, 2);
  1940. lua_interface->ResetFunctionStack(state);
  1941. if (spawn) {
  1942. spawn->SetHeading(value);
  1943. if (spawn->IsPlayer()) {
  1944. Client* client = ((Player*)spawn)->GetClient();
  1945. if (client) {
  1946. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1947. client->QueuePacket(packet);
  1948. }
  1949. }
  1950. }
  1951. return 0;
  1952. }
  1953. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1954. if (!lua_interface)
  1955. return 0;
  1956. Spawn* spawn = lua_interface->GetSpawn(state);
  1957. int16 value = lua_interface->GetInt16Value(state, 2);
  1958. lua_interface->ResetFunctionStack(state);
  1959. if (spawn)
  1960. spawn->SetModelType(value);
  1961. return 0;
  1962. }
  1963. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1964. if (!lua_interface)
  1965. return 0;
  1966. Spawn* spawn = lua_interface->GetSpawn(state);
  1967. int8 value = lua_interface->GetInt8Value(state, 2);
  1968. lua_interface->ResetFunctionStack(state);
  1969. if (spawn) {
  1970. if (spawn->IsPlayer())
  1971. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1972. else
  1973. spawn->SetAdventureClass(value);
  1974. }
  1975. return 0;
  1976. }
  1977. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1978. if (!lua_interface)
  1979. return 0;
  1980. Spawn* spawn = lua_interface->GetSpawn(state);
  1981. int8 value = lua_interface->GetInt8Value(state, 2);
  1982. lua_interface->ResetFunctionStack(state);
  1983. if (spawn) {
  1984. spawn->SetTradeskillClass(value);
  1985. if (spawn->IsEntity()) {
  1986. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1987. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1988. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1989. }
  1990. if (spawn->IsPlayer())
  1991. ((Player*)spawn)->SetCharSheetChanged(true);
  1992. }
  1993. return 0;
  1994. }
  1995. int EQ2Emu_lua_SetMount(lua_State* state) {
  1996. if (!lua_interface)
  1997. return 0;
  1998. Spawn* spawn = lua_interface->GetSpawn(state);
  1999. int16 value = lua_interface->GetInt16Value(state, 2);
  2000. if (spawn && spawn->IsEntity()) {
  2001. ((Entity*)spawn)->SetMount(value);
  2002. EQ2_Color color;
  2003. color.red = 255;
  2004. color.green = 255;
  2005. color.blue = 255;
  2006. ((Entity*)spawn)->SetMountColor(&color);
  2007. ((Entity*)spawn)->SetMountSaddleColor(&color);
  2008. }
  2009. return 0;
  2010. }
  2011. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  2012. if (!lua_interface)
  2013. return 0;
  2014. Spawn* spawn = lua_interface->GetSpawn(state);
  2015. EQ2_Color mount_color;
  2016. EQ2_Color saddle_color;
  2017. mount_color.red = lua_interface->GetInt8Value(state, 2);
  2018. mount_color.green = lua_interface->GetInt8Value(state, 3);
  2019. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  2020. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  2021. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  2022. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  2023. if (spawn && spawn->IsEntity()) {
  2024. ((Entity*)spawn)->SetMountColor(&mount_color);
  2025. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  2026. }
  2027. return 0;
  2028. }
  2029. int EQ2Emu_lua_GetMount(lua_State* state) {
  2030. if (!lua_interface)
  2031. return 0;
  2032. Spawn* spawn = lua_interface->GetSpawn(state);
  2033. if (spawn && spawn->IsEntity()) {
  2034. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2035. return 1;
  2036. }
  2037. return 0;
  2038. }
  2039. int EQ2Emu_lua_GetRace(lua_State* state) {
  2040. if (!lua_interface)
  2041. return 0;
  2042. Spawn* spawn = lua_interface->GetSpawn(state);
  2043. if (spawn)
  2044. {
  2045. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2046. lua_interface->SetInt32Value(state, spawn->GetRace());
  2047. return 1;
  2048. }
  2049. return 0;
  2050. }
  2051. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2052. if (!lua_interface)
  2053. return 0;
  2054. Spawn* spawn = lua_interface->GetSpawn(state);
  2055. if (spawn) {
  2056. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2057. return 1;
  2058. }
  2059. return 0;
  2060. }
  2061. int EQ2Emu_lua_GetClass(lua_State* state) {
  2062. Spawn* spawn = lua_interface->GetSpawn(state);
  2063. if (spawn) {
  2064. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2065. return 1;
  2066. }
  2067. return 0;
  2068. }
  2069. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2070. Spawn* spawn = lua_interface->GetSpawn(state);
  2071. if (spawn) {
  2072. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2073. return 1;
  2074. }
  2075. return 0;
  2076. }
  2077. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2078. if (!lua_interface)
  2079. return 0;
  2080. Spawn* spawn = lua_interface->GetSpawn(state);
  2081. float value = lua_interface->GetFloatValue(state, 2);
  2082. lua_interface->ResetFunctionStack(state);
  2083. if (spawn) {
  2084. spawn->SetSpeed(value);
  2085. if(spawn->IsEntity())
  2086. ((Entity*)spawn)->SetSpeed(value);
  2087. if (spawn->IsPlayer()) {
  2088. Client* client = ((Player*)spawn)->GetClient();
  2089. if (client) {
  2090. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2091. if (packet) {
  2092. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2093. packet->setDataByName("speed", value);
  2094. packet->setDataByName("size", 0.51);
  2095. EQ2Packet* app = packet->serialize();
  2096. client->QueuePacket(app);
  2097. safe_delete(packet);
  2098. }
  2099. }
  2100. }
  2101. }
  2102. return 0;
  2103. }
  2104. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2105. if (!lua_interface)
  2106. return 0;
  2107. Spawn* spawn = lua_interface->GetSpawn(state);
  2108. const int16 type = lua_interface->GetInt16Value(state, 2);
  2109. const float value = lua_interface->GetFloatValue(state, 3);
  2110. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2111. if(!luaspell || luaspell->resisted) {
  2112. lua_interface->ResetFunctionStack(state);
  2113. return 0;
  2114. }
  2115. int64 class_req = 0;
  2116. int32 class_id = 0;
  2117. vector<int16> faction_req;
  2118. vector<int16> race_req;
  2119. int32 i = 0;
  2120. int8 f = 0;
  2121. int8 r = 0;
  2122. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2123. if (class_id < 100) {
  2124. class_req += pow(2.0, double(class_id - 1));
  2125. }
  2126. else if (class_id > 100 && class_id < 1000) {
  2127. race_req.push_back(class_id);
  2128. r++;
  2129. }
  2130. else {
  2131. faction_req.push_back(class_id);
  2132. f++;
  2133. }
  2134. i++;
  2135. }
  2136. if (value != 0 && type >= 0) {
  2137. if (luaspell && luaspell->spell && luaspell->caster) {
  2138. ZoneServer* zone = luaspell->caster->GetZone();
  2139. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2140. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2141. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2142. if (target) {
  2143. if (target->IsPlayer()) {
  2144. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2145. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2146. if (((Player*)target)->GetGroupMemberInfo())
  2147. ((Player*)target)->UpdateGroupMemberInfo();
  2148. ((Player*)target)->SetCharSheetChanged(true);
  2149. }
  2150. else if (target->IsNPC())
  2151. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2152. else
  2153. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2154. }
  2155. }
  2156. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2157. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2158. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2159. }
  2160. else if (spawn && spawn->IsEntity()) {
  2161. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2162. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2163. if (spawn->IsPlayer())
  2164. ((Player*)spawn)->SetCharSheetChanged(true);
  2165. }
  2166. else
  2167. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2168. }
  2169. else
  2170. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2171. return 0;
  2172. }
  2173. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2174. if (!lua_interface)
  2175. return 0;
  2176. Spawn* spawn = lua_interface->GetSpawn(state);
  2177. int16 type = lua_interface->GetInt16Value(state, 2);
  2178. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2179. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2180. if (!spawn) {
  2181. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2182. return 0;
  2183. }
  2184. if (!spawn->IsEntity()) {
  2185. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2186. return 0;
  2187. }
  2188. if (value == 0) {
  2189. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2190. return 0;
  2191. }
  2192. if (!luaspell || !luaspell->spell) {
  2193. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2194. return 0;
  2195. }
  2196. if(luaspell->resisted) {
  2197. lua_interface->ResetFunctionStack(state);
  2198. return 0;
  2199. }
  2200. int32 class_req = 0;
  2201. vector<int16> faction_req;
  2202. vector<int16> race_req;
  2203. int32 class_id = 0;
  2204. int32 i = 0;
  2205. int8 f = 0;
  2206. int8 r = 0;
  2207. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2208. if (class_id < 100) {
  2209. class_req += pow(2.0, double(class_id - 1));
  2210. }
  2211. else if (class_id > 100 && class_id < 1000) {
  2212. race_req.push_back(class_id);
  2213. r++;
  2214. }
  2215. else {
  2216. faction_req.push_back(class_id);
  2217. f++;
  2218. }
  2219. i++;
  2220. }
  2221. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2222. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2223. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2224. if (spawn->IsPlayer())
  2225. ((Player*)spawn)->SetCharSheetChanged(true);
  2226. return 0;
  2227. }
  2228. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2229. if (!lua_interface)
  2230. return 0;
  2231. Spawn* spawn = lua_interface->GetSpawn(state);
  2232. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2233. if (!spawn) {
  2234. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2235. return 0;
  2236. }
  2237. if (!spawn->IsEntity()) {
  2238. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2239. return 0;
  2240. }
  2241. if (!luaspell || !luaspell->spell) {
  2242. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2243. return 0;
  2244. }
  2245. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2246. if (spawn->IsPlayer())
  2247. ((Player*)spawn)->SetCharSheetChanged(true);
  2248. return 0;
  2249. }
  2250. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2251. if (!lua_interface)
  2252. return 0;
  2253. Spawn* spawn = lua_interface->GetSpawn(state);
  2254. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2255. if (luaspell && luaspell->spell) {
  2256. ZoneServer* zone = luaspell->caster->GetZone();
  2257. Spawn* target = 0;
  2258. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2259. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2260. target = zone->GetSpawnByID(luaspell->targets[i]);
  2261. if (target && target->IsEntity()) {
  2262. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2263. if (target->IsPlayer())
  2264. ((Player*)target)->SetCharSheetChanged(true);
  2265. }
  2266. }
  2267. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2268. }
  2269. else if (spawn && spawn->IsEntity()) {
  2270. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2271. if (spawn->IsPlayer())
  2272. ((Player*)spawn)->SetCharSheetChanged(true);
  2273. }
  2274. return 0;
  2275. }
  2276. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2277. if (!lua_interface)
  2278. return 0;
  2279. Spawn* spawn = lua_interface->GetSpawn(state);
  2280. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2281. float value = lua_interface->GetFloatValue(state, 3);
  2282. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2283. if (value != 0) {
  2284. int32 spell_id = 0;
  2285. if (luaspell && luaspell->spell && luaspell->caster) {
  2286. if(luaspell->resisted) {
  2287. lua_interface->ResetFunctionStack(state);
  2288. return 0;
  2289. }
  2290. spell_id = luaspell->spell->GetSpellID();
  2291. ZoneServer* zone = luaspell->caster->GetZone();
  2292. Spawn* target = 0;
  2293. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2294. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2295. target = zone->GetSpawnByID(luaspell->targets[i]);
  2296. if (target && target->Alive()) {
  2297. if (target->IsPlayer()) {
  2298. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2299. Client* client = ((Player*)target)->GetClient();
  2300. if (client) {
  2301. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2302. if (packet)
  2303. client->QueuePacket(packet);
  2304. }
  2305. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2306. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2307. }
  2308. else if (target->IsNPC()) {
  2309. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2310. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2311. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2312. }
  2313. else
  2314. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2315. }
  2316. }
  2317. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2318. }
  2319. else if (spawn) {
  2320. if (spawn->IsPlayer()) {
  2321. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2322. Client* client = ((Player*)spawn)->GetClient();
  2323. if (client) {
  2324. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2325. if (packet)
  2326. client->QueuePacket(packet);
  2327. }
  2328. }
  2329. else if (spawn->IsNPC())
  2330. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2331. else
  2332. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2333. }
  2334. }
  2335. else
  2336. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2337. return 0;
  2338. }
  2339. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2340. if (!lua_interface)
  2341. return 0;
  2342. Spawn* spawn = lua_interface->GetSpawn(state);
  2343. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2344. if (spawn && spawn->IsPlayer()) {
  2345. int32 spell_id = 0;
  2346. if (luaspell && luaspell->spell) {
  2347. if(luaspell->resisted) {
  2348. lua_interface->ResetFunctionStack(state);
  2349. return 0;
  2350. }
  2351. spell_id = luaspell->spell->GetSpellID();
  2352. ZoneServer* zone = luaspell->caster->GetZone();
  2353. Spawn* target = 0;
  2354. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2355. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2356. target = zone->GetSpawnByID(luaspell->targets[i]);
  2357. if (target) {
  2358. if (target->IsPlayer()) {
  2359. ((Player*)target)->RemoveSkillBonus(spell_id);
  2360. Client* client = ((Player*)target)->GetClient();
  2361. if (client) {
  2362. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2363. if (packet)
  2364. client->QueuePacket(packet);
  2365. }
  2366. }
  2367. else if (target->IsNPC())
  2368. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2369. else
  2370. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2371. }
  2372. }
  2373. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2374. }
  2375. else if (spawn) {
  2376. if (spawn->IsPlayer()) {
  2377. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2378. Client* client = ((Player*)spawn)->GetClient();
  2379. if (client) {
  2380. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2381. if (packet)
  2382. client->QueuePacket(packet);
  2383. }
  2384. }
  2385. else if (spawn->IsNPC())
  2386. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2387. else
  2388. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2389. }
  2390. }
  2391. return 0;
  2392. }
  2393. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2394. if (!lua_interface)
  2395. return 0;
  2396. Spawn* spawn = lua_interface->GetSpawn(state);
  2397. int8 type = lua_interface->GetInt32Value(state, 2);
  2398. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2399. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2400. if(luaspell && luaspell->resisted) {
  2401. lua_interface->ResetFunctionStack(state);
  2402. return 0;
  2403. }
  2404. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2405. ZoneServer* zone = luaspell->caster->GetZone();
  2406. Spawn* target = 0;
  2407. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2408. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2409. target = zone->GetSpawnByID(luaspell->targets[i]);
  2410. if (target && target->IsEntity()) {
  2411. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2412. ((Entity*)target)->AddMezSpell(luaspell);
  2413. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2414. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2415. if (target->IsNPC())
  2416. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2417. }
  2418. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2419. ((Entity*)target)->AddStifleSpell(luaspell);
  2420. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2421. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2422. if (target->IsNPC())
  2423. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2424. }
  2425. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2426. ((Entity*)target)->AddDazeSpell(luaspell);
  2427. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2428. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2429. if (target->IsNPC())
  2430. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2431. }
  2432. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2433. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2434. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2435. ((Entity*)target)->AddStunSpell(luaspell);
  2436. if (target->IsNPC())
  2437. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2438. }
  2439. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2440. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2441. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2442. ((Entity*)target)->AddRootSpell(luaspell);
  2443. if (target->IsNPC())
  2444. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2445. }
  2446. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2447. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2448. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2449. ((Entity*)target)->AddFearSpell(luaspell);
  2450. if (target->IsNPC())
  2451. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2452. }
  2453. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2454. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2455. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2456. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2457. }
  2458. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2459. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2460. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2461. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2462. }
  2463. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2464. ((Entity*)target)->AddSnareSpell(luaspell);
  2465. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2466. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2467. if (target->IsNPC())
  2468. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2469. }
  2470. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2471. ((Entity*)target)->AddFlightSpell(luaspell);
  2472. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2473. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2474. }
  2475. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2476. ((Entity*)target)->AddGlideSpell(luaspell);
  2477. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2478. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2479. }
  2480. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2481. ((Entity*)target)->AddSafefallSpell(luaspell);
  2482. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2483. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2484. }
  2485. else
  2486. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2487. }
  2488. else
  2489. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2490. }
  2491. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2492. }
  2493. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2494. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2495. ((Entity*)spawn)->AddMezSpell(luaspell);
  2496. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2497. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2498. }
  2499. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2500. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2501. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2502. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2503. }
  2504. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2505. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2506. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2507. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2508. }
  2509. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2510. ((Entity*)spawn)->AddStunSpell(luaspell);
  2511. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2512. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2513. }
  2514. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2515. ((Entity*)spawn)->AddRootSpell(luaspell);
  2516. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2517. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2518. }
  2519. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2520. ((Entity*)spawn)->AddFearSpell(luaspell);
  2521. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2522. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2523. }
  2524. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2525. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2526. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2527. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2528. }
  2529. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2530. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2531. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2532. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2533. }
  2534. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2535. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2536. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2537. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2538. }
  2539. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2540. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2541. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2542. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2543. }
  2544. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2545. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2546. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2547. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2548. }
  2549. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2550. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2551. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2552. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2553. }
  2554. else
  2555. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2556. }
  2557. else
  2558. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2559. return 0;
  2560. }
  2561. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2562. if (!lua_interface)
  2563. return 0;
  2564. Spawn* spawn = lua_interface->GetSpawn(state);
  2565. int8 type = lua_interface->GetInt8Value(state, 2);
  2566. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2567. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2568. if (spawn && spawn->IsEntity()) {
  2569. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2570. ZoneServer* zone = luaspell->caster->GetZone();
  2571. Spawn* target = 0;
  2572. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2573. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2574. target = zone->GetSpawnByID(luaspell->targets[i]);
  2575. if (target) {
  2576. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2577. ((Entity*)target)->RemoveMezSpell(luaspell);
  2578. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2579. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2580. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2581. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2582. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2583. ((Entity*)target)->RemoveStunSpell(luaspell);
  2584. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2585. ((Entity*)target)->RemoveRootSpell(luaspell);
  2586. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2587. ((Entity*)target)->RemoveFearSpell(luaspell);
  2588. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2589. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2590. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2591. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2592. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2593. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2594. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2595. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2596. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2597. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2598. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2599. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2600. else
  2601. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2602. }
  2603. }
  2604. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2605. }
  2606. else if (only_remove_spawn) {
  2607. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2608. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2609. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2610. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2611. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2612. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2613. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2614. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2615. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2616. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2617. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2618. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2619. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2620. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2621. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2622. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2623. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2624. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2625. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2626. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2627. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2628. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2629. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2630. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2631. else
  2632. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2633. }
  2634. }
  2635. return 0;
  2636. }
  2637. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2638. if (!lua_interface)
  2639. return 0;
  2640. Spawn* spawn = lua_interface->GetSpawn(state);
  2641. int8 type = lua_interface->GetInt8Value(state, 2);
  2642. bool hasEffect = false;
  2643. if (!spawn)
  2644. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2645. else if (!spawn->IsEntity())
  2646. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2647. else if (type < CONTROL_MAX_EFFECTS)
  2648. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2649. else
  2650. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2651. lua_interface->SetBooleanValue(state, hasEffect);
  2652. return 1;
  2653. }
  2654. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2655. if (!lua_interface)
  2656. return 0;
  2657. Spawn* spawn = lua_interface->GetSpawn(state);
  2658. float distance = 0.0f;
  2659. if (!spawn)
  2660. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2661. else if (!spawn->IsNPC())
  2662. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2663. else
  2664. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2665. lua_interface->SetFloatValue(state, distance);
  2666. return 1;
  2667. }
  2668. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2669. if (!lua_interface)
  2670. return 0;
  2671. Spawn* spawn = lua_interface->GetSpawn(state);
  2672. float distance = 0.0f;
  2673. if (!spawn)
  2674. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2675. else if (!spawn->IsNPC())
  2676. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2677. else
  2678. distance = ((NPC*)spawn)->GetAggroRadius();
  2679. lua_interface->SetFloatValue(state, distance);
  2680. return 1;
  2681. }
  2682. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2683. if (!lua_interface)
  2684. return 0;
  2685. Spawn* spawn = lua_interface->GetSpawn(state);
  2686. float distance = lua_interface->GetFloatValue(state, 2);
  2687. bool override = lua_interface->GetBooleanValue(state, 3);
  2688. bool result = false;
  2689. lua_interface->ResetFunctionStack(state);
  2690. if (!spawn)
  2691. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2692. else if (!spawn->IsNPC())
  2693. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2694. else
  2695. {
  2696. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2697. result = true;
  2698. }
  2699. lua_interface->SetBooleanValue(state, result);
  2700. return 1;
  2701. }
  2702. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2703. if (!lua_interface)
  2704. return 0;
  2705. Spawn* spawn = lua_interface->GetSpawn(state);
  2706. int16 value = lua_interface->GetInt16Value(state, 2);
  2707. if (spawn && spawn->IsEntity()) {
  2708. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2709. if (spawn->IsPlayer())
  2710. ((Player*)spawn)->SetCharSheetChanged(true);
  2711. }
  2712. return 0;
  2713. }
  2714. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2715. if (!lua_interface)
  2716. return 0;
  2717. Spawn* spawn = lua_interface->GetSpawn(state);
  2718. int16 value = lua_interface->GetInt16Value(state, 2);
  2719. if (spawn && spawn->IsEntity()) {
  2720. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2721. if (spawn->IsPlayer())
  2722. ((Player*)spawn)->SetCharSheetChanged(true);
  2723. }
  2724. return 0;
  2725. }
  2726. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2727. if (!lua_interface)
  2728. return 0;
  2729. Spawn* spawn = lua_interface->GetSpawn(state);
  2730. int16 value = lua_interface->GetInt16Value(state, 2);
  2731. if (spawn && spawn->IsEntity()) {
  2732. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2733. if (spawn->IsPlayer())
  2734. ((Player*)spawn)->SetCharSheetChanged(true);
  2735. }
  2736. return 0;
  2737. }
  2738. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2739. if (!lua_interface)
  2740. return 0;
  2741. Spawn* spawn = lua_interface->GetSpawn(state);
  2742. int16 value = lua_interface->GetInt16Value(state, 2);
  2743. if (spawn && spawn->IsEntity()) {
  2744. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2745. if (spawn->IsPlayer())
  2746. ((Player*)spawn)->SetCharSheetChanged(true);
  2747. }
  2748. return 0;
  2749. }
  2750. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2751. if (!lua_interface)
  2752. return 0;
  2753. Spawn* spawn = lua_interface->GetSpawn(state);
  2754. int16 value = lua_interface->GetInt16Value(state, 2);
  2755. if (spawn && spawn->IsEntity()) {
  2756. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2757. if (spawn->IsPlayer())
  2758. ((Player*)spawn)->SetCharSheetChanged(true);
  2759. }
  2760. return 0;
  2761. }
  2762. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2763. if (!lua_interface)
  2764. return 0;
  2765. Spawn* spawn = lua_interface->GetSpawn(state);
  2766. int8 value = lua_interface->GetInt8Value(state, 2);
  2767. if (spawn && spawn->IsEntity()) {
  2768. ((Entity*)spawn)->SetDeity(value);
  2769. if (spawn->IsPlayer())
  2770. ((Player*)spawn)->SetCharSheetChanged(true);
  2771. }
  2772. lua_interface->ResetFunctionStack(state);
  2773. return 0;
  2774. }
  2775. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2776. if (!lua_interface)
  2777. return 0;
  2778. Spawn* spawn = lua_interface->GetSpawn(state);
  2779. if (spawn && spawn->IsEntity()) {
  2780. int8 deity = ((Entity*)spawn)->GetDeity();
  2781. lua_interface->SetInt32Value(state, deity);
  2782. return 1;
  2783. }
  2784. return 0;
  2785. }
  2786. int EQ2Emu_lua_SetInt(lua_State* state) {
  2787. if (!lua_interface)
  2788. return 0;
  2789. Spawn* spawn = lua_interface->GetSpawn(state);
  2790. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2791. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2792. if (spawn && spawn->IsEntity()) {
  2793. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_INT, value);
  2794. if (spawn->IsPlayer())
  2795. ((Player*)spawn)->SetCharSheetChanged(true);
  2796. }
  2797. return 0;
  2798. }
  2799. int EQ2Emu_lua_SetWis(lua_State* state) {
  2800. if (!lua_interface)
  2801. return 0;
  2802. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2803. Spawn* spawn = lua_interface->GetSpawn(state);
  2804. float value = lua_interface->GetFloatValue(state, 2);
  2805. if (spawn && spawn->IsEntity()) {
  2806. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_WIS, value);
  2807. if (spawn->IsPlayer())
  2808. ((Player*)spawn)->SetCharSheetChanged(true);
  2809. }
  2810. return 0;
  2811. }
  2812. int EQ2Emu_lua_SetSta(lua_State* state) {
  2813. if (!lua_interface)
  2814. return 0;
  2815. Spawn* spawn = lua_interface->GetSpawn(state);
  2816. float value = lua_interface->GetFloatValue(state, 2);
  2817. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2818. if (spawn && spawn->IsEntity()) {
  2819. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STA, value);
  2820. if (spawn->IsPlayer())
  2821. ((Player*)spawn)->SetCharSheetChanged(true);
  2822. }
  2823. return 0;
  2824. }
  2825. int EQ2Emu_lua_SetStr(lua_State* state) {
  2826. if (!lua_interface)
  2827. return 0;
  2828. Spawn* spawn = lua_interface->GetSpawn(state);
  2829. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2830. float value = lua_interface->GetFloatValue(state, 2);
  2831. if (spawn && spawn->IsEntity()) {
  2832. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STR, value);
  2833. if (spawn->IsPlayer())
  2834. ((Player*)spawn)->SetCharSheetChanged(true);
  2835. }
  2836. return 0;
  2837. }
  2838. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2839. if (!lua_interface)
  2840. return 0;
  2841. Spawn* spawn = lua_interface->GetSpawn(state);
  2842. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2843. float value = lua_interface->GetFloatValue(state, 2);
  2844. if (spawn && spawn->IsEntity()) {
  2845. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_AGI, value);
  2846. if (spawn->IsPlayer())
  2847. ((Player*)spawn)->SetCharSheetChanged(true);
  2848. }
  2849. return 0;
  2850. }
  2851. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2852. if (!lua_interface)
  2853. return 0;
  2854. Spawn* spawn = lua_interface->GetSpawn(state);
  2855. if (spawn) {
  2856. lua_interface->SetInt32Value(state, spawn->GetHP());
  2857. return 1;
  2858. }
  2859. return 0;
  2860. }
  2861. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2862. if (!lua_interface)
  2863. return 0;
  2864. Spawn* spawn = lua_interface->GetSpawn(state);
  2865. if (spawn) {
  2866. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2867. return 1;
  2868. }
  2869. return 0;
  2870. }
  2871. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2872. if (!lua_interface)
  2873. return 0;
  2874. Spawn* spawn = lua_interface->GetSpawn(state);
  2875. if (spawn) {
  2876. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2877. return 1;
  2878. }
  2879. return 0;
  2880. }
  2881. int EQ2Emu_lua_GetName(lua_State* state) {
  2882. if (!lua_interface)
  2883. return 0;
  2884. Spawn* spawn = lua_interface->GetSpawn(state);
  2885. if (spawn) {
  2886. lua_interface->SetStringValue(state, spawn->GetName());
  2887. return 1;
  2888. }
  2889. return 0;
  2890. }
  2891. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2892. Spawn* spawn = lua_interface->GetSpawn(state);
  2893. if (spawn) {
  2894. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2895. return 1;
  2896. }
  2897. return 0;
  2898. }
  2899. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2900. if (!lua_interface)
  2901. return 0;
  2902. Spawn* spawn = lua_interface->GetSpawn(state);
  2903. if (spawn) {
  2904. lua_interface->SetInt32Value(state, spawn->GetPower());
  2905. return 1;
  2906. }
  2907. return 0;
  2908. }
  2909. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2910. if (!lua_interface)
  2911. return 0;
  2912. Spawn* spawn = lua_interface->GetSpawn(state);
  2913. if (spawn) {
  2914. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2915. return 1;
  2916. }
  2917. return 0;
  2918. }
  2919. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2920. if (!lua_interface)
  2921. return 0;
  2922. Spawn* spawn = lua_interface->GetSpawn(state);
  2923. if (spawn) {
  2924. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2925. return 1;
  2926. }
  2927. return 0;
  2928. }
  2929. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2930. if (!lua_interface)
  2931. return 0;
  2932. Spawn* spawn = lua_interface->GetSpawn(state);
  2933. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2934. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2935. if (spawn && spawn2) {
  2936. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2937. lua_interface->SetFloatValue(state, distance);
  2938. return 1;
  2939. }
  2940. return 0;
  2941. }
  2942. int EQ2Emu_lua_GetX(lua_State* state) {
  2943. if (!lua_interface)
  2944. return 0;
  2945. Spawn* spawn = lua_interface->GetSpawn(state);
  2946. if (spawn) {
  2947. lua_interface->SetFloatValue(state, spawn->GetX());
  2948. return 1;
  2949. }
  2950. return 0;
  2951. }
  2952. int EQ2Emu_lua_GetY(lua_State* state) {
  2953. if (!lua_interface)
  2954. return 0;
  2955. Spawn* spawn = lua_interface->GetSpawn(state);
  2956. if (spawn) {
  2957. lua_interface->SetFloatValue(state, spawn->GetY());
  2958. return 1;
  2959. }
  2960. return 0;
  2961. }
  2962. int EQ2Emu_lua_GetZ(lua_State* state) {
  2963. if (!lua_interface)
  2964. return 0;
  2965. Spawn* spawn = lua_interface->GetSpawn(state);
  2966. if (spawn) {
  2967. lua_interface->SetFloatValue(state, spawn->GetZ());
  2968. return 1;
  2969. }
  2970. return 0;
  2971. }
  2972. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2973. if (!lua_interface)
  2974. return 0;
  2975. Spawn* spawn = lua_interface->GetSpawn(state);
  2976. if (spawn) {
  2977. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2978. return 1;
  2979. }
  2980. return 0;
  2981. }
  2982. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2983. if (!lua_interface)
  2984. return 0;
  2985. Spawn* spawn = lua_interface->GetSpawn(state);
  2986. if (spawn) {
  2987. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2988. return 1;
  2989. }
  2990. return 0;
  2991. }
  2992. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2993. if (!lua_interface)
  2994. return 0;
  2995. Spawn* spawn = lua_interface->GetSpawn(state);
  2996. if (spawn) {
  2997. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2998. return 1;
  2999. }
  3000. return 0;
  3001. }
  3002. int EQ2Emu_lua_HasMoved(lua_State* state) {
  3003. if (!lua_interface)
  3004. return 0;
  3005. Spawn* spawn = lua_interface->GetSpawn(state);
  3006. if (spawn && spawn->IsEntity()) {
  3007. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  3008. return 1;
  3009. }
  3010. return 0;
  3011. }
  3012. int EQ2Emu_lua_GetInt(lua_State* state) {
  3013. if (!lua_interface)
  3014. return 0;
  3015. Spawn* spawn = lua_interface->GetSpawn(state);
  3016. if (spawn && spawn->IsEntity()) {
  3017. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  3018. return 1;
  3019. }
  3020. return 0;
  3021. }
  3022. int EQ2Emu_lua_GetWis(lua_State* state) {
  3023. if (!lua_interface)
  3024. return 0;
  3025. Spawn* spawn = lua_interface->GetSpawn(state);
  3026. if (spawn && spawn->IsEntity()) {
  3027. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  3028. return 1;
  3029. }
  3030. return 0;
  3031. }
  3032. int EQ2Emu_lua_GetSta(lua_State* state) {
  3033. if (!lua_interface)
  3034. return 0;
  3035. Spawn* spawn = lua_interface->GetSpawn(state);
  3036. if (spawn && spawn->IsEntity()) {
  3037. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  3038. return 1;
  3039. }
  3040. return 0;
  3041. }
  3042. int EQ2Emu_lua_GetStr(lua_State* state) {
  3043. if (!lua_interface)
  3044. return 0;
  3045. Spawn* spawn = lua_interface->GetSpawn(state);
  3046. if (spawn && spawn->IsEntity()) {
  3047. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3048. return 1;
  3049. }
  3050. return 0;
  3051. }
  3052. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3053. if (!lua_interface)
  3054. return 0;
  3055. Spawn* spawn = lua_interface->GetSpawn(state);
  3056. if (spawn && spawn->IsEntity()) {
  3057. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3058. return 1;
  3059. }
  3060. return 0;
  3061. }
  3062. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3063. if (!lua_interface)
  3064. return 0;
  3065. Spawn* spawn = lua_interface->GetSpawn(state);
  3066. if (spawn && spawn->IsEntity()) {
  3067. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3068. return 1;
  3069. }
  3070. return 0;
  3071. }
  3072. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3073. if (!lua_interface)
  3074. return 0;
  3075. Spawn* spawn = lua_interface->GetSpawn(state);
  3076. if (spawn && spawn->IsEntity()) {
  3077. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3078. return 1;
  3079. }
  3080. return 0;
  3081. }
  3082. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3083. if (!lua_interface)
  3084. return 0;
  3085. Spawn* spawn = lua_interface->GetSpawn(state);
  3086. if (spawn && spawn->IsEntity()) {
  3087. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3088. return 1;
  3089. }
  3090. return 0;
  3091. }
  3092. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3093. if (!lua_interface)
  3094. return 0;
  3095. Spawn* spawn = lua_interface->GetSpawn(state);
  3096. if (spawn && spawn->IsEntity()) {
  3097. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3098. return 1;
  3099. }
  3100. return 0;
  3101. }
  3102. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3103. if (!lua_interface)
  3104. return 0;
  3105. Spawn* spawn = lua_interface->GetSpawn(state);
  3106. if (spawn && spawn->IsEntity()) {
  3107. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3108. return 1;
  3109. }
  3110. return 0;
  3111. }
  3112. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3113. if (!lua_interface)
  3114. return 0;
  3115. Spawn* player = lua_interface->GetSpawn(state);
  3116. if (!player || !player->IsPlayer()) {
  3117. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3118. return 0;
  3119. }
  3120. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3121. if (quest_id <= 0) {
  3122. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3123. return 0;
  3124. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3125. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3126. return 0;
  3127. }
  3128. int32 step = lua_interface->GetInt32Value(state, 3);
  3129. if (step > 0) {
  3130. Client* client = ((Player*)player)->GetClient();
  3131. if (client)
  3132. client->AddPendingQuestUpdate(quest_id, step);
  3133. } else {
  3134. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3135. }
  3136. return 0;
  3137. }
  3138. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3139. Spawn* player = lua_interface->GetSpawn(state);
  3140. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3141. int32 step = lua_interface->GetInt32Value(state, 3);
  3142. int32 progress = lua_interface->GetInt32Value(state, 4);
  3143. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3144. Client* client = ((Player*)player)->GetClient();
  3145. if (client)
  3146. client->AddPendingQuestUpdate(quest_id, step, progress);
  3147. }
  3148. return 0;
  3149. }
  3150. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3151. if (!lua_interface)
  3152. return 0;
  3153. Spawn* player = lua_interface->GetSpawn(state);
  3154. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3155. if (player && player->IsPlayer() && quest_id > 0) {
  3156. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3157. return 1;
  3158. }
  3159. return 0;
  3160. }
  3161. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3162. if (!lua_interface)
  3163. return 0;
  3164. Spawn* player = lua_interface->GetSpawn(state);
  3165. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3166. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3167. if (player && player->IsPlayer() && quest_id > 0) {
  3168. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3169. return 1;
  3170. }
  3171. return 0;
  3172. }
  3173. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3174. if (!lua_interface)
  3175. return 0;
  3176. Spawn* player = lua_interface->GetSpawn(state);
  3177. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3178. if (player && player->IsPlayer() && quest_id > 0) {
  3179. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3180. return 1;
  3181. }
  3182. return 0;
  3183. }
  3184. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3185. if (!lua_interface)
  3186. return 0;
  3187. Quest* quest = lua_interface->GetQuest(state);
  3188. string name = lua_interface->GetStringValue(state, 2);
  3189. string type = lua_interface->GetStringValue(state, 3);
  3190. string zone = lua_interface->GetStringValue(state, 4);
  3191. int16 level = lua_interface->GetInt16Value(state, 5);
  3192. string description = lua_interface->GetStringValue(state, 6);
  3193. bool load = true;
  3194. if (!quest) {
  3195. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3196. load = false;
  3197. }
  3198. if (load && name.length() == 0) {
  3199. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3200. load = false;
  3201. }
  3202. if (load && type.length() == 0) {
  3203. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3204. load = false;
  3205. }
  3206. if (load && zone.length() == 0) {
  3207. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3208. load = false;
  3209. }
  3210. if (load && description.length() == 0) {
  3211. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3212. load = false;
  3213. }
  3214. if (load && level == 0) {
  3215. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3216. load = false;
  3217. }
  3218. if (load)
  3219. quest->RegisterQuest(name, type, zone, level, description);
  3220. return 0;
  3221. }
  3222. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3223. if (!lua_interface)
  3224. return 0;
  3225. Quest* quest = lua_interface->GetQuest(state);
  3226. if (quest) {
  3227. int8 level = lua_interface->GetInt16Value(state, 2);
  3228. quest->SetPrereqLevel(level);
  3229. }
  3230. return 0;
  3231. }
  3232. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3233. if (!lua_interface)
  3234. return 0;
  3235. Quest* quest = lua_interface->GetQuest(state);
  3236. if (quest) {
  3237. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3238. quest->AddPrereqQuest(quest_id);
  3239. }
  3240. return 0;
  3241. }
  3242. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3243. if (!lua_interface)
  3244. return 0;
  3245. Quest* quest = lua_interface->GetQuest(state);
  3246. if (quest) {
  3247. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3248. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3249. if (quantity == 0)
  3250. quantity = 1;
  3251. Item* master_item = master_item_list.GetItem(item_id);
  3252. if (master_item) {
  3253. Item* item = new Item(master_item);
  3254. item->details.count = quantity;
  3255. quest->AddPrereqItem(item);
  3256. }
  3257. }
  3258. return 0;
  3259. }
  3260. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3261. if (!lua_interface)
  3262. return 0;
  3263. Spawn* player = lua_interface->GetSpawn(state);
  3264. if(!player || !player->IsPlayer()) {
  3265. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3266. return 0;
  3267. }
  3268. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3269. if (quest_id > 0) {
  3270. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3271. return 1;
  3272. } else {
  3273. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3274. }
  3275. return 0;
  3276. }
  3277. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3278. if (!lua_interface)
  3279. return 0;
  3280. Quest* quest = lua_interface->GetQuest(state);
  3281. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3282. lua_interface->ResetFunctionStack(state);
  3283. if (quest && spawn_id > 0)
  3284. quest->SetQuestReturnNPC(spawn_id);
  3285. return 0;
  3286. }
  3287. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3288. if (!lua_interface)
  3289. return 0;
  3290. Spawn* spawn = lua_interface->GetSpawn(state);
  3291. int32 time = lua_interface->GetInt32Value(state, 2);
  3292. string function = lua_interface->GetStringValue(state, 3);
  3293. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3294. Spawn* player = lua_interface->GetSpawn(state, 5);
  3295. lua_interface->ResetFunctionStack(state);
  3296. if (!spawn) {
  3297. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3298. return 0;
  3299. }
  3300. if (time <= 0) {
  3301. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3302. return 0;
  3303. }
  3304. if (function.length() == 0) {
  3305. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3306. return 0;
  3307. }
  3308. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3309. if ( time < 10)
  3310. time = 10;
  3311. timer->timer = Timer::GetCurrentTime2() + time;
  3312. timer->function = function;
  3313. timer->spawn = spawn->GetID();
  3314. timer->player = player ? player->GetID() : 0;
  3315. if (max_count == 0)
  3316. max_count = 1;
  3317. timer->max_count = max_count;
  3318. timer->current_count = 0;
  3319. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3320. return 0;
  3321. }
  3322. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3323. if (!lua_interface)
  3324. return 0;
  3325. Spawn* spawn = lua_interface->GetSpawn(state);
  3326. string function = lua_interface->GetStringValue(state, 2);
  3327. lua_interface->ResetFunctionStack(state);
  3328. if (!spawn) {
  3329. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3330. return 0;
  3331. }
  3332. if(!spawn->GetZone()) {
  3333. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3334. return 0;
  3335. }
  3336. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3337. return 0;
  3338. }
  3339. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3340. if (!lua_interface)
  3341. return 0;
  3342. Spawn* player = lua_interface->GetSpawn(state);
  3343. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3344. lua_interface->ResetFunctionStack(state);
  3345. if (player && player->IsPlayer() && quest_id > 0) {
  3346. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3347. return 1;
  3348. }
  3349. return 0;
  3350. }
  3351. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3352. if (!lua_interface)
  3353. return 0;
  3354. Spawn* player = lua_interface->GetSpawn(state);
  3355. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3356. lua_interface->ResetFunctionStack(state);
  3357. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3358. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3359. if (quest)
  3360. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3361. return 1;
  3362. }
  3363. return 0;
  3364. }
  3365. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3366. if (!lua_interface)
  3367. return 0;
  3368. Spawn* player = lua_interface->GetSpawn(state);
  3369. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3370. lua_interface->ResetFunctionStack(state);
  3371. if (player && player->IsPlayer() && quest_id > 0) {
  3372. lua_interface->SetBooleanValue(state, (((Player*)player)->HasQuestBeenCompleted(quest_id) != 0));
  3373. return 1;
  3374. }
  3375. return 0;
  3376. }
  3377. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3378. if (!lua_interface)
  3379. return 0;
  3380. Spawn* npc = lua_interface->GetSpawn(state);
  3381. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3382. lua_interface->ResetFunctionStack(state);
  3383. if (npc && !npc->IsPlayer() && quest_id > 0)
  3384. npc->AddProvidedQuest(quest_id);
  3385. return 0;
  3386. }
  3387. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3388. if (!lua_interface)
  3389. return 0;
  3390. Spawn* npc = lua_interface->GetSpawn(state);
  3391. Spawn* player = lua_interface->GetSpawn(state, 2);
  3392. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3393. bool forced = lua_interface->GetBooleanValue(state, 4);
  3394. lua_interface->ResetFunctionStack(state);
  3395. /* NPC is allowed to be null */
  3396. if (player && player->IsPlayer() && quest_id > 0) {
  3397. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3398. if (master_quest) {
  3399. Client* client = ((Player*)player)->GetClient();
  3400. if (!client) {
  3401. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3402. }
  3403. Quest* quest = new Quest(master_quest);
  3404. if (!quest) {
  3405. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3406. }
  3407. if (client && quest) {
  3408. if (npc)
  3409. quest->SetQuestGiver(npc->GetDatabaseID());
  3410. else
  3411. quest->SetQuestGiver(0);
  3412. client->AddPendingQuest(quest, forced);
  3413. }
  3414. }
  3415. else {
  3416. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3417. }
  3418. }
  3419. else {
  3420. 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);
  3421. }
  3422. return 0;
  3423. }
  3424. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3425. if (!lua_interface)
  3426. return 0;
  3427. Quest* quest = lua_interface->GetQuest(state);
  3428. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3429. lua_interface->ResetFunctionStack(state);
  3430. if (quest) {
  3431. quest->AddPrereqClass(class_id);
  3432. }
  3433. return 0;
  3434. }
  3435. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3436. if (!lua_interface)
  3437. return 0;
  3438. Quest* quest = lua_interface->GetQuest(state);
  3439. int8 race = lua_interface->GetInt8Value(state, 2);
  3440. lua_interface->ResetFunctionStack(state);
  3441. if (quest) {
  3442. quest->AddPrereqRace(race);
  3443. }
  3444. return 0;
  3445. }
  3446. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3447. if (!lua_interface)
  3448. return 0;
  3449. Quest* quest = lua_interface->GetQuest(state);
  3450. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3451. lua_interface->ResetFunctionStack(state);
  3452. if (quest) {
  3453. quest->AddPrereqModelType(model_type);
  3454. }
  3455. return 0;
  3456. }
  3457. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3458. if (!lua_interface)
  3459. return 0;
  3460. Quest* quest = lua_interface->GetQuest(state);
  3461. int8 level = lua_interface->GetInt8Value(state, 2);
  3462. lua_interface->ResetFunctionStack(state);
  3463. if (!quest) {
  3464. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3465. return 0;
  3466. }
  3467. quest->SetPrereqTSLevel(level);
  3468. return 0;
  3469. }
  3470. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3471. if (!lua_interface)
  3472. return 0;
  3473. Quest* quest = lua_interface->GetQuest(state);
  3474. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3475. lua_interface->ResetFunctionStack(state);
  3476. if (!quest) {
  3477. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3478. return 0;
  3479. }
  3480. quest->AddPrereqTradeskillClass(class_id);
  3481. return 0;
  3482. }
  3483. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3484. if (!lua_interface)
  3485. return 0;
  3486. Quest* quest = lua_interface->GetQuest(state);
  3487. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3488. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3489. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3490. lua_interface->ResetFunctionStack(state);
  3491. if (quest) {
  3492. quest->AddPrereqFaction(faction_id, min, max);
  3493. }
  3494. return 0;
  3495. }
  3496. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3497. if (!lua_interface)
  3498. return 0;
  3499. Quest* quest = lua_interface->GetQuest(state);
  3500. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3501. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3502. lua_interface->ResetFunctionStack(state);
  3503. if (quest) {
  3504. if (quantity == 0)
  3505. quantity = 1;
  3506. Item* master_item = master_item_list.GetItem(item_id);
  3507. if (master_item) {
  3508. Item* item = new Item(master_item);
  3509. item->details.count = quantity;
  3510. quest->AddSelectableRewardItem(item);
  3511. }
  3512. }
  3513. return 0;
  3514. }
  3515. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3516. if (!lua_interface)
  3517. return 0;
  3518. Quest* quest = lua_interface->GetQuest(state);
  3519. if (quest) {
  3520. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3521. vector<Item*>* items = quest->GetRewardItems();
  3522. if (items) {
  3523. vector<Item*>::iterator itr;
  3524. for (itr = items->begin(); itr != items->end(); itr++) {
  3525. if (*itr && (*itr)->details.item_id == item_id) {
  3526. lua_interface->SetBooleanValue(state, true);
  3527. return 1;
  3528. }
  3529. }
  3530. }
  3531. }
  3532. lua_interface->SetBooleanValue(state, false);
  3533. return 1;
  3534. }
  3535. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3536. if (!lua_interface)
  3537. return 0;
  3538. Quest* quest = lua_interface->GetQuest(state);
  3539. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3540. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3541. lua_interface->ResetFunctionStack(state);
  3542. if (quest) {
  3543. if (quantity == 0)
  3544. quantity = 1;
  3545. Item* master_item = master_item_list.GetItem(item_id);
  3546. if (master_item) {
  3547. Item* item = new Item(master_item);
  3548. item->details.count = quantity;
  3549. quest->AddRewardItem(item);
  3550. }
  3551. }
  3552. return 0;
  3553. }
  3554. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3555. if (!lua_interface)
  3556. return 0;
  3557. Quest* quest = lua_interface->GetQuest(state);
  3558. int32 copper = lua_interface->GetInt32Value(state, 2);
  3559. int32 silver = lua_interface->GetInt32Value(state, 3);
  3560. int32 gold = lua_interface->GetInt32Value(state, 4);
  3561. int32 plat = lua_interface->GetInt32Value(state, 5);
  3562. lua_interface->ResetFunctionStack(state);
  3563. if (quest) {
  3564. quest->AddRewardCoins(copper, silver, gold, plat);
  3565. }
  3566. return 0;
  3567. }
  3568. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3569. if (!lua_interface)
  3570. return 0;
  3571. Quest* quest = lua_interface->GetQuest(state);
  3572. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3573. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3574. lua_interface->ResetFunctionStack(state);
  3575. if (quest && faction_id > 0 && amount != 0)
  3576. quest->AddRewardFaction(faction_id, amount);
  3577. return 0;
  3578. }
  3579. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3580. if (!lua_interface)
  3581. return 0;
  3582. Quest* quest = lua_interface->GetQuest(state);
  3583. int32 status = lua_interface->GetInt32Value(state, 2);
  3584. lua_interface->ResetFunctionStack(state);
  3585. if (quest) {
  3586. quest->SetRewardStatus(status);
  3587. }
  3588. return 0;
  3589. }
  3590. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3591. if (!lua_interface)
  3592. return 0;
  3593. Quest* quest = lua_interface->GetQuest(state);
  3594. int32 status = lua_interface->GetInt32Value(state, 2);
  3595. lua_interface->ResetFunctionStack(state);
  3596. if (quest) {
  3597. quest->SetStatusTmpReward(status);
  3598. }
  3599. return 0;
  3600. }
  3601. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3602. if (!lua_interface)
  3603. return 0;
  3604. Quest* quest = lua_interface->GetQuest(state);
  3605. int64 coins = lua_interface->GetInt64Value(state, 2);
  3606. lua_interface->ResetFunctionStack(state);
  3607. if (quest) {
  3608. quest->SetCoinTmpReward(coins);
  3609. }
  3610. return 0;
  3611. }
  3612. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3613. if (!lua_interface)
  3614. return 0;
  3615. Quest* quest = lua_interface->GetQuest(state);
  3616. string comment = lua_interface->GetStringValue(state, 2);
  3617. lua_interface->ResetFunctionStack(state);
  3618. if (quest) {
  3619. quest->SetRewardComment(comment);
  3620. }
  3621. return 0;
  3622. }
  3623. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3624. if (!lua_interface)
  3625. return 0;
  3626. Quest* quest = lua_interface->GetQuest(state);
  3627. int32 exp = lua_interface->GetInt32Value(state, 2);
  3628. lua_interface->ResetFunctionStack(state);
  3629. if (quest) {
  3630. quest->SetRewardXP(exp);
  3631. }
  3632. return 0;
  3633. }
  3634. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3635. Quest* quest = lua_interface->GetQuest(state);
  3636. int32 step = lua_interface->GetInt32Value(state, 2);
  3637. string description = lua_interface->GetStringValue(state, 3);
  3638. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3639. float percentage = lua_interface->GetFloatValue(state, 5);
  3640. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3641. int16 icon = lua_interface->GetInt16Value(state, 7);
  3642. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3643. if (quest) {
  3644. const char* taskgroup = 0;
  3645. if (str_taskgroup.length() > 0)
  3646. taskgroup = str_taskgroup.c_str();
  3647. int32 id = 0;
  3648. vector<int32>* ids = 0;
  3649. int i = 0;
  3650. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3651. if (ids == 0)
  3652. ids = new vector<int32>;
  3653. ids->push_back(id);
  3654. i++;
  3655. }
  3656. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3657. if (quest_step && icon && quantity > 0)
  3658. quest_step->SetIcon(icon);
  3659. if (quest->GetPlayer()) {
  3660. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3661. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3662. }
  3663. }
  3664. lua_interface->ResetFunctionStack(state);
  3665. return 0;
  3666. }
  3667. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3668. {
  3669. if (!lua_interface)
  3670. return 0;
  3671. Quest* quest = lua_interface->GetQuest(state);
  3672. int32 step = lua_interface->GetInt32Value(state, 2);
  3673. string description = lua_interface->GetStringValue(state, 3);
  3674. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3675. float percentage = lua_interface->GetFloatValue(state, 5);
  3676. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3677. int16 icon = lua_interface->GetInt16Value(state, 7);
  3678. if (quest) {
  3679. const char* taskgroup = 0;
  3680. if (str_taskgroup.length() > 0)
  3681. taskgroup = str_taskgroup.c_str();
  3682. int32 id = 0;
  3683. vector<int32>* ids = 0;
  3684. int i = 0;
  3685. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3686. if (ids == 0)
  3687. ids = new vector<int32>;
  3688. ids->push_back(id);
  3689. i++;
  3690. }
  3691. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3692. if (quest_step && icon > 0 && quantity > 0)
  3693. quest_step->SetIcon(icon);
  3694. if (quest->GetPlayer()) {
  3695. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3696. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3697. }
  3698. safe_delete(ids);
  3699. }
  3700. lua_interface->ResetFunctionStack(state);
  3701. return 0;
  3702. }
  3703. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3704. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3705. }
  3706. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3707. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3708. }
  3709. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3710. if (!lua_interface)
  3711. return 0;
  3712. Quest* quest = lua_interface->GetQuest(state);
  3713. int32 step = lua_interface->GetInt32Value(state, 2);
  3714. string description = lua_interface->GetStringValue(state, 3);
  3715. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3716. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3717. int16 icon = lua_interface->GetInt16Value(state, 6);
  3718. if (quest) {
  3719. const char* taskgroup = 0;
  3720. if (str_taskgroup.length() > 0)
  3721. taskgroup = str_taskgroup.c_str();
  3722. int32 npc_id = 0;
  3723. vector<int32>* ids = 0;
  3724. int i = 0;
  3725. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3726. if (ids == 0)
  3727. ids = new vector<int32>;
  3728. ids->push_back(npc_id);
  3729. i++;
  3730. }
  3731. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3732. if (quest_step && icon > 0)
  3733. quest_step->SetIcon(icon);
  3734. if (quest->GetPlayer()) {
  3735. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3736. if(client)
  3737. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3738. }
  3739. safe_delete(ids);
  3740. }
  3741. lua_interface->ResetFunctionStack(state);
  3742. return 0;
  3743. }
  3744. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3745. if (!lua_interface)
  3746. return 0;
  3747. Quest* quest = lua_interface->GetQuest(state);
  3748. int32 step = lua_interface->GetInt32Value(state, 2);
  3749. string description = lua_interface->GetStringValue(state, 3);
  3750. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3751. float percentage = lua_interface->GetFloatValue(state, 5);
  3752. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3753. int16 icon = lua_interface->GetInt16Value(state, 7);
  3754. if (quest) {
  3755. const char* taskgroup = 0;
  3756. if (str_taskgroup.length() > 0)
  3757. taskgroup = str_taskgroup.c_str();
  3758. int32 item_id = 0;
  3759. vector<int32>* ids = 0;
  3760. int i = 0;
  3761. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3762. if (ids == 0)
  3763. ids = new vector<int32>;
  3764. ids->push_back(item_id);
  3765. i++;
  3766. }
  3767. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3768. if (quest_step && icon > 0 && quantity > 0)
  3769. quest_step->SetIcon(icon);
  3770. if (quest->GetPlayer()) {
  3771. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3772. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3773. }
  3774. safe_delete(ids);
  3775. }
  3776. lua_interface->ResetFunctionStack(state);
  3777. return 0;
  3778. }
  3779. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3780. if (!lua_interface)
  3781. return 0;
  3782. Quest* quest = lua_interface->GetQuest(state);
  3783. int32 step = lua_interface->GetInt32Value(state, 2);
  3784. string description = lua_interface->GetStringValue(state, 3);
  3785. float max_variation = lua_interface->GetFloatValue(state, 4);
  3786. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3787. int16 icon = lua_interface->GetInt16Value(state, 6);
  3788. if (quest) {
  3789. const char* taskgroup = 0;
  3790. if (str_taskgroup.length() > 0)
  3791. taskgroup = str_taskgroup.c_str();
  3792. vector<Location>* locations = 0;
  3793. int8 i = 7;
  3794. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3795. while (true) {
  3796. Location loc;
  3797. loc.x = lua_interface->GetFloatValue(state, i);
  3798. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3799. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3800. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3801. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3802. break;
  3803. if (locations == 0)
  3804. locations = new vector<Location>;
  3805. locations->push_back(loc);
  3806. i += 4;
  3807. }
  3808. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3809. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3810. if (quest_step && icon > 0)
  3811. quest_step->SetIcon(icon);
  3812. if (quest->GetPlayer()) {
  3813. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3814. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3815. }
  3816. }
  3817. lua_interface->ResetFunctionStack(state);
  3818. return 0;
  3819. }
  3820. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3821. if (!lua_interface)
  3822. return 0;
  3823. Quest* quest = lua_interface->GetQuest(state);
  3824. int32 step = lua_interface->GetInt32Value(state, 2);
  3825. string description = lua_interface->GetStringValue(state, 3);
  3826. float max_variation = lua_interface->GetFloatValue(state, 4);
  3827. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3828. int16 icon = lua_interface->GetInt16Value(state, 6);
  3829. if (quest) {
  3830. const char* taskgroup = 0;
  3831. if (str_taskgroup.length() > 0)
  3832. taskgroup = str_taskgroup.c_str();
  3833. vector<Location>* locations = 0;
  3834. int8 i = 7;
  3835. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3836. while (true) {
  3837. Location loc;
  3838. loc.x = lua_interface->GetFloatValue(state, i);
  3839. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3840. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3841. loc.zone_id = 0;
  3842. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3843. break;
  3844. if (locations == 0)
  3845. locations = new vector<Location>;
  3846. locations->push_back(loc);
  3847. i += 3;
  3848. }
  3849. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3850. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3851. if (quest_step && icon > 0)
  3852. quest_step->SetIcon(icon);
  3853. if (quest->GetPlayer()) {
  3854. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3855. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3856. }
  3857. }
  3858. lua_interface->ResetFunctionStack(state);
  3859. return 0;
  3860. }
  3861. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3862. if (!lua_interface)
  3863. return 0;
  3864. Quest* quest = lua_interface->GetQuest(state);
  3865. int32 step = lua_interface->GetInt32Value(state, 2);
  3866. string description = lua_interface->GetStringValue(state, 3);
  3867. float max_variation = lua_interface->GetFloatValue(state, 4);
  3868. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3869. int16 icon = lua_interface->GetInt16Value(state, 6);
  3870. if (quest) {
  3871. const char* taskgroup = 0;
  3872. if (str_taskgroup.length() > 0)
  3873. taskgroup = str_taskgroup.c_str();
  3874. vector<Location>* locations = 0;
  3875. int i = 7;
  3876. while (true) {
  3877. Location loc;
  3878. loc.x = lua_interface->GetFloatValue(state, i);
  3879. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3880. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3881. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3882. break;
  3883. if (locations == 0)
  3884. locations = new vector<Location>;
  3885. locations->push_back(loc);
  3886. i += 3;
  3887. }
  3888. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3889. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3890. if (quest_step && icon > 0)
  3891. quest_step->SetIcon(icon);
  3892. if (quest->GetPlayer()) {
  3893. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3894. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3895. }
  3896. }
  3897. lua_interface->ResetFunctionStack(state);
  3898. return 0;
  3899. }
  3900. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3901. Quest* quest = lua_interface->GetQuest(state);
  3902. int32 step = lua_interface->GetInt32Value(state, 2);
  3903. string description = lua_interface->GetStringValue(state, 3);
  3904. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3905. float percentage = lua_interface->GetFloatValue(state, 5);
  3906. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3907. int16 icon = lua_interface->GetInt16Value(state, 7);
  3908. if (quest) {
  3909. const char* taskgroup = 0;
  3910. if (str_taskgroup.length() > 0)
  3911. taskgroup = str_taskgroup.c_str();
  3912. int32 spell_id = 0;
  3913. vector<int32>* ids = 0;
  3914. int i = 0;
  3915. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3916. if (ids == 0)
  3917. ids = new vector<int32>;
  3918. ids->push_back(spell_id);
  3919. i++;
  3920. }
  3921. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3922. if (quest_step && icon > 0 && quantity > 0)
  3923. quest_step->SetIcon(icon);
  3924. if (quest->GetPlayer()) {
  3925. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3926. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3927. }
  3928. safe_delete(ids);
  3929. }
  3930. lua_interface->ResetFunctionStack(state);
  3931. return 0;
  3932. }
  3933. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3934. if (!lua_interface)
  3935. return 0;
  3936. Quest* quest = lua_interface->GetQuest(state);
  3937. int32 step = lua_interface->GetInt32Value(state, 2);
  3938. string description = lua_interface->GetStringValue(state, 3);
  3939. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3940. float percentage = lua_interface->GetFloatValue(state, 5);
  3941. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3942. int16 icon = lua_interface->GetInt16Value(state, 7);
  3943. if (quest) {
  3944. const char* taskgroup = 0;
  3945. if (str_taskgroup.length() > 0)
  3946. taskgroup = str_taskgroup.c_str();
  3947. int32 item_id = 0;
  3948. vector<int32>* ids = 0;
  3949. int i = 0;
  3950. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3951. if (ids == 0)
  3952. ids = new vector<int32>;
  3953. ids->push_back(item_id);
  3954. i++;
  3955. }
  3956. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3957. if (quest_step && icon > 0 && quantity > 0)
  3958. quest_step->SetIcon(icon);
  3959. if (quest->GetPlayer()) {
  3960. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3961. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3962. }
  3963. safe_delete(ids);
  3964. }
  3965. lua_interface->ResetFunctionStack(state);
  3966. return 0;
  3967. }
  3968. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3969. if (!lua_interface)
  3970. return 0;
  3971. Quest* quest = lua_interface->GetQuest(state);
  3972. int32 step = lua_interface->GetInt32Value(state, 2);
  3973. string description = lua_interface->GetStringValue(state, 3);
  3974. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3975. float percentage = lua_interface->GetFloatValue(state, 5);
  3976. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3977. int16 icon = lua_interface->GetInt16Value(state, 7);
  3978. if (quest) {
  3979. const char* taskgroup = 0;
  3980. if (str_taskgroup.length() > 0)
  3981. taskgroup = str_taskgroup.c_str();
  3982. int32 item_id = 0;
  3983. vector<int32>* ids = 0;
  3984. int i = 0;
  3985. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3986. if (ids == 0)
  3987. ids = new vector<int32>;
  3988. ids->push_back(item_id);
  3989. i++;
  3990. }
  3991. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3992. if (quest_step && icon > 0 && quantity > 0)
  3993. quest_step->SetIcon(icon);
  3994. if (quest->GetPlayer()) {
  3995. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3996. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3997. }
  3998. safe_delete(ids);
  3999. }
  4000. lua_interface->ResetFunctionStack(state);
  4001. return 0;
  4002. }
  4003. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  4004. if (!lua_interface)
  4005. return 0;
  4006. Quest* quest = lua_interface->GetQuest(state);
  4007. string action = lua_interface->GetStringValue(state, 2);
  4008. lua_interface->ResetFunctionStack(state);
  4009. if (quest) {
  4010. if (action.length() > 0)
  4011. quest->SetCompleteAction(action);
  4012. }
  4013. return 0;
  4014. }
  4015. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  4016. if (!lua_interface)
  4017. return 0;
  4018. Quest* quest = lua_interface->GetQuest(state);
  4019. int32 step = lua_interface->GetInt32Value(state, 2);
  4020. string action = lua_interface->GetStringValue(state, 3);
  4021. lua_interface->ResetFunctionStack(state);
  4022. if (quest) {
  4023. if (step > 0 && action.length() > 0)
  4024. quest->AddCompleteAction(step, action);
  4025. }
  4026. return 0;
  4027. }
  4028. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  4029. if (!lua_interface)
  4030. return 0;
  4031. Quest* quest = lua_interface->GetQuest(state);
  4032. int32 step = lua_interface->GetInt32Value(state, 2);
  4033. string action = lua_interface->GetStringValue(state, 3);
  4034. lua_interface->ResetFunctionStack(state);
  4035. if (quest) {
  4036. if (step > 0 && action.length() > 0)
  4037. quest->AddProgressAction(step, action);
  4038. }
  4039. return 0;
  4040. }
  4041. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  4042. if (!lua_interface)
  4043. return 0;
  4044. Quest* quest = lua_interface->GetQuest(state);
  4045. string description = lua_interface->GetStringValue(state, 2);
  4046. lua_interface->ResetFunctionStack(state);
  4047. if (quest && description.length() > 0)
  4048. quest->SetDescription(description);
  4049. return 0;
  4050. }
  4051. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4052. if (!lua_interface)
  4053. return 0;
  4054. Quest* quest = lua_interface->GetQuest(state);
  4055. string description = lua_interface->GetStringValue(state, 2);
  4056. lua_interface->ResetFunctionStack(state);
  4057. if (quest && description.length() > 0)
  4058. quest->SetCompletedDescription(description);
  4059. return 0;
  4060. }
  4061. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4062. if (!lua_interface)
  4063. return 0;
  4064. Quest* quest = lua_interface->GetQuest(state);
  4065. int32 step = lua_interface->GetInt32Value(state, 2);
  4066. string description = lua_interface->GetStringValue(state, 3);
  4067. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4068. lua_interface->ResetFunctionStack(state);
  4069. if (quest && step > 0 && description.length() > 0) {
  4070. quest->SetTaskGroupDescription(step, description, display_bullets);
  4071. /* if (quest->GetPlayer()) {
  4072. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4073. if (client)
  4074. client->SendQuestUpdateStep(quest, step, false);
  4075. }*/
  4076. }
  4077. return 0;
  4078. }
  4079. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4080. if (!lua_interface)
  4081. return 0;
  4082. Quest* quest = lua_interface->GetQuest(state);
  4083. int32 step = lua_interface->GetInt32Value(state, 2);
  4084. string description = lua_interface->GetStringValue(state, 3);
  4085. lua_interface->ResetFunctionStack(state);
  4086. if (quest && step > 0 && description.length() > 0) {
  4087. quest->SetStepDescription(step, description);
  4088. /*if (quest->GetPlayer()) {
  4089. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4090. if (client)
  4091. client->SendQuestUpdateStepImmediately(quest, step);
  4092. }*/
  4093. }
  4094. return 0;
  4095. }
  4096. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4097. Quest* quest = lua_interface->GetQuest(state);
  4098. string zone = lua_interface->GetStringValue(state, 2);
  4099. lua_interface->ResetFunctionStack(state);
  4100. if (quest && zone.length() > 0)
  4101. quest->SetZone(zone);
  4102. return 0;
  4103. }
  4104. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4105. if (!lua_interface)
  4106. return 0;
  4107. Quest* quest = lua_interface->GetQuest(state);
  4108. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4109. lua_interface->ResetFunctionStack(state);
  4110. if (quest && spawn) {
  4111. if (spawn->IsPlayer()) {
  4112. Client* client = ((Player*)spawn)->GetClient();
  4113. if (client) {
  4114. client->AddPendingQuestReward(quest);
  4115. }
  4116. }
  4117. }
  4118. return 0;
  4119. }
  4120. int EQ2Emu_lua_Harvest(lua_State* state) {
  4121. if (!lua_interface)
  4122. return 0;
  4123. Spawn* player = lua_interface->GetSpawn(state);
  4124. Spawn* node = lua_interface->GetSpawn(state, 2);
  4125. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4126. Client* client = ((Player*)player)->GetClient();
  4127. if (client) {
  4128. ((GroundSpawn*)node)->ProcessHarvest(client);
  4129. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4130. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4131. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4132. }
  4133. }
  4134. }
  4135. else if (player && player->IsPlayer()) {
  4136. Client* client = ((Player*)player)->GetClient();
  4137. if (client)
  4138. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4139. }
  4140. lua_interface->ResetFunctionStack(state);
  4141. return 0;
  4142. }
  4143. int EQ2Emu_lua_Bind(lua_State* state) {
  4144. if (!lua_interface)
  4145. return 0;
  4146. Spawn* spawn = lua_interface->GetSpawn(state);
  4147. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4148. float x = lua_interface->GetFloatValue(state, 3);
  4149. float y = lua_interface->GetFloatValue(state, 4);
  4150. float z = lua_interface->GetFloatValue(state, 5);
  4151. float h = lua_interface->GetFloatValue(state, 6);
  4152. lua_interface->ResetFunctionStack(state);
  4153. if (!spawn) {
  4154. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4155. return 0;
  4156. }
  4157. if (!spawn->IsPlayer()) {
  4158. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4159. return 0;
  4160. }
  4161. if (zone_id == 0) {
  4162. Client* client = ((Player*)spawn)->GetClient();
  4163. if (!client) {
  4164. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4165. return 0;
  4166. }
  4167. if (!client->Bind())
  4168. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4169. }
  4170. else {
  4171. Player* player = (Player*)spawn;
  4172. player->GetPlayerInfo()->SetBindZone(zone_id);
  4173. player->GetPlayerInfo()->SetBindX(x);
  4174. player->GetPlayerInfo()->SetBindY(y);
  4175. player->GetPlayerInfo()->SetBindZ(z);
  4176. player->GetPlayerInfo()->SetBindHeading(h);
  4177. }
  4178. return 0;
  4179. }
  4180. int EQ2Emu_lua_Gate(lua_State* state) {
  4181. if (!lua_interface)
  4182. return 0;
  4183. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4184. Spawn* spawn = lua_interface->GetSpawn(state);
  4185. lua_interface->ResetFunctionStack(state);
  4186. if (spawn) {
  4187. if (spawn->IsPlayer()) {
  4188. Client* client = ((Player*)spawn)->GetClient();
  4189. if (client) {
  4190. if (!client->Gate((spell != nullptr) ? true : false))
  4191. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4192. }
  4193. }
  4194. }
  4195. return 0;
  4196. }
  4197. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4198. if (!lua_interface)
  4199. return 0;
  4200. bool ret = false;
  4201. Spawn* spawn = lua_interface->GetSpawn(state);
  4202. lua_interface->ResetFunctionStack(state);
  4203. if (spawn) {
  4204. if (spawn->IsPlayer()) {
  4205. Client* client = ((Player*)spawn)->GetClient();
  4206. if (client)
  4207. ret = client->BindAllowed();
  4208. }
  4209. }
  4210. lua_interface->SetBooleanValue(state, ret);
  4211. return 1;
  4212. }
  4213. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4214. if (!lua_interface)
  4215. return 0;
  4216. bool ret = false;
  4217. Spawn* spawn = lua_interface->GetSpawn(state);
  4218. lua_interface->ResetFunctionStack(state);
  4219. if (spawn) {
  4220. if (spawn->IsPlayer()) {
  4221. Client* client = ((Player*)spawn)->GetClient();
  4222. ZoneServer* zone = lua_interface->GetZone(state);
  4223. if (client && zone){
  4224. ret = zone->GetCanGate();
  4225. }
  4226. }
  4227. }
  4228. lua_interface->SetBooleanValue(state, ret);
  4229. return 1;
  4230. }
  4231. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4232. Spawn* spawn = lua_interface->GetSpawn(state);
  4233. lua_interface->ResetFunctionStack(state);
  4234. if (spawn) {
  4235. lua_interface->SetBooleanValue(state, spawn->Alive());
  4236. return 1;
  4237. }
  4238. return 0;
  4239. }
  4240. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4241. if (!lua_interface)
  4242. return 0;
  4243. Spawn* spawn = lua_interface->GetSpawn(state);
  4244. lua_interface->ResetFunctionStack(state);
  4245. if (spawn && spawn->IsEntity()) {
  4246. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4247. return 1;
  4248. }
  4249. return 0;
  4250. }
  4251. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4252. Spawn* spawn = lua_interface->GetSpawn(state);
  4253. string message = lua_interface->GetStringValue(state, 2);
  4254. string color_str = lua_interface->GetStringValue(state, 3);
  4255. lua_interface->ResetFunctionStack(state);
  4256. int8 color = CHANNEL_NARRATIVE;
  4257. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4258. Client* client = ((Player*)spawn)->GetClient();
  4259. if (client) {
  4260. if (color_str.length() > 0) {
  4261. // leave for backwards compat, but all future should just use the number
  4262. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4263. color = CHANNEL_COLOR_RED;
  4264. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4265. color = CHANNEL_COLOR_YELLOW;
  4266. else
  4267. {
  4268. // use a number to specify the channel as per Commands/Commands.h defines
  4269. color = (int8)atoul(color_str.c_str());
  4270. }
  4271. }
  4272. client->SimpleMessage(color, message.c_str());
  4273. }
  4274. }
  4275. return 0;
  4276. }
  4277. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4278. Spawn* spawn = lua_interface->GetSpawn(state);
  4279. string message = lua_interface->GetStringValue(state, 2);
  4280. int8 red = lua_interface->GetInt8Value(state, 3);
  4281. int8 green = lua_interface->GetInt8Value(state, 4);
  4282. int8 blue = lua_interface->GetInt8Value(state, 5);
  4283. lua_interface->ResetFunctionStack(state);
  4284. if (!spawn) {
  4285. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4286. return 0;
  4287. }
  4288. if (!spawn->IsPlayer()) {
  4289. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not a player.", lua_interface->GetScriptName(state));
  4290. return 0;
  4291. }
  4292. int32 words = ::CountWordsInString(message.c_str());
  4293. if (words < 5)
  4294. words = 5;
  4295. Client* client = ((Player*)spawn)->GetClient();
  4296. if (client)
  4297. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4298. return 0;
  4299. }
  4300. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4301. Spawn* spawn = lua_interface->GetSpawn(state);
  4302. int8 param = lua_interface->GetInt8Value(state, 2);
  4303. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4304. int8 value = lua_interface->GetInt8Value(state, 4);
  4305. lua_interface->ResetFunctionStack(state);
  4306. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4307. Client* client = ((Player*)spawn)->GetClient();
  4308. if (client) {
  4309. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4310. switch (param) {
  4311. case 1: {
  4312. packet->setDataByName("parameter1", param_value);
  4313. break;
  4314. }
  4315. case 2: {
  4316. packet->setDataByName("parameter2", param_value);
  4317. break;
  4318. }
  4319. case 3: {
  4320. packet->setDataByName("parameter3", param_value);
  4321. break;
  4322. }
  4323. case 4: {
  4324. packet->setDataByName("parameter4", param_value);
  4325. break;
  4326. }
  4327. case 5: {
  4328. packet->setDataByName("parameter5", param_value);
  4329. break;
  4330. }
  4331. }
  4332. packet->setDataByName("value", value);
  4333. client->QueuePacket(packet->serialize());
  4334. safe_delete(packet);
  4335. }
  4336. }
  4337. return 0;
  4338. }
  4339. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4340. Spawn* spawn = lua_interface->GetSpawn(state);
  4341. lua_interface->ResetFunctionStack(state);
  4342. if (spawn && spawn->IsPlayer()) {
  4343. if (((Player*)spawn)->GetIsTracking())
  4344. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4345. else
  4346. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4347. }
  4348. return 0;
  4349. }
  4350. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4351. Spawn* player = lua_interface->GetSpawn(state);
  4352. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4353. string name = lua_interface->GetStringValue(state, 3);
  4354. float distance = lua_interface->GetFloatValue(state, 4);
  4355. string command = lua_interface->GetStringValue(state, 5);
  4356. string error_text = lua_interface->GetStringValue(state, 6);
  4357. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4358. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4359. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4360. lua_interface->ResetFunctionStack(state);
  4361. if (spawn) {
  4362. if (distance == 0)
  4363. distance = 10.0f;
  4364. if (command.length() == 0)
  4365. command = name;
  4366. if (command.length() < 1 && name.length() < 1)
  4367. {
  4368. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4369. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4370. spawn->RemovePrimaryCommands();
  4371. }
  4372. else
  4373. {
  4374. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4375. }
  4376. }
  4377. return 0;
  4378. }
  4379. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4380. if (!lua_interface)
  4381. return 0;
  4382. Spawn* player = lua_interface->GetSpawn(state);
  4383. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4384. int16 tier = lua_interface->GetInt16Value(state, 3);
  4385. lua_interface->ResetFunctionStack(state);
  4386. if (player && player->IsPlayer()) {
  4387. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4388. return 1;
  4389. }
  4390. return 0;
  4391. }
  4392. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4393. if (!lua_interface)
  4394. return 0;
  4395. Spawn* player = lua_interface->GetSpawn(state);
  4396. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4397. int16 tier = lua_interface->GetInt16Value(state, 3);
  4398. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4399. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4400. bool add_to_hotbar = true;
  4401. if (num_args > 4) {
  4402. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4403. }
  4404. lua_interface->ResetFunctionStack(state);
  4405. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4406. if (player && spell && player->IsPlayer()) {
  4407. Client* client = player->GetClient();
  4408. if (client) {
  4409. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4410. {
  4411. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4412. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4413. client->GetPlayer()->UnlockSpell(spell);
  4414. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4415. }
  4416. else
  4417. {
  4418. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4419. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4420. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4421. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4422. client->GetPlayer()->UnlockSpell(spell);
  4423. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4424. }
  4425. //if (client ) {
  4426. // ((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);
  4427. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4428. if (outapp)
  4429. client->QueuePacket(outapp);
  4430. }
  4431. }
  4432. return 0;
  4433. }
  4434. int EQ2Emu_lua_DeleteSpellBook(lua_State* state) {
  4435. if (!lua_interface)
  4436. return 0;
  4437. Spawn* player = lua_interface->GetSpawn(state);
  4438. int8 type_selection = lua_interface->GetInt8Value(state, 2);
  4439. lua_interface->ResetFunctionStack(state);
  4440. if (player && player->IsPlayer()) {
  4441. Client* client = player->GetClient();
  4442. if (client) {
  4443. ((Player*)player)->DeleteSpellBook(type_selection);
  4444. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4445. if (outapp)
  4446. client->QueuePacket(outapp);
  4447. }
  4448. }
  4449. return 0;
  4450. }
  4451. int EQ2Emu_lua_SendNewAdventureSpells(lua_State* state) {
  4452. if (!lua_interface)
  4453. return 0;
  4454. Spawn* player = lua_interface->GetSpawn(state);
  4455. lua_interface->ResetFunctionStack(state);
  4456. if (player && player->IsPlayer()) {
  4457. Client* client = player->GetClient();
  4458. if (client) {
  4459. client->SendNewAdventureSpells();
  4460. }
  4461. }
  4462. return 0;
  4463. }
  4464. int EQ2Emu_lua_SendNewTradeskillSpells(lua_State* state) {
  4465. if (!lua_interface)
  4466. return 0;
  4467. Spawn* player = lua_interface->GetSpawn(state);
  4468. lua_interface->ResetFunctionStack(state);
  4469. if (player && player->IsPlayer()) {
  4470. Client* client = player->GetClient();
  4471. if (client) {
  4472. client->SendNewTradeskillSpells();
  4473. }
  4474. }
  4475. return 0;
  4476. }
  4477. int EQ2Emu_lua_RemoveSpellBookEntry(lua_State* state) {
  4478. if (!lua_interface)
  4479. return 0;
  4480. Spawn* player = lua_interface->GetSpawn(state);
  4481. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4482. lua_interface->ResetFunctionStack(state);
  4483. if (player && player->IsPlayer()) {
  4484. SpellBookEntry* sbe = ((Player*)player)->GetSpellBookSpell(spellid);
  4485. Client* client = player->GetClient();
  4486. if (sbe && client) {
  4487. ((Player*)player)->RemoveSpellBookEntry(spellid);
  4488. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4489. if (outapp)
  4490. client->QueuePacket(outapp);
  4491. }
  4492. }
  4493. return 0;
  4494. }
  4495. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4496. if (!lua_interface)
  4497. return 0;
  4498. Spawn* player = lua_interface->GetSpawn(state);
  4499. lua_interface->ResetFunctionStack(state);
  4500. if (player && player->IsPlayer()) {
  4501. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4502. return 1;
  4503. }
  4504. return 0;
  4505. }
  4506. int EQ2Emu_lua_Attack(lua_State* state) {
  4507. if (lua_interface) {
  4508. Spawn* npc = lua_interface->GetSpawn(state);
  4509. Spawn* player = lua_interface->GetSpawn(state, 2);
  4510. lua_interface->ResetFunctionStack(state);
  4511. if (npc && player && npc->IsNPC() && player->IsEntity())
  4512. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4513. }
  4514. return 0;
  4515. }
  4516. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4517. if (lua_interface) {
  4518. Spawn* target = lua_interface->GetSpawn(state);
  4519. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4520. lua_interface->ResetFunctionStack(state);
  4521. if (target && target->GetZone())
  4522. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4523. }
  4524. return 0;
  4525. }
  4526. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4527. Spawn* player;
  4528. if (lua_interface) {
  4529. player = lua_interface->GetSpawn(state);
  4530. lua_interface->ResetFunctionStack(state);
  4531. if (player && player->IsPlayer()) {
  4532. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4533. return 1;
  4534. }
  4535. }
  4536. return 0;
  4537. }
  4538. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4539. Spawn* player;
  4540. Client* client;
  4541. if (lua_interface) {
  4542. player = lua_interface->GetSpawn(state);
  4543. lua_interface->ResetFunctionStack(state);
  4544. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4545. if ((client = ((Player*)player)->GetClient()))
  4546. client->HandInCollections();
  4547. }
  4548. return 0;
  4549. }
  4550. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4551. Spawn* widget;
  4552. if (lua_interface) {
  4553. widget = lua_interface->GetSpawn(state);
  4554. lua_interface->ResetFunctionStack(state);
  4555. if (widget && widget->IsWidget())
  4556. ((Widget*)widget)->HandleUse(nullptr, "");
  4557. }
  4558. return 0;
  4559. }
  4560. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4561. Spawn* spawn = 0;
  4562. int32 primary_list = 0;
  4563. int32 secondary_list = 0;
  4564. if (lua_interface) {
  4565. spawn = lua_interface->GetSpawn(state);
  4566. primary_list = lua_interface->GetInt32Value(state, 2);
  4567. secondary_list = lua_interface->GetInt32Value(state, 3);
  4568. lua_interface->ResetFunctionStack(state);
  4569. if (!spawn->IsNPC()) {
  4570. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4571. return 0;
  4572. }
  4573. NPC* npc = (NPC*)spawn;
  4574. npc->SetPrimarySpellList(primary_list);
  4575. npc->SetSecondarySpellList(secondary_list);
  4576. npc->SetSpells(world.GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4577. }
  4578. return 0;
  4579. }
  4580. int EQ2Emu_lua_GetPet(lua_State* state) {
  4581. if (!lua_interface)
  4582. return 0;
  4583. Spawn* spawn = lua_interface->GetSpawn(state);
  4584. lua_interface->ResetFunctionStack(state);
  4585. if (spawn) {
  4586. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4587. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4588. return 1;
  4589. }
  4590. }
  4591. return 0;
  4592. }
  4593. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4594. if (!lua_interface)
  4595. return 0;
  4596. Spawn* spawn = lua_interface->GetSpawn(state);
  4597. lua_interface->ResetFunctionStack(state);
  4598. if (spawn) {
  4599. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4600. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4601. return 1;
  4602. }
  4603. }
  4604. return 0;
  4605. }
  4606. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4607. if (!lua_interface)
  4608. return 0;
  4609. Spawn* spawn = lua_interface->GetSpawn(state);
  4610. lua_interface->ResetFunctionStack(state);
  4611. if (spawn) {
  4612. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4613. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4614. return 1;
  4615. }
  4616. }
  4617. return 0;
  4618. }
  4619. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4620. if (!lua_interface)
  4621. return 0;
  4622. Spawn* spawn = lua_interface->GetSpawn(state);
  4623. lua_interface->ResetFunctionStack(state);
  4624. if (spawn) {
  4625. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4626. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4627. return 1;
  4628. }
  4629. }
  4630. return 0;
  4631. }
  4632. int EQ2Emu_lua_Charm(lua_State* state) {
  4633. if (!lua_interface)
  4634. return 0;
  4635. Spawn* owner = lua_interface->GetSpawn(state);
  4636. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4637. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4638. lua_interface->ResetFunctionStack(state);
  4639. if (!luaspell) {
  4640. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4641. return 0;
  4642. }
  4643. if(luaspell->resisted) {
  4644. return 0;
  4645. }
  4646. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4647. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4648. pet->SetPet(true);
  4649. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4650. ((NPC*)pet)->SetOwner((Entity*)owner);
  4651. // If owner is player and player does not have a summoned pet set the players charsheet
  4652. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4653. Player* player = (Player*)owner;
  4654. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4655. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4656. player->GetInfoStruct()->set_pet_movement(2);
  4657. player->GetInfoStruct()->set_pet_behavior(3);
  4658. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4659. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4660. // Make sure the values get sent to the client
  4661. player->SetCharSheetChanged(true);
  4662. }
  4663. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4664. pet->SetSpawnScript("");
  4665. // Set faction to the same as the owner
  4666. pet->SetFactionID(owner->GetFactionID());
  4667. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4668. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4669. // Clear hate list
  4670. ((NPC*)pet)->Brain()->ClearHate();
  4671. // Set the brain to a pet brain
  4672. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4673. }
  4674. return 0;
  4675. }
  4676. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4677. if (!lua_interface)
  4678. return 0;
  4679. Spawn* spawn = lua_interface->GetSpawn(state);
  4680. lua_interface->ResetFunctionStack(state);
  4681. if (!spawn) {
  4682. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4683. return 0;
  4684. }
  4685. vector<Spawn*> groupMembers;
  4686. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4687. groupMembers = *spawn->GetSpawnGroup();
  4688. }
  4689. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4690. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4691. deque<GroupMemberInfo*>::iterator itr;
  4692. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4693. if (group)
  4694. {
  4695. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4696. deque<GroupMemberInfo*>* members = group->GetMembers();
  4697. GroupMemberInfo* info = 0;
  4698. for (itr = members->begin(); itr != members->end(); itr++) {
  4699. info = *itr;
  4700. if (info->client)
  4701. groupMembers.push_back(info->client->GetPlayer());
  4702. }
  4703. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4704. }
  4705. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4706. }
  4707. else
  4708. return 0;
  4709. lua_createtable(state, groupMembers.size(), 0);
  4710. int newTable = lua_gettop(state);
  4711. for (int32 i = 0; i < groupMembers.size(); i++) {
  4712. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4713. lua_rawseti(state, newTable, i + 1);
  4714. }
  4715. return 1;
  4716. }
  4717. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4718. if (!lua_interface)
  4719. return 0;
  4720. lua_interface->ResetFunctionStack(state);
  4721. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4722. lua_interface->SetOptionWindowValue(state, option_window);
  4723. return 1;
  4724. }
  4725. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4726. if (!lua_interface)
  4727. return 0;
  4728. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4729. if (option_window) {
  4730. OptionWindowOption option_window_option;
  4731. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4732. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4733. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4734. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4735. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4736. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4737. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4738. option_window->push_back(option_window_option);
  4739. }
  4740. lua_interface->ResetFunctionStack(state);
  4741. return 0;
  4742. }
  4743. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4744. if (!lua_interface)
  4745. return 0;
  4746. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4747. Spawn* player = lua_interface->GetSpawn(state, 2);
  4748. string window_title = lua_interface->GetStringValue(state, 3);
  4749. string cancel_command = lua_interface->GetStringValue(state, 4);
  4750. lua_interface->ResetFunctionStack(state);
  4751. if (!player->IsPlayer()) {
  4752. lua_interface->LogError("%s: LUA SendOptionWindow command error: spawn is not a player", lua_interface->GetScriptName(state));
  4753. return 0;
  4754. }
  4755. Client* client = ((Player*)player)->GetClient();
  4756. if (option_window && window_title.length() > 0 && client) {
  4757. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4758. if (!packet)
  4759. return 0;
  4760. packet->setDataByName("title_text", window_title.c_str());
  4761. if (cancel_command.length() > 0)
  4762. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4763. packet->setArrayLengthByName("num_selections", option_window->size());
  4764. vector<OptionWindowOption>::iterator itr;
  4765. int8 i = 0;
  4766. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4767. OptionWindowOption opt = *itr;
  4768. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4769. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4770. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4771. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4772. if (opt.optionCommand.length() > 0)
  4773. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4774. if (opt.optionConfirmTitle.length() > 0)
  4775. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4776. i++;
  4777. }
  4778. client->QueuePacket(packet->serialize());
  4779. lua_interface->SetLuaUserDataStale(option_window);
  4780. safe_delete(option_window);
  4781. safe_delete(packet);
  4782. }
  4783. return 0;
  4784. }
  4785. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4786. if (!lua_interface)
  4787. return 0;
  4788. Spawn* spawn = lua_interface->GetSpawn(state);
  4789. lua_interface->ResetFunctionStack(state);
  4790. if (spawn) {
  4791. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4792. return 1;
  4793. }
  4794. else
  4795. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4796. return 0;
  4797. }
  4798. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4799. if (!lua_interface)
  4800. return 0;
  4801. Spawn* spawn = lua_interface->GetSpawn(state);
  4802. lua_interface->ResetFunctionStack(state);
  4803. if (spawn) {
  4804. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4805. return 1;
  4806. }
  4807. else
  4808. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4809. return 0;
  4810. }
  4811. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4812. if (!lua_interface)
  4813. return 0;
  4814. Spawn* spawn = lua_interface->GetSpawn(state);
  4815. lua_interface->ResetFunctionStack(state);
  4816. if (spawn) {
  4817. int8 class_id = spawn->GetTradeskillClass();
  4818. // Need to add 42 for the offset in the array
  4819. class_id += 44;
  4820. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4821. return 1;
  4822. }
  4823. else
  4824. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4825. return 0;
  4826. }
  4827. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4828. if (!lua_interface)
  4829. return 0;
  4830. Spawn* spawn = lua_interface->GetSpawn(state);
  4831. int16 level = lua_interface->GetInt8Value(state, 2);
  4832. lua_interface->ResetFunctionStack(state);
  4833. if (spawn) {
  4834. if (spawn->IsPlayer() && ((Player*)spawn)->GetClient())
  4835. ((Player*)spawn)->GetClient()->ChangeTSLevel(spawn->GetTSLevel(), level);
  4836. else
  4837. spawn->SetTSLevel(level);
  4838. }
  4839. else
  4840. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4841. return 0;
  4842. }
  4843. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4844. if (!lua_interface)
  4845. return 0;
  4846. Spawn* spawn = lua_interface->GetSpawn(state);
  4847. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4848. lua_interface->ResetFunctionStack(state);
  4849. if (spawn) {
  4850. spawn->SetAttackable(attackable);
  4851. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4852. }
  4853. return 0;
  4854. }
  4855. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4856. // Check to see if we have a valid lua_interface
  4857. if (!lua_interface)
  4858. return 0;
  4859. // Get the spawn that is getting the pet
  4860. Spawn* spawn = lua_interface->GetSpawn(state);
  4861. // Get the DB ID of the pet
  4862. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4863. // The max level the pet can gain
  4864. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4865. // Get the spell that this command was called from
  4866. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4867. lua_interface->ResetFunctionStack(state);
  4868. // Check to make sure the spawn pointer is valid
  4869. if (!spawn) {
  4870. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4871. return 0;
  4872. }
  4873. // Check to make sure the spawn is an entity
  4874. if (!spawn->IsEntity()) {
  4875. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4876. return 0;
  4877. }
  4878. // Check to make sure the spawn doesn't already have a pet of this type
  4879. if (((Entity*)spawn)->GetPet()) {
  4880. if (spawn->IsPlayer()) {
  4881. Client* client = ((Player*)spawn)->GetClient();
  4882. if (client)
  4883. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4884. }
  4885. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4886. return 0;
  4887. }
  4888. // Check to see if the DB ID for the pet is set
  4889. if (pet_id == 0) {
  4890. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4891. return 0;
  4892. }
  4893. // Check to see if the pointer to the spell is valid
  4894. if (!luaspell) {
  4895. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4896. return 0;
  4897. }
  4898. if(luaspell->resisted) {
  4899. return 0;
  4900. }
  4901. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4902. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4903. if (!pet) {
  4904. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4905. return 0;
  4906. }
  4907. // Check to make sure the pet is an npc
  4908. if (!pet->IsNPC()) {
  4909. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4910. return 0;
  4911. }
  4912. // Spawn the pet at the same location as the owner
  4913. pet->SetX(spawn->GetX());
  4914. pet->SetY(spawn->GetY());
  4915. pet->SetZ(spawn->GetZ());
  4916. pet->SetLocation(spawn->GetLocation());
  4917. pet->SetHeading(spawn->GetHeading());
  4918. std::string petName = std::string("");
  4919. if(spawn->IsEntity()) {
  4920. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  4921. }
  4922. if(petName.size() < 1) {
  4923. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4924. petName = spawn->GetZone()->pet_names.at(rand_index);
  4925. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  4926. }
  4927. // If player set various values for the char sheet (pet window)
  4928. if (spawn->IsPlayer()) {
  4929. Player* player = (Player*)spawn;
  4930. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4931. player->GetInfoStruct()->set_pet_name(petName);
  4932. player->GetInfoStruct()->set_pet_movement(2);
  4933. player->GetInfoStruct()->set_pet_behavior(3);
  4934. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4935. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4936. // Make sure the values get sent to the client
  4937. player->SetCharSheetChanged(true);
  4938. }
  4939. // Set the pets name
  4940. pet->SetName(petName.c_str());
  4941. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4942. if (max_level > 0)
  4943. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4944. else
  4945. pet->SetLevel(spawn->GetLevel());
  4946. // Set the max level this pet can reach
  4947. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4948. ((NPC*)pet)->UpdateWeapons();
  4949. // Set the faction of the pet to the same faction as the owner
  4950. pet->SetFactionID(spawn->GetFactionID());
  4951. // Set the spawn as a pet
  4952. pet->SetPet(true);
  4953. // Give a pointer of the owner to the pet
  4954. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4955. // Give a pointer of the pet to the owner
  4956. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4957. // Set the pet type
  4958. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4959. // Set the spell id used to create this pet
  4960. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4961. // Set the spell tier used to create this pet
  4962. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4963. // Set the pets spawn type to 6
  4964. pet->SetSpawnType(6);
  4965. // Set the pets brain
  4966. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4967. // Check to see if the pet has a subtitle
  4968. if (strlen(pet->GetSubTitle()) > 0) {
  4969. // Add the players name to the front of the sub title
  4970. string pet_subtitle;
  4971. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4972. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4973. // Set the pets subtitle to the new one
  4974. pet->SetSubTitle(pet_subtitle.c_str());
  4975. }
  4976. // Add the "Pet Options" entity command to the pet
  4977. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4978. const char* spawn_script = world.GetSpawnScript(pet_id);
  4979. bool runScript = false;
  4980. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4981. runScript = true;
  4982. pet->SetSpawnScript(string(spawn_script));
  4983. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_PRESPAWN);
  4984. }
  4985. spawn->GetZone()->AddSpawn(pet);
  4986. if(runScript){
  4987. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_SPAWN);
  4988. }
  4989. // Set the pet as the return value for this function
  4990. lua_interface->SetSpawnValue(state, pet);
  4991. return 1;
  4992. }
  4993. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4994. if (!lua_interface)
  4995. return 0;
  4996. Spawn* spawn = lua_interface->GetSpawn(state);
  4997. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4998. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4999. lua_interface->ResetFunctionStack(state);
  5000. if (!spawn) {
  5001. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5002. return 0;
  5003. }
  5004. if (!spawn->IsEntity()) {
  5005. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5006. return 0;
  5007. }
  5008. if (((Entity*)spawn)->GetDeityPet()) {
  5009. if (spawn->IsPlayer()) {
  5010. Client* client = ((Player*)spawn)->GetClient();
  5011. if (client)
  5012. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  5013. }
  5014. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5015. return 0;
  5016. }
  5017. if (pet_id == 0) {
  5018. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5019. return 0;
  5020. }
  5021. if (!luaspell) {
  5022. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5023. return 0;
  5024. }
  5025. if(luaspell->resisted) {
  5026. return 0;
  5027. }
  5028. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5029. if (!pet) {
  5030. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5031. return 0;
  5032. }
  5033. if (!pet->IsNPC()) {
  5034. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5035. return 0;
  5036. }
  5037. pet->SetX(spawn->GetX());
  5038. pet->SetY(spawn->GetY());
  5039. pet->SetZ(spawn->GetZ());
  5040. pet->SetLocation(spawn->GetLocation());
  5041. pet->SetHeading(spawn->GetHeading());
  5042. spawn->GetZone()->AddSpawn(pet);
  5043. string random_pet_name;
  5044. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5045. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5046. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5047. pet->SetName(random_pet_name.c_str());
  5048. pet->SetLevel(spawn->GetLevel());
  5049. pet->SetFactionID(spawn->GetFactionID());
  5050. pet->SetPet(true);
  5051. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  5052. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5053. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  5054. pet->SetSpawnType(6);
  5055. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5056. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5057. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5058. if (strlen(pet->GetSubTitle()) > 0) {
  5059. string pet_subtitle;
  5060. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5061. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5062. pet->SetSubTitle(pet_subtitle.c_str());
  5063. }
  5064. // deity and cosmetic pets are not attackable
  5065. pet->SetAttackable(false);
  5066. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5067. lua_interface->SetSpawnValue(state, pet);
  5068. return 1;
  5069. }
  5070. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  5071. if (!lua_interface)
  5072. return 0;
  5073. Spawn* spawn = lua_interface->GetSpawn(state);
  5074. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5075. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5076. lua_interface->ResetFunctionStack(state);
  5077. if (!spawn) {
  5078. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5079. return 0;
  5080. }
  5081. if (!spawn->IsEntity()) {
  5082. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5083. return 0;
  5084. }
  5085. if (((Entity*)spawn)->GetCosmeticPet()) {
  5086. if (spawn->IsPlayer()) {
  5087. Client* client = ((Player*)spawn)->GetClient();
  5088. if (client)
  5089. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  5090. }
  5091. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5092. return 0;
  5093. }
  5094. if (pet_id == 0) {
  5095. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5096. return 0;
  5097. }
  5098. if (!luaspell) {
  5099. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5100. return 0;
  5101. }
  5102. if(luaspell->resisted) {
  5103. return 0;
  5104. }
  5105. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5106. if (!pet) {
  5107. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5108. return 0;
  5109. }
  5110. if (!pet->IsNPC()) {
  5111. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5112. return 0;
  5113. }
  5114. pet->SetX(spawn->GetX());
  5115. pet->SetY(spawn->GetY());
  5116. pet->SetZ(spawn->GetZ());
  5117. pet->SetLocation(spawn->GetLocation());
  5118. pet->SetHeading(spawn->GetHeading());
  5119. spawn->GetZone()->AddSpawn(pet);
  5120. string random_pet_name;
  5121. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5122. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5123. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5124. pet->SetName(random_pet_name.c_str());
  5125. pet->SetLevel(spawn->GetLevel());
  5126. pet->SetFactionID(spawn->GetFactionID());
  5127. pet->SetPet(true);
  5128. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  5129. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5130. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5131. pet->SetSpawnType(6);
  5132. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5133. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5134. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5135. if (strlen(pet->GetSubTitle()) > 0) {
  5136. string pet_subtitle;
  5137. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5138. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5139. pet->SetSubTitle(pet_subtitle.c_str());
  5140. }
  5141. pet->SetAttackable(false);
  5142. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5143. lua_interface->SetSpawnValue(state, pet);
  5144. return 1;
  5145. }
  5146. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5147. if (!lua_interface)
  5148. return 0;
  5149. Spawn* spawn = lua_interface->GetSpawn(state);
  5150. lua_interface->ResetFunctionStack(state);
  5151. if (!spawn) {
  5152. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5153. return 0;
  5154. }
  5155. if (!spawn->IsPet()) {
  5156. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5157. return 0;
  5158. }
  5159. if (!((NPC*)spawn)->IsDismissing() && ((NPC*)spawn)->GetOwner())
  5160. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5161. return 0;
  5162. }
  5163. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5164. if (!lua_interface)
  5165. return 0;
  5166. Quest* quest = lua_interface->GetQuest(state);
  5167. if (!quest) {
  5168. 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));
  5169. lua_interface->ResetFunctionStack(state);
  5170. return 0;
  5171. }
  5172. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5173. lua_interface->ResetFunctionStack(state);
  5174. if (feather_color > 0)
  5175. quest->SetFeatherColor(feather_color);
  5176. return 0;
  5177. }
  5178. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5179. if (!lua_interface)
  5180. return 0;
  5181. Spawn* spawn = lua_interface->GetSpawn(state);
  5182. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5183. lua_interface->ResetFunctionStack(state);
  5184. if (!spawn) {
  5185. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5186. return 0;
  5187. }
  5188. if (!spawn2) {
  5189. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5190. return 0;
  5191. }
  5192. spawn->RemoveSpawnAccess(spawn2);
  5193. return 0;
  5194. }
  5195. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5196. if (!lua_interface)
  5197. return 0;
  5198. ZoneServer* zone = lua_interface->GetZone(state);
  5199. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5200. lua_interface->ResetFunctionStack(state);
  5201. if (!zone) {
  5202. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5203. return 0;
  5204. }
  5205. if (location_id == 0) {
  5206. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5207. return 0;
  5208. }
  5209. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5210. if (!location) {
  5211. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5212. return 0;
  5213. }
  5214. Spawn* spawn = 0;
  5215. if (location->entities[0]) {
  5216. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5217. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5218. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5219. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5220. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5221. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5222. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5223. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5224. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5225. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5226. if(spawn && spawn->IsOmittedByDBFlag())
  5227. {
  5228. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5229. safe_delete(spawn);
  5230. spawn = 0;
  5231. return 0;
  5232. }
  5233. if (spawn) {
  5234. const char* script = 0;
  5235. for (int x = 0; x < 3; x++) {
  5236. switch (x) {
  5237. case 0:
  5238. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5239. break;
  5240. case 1:
  5241. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5242. break;
  5243. case 2:
  5244. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5245. break;
  5246. }
  5247. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5248. spawn->SetSpawnScript(string(script));
  5249. break;
  5250. }
  5251. }
  5252. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5253. lua_interface->SetSpawnValue(state, spawn);
  5254. return 1;
  5255. }
  5256. else {
  5257. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5258. safe_delete(spawn);
  5259. }
  5260. }
  5261. return 0;
  5262. }
  5263. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5264. if (!lua_interface)
  5265. return 0;
  5266. Spawn* caster = lua_interface->GetSpawn(state);
  5267. Spawn* target = lua_interface->GetSpawn(state, 2);
  5268. int32 id = lua_interface->GetInt32Value(state, 3);
  5269. string command = lua_interface->GetStringValue(state, 4);
  5270. lua_interface->ResetFunctionStack(state);
  5271. if (!caster) {
  5272. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5273. return 0;
  5274. }
  5275. if (!target) {
  5276. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5277. return 0;
  5278. }
  5279. if (!caster->IsPlayer()) {
  5280. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5281. return 0;
  5282. }
  5283. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5284. if (!entity_command) {
  5285. 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());
  5286. return 0;
  5287. }
  5288. Client* client = ((Player*)caster)->GetClient();
  5289. if (!client) {
  5290. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5291. return 0;
  5292. }
  5293. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5294. return 0;
  5295. }
  5296. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5297. if (!lua_interface)
  5298. return 0;
  5299. Spawn* spawn = lua_interface->GetSpawn(state);
  5300. lua_interface->ResetFunctionStack(state);
  5301. if (!spawn) {
  5302. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5303. return 0;
  5304. }
  5305. if (!spawn->IsNPC()) {
  5306. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5307. return 0;
  5308. }
  5309. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5310. return 0;
  5311. }
  5312. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5313. if (!lua_interface)
  5314. return 0;
  5315. Spawn* spawn = lua_interface->GetSpawn(state);
  5316. int16 tick = lua_interface->GetInt16Value(state, 2);
  5317. lua_interface->ResetFunctionStack(state);
  5318. if (!spawn) {
  5319. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5320. return 0;
  5321. }
  5322. if (!spawn->IsNPC()) {
  5323. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5324. return 0;
  5325. }
  5326. if (tick < 20) {
  5327. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5328. return 0;
  5329. }
  5330. ((NPC*)spawn)->Brain()->SetTick(tick);
  5331. return 0;
  5332. }
  5333. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5334. if (!lua_interface)
  5335. return 0;
  5336. Spawn* spawn = lua_interface->GetSpawn(state);
  5337. Spawn* target = lua_interface->GetSpawn(state, 2);
  5338. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5339. lua_interface->ResetFunctionStack(state);
  5340. if (!spawn) {
  5341. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5342. return 0;
  5343. }
  5344. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5345. spawn->SetFollowTarget(target, follow_distance);
  5346. return 0;
  5347. }
  5348. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5349. if (!lua_interface)
  5350. return 0;
  5351. Spawn* spawn = lua_interface->GetSpawn(state);
  5352. lua_interface->ResetFunctionStack(state);
  5353. if (!spawn) {
  5354. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5355. return 0;
  5356. }
  5357. Spawn* target = spawn->GetFollowTarget();
  5358. if (target) {
  5359. lua_interface->SetSpawnValue(state, target);
  5360. return 1;
  5361. }
  5362. return 0;
  5363. }
  5364. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5365. if (!lua_interface)
  5366. return 0;
  5367. Spawn* spawn = lua_interface->GetSpawn(state);
  5368. lua_interface->ResetFunctionStack(state);
  5369. if (!spawn) {
  5370. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5371. return 0;
  5372. }
  5373. if (spawn->following)
  5374. spawn->following = false;
  5375. else
  5376. spawn->following = true;
  5377. return 0;
  5378. }
  5379. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5380. if (!lua_interface)
  5381. return 0;
  5382. Spawn* spawn = lua_interface->GetSpawn(state);
  5383. lua_interface->ResetFunctionStack(state);
  5384. if (!spawn) {
  5385. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5386. return 0;
  5387. }
  5388. lua_interface->SetBooleanValue(state, spawn->following);
  5389. return 1;
  5390. }
  5391. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5392. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5393. // I will attempt to explain how this function works for future refrence
  5394. // Fist lets make sure lua_interface is valid, if not return out
  5395. if (!lua_interface)
  5396. return 0;
  5397. // Next we grab the first 2 params same as we usually would
  5398. Spawn* spawn = lua_interface->GetSpawn(state);
  5399. string var = lua_interface->GetStringValue(state, 2);
  5400. // 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
  5401. // 1 = Spawn
  5402. // 2 = Zone
  5403. // 3 = Item
  5404. // 4 = Quest
  5405. // 5 = String
  5406. // 6 = nil (null)
  5407. int8 dataType = 0;
  5408. // Define pointers for each potential type
  5409. Spawn* spawnVal = 0;
  5410. ZoneServer* zone = 0;
  5411. Item* item = 0;
  5412. Quest* quest = 0;
  5413. string val;
  5414. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5415. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5416. // options window are also light user data be we do not handle those.
  5417. // We check with lua_islightuserdata(lua_State*, index)
  5418. if (lua_islightuserdata(state, 3)) {
  5419. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5420. // and convert it to LUAUserData*
  5421. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5422. // Check to make sure the data we got is valid, if not give an error
  5423. if (!data || !data->IsCorrectlyInitialized()) {
  5424. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5425. }
  5426. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5427. else if (data->IsSpawn()) {
  5428. spawnVal = data->spawn;
  5429. dataType = 1;
  5430. }
  5431. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5432. else if (data->IsZone()) {
  5433. zone = data->zone;
  5434. dataType = 2;
  5435. }
  5436. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5437. else if (data->IsItem()) {
  5438. item = data->item;
  5439. dataType = 3;
  5440. }
  5441. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5442. else if (data->IsQuest()) {
  5443. quest = data->quest;
  5444. dataType = 4;
  5445. }
  5446. }
  5447. // Wasn't light user data, check if it is nil(null)
  5448. else if (lua_isnil(state, 3)) {
  5449. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5450. dataType = 6;
  5451. }
  5452. // Wasn't light user data or nil (null), must be a string
  5453. else {
  5454. // Set the string and dataType variable
  5455. val = lua_interface->GetStringValue(state, 3);
  5456. dataType = 5;
  5457. }
  5458. lua_interface->ResetFunctionStack(state);
  5459. // We now have all the params, lets check to make sure they are valid
  5460. if (!spawn) {
  5461. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5462. return 0;
  5463. }
  5464. if (var.length() == 0) {
  5465. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5466. return 0;
  5467. }
  5468. if (dataType == 0) {
  5469. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5470. return 0;
  5471. }
  5472. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5473. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5474. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5475. switch (dataType) {
  5476. case 1:
  5477. // 1 = Spawn
  5478. spawn->AddTempVariable(var, spawnVal);
  5479. break;
  5480. case 2:
  5481. // 2 = Zone
  5482. spawn->AddTempVariable(var, zone);
  5483. break;
  5484. case 3:
  5485. // 3 = Item
  5486. spawn->AddTempVariable(var, item);
  5487. break;
  5488. case 4:
  5489. // 4 = Quest
  5490. spawn->AddTempVariable(var, quest);
  5491. break;
  5492. case 5:
  5493. // 5 = String
  5494. spawn->AddTempVariable(var, val);
  5495. break;
  5496. case 6:
  5497. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5498. spawn->DeleteTempVariable(var);
  5499. break;
  5500. }
  5501. // And we are done so return out
  5502. return 0;
  5503. }
  5504. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5505. if (!lua_interface)
  5506. return 0;
  5507. Spawn* spawn = lua_interface->GetSpawn(state);
  5508. string var = lua_interface->GetStringValue(state, 2);
  5509. lua_interface->ResetFunctionStack(state);
  5510. if (!spawn) {
  5511. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5512. return 0;
  5513. }
  5514. if (var.length() == 0) {
  5515. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5516. return 0;
  5517. }
  5518. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5519. int8 type = spawn->GetTempVariableType(var);
  5520. Spawn* spawn2 = 0;
  5521. ZoneServer* zone = 0;
  5522. Item* item = 0;
  5523. Quest* quest = 0;
  5524. // Set the lua function return value based on the type of data the variable contains
  5525. switch (type) {
  5526. case 1:
  5527. spawn2 = spawn->GetTempVariableSpawn(var);
  5528. if (!spawn2)
  5529. return 0;
  5530. lua_interface->SetSpawnValue(state, spawn2);
  5531. break;
  5532. case 2:
  5533. zone = spawn->GetTempVariableZone(var);
  5534. if (!zone)
  5535. return 0;
  5536. lua_interface->SetZoneValue(state, zone);
  5537. break;
  5538. case 3:
  5539. item = spawn->GetTempVariableItem(var);
  5540. if (!item)
  5541. return 0;
  5542. lua_interface->SetItemValue(state, item);
  5543. break;
  5544. case 4:
  5545. quest = spawn->GetTempVariableQuest(var);
  5546. if (!quest)
  5547. return 0;
  5548. lua_interface->SetQuestValue(state, quest);
  5549. break;
  5550. case 5:
  5551. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5552. break;
  5553. default:
  5554. // Not a valid type then the variable was not set so return out
  5555. return 0;
  5556. }
  5557. // Return value was set so return out
  5558. return 1;
  5559. }
  5560. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5561. {
  5562. if (!lua_interface)
  5563. return 0;
  5564. Quest* quest = lua_interface->GetQuest(state);
  5565. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5566. string description = lua_interface->GetStringValue(state, 3);
  5567. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5568. if (!quest) {
  5569. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5570. lua_interface->ResetFunctionStack(state);
  5571. lua_interface->SetBooleanValue(state, false);
  5572. return 1;
  5573. }
  5574. if (!spawn) {
  5575. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5576. lua_interface->ResetFunctionStack(state);
  5577. lua_interface->SetBooleanValue(state, false);
  5578. return 1;
  5579. }
  5580. if (!spawn->IsPlayer()) {
  5581. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5582. lua_interface->ResetFunctionStack(state);
  5583. lua_interface->SetBooleanValue(state, false);
  5584. return 1;
  5585. }
  5586. if (item_id == 0) {
  5587. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5588. lua_interface->ResetFunctionStack(state);
  5589. lua_interface->SetBooleanValue(state, false);
  5590. return 1;
  5591. }
  5592. Client* client = ((Player*)spawn)->GetClient();
  5593. if (!client) {
  5594. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given player spawn", lua_interface->GetScriptName(state));
  5595. lua_interface->ResetFunctionStack(state);
  5596. lua_interface->SetBooleanValue(state, false);
  5597. return 1;
  5598. }
  5599. Item* item = master_item_list.GetItem(item_id);
  5600. if (!item) {
  5601. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5602. lua_interface->ResetFunctionStack(state);
  5603. lua_interface->SetBooleanValue(state, false);
  5604. return 1;
  5605. }
  5606. Item* firstItem = new Item(item);
  5607. quest->AddTmpRewardItem(firstItem);
  5608. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5609. bool itemsAddedSuccessfully = true;
  5610. if(num_args > 4)
  5611. {
  5612. for(int8 n=5;n<num_args+1;n++)
  5613. {
  5614. int32 new_item = lua_interface->GetInt32Value(state, n);
  5615. Item* tmpItem = master_item_list.GetItem(new_item);
  5616. if(tmpItem)
  5617. {
  5618. Item* newTmpItem = new Item(tmpItem);
  5619. quest->AddTmpRewardItem(newTmpItem);
  5620. }
  5621. else
  5622. itemsAddedSuccessfully = false;
  5623. }
  5624. }
  5625. client->AddPendingQuestReward(quest, true, true, description); // queue for display
  5626. lua_interface->ResetFunctionStack(state);
  5627. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5628. return 1;
  5629. }
  5630. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5631. if (!lua_interface)
  5632. return 0;
  5633. Quest* quest = lua_interface->GetQuest(state);
  5634. lua_interface->ResetFunctionStack(state);
  5635. if (!quest) {
  5636. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5637. return 0;
  5638. }
  5639. quest->SetRepeatable(true);
  5640. return 0;
  5641. }
  5642. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5643. if (!lua_interface)
  5644. return 0;
  5645. Spawn* spawn = lua_interface->GetSpawn(state);
  5646. lua_interface->ResetFunctionStack(state);
  5647. if (!spawn) {
  5648. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5649. return 0;
  5650. }
  5651. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5652. string ret = classes.GetClassNameCase(base_class);
  5653. if (ret.length() > 0) {
  5654. lua_interface->SetStringValue(state, ret.c_str());
  5655. return 1;
  5656. }
  5657. return 0;
  5658. }
  5659. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5660. if (!lua_interface)
  5661. return 0;
  5662. Spawn* player = lua_interface->GetSpawn(state);
  5663. lua_interface->ResetFunctionStack(state);
  5664. if (player && player->IsPlayer()) {
  5665. Client* client = player->GetClient();
  5666. if (client)
  5667. client->SendWaypoints();
  5668. }
  5669. return 0;
  5670. }
  5671. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5672. if (!lua_interface)
  5673. return 0;
  5674. Spawn* player = lua_interface->GetSpawn(state);
  5675. string name = lua_interface->GetStringValue(state, 2);
  5676. int32 type = lua_interface->GetInt32Value(state, 3);
  5677. lua_interface->ResetFunctionStack(state);
  5678. if (type == 0)
  5679. type = 2;
  5680. if (name.length() > 0) {
  5681. if (player && player->IsPlayer()) {
  5682. Client* client = player->GetClient();
  5683. if (client)
  5684. client->AddWaypoint(name, type);
  5685. }
  5686. }
  5687. return 0;
  5688. }
  5689. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5690. if (!lua_interface)
  5691. return 0;
  5692. Spawn* player = lua_interface->GetSpawn(state);
  5693. string name = lua_interface->GetStringValue(state, 2);
  5694. lua_interface->ResetFunctionStack(state);
  5695. if (name.length() > 0) {
  5696. if (player && player->IsPlayer()) {
  5697. Client* client = player->GetClient();
  5698. if (client)
  5699. client->RemoveWaypoint(name);
  5700. }
  5701. }
  5702. return 0;
  5703. }
  5704. int EQ2Emu_lua_AddWard(lua_State* state) {
  5705. if (!lua_interface)
  5706. return 0;
  5707. int32 damage = lua_interface->GetInt32Value(state);
  5708. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5709. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5710. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5711. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5712. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5713. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5714. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5715. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5716. lua_interface->ResetFunctionStack(state);
  5717. if(!spell || spell->resisted) {
  5718. return 0;
  5719. }
  5720. bool ward_was_added = false;
  5721. ZoneServer* zone = spell->caster->GetZone();
  5722. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5723. for (int32 i = 0; i < spell->targets.size(); i++) {
  5724. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5725. if (!target)
  5726. continue;
  5727. if (target->IsEntity()) {
  5728. // If the ward is already active remove it
  5729. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5730. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5731. // Create new ward info
  5732. WardInfo* ward = new WardInfo;
  5733. ward->Spell = spell;
  5734. ward->BaseDamage = damage;
  5735. ward->DamageLeft = damage;
  5736. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5737. ward->keepWard = keepWard;
  5738. ward->WardType = wardType;
  5739. if (damageAbsorptionPercent > 100)
  5740. damageAbsorptionPercent = 100;
  5741. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5742. if (damageAbsorptionMaxHealthPercent > 100)
  5743. damageAbsorptionMaxHealthPercent = 100;
  5744. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5745. ward->RedirectDamagePercent = redirectDamagePercent;
  5746. ward->LastRedirectDamage = 0;
  5747. ward->LastAbsorbedDamage = 0;
  5748. ward->HitCount = 0;
  5749. spell->num_triggers = maxHitCount;
  5750. spell->had_triggers = true;
  5751. spell->cancel_after_all_triggers = false;
  5752. ward->MaxHitCount = maxHitCount;
  5753. ward->RoundTriggered = false;
  5754. if (wardType == WARD_TYPE_MAGICAL)
  5755. ward->DamageType = damageTypes;
  5756. // Add the ward to the entity
  5757. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5758. ward_was_added = true;
  5759. }
  5760. }
  5761. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5762. if (ward_was_added && spell->caster->IsPlayer()) {
  5763. spell->had_dmg_remaining = true;
  5764. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, damage, 1);
  5765. }
  5766. return 0;
  5767. }
  5768. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5769. if (!lua_interface)
  5770. return 0;
  5771. int32 amount = lua_interface->GetInt32Value(state);
  5772. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5773. lua_interface->ResetFunctionStack(state);
  5774. WardInfo* ward = 0;
  5775. if(!spell || spell->resisted) {
  5776. return 0;
  5777. }
  5778. ZoneServer* zone = spell->caster->GetZone();
  5779. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5780. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5781. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5782. ward = target->GetWard(spell->spell->GetSpellID());
  5783. if (target && ward) {
  5784. ward->DamageLeft += amount;
  5785. if (ward->DamageLeft > ward->BaseDamage)
  5786. ward->DamageLeft = ward->BaseDamage;
  5787. for (int32 i = 0; i < spell->targets.size(); i++) {
  5788. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5789. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5790. }
  5791. }
  5792. }
  5793. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5794. if (ward && spell->caster->IsPlayer())
  5795. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
  5796. return 0;
  5797. }
  5798. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5799. if (!lua_interface)
  5800. return 0;
  5801. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5802. lua_interface->ResetFunctionStack(state);
  5803. if (!spell) {
  5804. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5805. return 0;
  5806. }
  5807. if (spell->caster && spell->caster->GetZone() && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5808. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5809. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5810. if (ward) {
  5811. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5812. return 1;
  5813. }
  5814. }
  5815. return 0;
  5816. }
  5817. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5818. if (!lua_interface)
  5819. return 0;
  5820. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5821. if (!spell) {
  5822. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5823. lua_interface->ResetFunctionStack(state);
  5824. return 0;
  5825. }
  5826. string type = lua_interface->GetStringValue(state, 2);
  5827. lua_interface->ResetFunctionStack(state);
  5828. if (spell->caster && spell->caster->GetZone() && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5829. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5830. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5831. if (ward) {
  5832. if (boost::iequals(type, "damageleft"))
  5833. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5834. else if (boost::iequals(type, "basedamage"))
  5835. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5836. else if (boost::iequals(type, "keepward"))
  5837. lua_interface->SetBooleanValue(state, ward->keepWard);
  5838. else if (boost::iequals(type, "wardtype"))
  5839. lua_interface->SetInt32Value(state, ward->WardType);
  5840. else if (boost::iequals(type, "dmgabsorptionpct"))
  5841. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5842. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5843. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5844. else if (boost::iequals(type, "redirectdamagepercent"))
  5845. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5846. else if (boost::iequals(type, "lastredirectdamage"))
  5847. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5848. else if (boost::iequals(type, "lastabsorbeddamage"))
  5849. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5850. else if (boost::iequals(type, "hitcount"))
  5851. lua_interface->SetInt32Value(state, ward->HitCount);
  5852. else if (boost::iequals(type, "maxhitcount"))
  5853. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5854. else
  5855. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5856. return 1;
  5857. }
  5858. }
  5859. return 0;
  5860. }
  5861. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5862. if (!lua_interface)
  5863. return 0;
  5864. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5865. lua_interface->ResetFunctionStack(state);
  5866. if(!spell) {
  5867. return 0;
  5868. }
  5869. ZoneServer* zone = spell->caster->GetZone();
  5870. Spawn* target = 0;
  5871. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5872. for (int32 i = 0; i < spell->targets.size(); i++) {
  5873. target = zone->GetSpawnByID(spell->targets.at(i));
  5874. if (target && target->IsEntity()) {
  5875. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5876. }
  5877. }
  5878. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5879. return 0;
  5880. }
  5881. int EQ2Emu_lua_Interrupt(lua_State* state)
  5882. {
  5883. if (!lua_interface)
  5884. return 0;
  5885. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5886. Spawn* target = lua_interface->GetSpawn(state, 2);
  5887. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5888. lua_interface->ResetFunctionStack(state);
  5889. if (!caster)
  5890. {
  5891. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5892. return 0;
  5893. }
  5894. if (!target)
  5895. {
  5896. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5897. return 0;
  5898. }
  5899. if (!spell) {
  5900. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5901. return 0;
  5902. }
  5903. if (!target->IsEntity() && !spell)
  5904. {
  5905. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5906. return 0;
  5907. }
  5908. if (!target && spell) {
  5909. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5910. for (int8 i = 0; i < spell->targets.size(); i++) {
  5911. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5912. if (!target || !target->IsEntity())
  5913. continue;
  5914. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5915. }
  5916. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5917. }
  5918. else
  5919. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5920. return 0;
  5921. }
  5922. int EQ2Emu_lua_Stealth(lua_State* state) {
  5923. if (!lua_interface)
  5924. return 0;
  5925. int8 type = lua_interface->GetInt8Value(state);
  5926. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5927. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5928. lua_interface->ResetFunctionStack(state);
  5929. if (!spell) {
  5930. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5931. return 0;
  5932. }
  5933. ZoneServer* zone = spell->caster->GetZone();
  5934. if (spawn) {
  5935. if (spawn->IsEntity()) {
  5936. if (type == 1) {
  5937. ((Entity*)spawn)->AddStealthSpell(spell);
  5938. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5939. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5940. }
  5941. else if (type == 2) {
  5942. ((Entity*)spawn)->AddInvisSpell(spell);
  5943. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5944. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5945. }
  5946. return 0;
  5947. }
  5948. else {
  5949. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5950. return 0;
  5951. }
  5952. }
  5953. else {
  5954. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5955. for (int32 i = 0; i < spell->targets.size(); i++) {
  5956. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5957. if (!spawn || !spawn->IsEntity())
  5958. continue;
  5959. if (type == 1) {
  5960. ((Entity*)spawn)->AddStealthSpell(spell);
  5961. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5962. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5963. }
  5964. else if (type == 2) {
  5965. ((Entity*)spawn)->AddInvisSpell(spell);
  5966. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5967. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5968. }
  5969. else {
  5970. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5971. break;
  5972. }
  5973. }
  5974. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5975. }
  5976. return 0;
  5977. }
  5978. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5979. if (!lua_interface)
  5980. return 0;
  5981. Spawn* spawn = lua_interface->GetSpawn(state);
  5982. lua_interface->ResetFunctionStack(state);
  5983. if (!spawn) {
  5984. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5985. return 0;
  5986. }
  5987. if (spawn->IsEntity()) {
  5988. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5989. return 1;
  5990. }
  5991. else
  5992. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5993. return 0;
  5994. }
  5995. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5996. if (!lua_interface)
  5997. return 0;
  5998. Spawn* spawn = lua_interface->GetSpawn(state);
  5999. lua_interface->ResetFunctionStack(state);
  6000. if (!spawn) {
  6001. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  6002. return 0;
  6003. }
  6004. if (spawn->IsEntity()) {
  6005. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  6006. return 1;
  6007. }
  6008. else
  6009. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  6010. return 0;
  6011. }
  6012. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  6013. if (!lua_interface)
  6014. return 0;
  6015. Spawn* player = lua_interface->GetSpawn(state);
  6016. int32 item_id = lua_interface->GetInt32Value(state, 2);
  6017. lua_interface->ResetFunctionStack(state);
  6018. if (!player->IsPlayer()) {
  6019. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  6020. return 0;
  6021. }
  6022. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  6023. return 1;
  6024. }
  6025. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  6026. if (!lua_interface)
  6027. return 0;
  6028. Spawn* spawn = lua_interface->GetSpawn(state);
  6029. int8 slot = lua_interface->GetInt8Value(state, 2);
  6030. lua_interface->ResetFunctionStack(state);
  6031. if (!spawn) {
  6032. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6033. return 0;
  6034. }
  6035. if (!spawn->IsEntity()) {
  6036. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6037. return 0;
  6038. }
  6039. Item* item = ((Entity*)spawn)->GetEquipmentList()->GetItem(slot);
  6040. if (!item) {
  6041. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  6042. return 0;
  6043. }
  6044. lua_interface->SetItemValue(state, item);
  6045. return 1;
  6046. }
  6047. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  6048. if (!lua_interface)
  6049. return 0;
  6050. Spawn* player = lua_interface->GetSpawn(state);
  6051. int32 id = lua_interface->GetInt32Value(state, 2);
  6052. lua_interface->ResetFunctionStack(state);
  6053. if (!player) {
  6054. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6055. return 0;
  6056. }
  6057. if (!player->IsPlayer()) {
  6058. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6059. return 0;
  6060. }
  6061. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  6062. if (!item) {
  6063. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  6064. return 0;
  6065. }
  6066. lua_interface->SetItemValue(state, item);
  6067. return 1;
  6068. }
  6069. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  6070. if (!lua_interface)
  6071. return 0;
  6072. Spawn* spawn = lua_interface->GetSpawn(state);
  6073. int8 slot = lua_interface->GetInt8Value(state, 2);
  6074. int32 item_id = lua_interface->GetInt32Value(state, 3);
  6075. lua_interface->ResetFunctionStack(state);
  6076. if (!spawn) {
  6077. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6078. return 0;
  6079. }
  6080. if (!spawn->IsEntity()) {
  6081. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6082. return 0;
  6083. }
  6084. Item* item = master_item_list.GetItem(item_id);
  6085. if (!item) {
  6086. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  6087. return 0;
  6088. }
  6089. Item* copy = new Item(item);
  6090. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  6091. if(result)
  6092. {
  6093. ((Entity*)spawn)->SetEquipment(copy, slot);
  6094. spawn->vis_changed = true;
  6095. if(spawn->IsPlayer())
  6096. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6097. }
  6098. else
  6099. {
  6100. safe_delete(copy);
  6101. }
  6102. lua_interface->SetBooleanValue(state, result);
  6103. return 1;
  6104. }
  6105. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  6106. if (!lua_interface)
  6107. return 0;
  6108. Spawn* spawn = lua_interface->GetSpawn(state);
  6109. int8 slot = lua_interface->GetInt8Value(state, 2);
  6110. Item* item = lua_interface->GetItem(state, 3);
  6111. lua_interface->ResetFunctionStack(state);
  6112. if (!spawn) {
  6113. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  6114. return 0;
  6115. }
  6116. if (!spawn->IsEntity()) {
  6117. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6118. return 0;
  6119. }
  6120. if (!item) {
  6121. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  6122. return 0;
  6123. }
  6124. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  6125. if(result)
  6126. {
  6127. ((Entity*)spawn)->SetEquipment(item, slot);
  6128. spawn->vis_changed = true;
  6129. if(spawn->IsPlayer())
  6130. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6131. }
  6132. lua_interface->SetBooleanValue(state, result);
  6133. return 1;
  6134. }
  6135. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  6136. if (!lua_interface)
  6137. return 0;
  6138. Spawn* spawn = lua_interface->GetSpawn(state);
  6139. int8 slot = lua_interface->GetInt8Value(state, 2);
  6140. 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
  6141. lua_interface->ResetFunctionStack(state);
  6142. if (!spawn) {
  6143. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6144. return 0;
  6145. }
  6146. if (!spawn->IsEntity()) {
  6147. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6148. return 0;
  6149. }
  6150. if(slot >= NUM_SLOTS) {
  6151. lua_interface->LogError("%s: LUA UnequipSlot command error: wrong slot id given %u, max %u", lua_interface->GetScriptName(state), slot, NUM_SLOTS);
  6152. return 0;
  6153. }
  6154. if(spawn->IsPlayer() && ((Player*)spawn)->GetClient()) {
  6155. Item* item = ((Player*)spawn)->GetEquipmentList()->GetItem(slot);
  6156. if(item) {
  6157. item->save_needed = true;
  6158. if(no_delete_item) {
  6159. database.DeleteItem(((Player*)spawn)->GetClient()->GetCharacterID(), item, 0);
  6160. ((Player*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6161. }
  6162. else{
  6163. Client* client = ((Player*)spawn)->GetClient();
  6164. client->UnequipItem(item->details.index);
  6165. }
  6166. }
  6167. }
  6168. else
  6169. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6170. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  6171. spawn->vis_changed = true;
  6172. if(spawn->IsPlayer())
  6173. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6174. lua_interface->SetBooleanValue(state, true);
  6175. return 1;
  6176. }
  6177. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  6178. if (!lua_interface)
  6179. return 0;
  6180. Spawn* spawn = lua_interface->GetSpawn(state);
  6181. int8 slot = lua_interface->GetInt8Value(state, 2);
  6182. int16 type = lua_interface->GetInt16Value(state, 3);
  6183. int8 r = lua_interface->GetInt8Value(state, 4);
  6184. int8 g = lua_interface->GetInt8Value(state, 5);
  6185. int8 b = lua_interface->GetInt8Value(state, 6);
  6186. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6187. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6188. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6189. lua_interface->ResetFunctionStack(state);
  6190. if (!spawn) {
  6191. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6192. return 0;
  6193. }
  6194. if (!spawn->IsEntity()) {
  6195. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6196. return 0;
  6197. }
  6198. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6199. spawn->vis_changed = true;
  6200. lua_interface->SetBooleanValue(state, true);
  6201. return 1;
  6202. }
  6203. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6204. if (!lua_interface)
  6205. return 0;
  6206. Spawn* player = lua_interface->GetSpawn(state);
  6207. int32 id = lua_interface->GetInt32Value(state, 2);
  6208. int8 count = lua_interface->GetInt8Value(state, 3);
  6209. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6210. lua_interface->ResetFunctionStack(state);
  6211. if (!player) {
  6212. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6213. return 0;
  6214. }
  6215. if (!player->IsPlayer()) {
  6216. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6217. return 0;
  6218. }
  6219. if (!count)
  6220. count = 1;
  6221. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6222. if (!item) {
  6223. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6224. return 0;
  6225. }
  6226. lua_interface->SetItemValue(state, item);
  6227. return 1;
  6228. }
  6229. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6230. if (!lua_interface)
  6231. return 0;
  6232. Spawn* spawn = lua_interface->GetSpawn(state);
  6233. int32 anim = lua_interface->GetInt32Value(state, 2);
  6234. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6235. int8 type = lua_interface->GetInt8Value(state, 4);
  6236. lua_interface->ResetFunctionStack(state);
  6237. if (!spawn) {
  6238. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6239. return 0;
  6240. }
  6241. if (spawn2) {
  6242. if (spawn2->IsPlayer()) {
  6243. if (type != 1 && type != 2)
  6244. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6245. else
  6246. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6247. return 0;
  6248. }
  6249. else {
  6250. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6251. return 0;
  6252. }
  6253. }
  6254. else
  6255. spawn->GetZone()->PlayAnimation(spawn, anim);
  6256. return 0;
  6257. }
  6258. int EQ2Emu_lua_IsPet(lua_State* state) {
  6259. if (!lua_interface)
  6260. return 0;
  6261. Spawn* spawn = lua_interface->GetSpawn(state);
  6262. lua_interface->ResetFunctionStack(state);
  6263. if (!spawn) {
  6264. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6265. return 0;
  6266. }
  6267. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6268. return 1;
  6269. }
  6270. int EQ2Emu_lua_GetOwner(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 GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6277. return 0;
  6278. }
  6279. if (!spawn->IsNPC()) {
  6280. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6281. return 0;
  6282. }
  6283. if (((NPC*)spawn)->GetOwner()) {
  6284. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6285. return 1;
  6286. }
  6287. return 0;
  6288. }
  6289. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6290. if (!lua_interface)
  6291. return 0;
  6292. Spawn* spawn = lua_interface->GetSpawn(state);
  6293. Spawn* target = lua_interface->GetSpawn(state, 2);
  6294. lua_interface->ResetFunctionStack(state);
  6295. if (!spawn) {
  6296. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6297. return 0;
  6298. }
  6299. if (!spawn) {
  6300. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6301. return 0;
  6302. }
  6303. spawn->SetTarget(target);
  6304. return 0;
  6305. }
  6306. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6307. if (!lua_interface)
  6308. return 0;
  6309. Spawn* spawn = lua_interface->GetSpawn(state);
  6310. bool val = lua_interface->GetBooleanValue(state, 2);
  6311. lua_interface->ResetFunctionStack(state);
  6312. if (!spawn) {
  6313. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6314. return 0;
  6315. }
  6316. if (!spawn->IsEntity()) {
  6317. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6318. return 0;
  6319. }
  6320. ((Entity*)spawn)->InCombat(val);
  6321. if (val) {
  6322. spawn->ClearRunningLocations();
  6323. spawn->CalculateRunningLocation(true);
  6324. }
  6325. return 0;
  6326. }
  6327. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6328. if (!lua_interface)
  6329. return 0;
  6330. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6331. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6332. lua_interface->ResetFunctionStack(state);
  6333. if (!spawn1) {
  6334. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6335. return 0;
  6336. }
  6337. if (!spawn2) {
  6338. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6339. return 0;
  6340. }
  6341. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6342. return 1;
  6343. }
  6344. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6345. if (!lua_interface)
  6346. return 0;
  6347. Spawn* spawn = lua_interface->GetSpawn(state);
  6348. lua_interface->ResetFunctionStack(state);
  6349. if (!spawn) {
  6350. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6351. return 0;
  6352. }
  6353. if (!spawn->IsNPC()) {
  6354. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6355. return 0;
  6356. }
  6357. ((NPC*)spawn)->ClearRunback();
  6358. return 0;
  6359. }
  6360. int EQ2Emu_lua_Runback(lua_State* state) {
  6361. if (!lua_interface)
  6362. return 0;
  6363. Spawn* spawn = lua_interface->GetSpawn(state);
  6364. lua_interface->ResetFunctionStack(state);
  6365. if (!spawn) {
  6366. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6367. return 0;
  6368. }
  6369. if (!spawn->IsNPC()) {
  6370. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6371. return 0;
  6372. }
  6373. ((NPC*)spawn)->Runback();
  6374. return 0;
  6375. }
  6376. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6377. if (!lua_interface)
  6378. return 0;
  6379. Spawn* spawn = lua_interface->GetSpawn(state);
  6380. lua_interface->ResetFunctionStack(state);
  6381. if (!spawn) {
  6382. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6383. return 0;
  6384. }
  6385. if (!spawn->IsNPC()) {
  6386. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6387. return 0;
  6388. }
  6389. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6390. return 1;
  6391. }
  6392. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6393. if (!lua_interface)
  6394. return 0;
  6395. Spawn* spawn = lua_interface->GetSpawn(state);
  6396. lua_interface->ResetFunctionStack(state);
  6397. if (!spawn) {
  6398. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6399. return 0;
  6400. }
  6401. if (!spawn->IsEntity()) {
  6402. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6403. return 0;
  6404. }
  6405. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6406. return 1;
  6407. }
  6408. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6409. if (!lua_interface)
  6410. return 0;
  6411. Spawn* spawn = lua_interface->GetSpawn(state);
  6412. lua_interface->ResetFunctionStack(state);
  6413. if (!spawn) {
  6414. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6415. return 0;
  6416. }
  6417. if (!spawn->IsEntity()) {
  6418. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6419. return 0;
  6420. }
  6421. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6422. return 1;
  6423. }
  6424. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6425. if (!lua_interface)
  6426. return 0;
  6427. Spawn* spawn = lua_interface->GetSpawn(state);
  6428. lua_interface->ResetFunctionStack(state);
  6429. if (!spawn) {
  6430. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6431. return 0;
  6432. }
  6433. if (!spawn->IsEntity()) {
  6434. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6435. return 0;
  6436. }
  6437. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6438. return 1;
  6439. }
  6440. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6441. if (!lua_interface)
  6442. return 0;
  6443. Spawn* spawn = lua_interface->GetSpawn(state);
  6444. lua_interface->ResetFunctionStack(state);
  6445. if (!spawn) {
  6446. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6447. return 0;
  6448. }
  6449. if (!spawn->IsEntity()) {
  6450. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6451. return 0;
  6452. }
  6453. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6454. return 1;
  6455. }
  6456. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6457. if (!lua_interface)
  6458. return 0;
  6459. Spawn* spawn = lua_interface->GetSpawn(state);
  6460. Spawn* target = lua_interface->GetSpawn(state, 2);
  6461. float distance = lua_interface->GetFloatValue(state, 3);
  6462. lua_interface->ResetFunctionStack(state);
  6463. if (!spawn) {
  6464. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6465. return 0;
  6466. }
  6467. if (!target) {
  6468. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6469. return 0;
  6470. }
  6471. if (!spawn->IsNPC()) {
  6472. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6473. return 0;
  6474. }
  6475. if (!target->IsEntity()) {
  6476. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6477. return 0;
  6478. }
  6479. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6480. return 1;
  6481. }
  6482. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6483. if (!lua_interface)
  6484. return 0;
  6485. Spawn* spawn = lua_interface->GetSpawn(state);
  6486. Spawn* target = lua_interface->GetSpawn(state, 2);
  6487. float distance = lua_interface->GetFloatValue(state, 3);
  6488. lua_interface->ResetFunctionStack(state);
  6489. if (!spawn) {
  6490. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6491. return 0;
  6492. }
  6493. if (!target) {
  6494. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6495. return 0;
  6496. }
  6497. if (!spawn->IsNPC()) {
  6498. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6499. return 0;
  6500. }
  6501. if (!target->IsEntity()) {
  6502. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6503. return 0;
  6504. }
  6505. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6506. return 0;
  6507. }
  6508. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6509. if (!lua_interface)
  6510. return 0;
  6511. Spawn* spawn = lua_interface->GetSpawn(state);
  6512. lua_interface->ResetFunctionStack(state);
  6513. if (!spawn) {
  6514. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6515. return 0;
  6516. }
  6517. if (!spawn->IsNPC()) {
  6518. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6519. return 0;
  6520. }
  6521. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6522. return 1;
  6523. }
  6524. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6525. if (!lua_interface)
  6526. return 0;
  6527. Spawn* spawn = lua_interface->GetSpawn(state);
  6528. lua_interface->ResetFunctionStack(state);
  6529. if (!spawn) {
  6530. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6531. return 0;
  6532. }
  6533. if (!spawn->IsNPC()) {
  6534. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6535. return 0;
  6536. }
  6537. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6538. return 1;
  6539. }
  6540. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6541. if (!lua_interface)
  6542. return 0;
  6543. Spawn* spawn = lua_interface->GetSpawn(state);
  6544. lua_interface->ResetFunctionStack(state);
  6545. if (!spawn) {
  6546. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6547. return 0;
  6548. }
  6549. if (!spawn->IsNPC()) {
  6550. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6551. return 0;
  6552. }
  6553. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6554. if (hated) {
  6555. lua_interface->SetSpawnValue(state, hated);
  6556. return 1;
  6557. }
  6558. return 0;
  6559. }
  6560. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6561. if (!lua_interface)
  6562. return 0;
  6563. Spawn* spawn = lua_interface->GetSpawn(state);
  6564. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6565. lua_interface->ResetFunctionStack(state);
  6566. if (!spawn) {
  6567. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6568. return 0;
  6569. }
  6570. if (!spawn->IsNPC()) {
  6571. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6572. return 0;
  6573. }
  6574. if (!hated) {
  6575. ((NPC*)spawn)->Brain()->ClearHate();
  6576. return 0;
  6577. }
  6578. else
  6579. {
  6580. if (!hated->IsEntity()) {
  6581. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6582. return 0;
  6583. }
  6584. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6585. return 0;
  6586. }
  6587. return 0;
  6588. }
  6589. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6590. if (!lua_interface)
  6591. return 0;
  6592. Spawn* spawn = lua_interface->GetSpawn(state);
  6593. lua_interface->ResetFunctionStack(state);
  6594. if (!spawn) {
  6595. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6596. return 0;
  6597. }
  6598. if (!spawn->IsNPC()) {
  6599. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6600. return 0;
  6601. }
  6602. ((NPC*)spawn)->Brain()->ClearEncounter();
  6603. return 0;
  6604. }
  6605. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6606. if (!lua_interface)
  6607. return 0;
  6608. Spawn* spawn = lua_interface->GetSpawn(state);
  6609. lua_interface->ResetFunctionStack(state);
  6610. if (!spawn) {
  6611. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6612. return 0;
  6613. }
  6614. if (!spawn->IsNPC()) {
  6615. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6616. return 0;
  6617. }
  6618. // Temp list to store hate list
  6619. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6620. if (encounterList->size() == 0) {
  6621. safe_delete(encounterList);
  6622. return 0;
  6623. }
  6624. lua_createtable(state, encounterList->size(), 0);
  6625. int newTable = lua_gettop(state);
  6626. for (int32 i = 0; i < encounterList->size(); i++) {
  6627. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6628. if (temp)
  6629. lua_interface->SetSpawnValue(state, temp);
  6630. lua_rawseti(state, newTable, i + 1);
  6631. }
  6632. safe_delete(encounterList);
  6633. return 1;
  6634. }
  6635. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6636. if (!lua_interface)
  6637. return 0;
  6638. Spawn* spawn = lua_interface->GetSpawn(state);
  6639. lua_interface->ResetFunctionStack(state);
  6640. if (!spawn) {
  6641. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6642. return 0;
  6643. }
  6644. if (!spawn->IsNPC()) {
  6645. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6646. return 0;
  6647. }
  6648. // Temp list to store hate list
  6649. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6650. if (hateList->size() == 0) {
  6651. safe_delete(hateList);
  6652. return 0;
  6653. }
  6654. lua_createtable(state, hateList->size(), 0);
  6655. int newTable = lua_gettop(state);
  6656. for (int32 i = 0; i < hateList->size(); i++) {
  6657. lua_interface->SetSpawnValue(state, hateList->at(i));
  6658. lua_rawseti(state, newTable, i + 1);
  6659. }
  6660. safe_delete(hateList);
  6661. return 1;
  6662. }
  6663. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6664. if (!lua_interface)
  6665. return 0;
  6666. Spawn* spawn = lua_interface->GetSpawn(state);
  6667. lua_interface->ResetFunctionStack(state);
  6668. if (!spawn) {
  6669. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6670. return 0;
  6671. }
  6672. if (spawn->IsPlayer()) {
  6673. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6674. lua_interface->SetBooleanValue(state, true);
  6675. else
  6676. lua_interface->SetBooleanValue(state, false);
  6677. return 1;
  6678. }
  6679. else {
  6680. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6681. return 1;
  6682. }
  6683. }
  6684. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6685. if (!lua_interface)
  6686. return 0;
  6687. Quest* quest = lua_interface->GetQuest(state);
  6688. lua_interface->ResetFunctionStack(state);
  6689. if (!quest) {
  6690. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6691. return 0;
  6692. }
  6693. quest->SetCompletedFlag(true);
  6694. return 0;
  6695. }
  6696. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6697. if (!lua_interface)
  6698. return 0;
  6699. Spawn* spawn = lua_interface->GetSpawn(state);
  6700. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6701. int8 tier = lua_interface->GetInt8Value(state, 3);
  6702. lua_interface->ResetFunctionStack(state);
  6703. if (!spawn) {
  6704. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6705. return 0;
  6706. }
  6707. if (!spawn->IsEntity()) {
  6708. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6709. return 0;
  6710. }
  6711. if (spellID == 0) {
  6712. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6713. return 0;
  6714. }
  6715. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6716. if (effect) {
  6717. if (tier > 0) {
  6718. // If a tier was passed chec to see if it is the same as the effect
  6719. if (tier == effect->tier)
  6720. lua_interface->SetBooleanValue(state, true);
  6721. else
  6722. lua_interface->SetBooleanValue(state, false);
  6723. return 1;
  6724. }
  6725. else {
  6726. // Have an effect but no tier was passed so return true
  6727. lua_interface->SetBooleanValue(state, true);
  6728. }
  6729. return 1;
  6730. }
  6731. // no effect so return false
  6732. lua_interface->SetBooleanValue(state, false);
  6733. return 1;
  6734. }
  6735. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6736. if (!lua_interface)
  6737. return 0;
  6738. Spawn* spawn = lua_interface->GetSpawn(state);
  6739. int32 id = lua_interface->GetInt32Value(state, 2);
  6740. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6741. lua_interface->ResetFunctionStack(state);
  6742. Spawn* spawn2 = 0;
  6743. vector<Spawn*> list;
  6744. if (!spawn) {
  6745. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6746. return 0;
  6747. }
  6748. //If zone not provided, use spawn's zone
  6749. if (!zone)
  6750. zone = spawn->GetZone();
  6751. list = zone->GetSpawnsByID(id);
  6752. if (list.size() == 0) {
  6753. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6754. return 0;
  6755. }
  6756. vector<Spawn*>::iterator itr = list.begin();
  6757. for (int8 i = 0; i < list.size(); i++) {
  6758. spawn2 = itr[i];
  6759. if (spawn2)
  6760. spawn2->AddAllowAccessSpawn(spawn);
  6761. }
  6762. return 0;
  6763. }
  6764. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6765. if (!lua_interface)
  6766. return 0;
  6767. Spawn* spawn = lua_interface->GetSpawn(state);
  6768. int32 id = lua_interface->GetInt32Value(state, 2);
  6769. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6770. lua_interface->ResetFunctionStack(state);
  6771. Spawn* spawn2 = 0;
  6772. if (!spawn) {
  6773. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6774. return 0;
  6775. }
  6776. //If zone not provided, use spawn's zone
  6777. if (!zone)
  6778. zone = spawn->GetZone();
  6779. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6780. vector<Spawn*>::iterator itr = list.begin();
  6781. if (list.size() == 0) {
  6782. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6783. return 0;
  6784. }
  6785. for (int8 i = 0; i < list.size(); i++) {
  6786. spawn2 = itr[i];
  6787. if (spawn2)
  6788. spawn2->RemoveSpawnAccess(spawn);
  6789. }
  6790. return 0;
  6791. }
  6792. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6793. if (!lua_interface)
  6794. return 0;
  6795. Quest* quest = lua_interface->GetQuest(state);
  6796. lua_interface->ResetFunctionStack(state);
  6797. if (!quest) {
  6798. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6799. return 0;
  6800. }
  6801. quest->SetYellowName(true);
  6802. return 0;
  6803. }
  6804. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6805. if (!lua_interface)
  6806. return 0;
  6807. Spawn* spawn = lua_interface->GetSpawn(state);
  6808. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6809. lua_interface->ResetFunctionStack(state);
  6810. if (!spawn) {
  6811. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6812. return 0;
  6813. }
  6814. if (!spawn->IsPlayer()) {
  6815. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6816. return 0;
  6817. }
  6818. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6819. return 1;
  6820. }
  6821. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6822. if (!lua_interface)
  6823. return 0;
  6824. Spawn* spawn = lua_interface->GetSpawn(state);
  6825. lua_interface->ResetFunctionStack(state);
  6826. if (!spawn) {
  6827. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6828. return 0;
  6829. }
  6830. if (!spawn->IsPlayer()) {
  6831. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6832. return 0;
  6833. }
  6834. ZoneServer* zone = spawn->GetZone();
  6835. if (!zone) {
  6836. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6837. return 0;
  6838. }
  6839. Instance_Type iType = zone->GetInstanceType();
  6840. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6841. iType == GROUP_LOCKOUT_INSTANCE ||
  6842. iType == RAID_LOCKOUT_INSTANCE ||
  6843. iType == SOLO_PERSIST_INSTANCE ||
  6844. iType == GROUP_PERSIST_INSTANCE ||
  6845. iType == RAID_PERSIST_INSTANCE) {
  6846. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6847. if (data) {
  6848. // Check to see if the timer has already been set, if it has return out.
  6849. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6850. return 0;
  6851. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6852. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6853. if(spawn->IsPlayer()) {
  6854. Client* client = ((Player*)spawn)->GetClient();
  6855. if (client) {
  6856. string time_msg = "";
  6857. int32 time = data->success_lockout_time;
  6858. int16 hour;
  6859. int8 min;
  6860. int8 sec;
  6861. hour = time / 3600;
  6862. time = time % 3600;
  6863. min = time / 60;
  6864. time = time % 60;
  6865. sec = time;
  6866. if (hour > 0) {
  6867. char temp[10];
  6868. sprintf(temp, " %i", hour);
  6869. time_msg.append(temp);
  6870. time_msg.append(" hour");
  6871. time_msg.append((hour > 1) ? "s" : "");
  6872. }
  6873. if (min > 0) {
  6874. char temp[5];
  6875. sprintf(temp, " %i", min);
  6876. time_msg.append(temp);
  6877. time_msg.append(" minute");
  6878. time_msg.append((min > 1) ? "s" : "");
  6879. }
  6880. // Only add seconds if minutes and hours are 0
  6881. if (hour == 0 && min == 0 && sec > 0) {
  6882. char temp[5];
  6883. sprintf(temp, " %i", sec);
  6884. time_msg.append(temp);
  6885. time_msg.append(" second");
  6886. time_msg.append((sec > 1) ? "s" : "");
  6887. }
  6888. 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());
  6889. }
  6890. else {
  6891. lua_interface->LogError("LUA SetSuccessTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6892. }
  6893. }
  6894. }
  6895. else
  6896. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6897. }
  6898. else
  6899. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6900. return 0;
  6901. }
  6902. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6903. if (!lua_interface)
  6904. return 0;
  6905. Spawn* spawn = lua_interface->GetSpawn(state);
  6906. lua_interface->ResetFunctionStack(state);
  6907. if (!spawn) {
  6908. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6909. return 0;
  6910. }
  6911. if (!spawn->IsPlayer()) {
  6912. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6913. return 0;
  6914. }
  6915. ZoneServer* zone = spawn->GetZone();
  6916. if (!zone) {
  6917. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6918. return 0;
  6919. }
  6920. Instance_Type iType = zone->GetInstanceType();
  6921. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6922. iType == GROUP_LOCKOUT_INSTANCE ||
  6923. iType == RAID_LOCKOUT_INSTANCE ||
  6924. iType == SOLO_PERSIST_INSTANCE ||
  6925. iType == GROUP_PERSIST_INSTANCE ||
  6926. iType == RAID_PERSIST_INSTANCE) {
  6927. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6928. if (data) {
  6929. // Check to see if the timer has already been set, if it has return out.
  6930. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6931. return 0;
  6932. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6933. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6934. if(spawn->IsPlayer()) {
  6935. Client* client = ((Player*)spawn)->GetClient();
  6936. if (client) {
  6937. string time_msg = "";
  6938. int32 time = data->failure_lockout_time;
  6939. int16 hour;
  6940. int8 min;
  6941. int8 sec;
  6942. hour = time / 3600;
  6943. time = time % 3600;
  6944. min = time / 60;
  6945. time = time % 60;
  6946. sec = time;
  6947. if (hour > 0) {
  6948. char temp[10];
  6949. sprintf(temp, " %i", hour);
  6950. time_msg.append(temp);
  6951. time_msg.append(" hour");
  6952. time_msg.append((hour > 1) ? "s" : "");
  6953. }
  6954. if (min > 0) {
  6955. char temp[5];
  6956. sprintf(temp, " %i", min);
  6957. time_msg.append(temp);
  6958. time_msg.append(" minute");
  6959. time_msg.append((min > 1) ? "s" : "");
  6960. }
  6961. // Only add seconds if minutes and hours are 0
  6962. if (hour == 0 && min == 0 && sec > 0) {
  6963. char temp[5];
  6964. sprintf(temp, " %i", sec);
  6965. time_msg.append(temp);
  6966. time_msg.append(" second");
  6967. time_msg.append((sec > 1) ? "s" : "");
  6968. }
  6969. 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());
  6970. }
  6971. }
  6972. else {
  6973. lua_interface->LogError("LUA SetFailureTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6974. }
  6975. }
  6976. else
  6977. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6978. }
  6979. else
  6980. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6981. return 0;
  6982. }
  6983. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6984. if (!lua_interface)
  6985. return 0;
  6986. Spawn* spawn = lua_interface->GetSpawn(state);
  6987. lua_interface->ResetFunctionStack(state);
  6988. if (!spawn) {
  6989. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6990. return 0;
  6991. }
  6992. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6993. return 1;
  6994. }
  6995. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6996. if (!lua_interface)
  6997. return 0;
  6998. Spawn* player = lua_interface->GetSpawn(state);
  6999. Spawn* ground = lua_interface->GetSpawn(state, 2);
  7000. if (!player) {
  7001. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7002. lua_interface->ResetFunctionStack(state);
  7003. return 0;
  7004. }
  7005. if (!player->IsPlayer()) {
  7006. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  7007. lua_interface->ResetFunctionStack(state);
  7008. return 0;
  7009. }
  7010. if (!ground) {
  7011. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7012. lua_interface->ResetFunctionStack(state);
  7013. return 0;
  7014. }
  7015. if (!ground->IsGroundSpawn()) {
  7016. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  7017. lua_interface->ResetFunctionStack(state);
  7018. return 0;
  7019. }
  7020. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7021. if (!groundspawn_entries) {
  7022. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7023. lua_interface->ResetFunctionStack(state);
  7024. return 0;
  7025. }
  7026. Skill* skill = 0;
  7027. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  7028. if (collection_skill == "Collecting")
  7029. skill = ((Player*)player)->GetSkillByName("Gathering");
  7030. else
  7031. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  7032. if (!skill) {
  7033. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  7034. lua_interface->ResetFunctionStack(state);
  7035. return 0;
  7036. }
  7037. vector<GroundSpawnEntry*>::iterator itr;
  7038. GroundSpawnEntry* entry = 0;
  7039. bool can_harvest = false;
  7040. sint32 min_skill = -1;
  7041. int16 totalSkill = skill->current_val;
  7042. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  7043. if(skillID != 0xFFFFFFFF)
  7044. {
  7045. ((Entity*)player)->MStats.lock();
  7046. totalSkill += ((Entity*)player)->stats[skillID];
  7047. ((Entity*)player)->MStats.unlock();
  7048. }
  7049. // first, iterate through groundspawn_entries, discard tables player cannot use
  7050. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  7051. {
  7052. entry = *itr;
  7053. if (min_skill == -1 || entry->min_skill_level < min_skill)
  7054. min_skill = entry->min_skill_level;
  7055. // if player lacks skill, skip table
  7056. if (entry->min_skill_level > totalSkill)
  7057. continue;
  7058. // if bonus, but player lacks level, skip table
  7059. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  7060. continue;
  7061. can_harvest = true;
  7062. break;
  7063. }
  7064. lua_interface->SetBooleanValue(state, can_harvest);
  7065. // If false, send the message to the client
  7066. if (!can_harvest) {
  7067. Client* client = ((Player*)player)->GetClient();
  7068. if (client) {
  7069. string msg = "You do not have enough skill to ";
  7070. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  7071. msg.append("gather");
  7072. else if (collection_skill == "Mining")
  7073. msg.append("mine");
  7074. else if (collection_skill == "Trapping")
  7075. msg.append("trap");
  7076. else if (collection_skill == "Foresting")
  7077. msg.append("forest");
  7078. else if (collection_skill == "Fishing")
  7079. msg.append("catch");
  7080. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  7081. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  7082. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  7083. }
  7084. }
  7085. lua_interface->ResetFunctionStack(state);
  7086. return 1;
  7087. }
  7088. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  7089. if (!lua_interface)
  7090. return 0;
  7091. Spawn* player = lua_interface->GetSpawn(state);
  7092. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  7093. lua_interface->ResetFunctionStack(state);
  7094. if (!player) {
  7095. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  7096. return 0;
  7097. }
  7098. if (!player->IsPlayer()) {
  7099. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  7100. return 0;
  7101. }
  7102. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  7103. lua_interface->SetBooleanValue(state, ret);
  7104. return 1;
  7105. }
  7106. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  7107. // Check to see if we have a valid lua_interface
  7108. if (!lua_interface)
  7109. return 0;
  7110. // Get the spawn that is getting the pet
  7111. Spawn* spawn = lua_interface->GetSpawn(state);
  7112. Spawn* target = lua_interface->GetSpawn(state, 2);
  7113. // Get the DB ID of the pet
  7114. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  7115. float x = lua_interface->GetFloatValue(state, 4);
  7116. float y = lua_interface->GetFloatValue(state, 5);
  7117. float z = lua_interface->GetFloatValue(state, 6);
  7118. // Get the spell that this command was called from
  7119. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7120. lua_interface->ResetFunctionStack(state);
  7121. // Check to make sure the spawn pointer is valid
  7122. if (!spawn) {
  7123. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  7124. return 0;
  7125. }
  7126. // Check to make sure the spawn is an entity
  7127. if (!spawn->IsEntity()) {
  7128. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  7129. return 0;
  7130. }
  7131. if (!target) {
  7132. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  7133. return 0;
  7134. }
  7135. if (!target->IsEntity()) {
  7136. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  7137. return 0;
  7138. }
  7139. // Check to see if the DB ID for the pet is set
  7140. if (pet_id == 0) {
  7141. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  7142. return 0;
  7143. }
  7144. // Check to see if the pointer to the spell is valid
  7145. if (!luaspell) {
  7146. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  7147. return 0;
  7148. }
  7149. if(luaspell->resisted) {
  7150. return 0;
  7151. }
  7152. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  7153. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  7154. if (!pet) {
  7155. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  7156. return 0;
  7157. }
  7158. // Check to make sure the pet is an npc
  7159. if (!pet->IsNPC()) {
  7160. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  7161. return 0;
  7162. }
  7163. if (x == 0)
  7164. x = spawn->GetX();
  7165. if (y == 0)
  7166. y = spawn->GetY();
  7167. if (z == 0)
  7168. z = spawn->GetZ();
  7169. // Spawn the pet at the same location as the owner
  7170. pet->SetX(x);
  7171. pet->SetY(y);
  7172. pet->SetZ(z);
  7173. pet->SetLocation(spawn->GetLocation());
  7174. pet->SetHeading(spawn->GetHeading());
  7175. spawn->GetZone()->AddSpawn(pet);
  7176. const char* spawn_script = world.GetSpawnScript(pet_id);
  7177. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  7178. spawn->SetSpawnScript(string(spawn_script));
  7179. spawn->GetZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7180. }
  7181. std::string petName = std::string("");
  7182. if(spawn->IsEntity()) {
  7183. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  7184. }
  7185. if(petName.size() < 1) {
  7186. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  7187. petName = spawn->GetZone()->pet_names.at(rand_index);
  7188. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  7189. }
  7190. // Set the pets name
  7191. pet->SetName(petName.c_str());
  7192. // Set the level of the pet to the owners level
  7193. pet->SetLevel(spawn->GetLevel());
  7194. // Set the faction of the pet to the same faction as the owner
  7195. pet->SetFactionID(spawn->GetFactionID());
  7196. // Set the spawn as a pet
  7197. pet->SetPet(true);
  7198. // Give a pointer of the owner to the pet
  7199. ((NPC*)pet)->SetOwner((Entity*)spawn);
  7200. // Set the pet type
  7201. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  7202. // Set the spell id used to create this pet
  7203. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  7204. // Set the spell tier used to create this pet
  7205. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  7206. // Set the pets spawn type to 6
  7207. pet->SetSpawnType(6);
  7208. // Set the pets brain
  7209. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  7210. // Check to see if the pet has a subtitle
  7211. if (strlen(pet->GetSubTitle()) > 0) {
  7212. // Add the players name to the front of the sub title
  7213. string pet_subtitle;
  7214. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  7215. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  7216. // Set the pets subtitle to the new one
  7217. pet->SetSubTitle(pet_subtitle.c_str());
  7218. }
  7219. // Set the pet as the return value for this function
  7220. lua_interface->SetSpawnValue(state, pet);
  7221. return 1;
  7222. }
  7223. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  7224. if (!lua_interface)
  7225. return 0;
  7226. Spawn* spawn = lua_interface->GetSpawn(state);
  7227. Spawn* player = lua_interface->GetSpawn(state, 2);
  7228. float max_distance = lua_interface->GetFloatValue(state, 3);
  7229. string type = lua_interface->GetStringValue(state, 4);
  7230. lua_interface->ResetFunctionStack(state);
  7231. if (!spawn || (spawn && spawn->IsPlayer())) {
  7232. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  7233. return 0;
  7234. }
  7235. if (!player || !player->IsPlayer()) {
  7236. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  7237. return 0;
  7238. }
  7239. Client* client = ((Player*)player)->GetClient();
  7240. if (!client) {
  7241. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7242. return 0;
  7243. }
  7244. //Set max_distance to default if not set or not proper value
  7245. if (max_distance <= 0)
  7246. max_distance = 500;
  7247. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7248. if (packet) {
  7249. float unknown2_3 = 0;
  7250. int8 placement_mode = 0;
  7251. if (type == "wall") {
  7252. placement_mode = 2;
  7253. unknown2_3 = 150;
  7254. }
  7255. else if (type == "ceiling")
  7256. placement_mode = 1;
  7257. packet->setDataByName("placement_mode", placement_mode);
  7258. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7259. packet->setDataByName("model_type", spawn->GetModelType());
  7260. packet->setDataByName("unknown", 1); //size
  7261. packet->setDataByName("unknown2", 1); //size 2
  7262. packet->setDataByName("unknown2", .5, 1); //size 3
  7263. packet->setDataByName("unknown2", 3, 2);
  7264. packet->setDataByName("unknown2", unknown2_3, 3);
  7265. packet->setDataByName("max_distance", max_distance);
  7266. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7267. client->QueuePacket(packet->serialize());
  7268. safe_delete(packet);
  7269. }
  7270. return 0;
  7271. }
  7272. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7273. if (!lua_interface)
  7274. return 0;
  7275. Item* item = lua_interface->GetItem(state);
  7276. lua_interface->ResetFunctionStack(state);
  7277. if (!item) {
  7278. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7279. return 0;
  7280. }
  7281. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7282. return 1;
  7283. }
  7284. int EQ2Emu_lua_GetItemEffectType(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 GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7291. return 0;
  7292. }
  7293. lua_interface->SetInt32Value(state, item->effect_type);
  7294. return 1;
  7295. }
  7296. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7297. if (!lua_interface)
  7298. return 0;
  7299. Spawn* spawn = lua_interface->GetSpawn(state);
  7300. lua_interface->ResetFunctionStack(state);
  7301. if (!spawn) {
  7302. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7303. return 0;
  7304. }
  7305. if (spawn->GetZone())
  7306. spawn->GetZone()->AddTransportSpawn(spawn);
  7307. return 0;
  7308. }
  7309. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7310. if (!lua_interface)
  7311. return 0;
  7312. Spawn* spawn = lua_interface->GetSpawn(state);
  7313. lua_interface->ResetFunctionStack(state);
  7314. if (!spawn) {
  7315. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7316. return 0;
  7317. }
  7318. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7319. return 1;
  7320. }
  7321. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7322. if (!lua_interface)
  7323. return 0;
  7324. Skill* skill = lua_interface->GetSkill(state);
  7325. lua_interface->ResetFunctionStack(state);
  7326. if (!skill) {
  7327. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7328. return 0;
  7329. }
  7330. lua_interface->SetInt32Value(state, skill->current_val);
  7331. return 1;
  7332. }
  7333. int EQ2Emu_lua_GetSkillMaxValue(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 GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7340. return 0;
  7341. }
  7342. lua_interface->SetInt32Value(state, skill->max_val);
  7343. return 1;
  7344. }
  7345. int EQ2Emu_lua_GetSkillName(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 GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7352. return 0;
  7353. }
  7354. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7355. return 1;
  7356. }
  7357. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7358. if (!lua_interface)
  7359. return 0;
  7360. Skill* skill = lua_interface->GetSkill(state);
  7361. int16 value = lua_interface->GetInt16Value(state, 2);
  7362. lua_interface->ResetFunctionStack(state);
  7363. if (!skill) {
  7364. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7365. return 0;
  7366. }
  7367. skill->max_val = value;
  7368. if (skill->max_val < skill->current_val)
  7369. skill->current_val = skill->max_val;
  7370. return 0;
  7371. }
  7372. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7373. if (!lua_interface)
  7374. return 0;
  7375. Skill* skill = lua_interface->GetSkill(state);
  7376. int16 value = lua_interface->GetInt16Value(state, 2);
  7377. lua_interface->ResetFunctionStack(state);
  7378. if (!skill) {
  7379. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7380. return 0;
  7381. }
  7382. if (value > skill->max_val)
  7383. skill->current_val = skill->max_val;
  7384. else
  7385. skill->current_val = value;
  7386. return 0;
  7387. }
  7388. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7389. if (!lua_interface)
  7390. return 0;
  7391. Spawn* player = lua_interface->GetSpawn(state);
  7392. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7393. lua_interface->ResetFunctionStack(state);
  7394. if (skill_id > 0 && player && player->IsPlayer()) {
  7395. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7396. return 1;
  7397. }
  7398. return 0;
  7399. }
  7400. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7401. if (!lua_interface)
  7402. return 0;
  7403. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7404. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7405. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7406. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7407. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7408. lua_interface->ResetFunctionStack(state);
  7409. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7410. if (player_spawn && player_spawn->IsPlayer()) {
  7411. Player* player = (Player*)player_spawn;
  7412. bool added = false;
  7413. if (!player->skill_list.HasSkill(skill_id)) {
  7414. player->AddSkill(skill_id, current_val, max_val, true);
  7415. added = true;
  7416. }
  7417. 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
  7418. Client* client = player->GetClient();
  7419. if (client) {
  7420. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7421. if (packet)
  7422. client->QueuePacket(packet);
  7423. }
  7424. }
  7425. if (added) {
  7426. lua_interface->SetBooleanValue(state, true);
  7427. return 1;
  7428. }
  7429. }
  7430. else {
  7431. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7432. }
  7433. }
  7434. else {
  7435. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7436. }
  7437. lua_interface->SetBooleanValue(state, false);
  7438. return 1;
  7439. }
  7440. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7441. if (!lua_interface)
  7442. return 0;
  7443. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7444. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7445. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7446. lua_interface->ResetFunctionStack(state);
  7447. if (skill_id > 0) {
  7448. if (player_spawn && player_spawn->IsPlayer()) {
  7449. Player* player = (Player*)player_spawn;
  7450. if (player->skill_list.HasSkill(skill_id)) {
  7451. player->RemovePlayerSkill(skill_id);
  7452. if (!more_to_remove) {
  7453. Client* client = player->GetClient();
  7454. if (client) {
  7455. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7456. if (packet)
  7457. client->QueuePacket(packet);
  7458. }
  7459. }
  7460. }
  7461. }
  7462. else {
  7463. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7464. }
  7465. }
  7466. else {
  7467. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7468. }
  7469. return 0;
  7470. }
  7471. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7472. if (!lua_interface)
  7473. return 0;
  7474. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7475. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7476. int16 amount = lua_interface->GetInt8Value(state, 3);
  7477. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7478. lua_interface->ResetFunctionStack(state);
  7479. if (amount > 0 && skill_type < 100) {
  7480. if (player_spawn && player_spawn->IsPlayer()) {
  7481. Player* player = (Player*)player_spawn;
  7482. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7483. if (!more_to_increase) {
  7484. Client* client = player->GetClient();
  7485. if (client) {
  7486. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7487. if (packet)
  7488. client->QueuePacket(packet);
  7489. }
  7490. }
  7491. }
  7492. else {
  7493. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7494. }
  7495. }
  7496. else {
  7497. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7498. }
  7499. return 0;
  7500. }
  7501. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7502. if (!lua_interface)
  7503. return 0;
  7504. Spawn* spawn = lua_interface->GetSpawn(state);
  7505. string name = lua_interface->GetStringValue(state, 2);
  7506. lua_interface->ResetFunctionStack(state);
  7507. if (!spawn) {
  7508. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7509. return 0;
  7510. }
  7511. if (!spawn->IsEntity()) {
  7512. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7513. return 0;
  7514. }
  7515. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7516. if (skill) {
  7517. lua_interface->SetSkillValue(state, skill);
  7518. return 1;
  7519. }
  7520. return 0;
  7521. }
  7522. int EQ2Emu_lua_AddProc(lua_State* state) {
  7523. if (!lua_interface)
  7524. return 0;
  7525. Spawn* spawn = lua_interface->GetSpawn(state);
  7526. int8 type = lua_interface->GetInt8Value(state, 2);
  7527. float chance = lua_interface->GetFloatValue(state, 3);
  7528. Item* item = lua_interface->GetItem(state, 4);
  7529. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7530. LuaSpell* spell = 0;
  7531. if (!spawn && (!spell || !use_all_spelltargets)) {
  7532. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7533. return 0;
  7534. }
  7535. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7536. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7537. return 0;
  7538. }
  7539. if (!item)
  7540. spell = lua_interface->GetCurrentSpell(state);
  7541. if (!item && !spell) {
  7542. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7543. return 0;
  7544. }
  7545. if(spell && spell->resisted) {
  7546. return 0;
  7547. }
  7548. if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
  7549. Spawn* target;
  7550. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7551. for (int8 i = 0; i < spell->targets.size(); i++) {
  7552. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7553. if (!target || !target->IsEntity())
  7554. continue;
  7555. ((Entity*)target)->AddProc(type, chance, item, spell);
  7556. }
  7557. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7558. }
  7559. else
  7560. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7561. return 0;
  7562. }
  7563. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7564. if (!lua_interface)
  7565. return 0;
  7566. Spawn* spawn = lua_interface->GetSpawn(state);
  7567. Item* item = lua_interface->GetItem(state, 2);
  7568. LuaSpell* spell = 0;
  7569. if (!spawn) {
  7570. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7571. lua_interface->ResetFunctionStack(state);
  7572. return 0;
  7573. }
  7574. if (!spawn->IsEntity()) {
  7575. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7576. lua_interface->ResetFunctionStack(state);
  7577. return 0;
  7578. }
  7579. if (!item)
  7580. spell = lua_interface->GetCurrentSpell(state);
  7581. lua_interface->ResetFunctionStack(state);
  7582. if (!item && !spell) {
  7583. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7584. return 0;
  7585. }
  7586. if (spell && spell->caster && spell->caster->GetZone()) {
  7587. Spawn* target;
  7588. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7589. for (int8 i = 0; i < spell->targets.size(); i++) {
  7590. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7591. if (!target || !target->IsEntity())
  7592. continue;
  7593. ((Entity*)target)->RemoveProc(item, spell);
  7594. }
  7595. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7596. spell->caster->RemoveProc(item, spell);
  7597. }
  7598. else
  7599. ((Entity*)spawn)->RemoveProc(item, spell);
  7600. return 0;
  7601. }
  7602. int EQ2Emu_lua_Knockback(lua_State* state) {
  7603. if (!lua_interface)
  7604. return 0;
  7605. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7606. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7607. int32 duration = lua_interface->GetInt32Value(state, 3);
  7608. float vertical = lua_interface->GetFloatValue(state, 4);
  7609. float horizontal = lua_interface->GetFloatValue(state, 5);
  7610. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7611. lua_interface->ResetFunctionStack(state);
  7612. if (!target_spawn) {
  7613. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7614. return 0;
  7615. }
  7616. if (!spawn) {
  7617. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7618. return 0;
  7619. }
  7620. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7621. Client* client = ((Player*)spawn)->GetClient();
  7622. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7623. if (packet) {
  7624. packet->setDataByName("target_x", target_spawn->GetX());
  7625. packet->setDataByName("target_y", target_spawn->GetY());
  7626. packet->setDataByName("target_z", target_spawn->GetZ());
  7627. packet->setDataByName("vertical_movement", vertical);
  7628. packet->setDataByName("horizontal_movement", horizontal);
  7629. if (use_heading)
  7630. packet->setDataByName("use_player_heading", 1);
  7631. client->QueuePacket(packet->serialize());
  7632. }
  7633. safe_delete(packet);
  7634. }
  7635. return 0;
  7636. }
  7637. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7638. if (!lua_interface)
  7639. return 0;
  7640. Spawn* spawn = lua_interface->GetSpawn(state);
  7641. lua_interface->ResetFunctionStack(state);
  7642. if (!spawn) {
  7643. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7644. return 0;
  7645. }
  7646. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7647. return 1;
  7648. }
  7649. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7650. if (!lua_interface)
  7651. return 0;
  7652. Spawn* caster = lua_interface->GetSpawn(state);
  7653. Spawn* target = lua_interface->GetSpawn(state, 2);
  7654. string name = lua_interface->GetStringValue(state, 3);
  7655. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7656. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7657. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7658. string success_msg = lua_interface->GetStringValue(state, 7);
  7659. string effect_msg = lua_interface->GetStringValue(state, 8);
  7660. lua_interface->ResetFunctionStack(state);
  7661. if (!caster) {
  7662. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7663. return 0;
  7664. }
  7665. if (!caster->IsEntity()) {
  7666. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7667. return 0;
  7668. }
  7669. if (!target) {
  7670. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7671. return 0;
  7672. }
  7673. if (!target->IsEntity()) {
  7674. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7675. return 0;
  7676. }
  7677. if (name.length() == 0) {
  7678. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7679. return 0;
  7680. }
  7681. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7682. return 0;
  7683. }
  7684. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7685. if (!lua_interface)
  7686. return 0;
  7687. string name = lua_interface->GetStringValue(state);
  7688. lua_interface->ResetFunctionStack(state);
  7689. if (name.length() == 0) {
  7690. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7691. return 0;
  7692. }
  7693. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7694. if (!skill) {
  7695. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7696. return 0;
  7697. }
  7698. lua_interface->SetInt32Value(state, skill->skill_id);
  7699. return 1;
  7700. }
  7701. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7702. if (!lua_interface)
  7703. return 0;
  7704. Spawn* spawn = lua_interface->GetSpawn(state);
  7705. lua_interface->ResetFunctionStack(state);
  7706. if (!spawn) {
  7707. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7708. return 0;
  7709. }
  7710. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7711. return 1;
  7712. }
  7713. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7714. if (!lua_interface)
  7715. return 0;
  7716. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7717. lua_interface->ResetFunctionStack(state);
  7718. if (!luaspell) {
  7719. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7720. return 0;
  7721. }
  7722. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7723. return 1;
  7724. }
  7725. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7726. if (!lua_interface)
  7727. return 0;
  7728. Spawn* spawn = lua_interface->GetSpawn(state);
  7729. Spawn* target = lua_interface->GetSpawn(state, 2);
  7730. lua_interface->ResetFunctionStack(state);
  7731. if (!spawn) {
  7732. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7733. return 0;
  7734. }
  7735. if (!spawn->IsEntity()) {
  7736. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7737. return 0;
  7738. }
  7739. if (!target) {
  7740. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7741. return 0;
  7742. }
  7743. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7744. return 1;
  7745. }
  7746. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7747. if (!lua_interface)
  7748. return 0;
  7749. Spawn* spawn = lua_interface->GetSpawn(state);
  7750. Spawn* target = lua_interface->GetSpawn(state, 2);
  7751. lua_interface->ResetFunctionStack(state);
  7752. if (!spawn) {
  7753. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7754. return 0;
  7755. }
  7756. if (!spawn->IsEntity()) {
  7757. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7758. return 0;
  7759. }
  7760. if (!target) {
  7761. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7762. return 0;
  7763. }
  7764. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7765. return 1;
  7766. }
  7767. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7768. if (!lua_interface)
  7769. return 0;
  7770. Item* item = lua_interface->GetItem(state);
  7771. lua_interface->ResetFunctionStack(state);
  7772. if (!item) {
  7773. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7774. return 0;
  7775. }
  7776. lua_interface->SetInt32Value(state, item->details.count);
  7777. return 1;
  7778. }
  7779. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7780. if (!lua_interface)
  7781. return 0;
  7782. Item* item = lua_interface->GetItem(state);
  7783. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7784. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7785. lua_interface->ResetFunctionStack(state);
  7786. if (!item) {
  7787. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7788. return 0;
  7789. }
  7790. if (!owner) {
  7791. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7792. return 0;
  7793. }
  7794. if (!owner->IsPlayer()) {
  7795. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7796. return 0;
  7797. }
  7798. if (item->stack_count < new_count) {
  7799. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7800. return 0;
  7801. }
  7802. if (new_count > 0) {
  7803. item->details.count = new_count;
  7804. item->save_needed = true;
  7805. }
  7806. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7807. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7808. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7809. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7810. else
  7811. {
  7812. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7813. return 0;
  7814. }
  7815. Client* client = ((Player*)owner)->GetClient();
  7816. if (!client)
  7817. return 0;
  7818. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7819. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7820. if (app)
  7821. client->QueuePacket(app);
  7822. return 0;
  7823. }
  7824. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7825. if (!lua_interface)
  7826. return 0;
  7827. int32 time = lua_interface->GetInt32Value(state);
  7828. string function = lua_interface->GetStringValue(state, 2);
  7829. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7830. Spawn* target = lua_interface->GetSpawn(state, 4);
  7831. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7832. lua_interface->ResetFunctionStack(state);
  7833. if (time == 0) {
  7834. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7835. return 0;
  7836. }
  7837. if (function.length() == 0) {
  7838. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7839. return 0;
  7840. }
  7841. if (!spell || (!spell->caster || !spell->caster->GetZone())) {
  7842. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7843. return 0;
  7844. }
  7845. SpellScriptTimer* timer = new SpellScriptTimer;
  7846. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7847. #ifdef WIN32
  7848. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7849. #else
  7850. bzero(timer, sizeof(SpellScriptTimer));
  7851. #endif*/
  7852. timer->caster = 0;
  7853. timer->deleteWhenDone = false;
  7854. timer->target = 0;
  7855. timer->time = Timer::GetCurrentTime2() + time;
  7856. timer->customFunction = function;
  7857. timer->spell = spell;
  7858. if (caster)
  7859. timer->caster = caster->GetID();
  7860. if (target)
  7861. timer->target = target->GetID();
  7862. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7863. return 0;
  7864. }
  7865. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7866. if (!lua_interface)
  7867. return 0;
  7868. float hp_perc = lua_interface->GetFloatValue(state);
  7869. float power_perc = lua_interface->GetFloatValue(state, 2);
  7870. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7871. Spawn* target = lua_interface->GetSpawn(state, 4);
  7872. string heal_name = lua_interface->GetStringValue(state, 5);
  7873. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7874. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7875. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7876. lua_interface->ResetFunctionStack(state);
  7877. if (!spell) {
  7878. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7879. return 0;
  7880. }
  7881. Entity* caster = spell->caster;
  7882. if (!caster) {
  7883. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7884. return 0;
  7885. }
  7886. Client* client = 0;
  7887. PendingResurrection* rez = 0;
  7888. ZoneServer* zone = spell->caster->GetZone();
  7889. if (!target) {
  7890. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7891. if (spell->targets.size() > 0) {
  7892. vector<int32> spell_targets = spell->targets;
  7893. for (int8 i = 0; i < spell_targets.size(); i++) {
  7894. target = zone->GetSpawnByID(spell_targets.at(i));
  7895. if (!target)
  7896. continue;
  7897. if (!target->IsPlayer())
  7898. continue;
  7899. client = ((Player*)target)->GetClient();
  7900. if (!client)
  7901. continue;
  7902. rez = client->GetCurrentRez();
  7903. if (rez->active)
  7904. continue;
  7905. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7906. rez->active = true;
  7907. rez->caster = caster;
  7908. rez->expire_timer = new Timer;
  7909. int32 duration = spell->spell->GetSpellDuration();
  7910. rez->expire_timer->Start(duration * 100);
  7911. rez->hp_perc = hp_perc;
  7912. rez->mp_perc = power_perc;
  7913. rez->range = spell->spell->GetSpellData()->range;
  7914. rez->spell_name = spell->spell->GetName();
  7915. if (heal_name.length() > 0)
  7916. rez->heal_name = heal_name;
  7917. else
  7918. rez->heal_name = rez->spell_name;
  7919. rez->no_calcs = no_calcs;
  7920. rez->crit_mod = crit_mod;
  7921. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7922. if (send_window)
  7923. client->SendResurrectionWindow();
  7924. else {
  7925. target->GetZone()->ResurrectSpawn(target, client);
  7926. rez->should_delete = true;
  7927. }
  7928. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7929. }
  7930. }
  7931. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7932. }
  7933. else {
  7934. if(!target->IsPlayer())
  7935. return 0;
  7936. client = ((Player*)target)->GetClient();
  7937. if (!client)
  7938. return 0;
  7939. rez = client->GetCurrentRez();
  7940. if (rez->active)
  7941. return 0;
  7942. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7943. rez->active = true;
  7944. rez->caster = caster;
  7945. rez->expire_timer = new Timer;
  7946. int32 duration = spell->spell->GetSpellDuration();
  7947. rez->expire_timer->Start(duration * 100);
  7948. rez->hp_perc = hp_perc;
  7949. rez->mp_perc = power_perc;
  7950. rez->range = spell->spell->GetSpellData()->range;
  7951. rez->spell_name = spell->spell->GetName();
  7952. if (heal_name.length() > 0)
  7953. rez->heal_name = heal_name;
  7954. else
  7955. rez->heal_name = rez->spell_name;
  7956. rez->no_calcs = no_calcs;
  7957. rez->crit_mod = crit_mod;
  7958. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7959. if (send_window)
  7960. client->SendResurrectionWindow();
  7961. else {
  7962. target->GetZone()->ResurrectSpawn(target, client);
  7963. rez->should_delete = true;
  7964. }
  7965. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7966. }
  7967. return 0;
  7968. }
  7969. int EQ2Emu_lua_SetVision(lua_State* state) {
  7970. if (!lua_interface)
  7971. return 0;
  7972. Spawn* spawn = lua_interface->GetSpawn(state);
  7973. int32 vision = lua_interface->GetInt32Value(state, 2);
  7974. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7975. lua_interface->ResetFunctionStack(state);
  7976. if (!spawn) {
  7977. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7978. return 0;
  7979. }
  7980. if (!spawn->IsEntity()) {
  7981. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7982. return 0;
  7983. }
  7984. if (spell && spell->targets.size() > 0) {
  7985. ZoneServer* zone = spell->caster->GetZone();
  7986. for (int8 i = 0; i < spell->targets.size(); i++) {
  7987. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7988. if (target && target->IsEntity()) {
  7989. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7990. if (target->IsPlayer())
  7991. ((Player*)target)->SetCharSheetChanged(true);
  7992. }
  7993. }
  7994. }
  7995. else {
  7996. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7997. if (spawn->IsPlayer())
  7998. ((Player*)spawn)->SetCharSheetChanged(true);
  7999. }
  8000. return 0;
  8001. }
  8002. int EQ2Emu_lua_BlurVision(lua_State* state) {
  8003. if (!lua_interface)
  8004. return 0;
  8005. Spawn* spawn = lua_interface->GetSpawn(state);
  8006. float intensity = lua_interface->GetFloatValue(state, 2);
  8007. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8008. lua_interface->ResetFunctionStack(state);
  8009. if (!spawn) {
  8010. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8011. return 0;
  8012. }
  8013. if (!spawn->IsEntity()) {
  8014. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8015. return 0;
  8016. }
  8017. if (spell && spell->targets.size() > 0) {
  8018. ZoneServer* zone = spell->caster->GetZone();
  8019. for (int8 i = 0; i < spell->targets.size(); i++) {
  8020. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8021. if (target && target->IsEntity()) {
  8022. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  8023. if (target->IsPlayer())
  8024. ((Player*)target)->SetCharSheetChanged(true);
  8025. }
  8026. }
  8027. }
  8028. else {
  8029. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  8030. if (spawn->IsPlayer())
  8031. ((Player*)spawn)->SetCharSheetChanged(true);
  8032. }
  8033. return 0;
  8034. }
  8035. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  8036. if (!lua_interface)
  8037. return 0;
  8038. Spawn* spawn = lua_interface->GetSpawn(state);
  8039. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  8040. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8041. lua_interface->ResetFunctionStack(state);
  8042. if (!spawn) {
  8043. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  8044. return 0;
  8045. }
  8046. if (!spawn->IsEntity()) {
  8047. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  8048. return 0;
  8049. }
  8050. if (spell && spell->targets.size() > 0) {
  8051. ZoneServer* zone = spell->caster->GetZone();
  8052. for (int8 i = 0; i < spell->targets.size(); i++) {
  8053. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8054. if (target && target->IsEntity()) {
  8055. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8056. if (target->IsPlayer())
  8057. ((Player*)target)->SetCharSheetChanged(true);
  8058. }
  8059. }
  8060. }
  8061. else {
  8062. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8063. if (spawn->IsPlayer())
  8064. ((Player*)spawn)->SetCharSheetChanged(true);
  8065. }
  8066. return 0;
  8067. }
  8068. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  8069. if (!lua_interface)
  8070. return 0;
  8071. Item* item = lua_interface->GetItem(state);
  8072. int8 type = lua_interface->GetInt32Value(state, 2);
  8073. lua_interface->ResetFunctionStack(state);
  8074. if (!item) {
  8075. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  8076. return 0;
  8077. }
  8078. if (type == 1)
  8079. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  8080. else if (type == 2)
  8081. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  8082. return 1;
  8083. }
  8084. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  8085. if (!lua_interface)
  8086. return 0;
  8087. Spawn* target = lua_interface->GetSpawn(state);
  8088. float val = lua_interface->GetFloatValue(state, 2);
  8089. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8090. lua_interface->ResetFunctionStack(state);
  8091. // Added from Gangrenous post
  8092. if (spell && spell->resisted)
  8093. return 0;
  8094. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  8095. if (val > 1.0f)
  8096. val = 1.0f - (val / 100.0f);
  8097. if (spell && spell->spell && spell->targets.size() > 0) {
  8098. ZoneServer* zone = spell->caster->GetZone();
  8099. for (int32 i = 0; i != spell->targets.size(); i++) {
  8100. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  8101. if (spawn && spawn->IsEntity()) {
  8102. ((Entity*)spawn)->SetSpeedMultiplier(val);
  8103. if (spawn->IsPlayer())
  8104. ((Player*)spawn)->SetCharSheetChanged(true);
  8105. }
  8106. }
  8107. }
  8108. else {
  8109. if (target && target->IsEntity()) {
  8110. ((Entity*)target)->SetSpeedMultiplier(val);
  8111. if (target->IsPlayer())
  8112. ((Player*)target)->SetCharSheetChanged(true);
  8113. }
  8114. }
  8115. return 0;
  8116. }
  8117. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  8118. if (!lua_interface)
  8119. return 0;
  8120. Spawn* spawn = lua_interface->GetSpawn(state);
  8121. int16 model = lua_interface->GetInt16Value(state, 2);
  8122. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8123. lua_interface->ResetFunctionStack(state);
  8124. if (spell && spell->spell && spell->targets.size() > 0) {
  8125. ZoneServer* zone = spell->caster->GetZone();
  8126. for (int32 i = 0; i < spell->targets.size(); i++) {
  8127. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8128. if (target)
  8129. target->SetIllusionModel(model);
  8130. }
  8131. }
  8132. else {
  8133. if (!spawn) {
  8134. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8135. return 0;
  8136. }
  8137. spawn->SetIllusionModel(model);
  8138. }
  8139. return 0;
  8140. }
  8141. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  8142. if (!lua_interface)
  8143. return 0;
  8144. Spawn* spawn = lua_interface->GetSpawn(state);
  8145. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8146. lua_interface->ResetFunctionStack(state);
  8147. if (spell && spell->spell && spell->targets.size() > 0) {
  8148. ZoneServer* zone = spell->caster->GetZone();
  8149. for (int32 i = 0; i < spell->targets.size(); i++) {
  8150. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8151. if (target)
  8152. target->SetIllusionModel(0);
  8153. }
  8154. }
  8155. else {
  8156. if (!spawn) {
  8157. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8158. return 0;
  8159. }
  8160. spawn->SetIllusionModel(0);
  8161. }
  8162. return 0;
  8163. }
  8164. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  8165. if (!lua_interface)
  8166. return 0;
  8167. Spawn* caster = lua_interface->GetSpawn(state);
  8168. Spawn* target = lua_interface->GetSpawn(state, 2);
  8169. float chance = lua_interface->GetFloatValue(state, 3);
  8170. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8171. lua_interface->ResetFunctionStack(state);
  8172. if (!caster) {
  8173. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8174. return 0;
  8175. }
  8176. if (!caster->IsEntity()) {
  8177. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  8178. return 0;
  8179. }
  8180. if (!target) {
  8181. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8182. return 0;
  8183. }
  8184. if (!target->IsEntity()) {
  8185. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  8186. return 0;
  8187. }
  8188. if (chance <= 0) {
  8189. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  8190. return 0;
  8191. }
  8192. if (!spell) {
  8193. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8194. return 0;
  8195. }
  8196. if(spell->resisted) {
  8197. return 0;
  8198. }
  8199. if (((Entity*)caster)->GetThreatTransfer()) {
  8200. return 0;
  8201. }
  8202. ThreatTransfer* transfer = new ThreatTransfer;
  8203. transfer->Target = target->GetID();
  8204. transfer->Amount = chance;
  8205. transfer->Spell = spell;
  8206. ((Entity*)caster)->SetThreatTransfer(transfer);
  8207. return 0;
  8208. }
  8209. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  8210. if (!lua_interface)
  8211. return 0;
  8212. Spawn* spawn = lua_interface->GetSpawn(state);
  8213. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8214. lua_interface->ResetFunctionStack(state);
  8215. if (!spawn) {
  8216. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  8217. return 0;
  8218. }
  8219. if (!spell) {
  8220. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8221. return 0;
  8222. }
  8223. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  8224. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  8225. if(transfer && transfer->Spell != spell) {
  8226. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  8227. return 0;
  8228. }
  8229. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  8230. }
  8231. return 0;
  8232. }
  8233. int EQ2Emu_lua_CureByType(lua_State* state) {
  8234. if (!lua_interface)
  8235. return 0;
  8236. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8237. int8 cure_count = lua_interface->GetInt8Value(state);
  8238. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8239. string cure_name = lua_interface->GetStringValue(state, 3);
  8240. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8241. Spawn* target = lua_interface->GetSpawn(state, 5);
  8242. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  8243. lua_interface->ResetFunctionStack(state);
  8244. if(spell && spell->resisted) {
  8245. return 0;
  8246. }
  8247. if (target) {
  8248. if (!target->IsEntity()) {
  8249. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8250. return 0;
  8251. }
  8252. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8253. std::string alternate_name = "item";
  8254. if(spell)
  8255. alternate_name = std::string(spell->spell->GetName());
  8256. if(!caster && spell)
  8257. caster = (Spawn*)spell->caster;
  8258. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  8259. }
  8260. }
  8261. else {
  8262. ZoneServer* zone = spell->caster->GetZone();
  8263. vector<int32> targets = spell->targets;
  8264. vector<Entity*> targets_to_cure;
  8265. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8266. for (int8 i = 0; i < targets.size(); i++) {
  8267. target = zone->GetSpawnByID(targets.at(i));
  8268. if (!target || !target->IsEntity())
  8269. continue;
  8270. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8271. targets_to_cure.push_back((Entity*)target);
  8272. }
  8273. }
  8274. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8275. vector<Entity*>::iterator itr;
  8276. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  8277. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8278. }
  8279. }
  8280. return 0;
  8281. }
  8282. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  8283. if (!lua_interface)
  8284. return 0;
  8285. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8286. if (!spell) {
  8287. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8288. lua_interface->ResetFunctionStack(state);
  8289. return 0;
  8290. }
  8291. if(spell->resisted) {
  8292. lua_interface->ResetFunctionStack(state);
  8293. return 0;
  8294. }
  8295. int8 cure_count = lua_interface->GetInt8Value(state);
  8296. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8297. string cure_name = lua_interface->GetStringValue(state, 3);
  8298. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8299. Spawn* target = lua_interface->GetSpawn(state, 5);
  8300. lua_interface->ResetFunctionStack(state);
  8301. if (target) {
  8302. if (!target->IsEntity()) {
  8303. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8304. return 0;
  8305. }
  8306. if (((Entity*)target)->GetDetCount() > 0)
  8307. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8308. }
  8309. else {
  8310. ZoneServer* zone = spell->caster->GetZone();
  8311. vector<int32> targets = spell->targets;
  8312. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8313. for (int8 i = 0; i < targets.size(); i++) {
  8314. target = zone->GetSpawnByID(targets.at(i));
  8315. if (!target || !target->IsEntity())
  8316. continue;
  8317. if (((Entity*)target)->GetDetCount() > 0)
  8318. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8319. }
  8320. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8321. }
  8322. return 0;
  8323. }
  8324. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8325. if (!lua_interface)
  8326. return 0;
  8327. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8328. lua_interface->ResetFunctionStack(state);
  8329. if (!spell) {
  8330. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8331. return 0;
  8332. }
  8333. if (!spell->caster) {
  8334. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8335. return 0;
  8336. }
  8337. if (!spell->caster->GetZone()) {
  8338. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8339. return 0;
  8340. }
  8341. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8342. return 0;
  8343. }
  8344. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8345. if (!lua_interface)
  8346. return 0;
  8347. Spawn* spawn = lua_interface->GetSpawn(state);
  8348. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8349. lua_interface->ResetFunctionStack(state);
  8350. if (!spell) {
  8351. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8352. return 0;
  8353. }
  8354. if (spawn && spawn->IsEntity())
  8355. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8356. else {
  8357. ZoneServer* zone = spell->caster->GetZone();
  8358. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8359. for (int32 i = 0; i < spell->targets.size(); i++) {
  8360. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8361. if (!spawn || !spawn->IsEntity())
  8362. continue;
  8363. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8364. }
  8365. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8366. }
  8367. return 0;
  8368. }
  8369. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8370. if (!lua_interface)
  8371. return 0;
  8372. Spawn* spawn = lua_interface->GetSpawn(state);
  8373. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8374. lua_interface->ResetFunctionStack(state);
  8375. if (!spell) {
  8376. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8377. return 0;
  8378. }
  8379. if (spawn && spawn->IsEntity())
  8380. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8381. else {
  8382. ZoneServer* zone = spell->caster->GetZone();
  8383. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8384. for (int32 i = 0; i < spell->targets.size(); i++) {
  8385. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8386. if (!spawn || !spawn->IsEntity())
  8387. continue;
  8388. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8389. }
  8390. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8391. }
  8392. return 0;
  8393. }
  8394. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8395. if (!lua_interface)
  8396. return 0;
  8397. Spawn* caster = lua_interface->GetSpawn(state);
  8398. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8399. lua_interface->ResetFunctionStack(state);
  8400. if (!caster) {
  8401. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8402. return 0;
  8403. }
  8404. if (!caster->IsPlayer()) {
  8405. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8406. return 0;
  8407. }
  8408. Spawn* target = caster->GetTarget();
  8409. if (!target) {
  8410. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8411. return 0;
  8412. }
  8413. Client* client = ((Player*)caster)->GetClient();
  8414. if (!client) {
  8415. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8416. return 0;
  8417. }
  8418. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8419. if (ho) {
  8420. ho->SetTarget(target->GetID());
  8421. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8422. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8423. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8424. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8425. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8426. deque<GroupMemberInfo*>::iterator itr;
  8427. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8428. if (group)
  8429. {
  8430. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8431. deque<GroupMemberInfo*>* members = group->GetMembers();
  8432. for (itr = members->begin(); itr != members->end(); itr++) {
  8433. if ((*itr)->client)
  8434. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8435. }
  8436. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8437. }
  8438. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8439. }
  8440. else
  8441. safe_delete(ho);
  8442. }
  8443. else {
  8444. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8445. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8446. }
  8447. else
  8448. safe_delete(ho);
  8449. }
  8450. }
  8451. return 0;
  8452. }
  8453. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8454. if (!lua_interface)
  8455. return 0;
  8456. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8457. if (!spell) {
  8458. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8459. return 0;
  8460. }
  8461. int16 triggerCount = lua_interface->GetInt16Value(state);
  8462. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8463. if (!triggerCount) {
  8464. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8465. return 0;
  8466. }
  8467. spell->num_triggers = triggerCount;
  8468. spell->had_triggers = true;
  8469. spell->cancel_after_all_triggers = cancel_after_triggers;
  8470. return 0;
  8471. }
  8472. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8473. if (!lua_interface)
  8474. return 0;
  8475. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8476. lua_interface->ResetFunctionStack(state);
  8477. if (!spell) {
  8478. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8479. return 0;
  8480. }
  8481. lua_interface->SetInt32Value(state, spell->num_triggers);
  8482. return 1;
  8483. }
  8484. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8485. if (!lua_interface)
  8486. return 0;
  8487. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8488. if (!spell) {
  8489. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8490. lua_interface->ResetFunctionStack(state);
  8491. return 0;
  8492. }
  8493. if (!spell->caster || !spell->caster->GetZone()) {
  8494. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: caster / caster zone must be set!", lua_interface->GetScriptName(state));
  8495. lua_interface->ResetFunctionStack(state);
  8496. return 0;
  8497. }
  8498. int16 remove_count = lua_interface->GetInt16Value(state);
  8499. lua_interface->ResetFunctionStack(state);
  8500. if (!remove_count)
  8501. remove_count = 1;
  8502. if (remove_count >= spell->num_triggers) {
  8503. spell->num_triggers = 0;
  8504. if (spell->cancel_after_all_triggers)
  8505. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8506. }
  8507. else {
  8508. spell->num_triggers -= remove_count;
  8509. Client* client = spell->caster->IsPlayer() ? ((Player*)spell->caster)->GetClient() : nullptr;
  8510. ClientPacketFunctions::SendMaintainedExamineUpdate(client, spell->slot_pos, spell->num_triggers, 0);
  8511. }
  8512. return 0;
  8513. }
  8514. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8515. if (!lua_interface)
  8516. return 0;
  8517. Spawn* spawn = lua_interface->GetSpawn(state);
  8518. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8519. lua_interface->ResetFunctionStack(state);
  8520. if (!spawn) {
  8521. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8522. return 0;
  8523. }
  8524. if (!copy_spawn) {
  8525. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8526. return 0;
  8527. }
  8528. spawn->CopySpawnAppearance(copy_spawn);
  8529. return 0;
  8530. }
  8531. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8532. Spawn* spawn = lua_interface->GetSpawn(state);
  8533. int8 type = lua_interface->GetInt8Value(state, 2);
  8534. lua_interface->ResetFunctionStack(state);
  8535. if (!spawn) {
  8536. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8537. return 0;
  8538. }
  8539. else if (!spawn->IsEntity()) {
  8540. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8541. return 0;
  8542. }
  8543. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8544. return 1;
  8545. }
  8546. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8547. if (!lua_interface)
  8548. return 0;
  8549. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8550. int8 type = lua_interface->GetInt8Value(state);
  8551. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8552. lua_interface->ResetFunctionStack(state);
  8553. if (!spell) {
  8554. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8555. return 0;
  8556. }
  8557. if(spell->resisted) {
  8558. return 0;
  8559. }
  8560. if (spawn) {
  8561. if (!spawn->IsEntity()) {
  8562. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8563. return 0;
  8564. }
  8565. Entity* entity = ((Entity*)spawn);
  8566. entity->AddImmunity(spell, type);
  8567. }
  8568. else if(spell->caster && spell->caster->GetZone()) {
  8569. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8570. for (int8 i = 0; i < spell->targets.size(); i++) {
  8571. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8572. if (!spawn || !spawn->IsEntity())
  8573. continue;
  8574. Entity* entity = ((Entity*)spawn);
  8575. entity->AddImmunity(spell, type);
  8576. }
  8577. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8578. }
  8579. return 0;
  8580. }
  8581. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8582. if (!lua_interface)
  8583. return 0;
  8584. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8585. int8 type = lua_interface->GetInt8Value(state);
  8586. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8587. lua_interface->ResetFunctionStack(state);
  8588. if (!spell) {
  8589. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8590. return 0;
  8591. }
  8592. if (spawn) {
  8593. if (!spawn->IsEntity()) {
  8594. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8595. return 0;
  8596. }
  8597. Entity* entity = ((Entity*)spawn);
  8598. entity->RemoveImmunity(spell, type);
  8599. }
  8600. else if(spell->caster && spell->caster->GetZone()) {
  8601. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8602. for (int8 i = 0; i < spell->targets.size(); i++) {
  8603. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8604. if (!spawn || !spawn->IsEntity())
  8605. continue;
  8606. Entity* entity = ((Entity*)spawn);
  8607. entity->RemoveImmunity(spell, type);
  8608. }
  8609. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8610. }
  8611. return 0;
  8612. }
  8613. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8614. if (!lua_interface)
  8615. return 0;
  8616. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8617. if (!spell) {
  8618. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8619. lua_interface->ResetFunctionStack(state);
  8620. return 0;
  8621. }
  8622. if(spell->resisted) {
  8623. lua_interface->ResetFunctionStack(state);
  8624. return 0;
  8625. }
  8626. float snare = lua_interface->GetFloatValue(state);
  8627. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8628. lua_interface->ResetFunctionStack(state);
  8629. // convert the val to the speed multipler value (100 - val)
  8630. float val = 100.0 - snare;
  8631. val /= 100.0;
  8632. if (spawn) {
  8633. if (!spawn->IsEntity()) {
  8634. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8635. return 0;
  8636. }
  8637. ((Entity*)spawn)->SetSnareValue(spell, val);
  8638. }
  8639. else if(spell->caster && spell->caster->GetZone()) {
  8640. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8641. for (int8 i = 0; i < spell->targets.size(); i++) {
  8642. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8643. if (!spawn || !spawn->IsEntity())
  8644. continue;
  8645. ((Entity*)spawn)->SetSnareValue(spell, val);
  8646. }
  8647. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8648. }
  8649. return 0;
  8650. }
  8651. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8652. if (!lua_interface)
  8653. return 0;
  8654. Spawn* spawn = lua_interface->GetSpawn(state);
  8655. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8656. lua_interface->ResetFunctionStack(state);
  8657. if (!spawn) {
  8658. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8659. return 0;
  8660. }
  8661. if (race_id == 0) {
  8662. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8663. return 0;
  8664. }
  8665. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8666. return 1;
  8667. }
  8668. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8669. if (!lua_interface)
  8670. return 0;
  8671. Spawn* spawn = lua_interface->GetSpawn(state);
  8672. lua_interface->ResetFunctionStack(state);
  8673. if (!spawn) {
  8674. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8675. return 0;
  8676. }
  8677. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8678. return 1;
  8679. }
  8680. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8681. if (!lua_interface)
  8682. return 0;
  8683. Spawn* spawn = lua_interface->GetSpawn(state);
  8684. lua_interface->ResetFunctionStack(state);
  8685. if (!spawn) {
  8686. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8687. return 0;
  8688. }
  8689. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8690. return 1;
  8691. }
  8692. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8693. if (!lua_interface)
  8694. return 0;
  8695. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8696. lua_interface->ResetFunctionStack(state);
  8697. if (!spell) {
  8698. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8699. return 0;
  8700. }
  8701. lua_interface->SetStringValue(state, spell->spell->GetName());
  8702. return 1;
  8703. }
  8704. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8705. if (!lua_interface)
  8706. return 0;
  8707. Quest* quest = lua_interface->GetQuest(state);
  8708. lua_interface->ResetFunctionStack(state);
  8709. if (!quest) {
  8710. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8711. return 0;
  8712. }
  8713. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8714. return 1;
  8715. }
  8716. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8717. if (!lua_interface)
  8718. return 0;
  8719. Quest* quest = lua_interface->GetQuest(state);
  8720. int32 flags = lua_interface->GetInt32Value(state, 2);
  8721. lua_interface->ResetFunctionStack(state);
  8722. if (!quest) {
  8723. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8724. return 0;
  8725. }
  8726. quest->SetQuestFlags(flags);
  8727. return 0;
  8728. }
  8729. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8730. if (!lua_interface)
  8731. return 0;
  8732. Quest* quest = lua_interface->GetQuest(state);
  8733. Spawn* player = lua_interface->GetSpawn(state, 2);
  8734. int32 step = lua_interface->GetInt32Value(state, 3);
  8735. int32 duration = lua_interface->GetInt32Value(state, 4);
  8736. string action = lua_interface->GetStringValue(state, 5);
  8737. lua_interface->ResetFunctionStack(state);
  8738. if (!quest) {
  8739. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8740. return 0;
  8741. }
  8742. if (!player) {
  8743. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8744. return 0;
  8745. }
  8746. if (!player->IsPlayer()) {
  8747. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8748. return 0;
  8749. }
  8750. if (step == 0) {
  8751. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8752. return 0;
  8753. }
  8754. if (duration == 0) {
  8755. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8756. return 0;
  8757. }
  8758. if (action.length() == 0) {
  8759. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8760. return 0;
  8761. }
  8762. Client* client = ((Player*)player)->GetClient();
  8763. if (!client) {
  8764. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8765. return 0;
  8766. }
  8767. quest->SetTimerStep(step);
  8768. quest->AddFailedAction(step, action);
  8769. quest->SetStepTimer(duration);
  8770. client->AddQuestTimer(quest->GetQuestID());
  8771. return 0;
  8772. }
  8773. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8774. if (!lua_interface)
  8775. return 0;
  8776. Quest* quest = lua_interface->GetQuest(state);
  8777. Spawn* player = lua_interface->GetSpawn(state, 2);
  8778. lua_interface->ResetFunctionStack(state);
  8779. if (!quest) {
  8780. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8781. return 0;
  8782. }
  8783. if (!player) {
  8784. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8785. return 0;
  8786. }
  8787. if (!player->IsPlayer()) {
  8788. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8789. return 0;
  8790. }
  8791. Client* client = ((Player*)player)->GetClient();
  8792. if (!client) {
  8793. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8794. return 0;
  8795. }
  8796. quest->SetTimerStep(0);
  8797. quest->SetStepTimer(0);
  8798. client->RemoveQuestTimer(quest->GetQuestID());
  8799. return 0;
  8800. }
  8801. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8802. if (!lua_interface)
  8803. return 0;
  8804. Spawn* player = lua_interface->GetSpawn(state);
  8805. Quest* quest = lua_interface->GetQuest(state, 2);
  8806. int32 step = lua_interface->GetInt32Value(state, 3);
  8807. lua_interface->ResetFunctionStack(state);
  8808. if (!player) {
  8809. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8810. return 0;
  8811. }
  8812. if (!player->IsPlayer()) {
  8813. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8814. return 0;
  8815. }
  8816. if (!quest) {
  8817. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8818. return 0;
  8819. }
  8820. if (step == 0) {
  8821. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8822. return 0;
  8823. }
  8824. Client* client = ((Player*)player)->GetClient();
  8825. if (!client) {
  8826. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8827. return 0;
  8828. }
  8829. if (quest->RemoveQuestStep(step, client)) {
  8830. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8831. client->GetCurrentZone()->SendQuestUpdates(client);
  8832. }
  8833. else
  8834. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8835. return 0;
  8836. }
  8837. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8838. if (!lua_interface)
  8839. return 0;
  8840. Quest* quest = lua_interface->GetQuest(state, 1);
  8841. int32 step = lua_interface->GetInt32Value(state, 2);
  8842. string desc = lua_interface->GetStringValue(state, 3);
  8843. string task_group = lua_interface->GetStringValue(state, 4);
  8844. lua_interface->ResetFunctionStack(state);
  8845. if (!quest) {
  8846. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8847. return 0;
  8848. }
  8849. if (step == 0) {
  8850. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8851. return 0;
  8852. }
  8853. QuestStep* quest_step = quest->GetQuestStep(step);
  8854. if (!quest_step) {
  8855. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8856. return 0;
  8857. }
  8858. quest_step->SetStepProgress(0);
  8859. quest_step->SetTaskGroup(task_group);
  8860. quest_step->SetDescription(desc);
  8861. return 0;
  8862. }
  8863. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8864. if (!lua_interface)
  8865. return 0;
  8866. Quest* quest = lua_interface->GetQuest(state);
  8867. int32 step = lua_interface->GetInt32Value(state, 2);
  8868. string action = lua_interface->GetStringValue(state, 3);
  8869. lua_interface->ResetFunctionStack(state);
  8870. if (!quest) {
  8871. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8872. return 0;
  8873. }
  8874. if (step == 0) {
  8875. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8876. return 0;
  8877. }
  8878. if (action.length() == 0) {
  8879. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8880. return 0;
  8881. }
  8882. quest->AddFailedAction(step, action);
  8883. return 0;
  8884. }
  8885. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8886. if (!lua_interface)
  8887. return 0;
  8888. Spawn* player = lua_interface->GetSpawn(state);
  8889. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8890. int32 step = lua_interface->GetInt32Value(state, 3);
  8891. lua_interface->ResetFunctionStack(state);
  8892. if (!player) {
  8893. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8894. return 0;
  8895. }
  8896. if (!player->IsPlayer()) {
  8897. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8898. return 0;
  8899. }
  8900. if (quest_id == 0) {
  8901. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8902. return 0;
  8903. }
  8904. if (step == 0) {
  8905. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8906. return 0;
  8907. }
  8908. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8909. if (!quest) {
  8910. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8911. return 0;
  8912. }
  8913. quest->StepFailed(step);
  8914. return 0;
  8915. }
  8916. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8917. if (!lua_interface)
  8918. return 0;
  8919. Spawn* player = lua_interface->GetSpawn(state);
  8920. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8921. lua_interface->ResetFunctionStack(state);
  8922. if (!player) {
  8923. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8924. return 0;
  8925. }
  8926. if (!player->IsPlayer()) {
  8927. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8928. return 0;
  8929. }
  8930. if (quest_id == 0) {
  8931. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8932. return 0;
  8933. }
  8934. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestCompletedCount(quest_id));
  8935. return 1;
  8936. }
  8937. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8938. if (!lua_interface)
  8939. return 0;
  8940. string name = lua_interface->GetStringValue(state);
  8941. string value = lua_interface->GetStringValue(state, 2);
  8942. string comment = lua_interface->GetStringValue(state, 3);
  8943. lua_interface->ResetFunctionStack(state);
  8944. if (name.length() == 0) {
  8945. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8946. return 0;
  8947. }
  8948. if (value.length() == 0) {
  8949. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8950. return 0;
  8951. }
  8952. string varname = string("lua_").append(name);
  8953. Variable* var = variables.FindVariable(varname);
  8954. if (var)
  8955. var->SetValue(value.c_str());
  8956. else {
  8957. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8958. variables.AddVariable(var);
  8959. }
  8960. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8961. return 0;
  8962. }
  8963. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8964. if (!lua_interface)
  8965. return 0;
  8966. string name = lua_interface->GetStringValue(state);
  8967. lua_interface->ResetFunctionStack(state);
  8968. if (name.length() == 0) {
  8969. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8970. return 0;
  8971. }
  8972. string varname = string("lua_").append(name);
  8973. Variable* var = variables.FindVariable(varname);
  8974. if (var)
  8975. lua_interface->SetStringValue(state, var->GetValue());
  8976. else
  8977. lua_interface->SetStringValue(state, "NULL");
  8978. return 1;
  8979. }
  8980. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8981. if (!lua_interface)
  8982. return 0;
  8983. Spawn* player = lua_interface->GetSpawn(state);
  8984. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8985. lua_interface->ResetFunctionStack(state);
  8986. if (!player) {
  8987. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8988. return 0;
  8989. }
  8990. if (!player->IsPlayer()) {
  8991. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8992. return 0;
  8993. }
  8994. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8995. return 1;
  8996. }
  8997. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8998. if (!lua_interface)
  8999. return 0;
  9000. Spawn* player = lua_interface->GetSpawn(state);
  9001. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9002. lua_interface->ResetFunctionStack(state);
  9003. if (!player) {
  9004. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9005. return 0;
  9006. }
  9007. if (!player->IsPlayer()) {
  9008. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9009. return 0;
  9010. }
  9011. Language* language = master_languages_list.GetLanguage(language_id);
  9012. if (language)
  9013. {
  9014. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  9015. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID(), 0);
  9016. }
  9017. return 0;
  9018. }
  9019. int EQ2Emu_lua_IsNight(lua_State* state) {
  9020. if (!lua_interface)
  9021. return 0;
  9022. ZoneServer* zone = lua_interface->GetZone(state);
  9023. lua_interface->ResetFunctionStack(state);
  9024. if (!zone) {
  9025. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  9026. return 0;
  9027. }
  9028. lua_interface->SetBooleanValue(state, zone->IsDusk());
  9029. return 1;
  9030. }
  9031. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  9032. if (!lua_interface)
  9033. return 0;
  9034. Spawn* spawn = lua_interface->GetSpawn(state);
  9035. lua_interface->ResetFunctionStack(state);
  9036. if (!spawn) {
  9037. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  9038. return 0;
  9039. }
  9040. if (!spawn->IsWidget()) {
  9041. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  9042. return 0;
  9043. }
  9044. ((Widget*)spawn)->SetMultiFloorLift(true);
  9045. if (spawn->GetZone())
  9046. spawn->GetZone()->AddTransportSpawn(spawn);
  9047. return 0;
  9048. }
  9049. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  9050. if (!lua_interface)
  9051. return 0;
  9052. Spawn* player = lua_interface->GetSpawn(state);
  9053. int32 path = lua_interface->GetInt32Value(state, 2);
  9054. lua_interface->ResetFunctionStack(state);
  9055. if (!player) {
  9056. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9057. return 0;
  9058. }
  9059. if (!player->IsPlayer()) {
  9060. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9061. return 0;
  9062. }
  9063. if (path == 0) {
  9064. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  9065. return 0;
  9066. }
  9067. Client* client = ((Player*)player)->GetClient();
  9068. if (!client) {
  9069. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9070. return 0;
  9071. }
  9072. client->SendFlightAutoMount(path);
  9073. return 0;
  9074. }
  9075. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  9076. if (!lua_interface)
  9077. return 0;
  9078. Spawn* player = lua_interface->GetSpawn(state);
  9079. if (!player) {
  9080. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9081. return 0;
  9082. }
  9083. if (!player->IsPlayer()) {
  9084. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9085. return 0;
  9086. }
  9087. Client* client = ((Player*)player)->GetClient();
  9088. if (!client) {
  9089. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9090. return 0;
  9091. }
  9092. client->EndAutoMount();
  9093. return 0;
  9094. }
  9095. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  9096. if (!lua_interface)
  9097. return 0;
  9098. Spawn* player = lua_interface->GetSpawn(state);
  9099. lua_interface->ResetFunctionStack(state);
  9100. if (!player) {
  9101. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  9102. return 0;
  9103. }
  9104. if (!player->IsPlayer()) {
  9105. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9106. return 0;
  9107. }
  9108. Client* client = ((Player*)player)->GetClient();
  9109. if (!client) {
  9110. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9111. return 0;
  9112. }
  9113. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  9114. return 1;
  9115. }
  9116. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  9117. if (!lua_interface)
  9118. return 0;
  9119. Spawn* player = lua_interface->GetSpawn(state);
  9120. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9121. int32 value = lua_interface->GetInt32Value(state, 3);
  9122. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9123. lua_interface->ResetFunctionStack(state);
  9124. if (!player) {
  9125. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9126. return 0;
  9127. }
  9128. if (!player->IsPlayer()) {
  9129. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9130. return 0;
  9131. }
  9132. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  9133. return 0;
  9134. }
  9135. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  9136. if (!lua_interface)
  9137. return 0;
  9138. Spawn* player = lua_interface->GetSpawn(state);
  9139. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9140. lua_interface->ResetFunctionStack(state);
  9141. if (!player) {
  9142. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9143. return 0;
  9144. }
  9145. if (!player->IsPlayer()) {
  9146. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9147. return 0;
  9148. }
  9149. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  9150. if (!hd)
  9151. return 0;
  9152. lua_interface->SetInt32Value(state, hd->Value);
  9153. lua_interface->SetInt32Value(state, hd->Value2);
  9154. return 2;
  9155. }
  9156. int EQ2Emu_lua_SetGridID(lua_State* state) {
  9157. if (!lua_interface)
  9158. return 0;
  9159. Spawn* spawn = lua_interface->GetSpawn(state);
  9160. int32 grid = lua_interface->GetInt32Value(state, 2);
  9161. lua_interface->ResetFunctionStack(state);
  9162. if (!spawn) {
  9163. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9164. return 0;
  9165. }
  9166. if (grid == 0) {
  9167. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  9168. return 0;
  9169. }
  9170. spawn->SetLocation(grid);
  9171. return 0;
  9172. }
  9173. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  9174. if (!lua_interface)
  9175. return 0;
  9176. Spawn* spawn = lua_interface->GetSpawn(state);
  9177. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9178. int32 value1 = lua_interface->GetInt32Value(state, 3);
  9179. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9180. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  9181. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  9182. lua_interface->ResetFunctionStack(state);
  9183. if (!spawn) {
  9184. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9185. return 0;
  9186. }
  9187. //Add this quest to the list of required quests for this spawn
  9188. spawn->SetRequiredHistory(event_id, value1, value2);
  9189. //If private spawn value set
  9190. if (private_spawn) {
  9191. //Set the spawn to be private when not granted access via history
  9192. spawn->AddAllowAccessSpawn(spawn);
  9193. spawn->SetPrivateQuestSpawn(true);
  9194. }
  9195. //This value will override vis_flags in the vis packet
  9196. if (flag_override > 0)
  9197. spawn->SetQuestsRequiredOverride(flag_override);
  9198. return 0;
  9199. }
  9200. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  9201. if (!lua_interface)
  9202. return 0;
  9203. Spawn* player = lua_interface->GetSpawn(state);
  9204. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9205. int32 step_id = lua_interface->GetInt32Value(state, 3);
  9206. lua_interface->ResetFunctionStack(state);
  9207. if (!player) {
  9208. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  9209. return 0;
  9210. }
  9211. if (!player->IsPlayer()) {
  9212. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  9213. return 0;
  9214. }
  9215. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  9216. return 1;
  9217. }
  9218. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  9219. if (!lua_interface)
  9220. return 0;
  9221. Spawn* player = lua_interface->GetSpawn(state);
  9222. int8 level = lua_interface->GetInt8Value(state, 2);
  9223. lua_interface->ResetFunctionStack(state);
  9224. if (!player) {
  9225. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  9226. return 0;
  9227. }
  9228. if (!player->IsPlayer()) {
  9229. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  9230. return 0;
  9231. }
  9232. if (level == 0) {
  9233. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  9234. return 0;
  9235. }
  9236. Client* client = ((Player*)player)->GetClient();
  9237. if (!client) {
  9238. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  9239. return 0;
  9240. }
  9241. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  9242. return 0;
  9243. }
  9244. int EQ2Emu_lua_AddCoin(lua_State* state) {
  9245. if (!lua_interface)
  9246. return 0;
  9247. Spawn* player = lua_interface->GetSpawn(state);
  9248. int32 amount = lua_interface->GetInt32Value(state, 2);
  9249. lua_interface->ResetFunctionStack(state);
  9250. if (!player) {
  9251. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9252. return 0;
  9253. }
  9254. if (!player->IsPlayer()) {
  9255. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9256. return 0;
  9257. }
  9258. if (amount == 0) {
  9259. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9260. return 0;
  9261. }
  9262. ((Player*)player)->AddCoins(amount);
  9263. return 0;
  9264. }
  9265. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  9266. if (!lua_interface)
  9267. return 0;
  9268. Spawn* player = lua_interface->GetSpawn(state);
  9269. int32 amount = lua_interface->GetInt32Value(state, 2);
  9270. lua_interface->ResetFunctionStack(state);
  9271. if (!player) {
  9272. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9273. return 0;
  9274. }
  9275. if (!player->IsPlayer()) {
  9276. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9277. return 0;
  9278. }
  9279. if (amount == 0) {
  9280. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9281. return 0;
  9282. }
  9283. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  9284. return 1;
  9285. }
  9286. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  9287. if (!lua_interface)
  9288. return 0;
  9289. ZoneServer* zone = lua_interface->GetZone(state);
  9290. lua_interface->ResetFunctionStack(state);
  9291. if (!zone) {
  9292. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9293. return 0;
  9294. }
  9295. vector<Entity*> players = zone->GetPlayers();
  9296. if (players.size() == 0)
  9297. return 0;
  9298. lua_createtable(state, players.size(), 0);
  9299. int newTable = lua_gettop(state);
  9300. for (int32 i = 0; i < players.size(); i++) {
  9301. lua_interface->SetSpawnValue(state, players.at(i));
  9302. lua_rawseti(state, newTable, i + 1);
  9303. }
  9304. return 1;
  9305. }
  9306. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  9307. if (!lua_interface)
  9308. return 0;
  9309. ZoneServer* zone = lua_interface->GetZone(state, 1);
  9310. if (!zone) {
  9311. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9312. return 0;
  9313. }
  9314. int32 group_id = lua_interface->GetInt32Value(state, 2);
  9315. lua_interface->ResetFunctionStack(state);
  9316. //Map of <placement_id, location_id>
  9317. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  9318. map<int32, int32>::iterator itr;
  9319. vector<Spawn*> group;
  9320. for (itr = locs->begin(); itr != locs->end(); itr++) {
  9321. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  9322. if (!location) {
  9323. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  9324. return 0;
  9325. }
  9326. Spawn* spawn = 0;
  9327. if (location->entities[0]) {
  9328. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  9329. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  9330. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  9331. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  9332. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  9333. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  9334. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  9335. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  9336. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9337. spawn = zone->AddSignSpawn(location, location->entities[0]);
  9338. if(spawn && spawn->IsOmittedByDBFlag())
  9339. {
  9340. 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);
  9341. safe_delete(spawn);
  9342. continue;
  9343. }
  9344. if (spawn) {
  9345. const char* script = 0;
  9346. for (int x = 0; x < 3; x++) {
  9347. switch (x) {
  9348. case 0:
  9349. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  9350. break;
  9351. case 1:
  9352. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  9353. break;
  9354. case 2:
  9355. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  9356. break;
  9357. }
  9358. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9359. spawn->SetSpawnScript(string(script));
  9360. break;
  9361. }
  9362. }
  9363. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9364. lua_interface->SetSpawnValue(state, spawn);
  9365. group.push_back(spawn);
  9366. }
  9367. else {
  9368. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  9369. safe_delete(spawn);
  9370. }
  9371. }
  9372. }
  9373. if (!group.empty()) {
  9374. lua_createtable(state, group.size(), 0);
  9375. int newTable = lua_gettop(state);
  9376. for (int32 i = 0; i < group.size(); i++) {
  9377. lua_interface->SetSpawnValue(state, group[i]);
  9378. lua_rawseti(state, newTable, i + 1);
  9379. }
  9380. }
  9381. else
  9382. lua_pushnil(state);
  9383. return 1;
  9384. }
  9385. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9386. if (!lua_interface)
  9387. return 0;
  9388. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9389. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9390. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9391. lua_interface->ResetFunctionStack(state);
  9392. if (!spawn) {
  9393. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9394. return 0;
  9395. }
  9396. if (anim_id == 0) {
  9397. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9398. return 0;
  9399. }
  9400. if (leeway == 0)
  9401. leeway = 5000;
  9402. spawn->SetSpawnAnim(anim_id);
  9403. spawn->SetSpawnAnimLeeway(leeway);
  9404. return 0;
  9405. }
  9406. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9407. if (!lua_interface)
  9408. return 0;
  9409. Spawn* player = lua_interface->GetSpawn(state);
  9410. lua_interface->ResetFunctionStack(state);
  9411. if (!player || !player->IsPlayer()) {
  9412. return 0;
  9413. }
  9414. Client* client = ((Player*)player)->GetClient();
  9415. if (!client) {
  9416. return 0;
  9417. }
  9418. lua_interface->SetInt32Value(state, client->GetVersion());
  9419. return 1;
  9420. }
  9421. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9422. if (!lua_interface)
  9423. return 0;
  9424. Item* item = lua_interface->GetItem(state);
  9425. lua_interface->ResetFunctionStack(state);
  9426. if (!item) {
  9427. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9428. return 0;
  9429. }
  9430. lua_interface->SetInt32Value(state, item->details.item_id);
  9431. return 1;
  9432. }
  9433. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9434. if (!lua_interface)
  9435. return 0;
  9436. Spawn* spawn = lua_interface->GetSpawn(state);
  9437. lua_interface->ResetFunctionStack(state);
  9438. if (!spawn) {
  9439. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9440. return 0;
  9441. }
  9442. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9443. return 1;
  9444. }
  9445. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9446. if (!lua_interface)
  9447. return 0;
  9448. Spawn* spawn = lua_interface->GetSpawn(state);
  9449. lua_interface->ResetFunctionStack(state);
  9450. if (!spawn) {
  9451. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9452. return 0;
  9453. }
  9454. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9455. return 1;
  9456. }
  9457. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9458. if (!lua_interface)
  9459. return 0;
  9460. Spawn* spawn = lua_interface->GetSpawn(state);
  9461. lua_interface->ResetFunctionStack(state);
  9462. if (!spawn) {
  9463. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9464. return 0;
  9465. }
  9466. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9467. return 1;
  9468. }
  9469. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9470. if (!lua_interface)
  9471. return 0;
  9472. Spawn* spawn = lua_interface->GetSpawn(state);
  9473. lua_interface->ResetFunctionStack(state);
  9474. if (!spawn) {
  9475. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9476. return 0;
  9477. }
  9478. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9479. return 1;
  9480. }
  9481. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9482. if (!lua_interface)
  9483. return 0;
  9484. Spawn* spawn = lua_interface->GetSpawn(state);
  9485. float pct = lua_interface->GetFloatValue(state, 2);
  9486. lua_interface->ResetFunctionStack(state);
  9487. if (!spawn) {
  9488. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9489. return 0;
  9490. }
  9491. if (pct == 0) {
  9492. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9493. return 0;
  9494. }
  9495. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9496. lua_interface->SetInt32Value(state, amount);
  9497. return 1;
  9498. }
  9499. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9500. if (!lua_interface)
  9501. return 0;
  9502. Spawn* spawn = lua_interface->GetSpawn(state);
  9503. float pct = lua_interface->GetFloatValue(state, 2);
  9504. lua_interface->ResetFunctionStack(state);
  9505. if (!spawn) {
  9506. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9507. return 0;
  9508. }
  9509. if (pct == 0) {
  9510. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9511. return 0;
  9512. }
  9513. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9514. lua_interface->SetInt32Value(state, amount);
  9515. return 1;
  9516. }
  9517. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9518. if (!lua_interface)
  9519. return 0;
  9520. Spawn* spawn = lua_interface->GetSpawn(state);
  9521. lua_interface->ResetFunctionStack(state);
  9522. if (!spawn) {
  9523. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9524. return 0;
  9525. }
  9526. if (!spawn->IsPlayer()) {
  9527. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9528. return 0;
  9529. }
  9530. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9531. return 1;
  9532. }
  9533. int EQ2Emu_lua_Evac(lua_State* state) {
  9534. if (!lua_interface)
  9535. return 0;
  9536. Spawn* target = lua_interface->GetSpawn(state);
  9537. if (target) {
  9538. float x = target->GetZone()->GetSafeX();
  9539. float y = target->GetZone()->GetSafeY();
  9540. float z = target->GetZone()->GetSafeZ();
  9541. float h = target->GetZone()->GetSafeHeading();
  9542. target->SetX(x);
  9543. target->SetY(y);
  9544. target->SetZ(z);
  9545. target->SetHeading(h);
  9546. target->SetSpawnOrigX(x);
  9547. target->SetSpawnOrigY(y);
  9548. target->SetSpawnOrigZ(z);
  9549. target->SetSpawnOrigHeading(h);
  9550. if (target->IsPlayer()) {
  9551. Client* client = ((Player*)target)->GetClient();
  9552. if (client) {
  9553. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9554. int numargs = lua_interface->GetNumberOfArgs(state);
  9555. if(numargs == 4) {
  9556. x = lua_interface->GetFloatValue(state,1);
  9557. y = lua_interface->GetFloatValue(state,2);
  9558. z = lua_interface->GetFloatValue(state,3);
  9559. h = lua_interface->GetFloatValue(state,4);
  9560. }
  9561. client->SetReloadingZone(true);
  9562. target->SetX(x);
  9563. target->SetY(y);
  9564. target->SetZ(z);
  9565. target->SetHeading(h);
  9566. target->SetSpawnOrigX(x);
  9567. target->SetSpawnOrigY(y);
  9568. target->SetSpawnOrigZ(z);
  9569. target->SetSpawnOrigHeading(h);
  9570. target->SetAppearancePosition(x,y,z);
  9571. client->SetZoningCoords(x,y,z,h);
  9572. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9573. if (packet)
  9574. {
  9575. packet->setDataByName("x", x);
  9576. packet->setDataByName("y", y);
  9577. packet->setDataByName("z", z);
  9578. client->QueuePacket(packet->serialize());
  9579. safe_delete(packet);
  9580. }
  9581. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9582. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9583. }
  9584. }
  9585. lua_interface->ResetFunctionStack(state);
  9586. }
  9587. else {
  9588. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9589. if(!spell || !spell->caster || !spell->caster->GetZone()) {
  9590. lua_interface->ResetFunctionStack(state);
  9591. return 0;
  9592. }
  9593. ZoneServer* zone = spell->caster->GetZone();
  9594. float x = spell->caster->GetZone()->GetSafeX();
  9595. float y = spell->caster->GetZone()->GetSafeY();
  9596. float z = spell->caster->GetZone()->GetSafeZ();
  9597. float h = spell->caster->GetZone()->GetSafeHeading();
  9598. int numargs = lua_interface->GetNumberOfArgs(state);
  9599. if(numargs == 4) {
  9600. x = lua_interface->GetFloatValue(state,1);
  9601. y = lua_interface->GetFloatValue(state,2);
  9602. z = lua_interface->GetFloatValue(state,3);
  9603. h = lua_interface->GetFloatValue(state,4);
  9604. }
  9605. lua_interface->ResetFunctionStack(state);
  9606. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9607. for (int32 i = 0; i < spell->targets.size(); i++) {
  9608. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9609. if (!target2)
  9610. continue;
  9611. if (target2->IsPlayer()) {
  9612. Client* client = ((Player*)target2)->GetClient();
  9613. if (client) {
  9614. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9615. client->SetReloadingZone(true);
  9616. target2->SetX(x);
  9617. target2->SetY(y);
  9618. target2->SetZ(z);
  9619. target2->SetHeading(h);
  9620. target2->SetSpawnOrigX(x);
  9621. target2->SetSpawnOrigY(y);
  9622. target2->SetSpawnOrigZ(z);
  9623. target2->SetSpawnOrigHeading(h);
  9624. target2->SetAppearancePosition(x,y,z);
  9625. client->SetZoningCoords(x,y,z,h);
  9626. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9627. if (packet)
  9628. {
  9629. packet->setDataByName("x", x);
  9630. packet->setDataByName("y", y);
  9631. packet->setDataByName("z", z);
  9632. client->QueuePacket(packet->serialize());
  9633. safe_delete(packet);
  9634. }
  9635. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9636. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9637. }
  9638. }
  9639. }
  9640. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9641. }
  9642. return 0;
  9643. }
  9644. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9645. if (!lua_interface)
  9646. return 0;
  9647. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9648. lua_interface->ResetFunctionStack(state);
  9649. if (!luaspell) {
  9650. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9651. return 0;
  9652. }
  9653. int8 tier = luaspell->spell->GetSpellTier();
  9654. lua_interface->SetInt32Value(state, tier);
  9655. return 1;
  9656. }
  9657. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9658. if (!lua_interface)
  9659. return 0;
  9660. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9661. lua_interface->ResetFunctionStack(state);
  9662. if (!luaspell) {
  9663. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9664. return 0;
  9665. }
  9666. int32 spell_id = luaspell->spell->GetSpellID();
  9667. lua_interface->SetInt32Value(state, spell_id);
  9668. return 1;
  9669. }
  9670. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9671. if (!lua_interface)
  9672. return 0;
  9673. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9674. lua_interface->ResetFunctionStack(state);
  9675. if (!spawn) {
  9676. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9677. return 0;
  9678. }
  9679. if (!spawn->IsPlayer()) {
  9680. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9681. return 0;
  9682. }
  9683. ZoneServer* zone = spawn->GetZone();
  9684. if (!zone) {
  9685. return 0;
  9686. }
  9687. Client* client = ((Player*)spawn)->GetClient();
  9688. if (!client) {
  9689. return 0;
  9690. }
  9691. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9692. return 0;
  9693. }
  9694. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9695. if (!lua_interface)
  9696. return 0;
  9697. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9698. lua_interface->ResetFunctionStack(state);
  9699. if (!spawn) {
  9700. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9701. return 0;
  9702. }
  9703. if (!spawn->IsPlayer()) {
  9704. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9705. return 0;
  9706. }
  9707. ZoneServer* zone = spawn->GetZone();
  9708. if (!zone) {
  9709. return 0;
  9710. }
  9711. Client* client = ((Player*)spawn)->GetClient();
  9712. if (!client) {
  9713. return 0;
  9714. }
  9715. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9716. return 0;
  9717. }
  9718. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9719. if (!lua_interface)
  9720. return 0;
  9721. Spawn* caster = lua_interface->GetSpawn(state);
  9722. Spawn* target = lua_interface->GetSpawn(state, 2);
  9723. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9724. string spell_name = lua_interface->GetStringValue(state, 4);
  9725. lua_interface->ResetFunctionStack(state);
  9726. if (!caster) {
  9727. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9728. return 0;
  9729. }
  9730. if (!caster->IsEntity()) {
  9731. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9732. return 0;
  9733. }
  9734. if (!target) {
  9735. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9736. return 0;
  9737. }
  9738. if (!target->IsEntity()) {
  9739. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9740. return 0;
  9741. }
  9742. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9743. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9744. return 0;
  9745. }
  9746. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9747. if (!lua_interface)
  9748. return 0;
  9749. Spawn* player = lua_interface->GetSpawn(state);
  9750. int32 amount = lua_interface->GetInt32Value(state, 2);
  9751. lua_interface->ResetFunctionStack(state);
  9752. if (player && player->IsPlayer() && amount > 0) {
  9753. ((Player*)player)->AddXP(amount);
  9754. }
  9755. return 0;
  9756. }
  9757. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9758. if (!lua_interface)
  9759. return 0;
  9760. Spawn* player = lua_interface->GetSpawn(state);
  9761. int8 type = lua_interface->GetInt8Value(state, 2);
  9762. string text = lua_interface->GetStringValue(state, 3);
  9763. lua_interface->ResetFunctionStack(state);
  9764. Client* client = 0;
  9765. if (player && player->IsPlayer())
  9766. client = ((Player*)player)->GetClient();
  9767. if (!client || text.length() == 0) {
  9768. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9769. return 0;
  9770. }
  9771. client->SimpleMessage(type, text.c_str());
  9772. return 0;
  9773. }
  9774. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9775. if (!lua_interface)
  9776. return 0;
  9777. Spawn* player = lua_interface->GetSpawn(state);
  9778. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9779. lua_interface->ResetFunctionStack(state);
  9780. Client* client = 0;
  9781. if (player && player->IsPlayer())
  9782. client = ((Player*)player)->GetClient();
  9783. if (!client || !spawn) {
  9784. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9785. return 0;
  9786. }
  9787. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9788. if (!items) {
  9789. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9790. return 0;
  9791. }
  9792. client->Loot(spawn->GetLootCoins(), items, spawn);
  9793. return 0;
  9794. }
  9795. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9796. if (!lua_interface)
  9797. return 0;
  9798. Spawn* spawnref = lua_interface->GetSpawn(state);
  9799. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9800. lua_interface->ResetFunctionStack(state);
  9801. if (spawn_id > 0 && spawnref) {
  9802. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9803. if (spawns.size() == 0) {
  9804. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9805. return 0;
  9806. }
  9807. Spawn* spawn = 0;
  9808. int16 index = MakeRandomInt(0, spawns.size());
  9809. if (index >= spawns.size() || index < 0)
  9810. index = 0;
  9811. spawn = spawns[index];
  9812. lua_interface->SetSpawnValue(state, spawn);
  9813. return 1;
  9814. }
  9815. else {
  9816. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9817. }
  9818. return 0;
  9819. }
  9820. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9821. Spawn* player = lua_interface->GetSpawn(state);
  9822. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9823. string name = lua_interface->GetStringValue(state, 3);
  9824. float distance = lua_interface->GetFloatValue(state, 4);
  9825. string command = lua_interface->GetStringValue(state, 5);
  9826. string error_text = lua_interface->GetStringValue(state, 6);
  9827. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9828. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9829. lua_interface->ResetFunctionStack(state);
  9830. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9831. if (distance == 0)
  9832. distance = 10.0f;
  9833. if (command.length() == 0)
  9834. command = name;
  9835. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9836. if (spawns.size() == 0) {
  9837. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9838. return 0;
  9839. }
  9840. Spawn* spawn = 0;
  9841. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9842. spawn = *itr;
  9843. if (spawn) {
  9844. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9845. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9846. }
  9847. }
  9848. }
  9849. return 0;
  9850. }
  9851. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9852. if (!lua_interface)
  9853. return 0;
  9854. Client* client = 0;
  9855. Spawn* player = lua_interface->GetSpawn(state);
  9856. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9857. lua_interface->ResetFunctionStack(state);
  9858. if (player && player->IsPlayer() && player->GetZone())
  9859. client = ((Player*)player)->GetClient();
  9860. else{
  9861. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9862. return 0;
  9863. }
  9864. if (client) {
  9865. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9866. if (packet) {
  9867. packet->setDataByName("goal_num", goal_num);
  9868. client->QueuePacket(packet->serialize());
  9869. safe_delete(packet);
  9870. }
  9871. }
  9872. return 0;
  9873. }
  9874. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9875. if (!lua_interface)
  9876. return 0;
  9877. Client* client = 0;
  9878. Spawn* player = lua_interface->GetSpawn(state);
  9879. lua_interface->ResetFunctionStack(state);
  9880. if (player && player->IsPlayer() && player->GetZone())
  9881. client = ((Player*)player)->GetClient();
  9882. else {
  9883. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9884. return 0;
  9885. }
  9886. if (client) {
  9887. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9888. }
  9889. return 0;
  9890. }
  9891. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9892. if (!lua_interface)
  9893. return 0;
  9894. Client* client = 0;
  9895. Spawn* player = lua_interface->GetSpawn(state);
  9896. float duration = lua_interface->GetFloatValue(state, 2);
  9897. string text = lua_interface->GetStringValue(state, 3);
  9898. string voice = lua_interface->GetStringValue(state, 4);
  9899. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9900. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9901. string signal = lua_interface->GetStringValue(state, 7);
  9902. string goal1 = lua_interface->GetStringValue(state, 8);
  9903. string task1 = lua_interface->GetStringValue(state, 9);
  9904. string goal2 = lua_interface->GetStringValue(state, 10);
  9905. string task2 = lua_interface->GetStringValue(state, 11);
  9906. string goal3 = lua_interface->GetStringValue(state, 12);
  9907. string task3 = lua_interface->GetStringValue(state, 13);
  9908. string goal4 = lua_interface->GetStringValue(state, 14);
  9909. string task4 = lua_interface->GetStringValue(state, 15);
  9910. lua_interface->ResetFunctionStack(state);
  9911. if (!player) {
  9912. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9913. return 0;
  9914. }
  9915. if (!player->IsPlayer()) {
  9916. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9917. return 0;
  9918. }
  9919. else
  9920. client = ((Player*)player)->GetClient();
  9921. if (!client) {
  9922. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9923. return 0;
  9924. }
  9925. if (text.length() == 0) {
  9926. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9927. return 0;
  9928. }
  9929. if (duration >= 0 && duration < 2)
  9930. duration = 2;
  9931. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9932. if (packet) {
  9933. packet->setDataByName("open_seconds_max", duration);
  9934. packet->setDataByName("text", text.c_str());
  9935. packet->setDataByName("voice", voice.c_str());
  9936. int8 num_goals = 1;
  9937. if (task2.length() > 0)
  9938. num_goals++;
  9939. if (task3.length() > 0)
  9940. num_goals++;
  9941. if (task4.length() > 0)
  9942. num_goals++;
  9943. packet->setArrayLengthByName("num_goals", num_goals);
  9944. for (int8 i = 0; i < num_goals; i++) {
  9945. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9946. }
  9947. if (goal1.length() > 0)
  9948. packet->setArrayDataByName("goal_text", goal1.c_str());
  9949. if (goal2.length() > 0)
  9950. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9951. if (goal3.length() > 0)
  9952. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9953. if (goal4.length() > 0)
  9954. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9955. packet->setSubArrayDataByName("task_text", task1.c_str());
  9956. if (task2.length() > 0)
  9957. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9958. if (task3.length() > 0)
  9959. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9960. if (task4.length() > 0)
  9961. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9962. packet->setDataByName("complete_sound", "click");
  9963. packet->setDataByName("signal", signal.c_str());
  9964. packet->setDataByName("voice_key1", voice_key1);
  9965. packet->setDataByName("voice_key2", voice_key2);
  9966. client->QueuePacket(packet->serialize());
  9967. safe_delete(packet);
  9968. }
  9969. return 0;
  9970. }
  9971. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9972. if (!lua_interface)
  9973. return 0;
  9974. Client* client = 0;
  9975. Spawn* player = lua_interface->GetSpawn(state);
  9976. string window = lua_interface->GetStringValue(state, 2);
  9977. int8 show = lua_interface->GetInt8Value(state, 3);
  9978. lua_interface->ResetFunctionStack(state);
  9979. if (!player) {
  9980. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9981. return 0;
  9982. }
  9983. if (!player->IsPlayer()) {
  9984. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9985. return 0;
  9986. }
  9987. else
  9988. client = ((Player*)player)->GetClient();
  9989. if (!client) {
  9990. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9991. return 0;
  9992. }
  9993. if (window.length() == 0) {
  9994. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9995. return 0;
  9996. }
  9997. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9998. if (packet) {
  9999. packet->setDataByName("window", window.c_str());
  10000. packet->setDataByName("show", show);
  10001. client->QueuePacket(packet->serialize());
  10002. safe_delete(packet);
  10003. }
  10004. return 0;
  10005. }
  10006. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  10007. //See GameEvents.txt for options that can be used for this function
  10008. if (!lua_interface)
  10009. return 0;
  10010. Client* client = 0;
  10011. Spawn* player = lua_interface->GetSpawn(state);
  10012. string event_name = lua_interface->GetStringValue(state, 2);
  10013. int8 enabled = lua_interface->GetInt8Value(state, 3);
  10014. lua_interface->ResetFunctionStack(state);
  10015. if (!player || !player->IsPlayer()) {
  10016. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  10017. return 0;
  10018. }
  10019. client = ((Player*)player)->GetClient();
  10020. if (!client) {
  10021. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  10022. return 0;
  10023. }
  10024. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  10025. if (packet) {
  10026. packet->setDataByName("event_name", event_name.c_str());
  10027. packet->setDataByName("enabled", enabled);
  10028. client->QueuePacket(packet->serialize());
  10029. safe_delete(packet);
  10030. }
  10031. return 0;
  10032. }
  10033. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  10034. if (!lua_interface)
  10035. return 0;
  10036. Spawn* player = lua_interface->GetSpawn(state);
  10037. lua_interface->ResetFunctionStack(state);
  10038. if (player && player->IsPlayer()) {
  10039. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  10040. return 1;
  10041. }
  10042. return 0;
  10043. }
  10044. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  10045. if (!lua_interface)
  10046. return 0;
  10047. Spawn* player = lua_interface->GetSpawn(state);
  10048. int8 step = lua_interface->GetInt8Value(state, 2);
  10049. lua_interface->ResetFunctionStack(state);
  10050. if (player && player->IsPlayer() && step > 0) {
  10051. ((Player*)player)->SetTutorialStep(step);
  10052. }
  10053. return 0;
  10054. }
  10055. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  10056. if (!lua_interface)
  10057. return 0;
  10058. Client* client = 0;
  10059. Spawn* player = lua_interface->GetSpawn(state);
  10060. string window = lua_interface->GetStringValue(state, 2);
  10061. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  10062. lua_interface->ResetFunctionStack(state);
  10063. if (!player) {
  10064. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  10065. return 0;
  10066. }
  10067. if (!player->IsPlayer()) {
  10068. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  10069. return 0;
  10070. }
  10071. else
  10072. client = ((Player*)player)->GetClient();
  10073. if (!client) {
  10074. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  10075. return 0;
  10076. }
  10077. if (window.length() == 0) {
  10078. lua_interface->LogError("LUA FlashWindow required parameters not given");
  10079. return 0;
  10080. }
  10081. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  10082. if (packet) {
  10083. packet->setDataByName("window", window.c_str());
  10084. packet->setDataByName("flash_seconds", flash_seconds);
  10085. client->QueuePacket(packet->serialize());
  10086. safe_delete(packet);
  10087. }
  10088. return 0;
  10089. }
  10090. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  10091. if (!lua_interface)
  10092. return 0;
  10093. Spawn* spawn = lua_interface->GetSpawn(state);
  10094. Spawn* target = lua_interface->GetSpawn(state, 2);
  10095. lua_interface->ResetFunctionStack(state);
  10096. if (spawn && target)
  10097. return spawn->CheckLoS(target);
  10098. return 0;
  10099. }
  10100. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  10101. if (!lua_interface)
  10102. return 0;
  10103. Spawn* spawn = lua_interface->GetSpawn(state);
  10104. float x = lua_interface->GetFloatValue(state, 2);
  10105. float y = lua_interface->GetFloatValue(state, 3);
  10106. float z = lua_interface->GetFloatValue(state, 4);
  10107. lua_interface->ResetFunctionStack(state);
  10108. if (spawn)
  10109. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  10110. return 0;
  10111. }
  10112. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  10113. if (!lua_interface)
  10114. return 0;
  10115. ZoneServer* zone = lua_interface->GetZone(state);
  10116. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  10117. lua_interface->ResetFunctionStack(state);
  10118. if (zone)
  10119. zone->SetExpansionFlag(xpackFlag);
  10120. return 0;
  10121. }
  10122. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  10123. if (!lua_interface)
  10124. return 0;
  10125. ZoneServer* zone = lua_interface->GetZone(state);
  10126. lua_interface->ResetFunctionStack(state);
  10127. if (zone) {
  10128. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  10129. return 1;
  10130. }
  10131. return 0;
  10132. }
  10133. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  10134. if (!lua_interface)
  10135. return 0;
  10136. ZoneServer* zone = lua_interface->GetZone(state);
  10137. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  10138. lua_interface->ResetFunctionStack(state);
  10139. if (zone)
  10140. zone->SetHolidayFlag(holidayFlag);
  10141. return 0;
  10142. }
  10143. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  10144. if (!lua_interface)
  10145. return 0;
  10146. ZoneServer* zone = lua_interface->GetZone(state);
  10147. lua_interface->ResetFunctionStack(state);
  10148. if (zone) {
  10149. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  10150. return 1;
  10151. }
  10152. return 0;
  10153. }
  10154. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  10155. if (!lua_interface)
  10156. return 0;
  10157. Spawn* player = lua_interface->GetSpawn(state);
  10158. ZoneServer* zone = player->GetZone();
  10159. bool canbind = lua_interface->GetInt32Value(state, 2);
  10160. lua_interface->ResetFunctionStack(state);
  10161. if (zone)
  10162. zone->SetCanBind(canbind);
  10163. return 0;
  10164. }
  10165. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  10166. if (!lua_interface)
  10167. return 0;
  10168. Spawn* player = lua_interface->GetSpawn(state);
  10169. ZoneServer* zone = player->GetZone();
  10170. lua_interface->ResetFunctionStack(state);
  10171. if (zone) {
  10172. lua_interface->SetInt32Value(state, zone->GetCanBind());
  10173. return 1;
  10174. }
  10175. return 0;
  10176. }
  10177. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  10178. if (!lua_interface)
  10179. return 0;
  10180. Spawn* player = lua_interface->GetSpawn(state);
  10181. ZoneServer* zone = player->GetZone();
  10182. bool cangate = lua_interface->GetInt32Value(state, 2);
  10183. lua_interface->ResetFunctionStack(state);
  10184. if (zone)
  10185. zone->SetCanGate(cangate);
  10186. return 0;
  10187. }
  10188. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  10189. if (!lua_interface)
  10190. return 0;
  10191. Spawn* player = lua_interface->GetSpawn(state);
  10192. ZoneServer* zone = player->GetZone();
  10193. lua_interface->ResetFunctionStack(state);
  10194. if (zone) {
  10195. lua_interface->SetInt32Value(state, zone->GetCanGate());
  10196. return 1;
  10197. }
  10198. return 0;
  10199. }
  10200. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  10201. if (!lua_interface)
  10202. return 0;
  10203. Spawn* spawn = lua_interface->GetSpawn(state);
  10204. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  10205. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  10206. float distance = lua_interface->GetFloatValue(state, 4);
  10207. string in_range_function = lua_interface->GetStringValue(state, 5);
  10208. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  10209. lua_interface->ResetFunctionStack(state);
  10210. if (spawn && distance > 0 && in_range_function.length() > 0)
  10211. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  10212. return 0;
  10213. }
  10214. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  10215. if (!lua_interface)
  10216. return 0;
  10217. Spawn* spawn = lua_interface->GetSpawn(state);
  10218. Spawn* target = lua_interface->GetSpawn(state, 2);
  10219. lua_interface->ResetFunctionStack(state);
  10220. if (spawn && target)
  10221. {
  10222. if (spawn->IsPlayer() && target->IsEntity())
  10223. {
  10224. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  10225. return 1;
  10226. }
  10227. else if (spawn->IsEntity() && target->IsEntity())
  10228. {
  10229. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  10230. return 1;
  10231. }
  10232. }
  10233. return 0;
  10234. }
  10235. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  10236. if (!lua_interface)
  10237. return 0;
  10238. Spawn* spawn = lua_interface->GetSpawn(state);
  10239. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10240. lua_interface->ResetFunctionStack(state);
  10241. if (spawn && spawn->IsEntity())
  10242. {
  10243. ((Entity*)spawn)->SetSeeInvisSpell(val);
  10244. if (spawn->IsPlayer())
  10245. {
  10246. Client* client = ((Player*)spawn)->GetClient();
  10247. if (client)
  10248. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  10249. }
  10250. }
  10251. return 0;
  10252. }
  10253. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  10254. if (!lua_interface)
  10255. return 0;
  10256. Spawn* spawn = lua_interface->GetSpawn(state);
  10257. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10258. lua_interface->ResetFunctionStack(state);
  10259. if (spawn && spawn->IsEntity())
  10260. {
  10261. ((Entity*)spawn)->SetSeeHideSpell(val);
  10262. if (spawn->IsPlayer())
  10263. {
  10264. Client* client = ((Player*)spawn)->GetClient();
  10265. if (client)
  10266. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  10267. }
  10268. }
  10269. return 0;
  10270. }
  10271. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  10272. {
  10273. if (!lua_interface)
  10274. return 0;
  10275. Spawn* player = lua_interface->GetSpawn(state);
  10276. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10277. string command = lua_interface->GetStringValue(state, 3);
  10278. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10279. lua_interface->ResetFunctionStack(state);
  10280. if (spawn && player && player->IsPlayer())
  10281. {
  10282. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10283. bool res = false;
  10284. if (cmd)
  10285. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  10286. lua_interface->SetBooleanValue(state, res);
  10287. return 1;
  10288. }
  10289. return 0;
  10290. }
  10291. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  10292. {
  10293. if (!lua_interface)
  10294. return 0;
  10295. Spawn* spawn = lua_interface->GetSpawn(state);
  10296. int32 charID = lua_interface->GetInt32Value(state, 2);
  10297. string command = lua_interface->GetStringValue(state, 3);
  10298. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10299. lua_interface->ResetFunctionStack(state);
  10300. if (spawn && charID)
  10301. {
  10302. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10303. bool res = false;
  10304. if (cmd)
  10305. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  10306. lua_interface->SetBooleanValue(state, res);
  10307. return 1;
  10308. }
  10309. return 0;
  10310. }
  10311. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  10312. {
  10313. if (!lua_interface)
  10314. return 0;
  10315. Spawn* spawn = lua_interface->GetSpawn(state);
  10316. string command = lua_interface->GetStringValue(state, 2);
  10317. lua_interface->ResetFunctionStack(state);
  10318. if (spawn && command.length() > 0)
  10319. spawn->RemovePrimaryEntityCommand(command.c_str());
  10320. return 0;
  10321. }
  10322. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  10323. if (!lua_interface)
  10324. return 0;
  10325. Spawn* spawn = lua_interface->GetSpawn(state);
  10326. float distance = lua_interface->GetFloatValue(state, 2);
  10327. string command = lua_interface->GetStringValue(state, 3);
  10328. Spawn* player = lua_interface->GetSpawn(state, 4);
  10329. lua_interface->ResetFunctionStack(state);
  10330. if (spawn) {
  10331. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  10332. }
  10333. return 0;
  10334. }
  10335. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  10336. if (!lua_interface)
  10337. return 0;
  10338. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10339. Spawn* spawn = lua_interface->GetSpawn(state);
  10340. Spawn* player = lua_interface->GetSpawn(state, 2);
  10341. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  10342. lua_interface->ResetFunctionStack(state);
  10343. if (spawn && player && transport_id && player->IsPlayer()) {
  10344. Client* client = 0;
  10345. if (player && player->IsPlayer())
  10346. client = ((Player*)player)->GetClient();
  10347. if (!client)
  10348. return 0;
  10349. vector<TransportDestination*> destinations;
  10350. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  10351. if (destinations.size())
  10352. {
  10353. client->SetTemporaryTransportID(transport_id);
  10354. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  10355. }
  10356. else
  10357. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  10358. }
  10359. return 0;
  10360. }
  10361. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  10362. if (!lua_interface)
  10363. return 0;
  10364. Spawn* player = lua_interface->GetSpawn(state);
  10365. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  10366. lua_interface->ResetFunctionStack(state);
  10367. if (player && player->IsPlayer()) {
  10368. Client* client = 0;
  10369. if (player && player->IsPlayer())
  10370. client = ((Player*)player)->GetClient();
  10371. if (!client)
  10372. return 0;
  10373. client->SetTemporaryTransportID(transport_id);
  10374. }
  10375. return 0;
  10376. }
  10377. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10378. if (!lua_interface)
  10379. return 0;
  10380. Spawn* player = lua_interface->GetSpawn(state);
  10381. lua_interface->ResetFunctionStack(state);
  10382. if (player && player->IsPlayer()) {
  10383. Client* client = 0;
  10384. if (player && player->IsPlayer())
  10385. client = ((Player*)player)->GetClient();
  10386. if (!client)
  10387. return 0;
  10388. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10389. return 1;
  10390. }
  10391. return 0;
  10392. }
  10393. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10394. if (!lua_interface)
  10395. return 0;
  10396. Spawn* spawn = lua_interface->GetSpawn(state);
  10397. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10398. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10399. if (!spawn) {
  10400. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10401. return 0;
  10402. }
  10403. if (!spawn->IsEntity()) {
  10404. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10405. return 0;
  10406. }
  10407. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10408. {
  10409. 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);
  10410. return 0;
  10411. }
  10412. lua_interface->ResetFunctionStack(state);
  10413. if (spell && spell->targets.size() > 0) {
  10414. ZoneServer* zone = spell->caster->GetZone();
  10415. for (int8 i = 0; i < spell->targets.size(); i++) {
  10416. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10417. if (target && target->IsEntity()) {
  10418. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10419. if (target->IsPlayer())
  10420. ((Player*)target)->SetCharSheetChanged(true);
  10421. }
  10422. }
  10423. }
  10424. else {
  10425. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10426. if (spawn->IsPlayer())
  10427. ((Player*)spawn)->SetCharSheetChanged(true);
  10428. }
  10429. return 0;
  10430. }
  10431. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10432. if (!lua_interface)
  10433. return 0;
  10434. Spawn* spawn = lua_interface->GetSpawn(state);
  10435. lua_interface->ResetFunctionStack(state);
  10436. if (!spawn) {
  10437. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10438. return 0;
  10439. }
  10440. if (!spawn->IsEntity()) {
  10441. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10442. return 0;
  10443. }
  10444. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10445. return 1;
  10446. }
  10447. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10448. if (!lua_interface)
  10449. return 0;
  10450. int32 spell_id = lua_interface->GetInt32Value(state);
  10451. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10452. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10453. if (spell_id > 0) {
  10454. if (spell_tier == 0)
  10455. spell_tier = 1;
  10456. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10457. LuaSpell* lua_spell = 0;
  10458. if(custom_lua_script.size() > 0)
  10459. {
  10460. // attempt to load the custom script since it isn't already loaded
  10461. // we will re-obtain the lua_spell further below
  10462. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10463. {
  10464. 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());
  10465. lua_interface->LoadLuaSpell(custom_lua_script);
  10466. }
  10467. }
  10468. else
  10469. custom_lua_script = spell->GetSpellData()->lua_script;
  10470. if (!lua_spell && lua_interface)
  10471. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10472. if (!lua_spell)
  10473. {
  10474. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10475. return 0;
  10476. }
  10477. lua_spell->spell = new Spell(spell);
  10478. lua_interface->AddCustomSpell(lua_spell);
  10479. lua_interface->SetSpellValue(state, lua_spell);
  10480. return 1;
  10481. }
  10482. return 0;
  10483. }
  10484. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10485. if (!lua_interface)
  10486. return 0;
  10487. LuaSpell* spell = lua_interface->GetSpell(state);
  10488. string field = lua_interface->GetStringValue(state, 2);
  10489. if (!spell) {
  10490. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10491. return 0;
  10492. }
  10493. if (!spell->spell || !spell->spell->GetSpellData()) {
  10494. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10495. return 0;
  10496. }
  10497. boost::to_lower(field);
  10498. return spell->spell->GetSpellData(state, field);
  10499. }
  10500. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10501. if (!lua_interface)
  10502. return 0;
  10503. LuaSpell* spell = lua_interface->GetSpell(state);
  10504. string field = lua_interface->GetStringValue(state, 2);
  10505. int8 fieldArg = 3; // field value after the initial set
  10506. if (!spell) {
  10507. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10508. return 0;
  10509. }
  10510. if (!spell->spell || !spell->spell->GetSpellData()) {
  10511. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10512. return 0;
  10513. }
  10514. boost::to_lower(field);
  10515. bool valSet = false;
  10516. spell->spell->SetSpellData(state, field, fieldArg);
  10517. return valSet;
  10518. }
  10519. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10520. if (!lua_interface)
  10521. return 0;
  10522. LuaSpell* spell = lua_interface->GetSpell(state);
  10523. int8 idx = lua_interface->GetInt32Value(state, 2);
  10524. if (!spell) {
  10525. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10526. return 0;
  10527. }
  10528. if (!spell->spell || !spell->spell->GetSpellData()) {
  10529. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10530. return 0;
  10531. }
  10532. if (spell->spell->lua_data.size() <= idx)
  10533. {
  10534. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10535. return 0;
  10536. }
  10537. bool setVal = true;
  10538. LUAData* data = spell->spell->lua_data[idx];
  10539. switch (data->type)
  10540. {
  10541. case 0:
  10542. {
  10543. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10544. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10545. data->int_value = value;
  10546. data->int_value2 = value2;
  10547. break;
  10548. }
  10549. case 1:
  10550. {
  10551. float value = lua_interface->GetFloatValue(state, 3);
  10552. float value2 = lua_interface->GetFloatValue(state, 4);
  10553. data->float_value = value;
  10554. data->float_value2 = value2;
  10555. break;
  10556. }
  10557. case 2:
  10558. {
  10559. bool value = lua_interface->GetBooleanValue(state, 3);
  10560. data->bool_value = value;
  10561. break;
  10562. }
  10563. case 3:
  10564. {
  10565. string value = lua_interface->GetStringValue(state, 3);
  10566. string value2 = lua_interface->GetStringValue(state, 4);
  10567. data->string_value = value;
  10568. data->string_value2 = value2;
  10569. break;
  10570. }
  10571. default:
  10572. setVal = false;
  10573. }
  10574. return setVal;
  10575. }
  10576. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10577. if (!lua_interface)
  10578. return 0;
  10579. LuaSpell* spell = lua_interface->GetSpell(state);
  10580. int8 idx = lua_interface->GetInt32Value(state, 2);
  10581. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10582. if (!spell) {
  10583. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10584. return 0;
  10585. }
  10586. if (!spell->spell || !spell->spell->GetSpellData()) {
  10587. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10588. return 0;
  10589. }
  10590. if (spell->spell->lua_data.size() <= idx)
  10591. {
  10592. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10593. return 0;
  10594. }
  10595. bool setVal = true;
  10596. LUAData* data = spell->spell->lua_data[idx];
  10597. switch (data->type)
  10598. {
  10599. case 0:
  10600. {
  10601. if(!secondfield)
  10602. lua_interface->SetSInt32Value(state, data->int_value);
  10603. else
  10604. lua_interface->SetSInt32Value(state, data->int_value2);
  10605. break;
  10606. }
  10607. case 1:
  10608. {
  10609. if (!secondfield)
  10610. lua_interface->SetFloatValue(state, data->float_value);
  10611. else
  10612. lua_interface->SetFloatValue(state, data->float_value2);
  10613. break;
  10614. }
  10615. case 2:
  10616. {
  10617. lua_interface->SetBooleanValue(state, data->bool_value);
  10618. break;
  10619. }
  10620. case 3:
  10621. {
  10622. if (!secondfield)
  10623. lua_interface->SetStringValue(state, data->string_value.c_str());
  10624. else
  10625. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10626. break;
  10627. }
  10628. default:
  10629. setVal = false;
  10630. }
  10631. return setVal;
  10632. }
  10633. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10634. if (!lua_interface)
  10635. return 0;
  10636. LuaSpell* spell = lua_interface->GetSpell(state);
  10637. int8 idx = lua_interface->GetInt32Value(state, 2);
  10638. string field = lua_interface->GetStringValue(state, 3);
  10639. boost::to_lower(field);
  10640. if (!spell) {
  10641. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10642. return 0;
  10643. }
  10644. if (!spell->spell || !spell->spell->GetSpellData()) {
  10645. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10646. return 0;
  10647. }
  10648. if (spell->spell->effects.size() <= idx)
  10649. {
  10650. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10651. return 0;
  10652. }
  10653. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10654. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10655. if (field == "description")
  10656. effect->description = string(lua_interface->GetStringValue(state, 4));
  10657. else if (field == "bullet")
  10658. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10659. else if (field == "percentage")
  10660. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10661. else // no match
  10662. return 0;
  10663. return 1;
  10664. }
  10665. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10666. if (!lua_interface)
  10667. return 0;
  10668. LuaSpell* spell = lua_interface->GetSpell(state);
  10669. int8 idx = lua_interface->GetInt32Value(state, 2);
  10670. string field = lua_interface->GetStringValue(state, 3);
  10671. boost::to_lower(field);
  10672. if (!spell) {
  10673. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10674. return 0;
  10675. }
  10676. if (!spell->spell || !spell->spell->GetSpellData()) {
  10677. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10678. return 0;
  10679. }
  10680. if (spell->spell->effects.size() <= idx)
  10681. {
  10682. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10683. return 0;
  10684. }
  10685. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10686. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10687. if (field == "description")
  10688. lua_interface->SetStringValue(state, effect->description.c_str());
  10689. else if (field == "bullet")
  10690. lua_interface->SetInt32Value(state, effect->subbullet);
  10691. else if (field == "percentage")
  10692. lua_interface->SetInt32Value(state, effect->percentage);
  10693. else // no match
  10694. return 0;
  10695. return 1;
  10696. }
  10697. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10698. if (!lua_interface)
  10699. return 0;
  10700. LuaSpell* spell = lua_interface->GetSpell(state);
  10701. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10702. Spawn* target = lua_interface->GetSpawn(state, 3);
  10703. if (!target) {
  10704. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10705. return 0;
  10706. }
  10707. if (!target->IsEntity()) {
  10708. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10709. return 0;
  10710. }
  10711. if (!spell) {
  10712. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10713. return 0;
  10714. }
  10715. if (caster && !caster->IsEntity()) {
  10716. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10717. return 0;
  10718. }
  10719. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10720. return 0;
  10721. }
  10722. int EQ2Emu_lua_InWater(lua_State* state) {
  10723. if (!lua_interface)
  10724. return 0;
  10725. Spawn* spawn = lua_interface->GetSpawn(state);
  10726. lua_interface->ResetFunctionStack(state);
  10727. if (spawn) {
  10728. lua_interface->SetBooleanValue(state, spawn->InWater());
  10729. return 1;
  10730. }
  10731. return 0;
  10732. }
  10733. int EQ2Emu_lua_InLava(lua_State* state) {
  10734. if (!lua_interface)
  10735. return 0;
  10736. Spawn* spawn = lua_interface->GetSpawn(state);
  10737. lua_interface->ResetFunctionStack(state);
  10738. if (spawn) {
  10739. lua_interface->SetBooleanValue(state, spawn->InLava());
  10740. return 1;
  10741. }
  10742. return 0;
  10743. }
  10744. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10745. if (!lua_interface)
  10746. return 0;
  10747. Spawn* attacker = lua_interface->GetSpawn(state);
  10748. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10749. int8 type = lua_interface->GetInt8Value(state, 3);
  10750. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10751. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10752. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10753. string spell_name = lua_interface->GetStringValue(state, 7);
  10754. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10755. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10756. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10757. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10758. lua_interface->ResetFunctionStack(state);
  10759. if (!attacker) {
  10760. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10761. return 0;
  10762. }
  10763. if (!attacker->IsEntity()) {
  10764. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10765. return 0;
  10766. }
  10767. if (!victim) {
  10768. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10769. return 0;
  10770. }
  10771. if (!victim->IsEntity()) {
  10772. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10773. return 0;
  10774. }
  10775. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10776. return 0;
  10777. }
  10778. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10779. if (!lua_interface)
  10780. return 0;
  10781. Spawn* spawn = lua_interface->GetSpawn(state);
  10782. lua_interface->ResetFunctionStack(state);
  10783. if (spawn) {
  10784. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10785. return 1;
  10786. }
  10787. return 0;
  10788. }
  10789. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10790. if (!lua_interface)
  10791. return 0;
  10792. Spawn* spawn = lua_interface->GetSpawn(state);
  10793. bool invul = lua_interface->GetBooleanValue(state, 2);
  10794. lua_interface->ResetFunctionStack(state);
  10795. if (spawn) {
  10796. spawn->SetInvulnerable(invul);
  10797. }
  10798. return 0;
  10799. }
  10800. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10801. if (!lua_interface)
  10802. return 0;
  10803. string category = lua_interface->GetStringValue(state);
  10804. string name = lua_interface->GetStringValue(state, 2);
  10805. lua_interface->ResetFunctionStack(state);
  10806. Rule *ret = 0;
  10807. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10808. lua_interface->SetBooleanValue(state, ret->GetBool());
  10809. return 1;
  10810. }
  10811. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10812. return 0;
  10813. }
  10814. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10815. if (!lua_interface)
  10816. return 0;
  10817. string category = lua_interface->GetStringValue(state);
  10818. string name = lua_interface->GetStringValue(state, 2);
  10819. lua_interface->ResetFunctionStack(state);
  10820. Rule *ret = 0;
  10821. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10822. lua_interface->SetInt32Value(state, ret->GetInt32());
  10823. return 1;
  10824. }
  10825. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10826. return 0;
  10827. }
  10828. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10829. if (!lua_interface)
  10830. return 0;
  10831. string category = lua_interface->GetStringValue(state);
  10832. string name = lua_interface->GetStringValue(state, 2);
  10833. lua_interface->ResetFunctionStack(state);
  10834. Rule *ret = 0;
  10835. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10836. lua_interface->SetFloatValue(state, ret->GetFloat());
  10837. return 1;
  10838. }
  10839. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10840. return 0;
  10841. }
  10842. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10843. if (!lua_interface)
  10844. return 0;
  10845. Spawn* spawn = lua_interface->GetSpawn(state);
  10846. string type = lua_interface->GetStringValue(state, 2);
  10847. lua_interface->ResetFunctionStack(state);
  10848. if (spawn) {
  10849. int res = 1;
  10850. boost::to_lower(type);
  10851. if(type == "assigned_aa")
  10852. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10853. else if ( type == "unassigned_aa")
  10854. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10855. else if ( type == "assigned_tradeskill_aa")
  10856. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10857. else if ( type == "unassigned_tradeskill_aa")
  10858. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10859. else if ( type == "assigned_prestige_aa")
  10860. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10861. else if ( type == "unassigned_prestige_aa")
  10862. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10863. else if ( type == "assigned_tradeskill_prestige_aa")
  10864. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10865. else if ( type == "unassigned_tradeskill_prestige_aa")
  10866. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10867. else
  10868. res = 0;
  10869. return res;
  10870. }
  10871. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10872. return 0;
  10873. }
  10874. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10875. if (!lua_interface)
  10876. return 0;
  10877. Spawn* spawn = lua_interface->GetSpawn(state);
  10878. string type = lua_interface->GetStringValue(state, 2);
  10879. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10880. lua_interface->ResetFunctionStack(state);
  10881. if (spawn) {
  10882. boost::to_lower(type);
  10883. if(type == "assigned_aa")
  10884. spawn->SetAssignedAA((sint16)value);
  10885. else if ( type == "unassigned_aa")
  10886. spawn->SetUnassignedAA((sint16)value);
  10887. else if ( type == "assigned_tradeskill_aa")
  10888. spawn->SetTradeskillAA((sint16)value);
  10889. else if ( type == "unassigned_tradeskill_aa")
  10890. spawn->SetUnassignedTradeskillAA((sint16)value);
  10891. else if ( type == "assigned_prestige_aa")
  10892. spawn->SetPrestigeAA((sint16)value);
  10893. else if ( type == "unassigned_prestige_aa")
  10894. spawn->SetUnassignedPrestigeAA((sint16)value);
  10895. else if ( type == "assigned_tradeskill_prestige_aa")
  10896. spawn->SetTradeskillPrestigeAA((sint16)value);
  10897. else if ( type == "unassigned_tradeskill_prestige_aa")
  10898. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10899. if(spawn->IsPlayer())
  10900. ((Player*)spawn)->SetCharSheetChanged(true);
  10901. }
  10902. return 0;
  10903. }
  10904. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10905. if (!lua_interface)
  10906. return 0;
  10907. string titleName = lua_interface->GetStringValue(state);
  10908. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10909. lua_interface->ResetFunctionStack(state);
  10910. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10911. lua_interface->SetSInt32Value(state, index);
  10912. return 1;
  10913. }
  10914. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10915. if (!lua_interface)
  10916. return 0;
  10917. Spawn* spawn = lua_interface->GetSpawn(state);
  10918. string titleName = lua_interface->GetStringValue(state, 2);
  10919. lua_interface->ResetFunctionStack(state);
  10920. if(!spawn->IsPlayer())
  10921. {
  10922. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10923. lua_interface->SetSInt32Value(state, -1);
  10924. return 1;
  10925. }
  10926. Player* player = (Player*)spawn;
  10927. // check if player already has the title, don't need to add twice
  10928. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10929. if ( playerHasTitle)
  10930. {
  10931. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10932. return 1;
  10933. }
  10934. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10935. if(!title)
  10936. {
  10937. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10938. lua_interface->SetSInt32Value(state, -1);
  10939. return 1;
  10940. }
  10941. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10942. if(returnIdx < 0)
  10943. {
  10944. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10945. }
  10946. lua_interface->SetSInt32Value(state, returnIdx);
  10947. player->GetClient()->SendTitleUpdate();
  10948. return 1;
  10949. }
  10950. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10951. if (!lua_interface)
  10952. return 0;
  10953. Spawn* spawn = lua_interface->GetSpawn(state);
  10954. string titleName = lua_interface->GetStringValue(state, 2);
  10955. lua_interface->ResetFunctionStack(state);
  10956. if(!spawn->IsPlayer())
  10957. {
  10958. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10959. return 0;
  10960. }
  10961. Player* player = (Player*)spawn;
  10962. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10963. if(!title)
  10964. {
  10965. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10966. return 0;
  10967. }
  10968. if(title->GetPrefix())
  10969. {
  10970. 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());
  10971. return 0;
  10972. }
  10973. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10974. player->GetClient()->SendTitleUpdate();
  10975. return 1;
  10976. }
  10977. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10978. if (!lua_interface)
  10979. return 0;
  10980. Spawn* spawn = lua_interface->GetSpawn(state);
  10981. string titleName = lua_interface->GetStringValue(state, 2);
  10982. lua_interface->ResetFunctionStack(state);
  10983. if(!spawn->IsPlayer())
  10984. {
  10985. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10986. return 0;
  10987. }
  10988. Player* player = (Player*)spawn;
  10989. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10990. if(!title)
  10991. {
  10992. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10993. return 0;
  10994. }
  10995. if(!title->GetPrefix())
  10996. {
  10997. 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());
  10998. return 0;
  10999. }
  11000. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  11001. player->GetClient()->SendTitleUpdate();
  11002. return 1;
  11003. }
  11004. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  11005. if (!lua_interface)
  11006. return 0;
  11007. Spawn* spawn = lua_interface->GetSpawn(state);
  11008. lua_interface->ResetFunctionStack(state);
  11009. if(!spawn->IsPlayer())
  11010. {
  11011. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11012. return 0;
  11013. }
  11014. Player* player = (Player*)spawn;
  11015. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  11016. player->GetClient()->SendTitleUpdate();
  11017. return 1;
  11018. }
  11019. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  11020. if (!lua_interface)
  11021. return 0;
  11022. Spawn* spawn = lua_interface->GetSpawn(state);
  11023. lua_interface->ResetFunctionStack(state);
  11024. if(!spawn->IsPlayer())
  11025. {
  11026. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11027. return 0;
  11028. }
  11029. Player* player = (Player*)spawn;
  11030. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  11031. player->GetClient()->SendTitleUpdate();
  11032. return 1;
  11033. }
  11034. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  11035. if (!lua_interface)
  11036. return 0;
  11037. Spawn* spawn = lua_interface->GetSpawn(state);
  11038. string field = lua_interface->GetStringValue(state, 2);
  11039. lua_interface->ResetFunctionStack(state);
  11040. if(!spawn || !spawn->IsEntity())
  11041. {
  11042. 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));
  11043. return 0;
  11044. }
  11045. Entity* ent = (Entity*)spawn;
  11046. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  11047. return 1;
  11048. }
  11049. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  11050. if (!lua_interface)
  11051. return 0;
  11052. Spawn* spawn = lua_interface->GetSpawn(state);
  11053. string field = lua_interface->GetStringValue(state, 2);
  11054. lua_interface->ResetFunctionStack(state);
  11055. if(!spawn || !spawn->IsEntity())
  11056. {
  11057. 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));
  11058. return 0;
  11059. }
  11060. Entity* ent = (Entity*)spawn;
  11061. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  11062. return 1;
  11063. }
  11064. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  11065. if (!lua_interface)
  11066. return 0;
  11067. Spawn* spawn = lua_interface->GetSpawn(state);
  11068. string field = lua_interface->GetStringValue(state, 2);
  11069. lua_interface->ResetFunctionStack(state);
  11070. if(!spawn || !spawn->IsEntity())
  11071. {
  11072. 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));
  11073. return 0;
  11074. }
  11075. Entity* ent = (Entity*)spawn;
  11076. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  11077. return 1;
  11078. }
  11079. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  11080. if (!lua_interface)
  11081. return 0;
  11082. Spawn* spawn = lua_interface->GetSpawn(state);
  11083. string field = lua_interface->GetStringValue(state, 2);
  11084. lua_interface->ResetFunctionStack(state);
  11085. if(!spawn || !spawn->IsEntity())
  11086. {
  11087. 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));
  11088. return 0;
  11089. }
  11090. Entity* ent = (Entity*)spawn;
  11091. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  11092. return 1;
  11093. }
  11094. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  11095. if (!lua_interface)
  11096. return 0;
  11097. Spawn* spawn = lua_interface->GetSpawn(state);
  11098. string field = lua_interface->GetStringValue(state, 2);
  11099. string value = lua_interface->GetStringValue(state, 3);
  11100. lua_interface->ResetFunctionStack(state);
  11101. if(!spawn || !spawn->IsEntity())
  11102. {
  11103. 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));
  11104. return 0;
  11105. }
  11106. Entity* ent = (Entity*)spawn;
  11107. bool set_ = ent->SetInfoStructString(field, value);
  11108. lua_interface->SetBooleanValue(state, set_);
  11109. return 1;
  11110. }
  11111. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  11112. if (!lua_interface)
  11113. return 0;
  11114. Spawn* spawn = lua_interface->GetSpawn(state);
  11115. string field = lua_interface->GetStringValue(state, 2);
  11116. int64 value = lua_interface->GetInt64Value(state, 3);
  11117. lua_interface->ResetFunctionStack(state);
  11118. if(!spawn || !spawn->IsEntity())
  11119. {
  11120. 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));
  11121. return 0;
  11122. }
  11123. Entity* ent = (Entity*)spawn;
  11124. bool set_ = ent->SetInfoStructUInt(field, value);
  11125. lua_interface->SetBooleanValue(state, set_);
  11126. return 1;
  11127. }
  11128. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  11129. if (!lua_interface)
  11130. return 0;
  11131. Spawn* spawn = lua_interface->GetSpawn(state);
  11132. string field = lua_interface->GetStringValue(state, 2);
  11133. sint64 value = lua_interface->GetSInt64Value(state, 3);
  11134. lua_interface->ResetFunctionStack(state);
  11135. if(!spawn || !spawn->IsEntity())
  11136. {
  11137. 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));
  11138. return 0;
  11139. }
  11140. Entity* ent = (Entity*)spawn;
  11141. bool set_ = ent->SetInfoStructSInt(field, value);
  11142. lua_interface->SetBooleanValue(state, set_);
  11143. return 1;
  11144. }
  11145. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  11146. if (!lua_interface)
  11147. return 0;
  11148. Spawn* spawn = lua_interface->GetSpawn(state);
  11149. string field = lua_interface->GetStringValue(state, 2);
  11150. float value = lua_interface->GetFloatValue(state, 3);
  11151. lua_interface->ResetFunctionStack(state);
  11152. if(!spawn || !spawn->IsEntity())
  11153. {
  11154. 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));
  11155. return 0;
  11156. }
  11157. Entity* ent = (Entity*)spawn;
  11158. bool set_ = ent->SetInfoStructFloat(field, value);
  11159. lua_interface->SetBooleanValue(state, set_);
  11160. return 1;
  11161. }
  11162. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  11163. if (!lua_interface)
  11164. return 0;
  11165. Spawn* spawn = lua_interface->GetSpawn(state);
  11166. bool value = lua_interface->GetBooleanValue(state, 2);
  11167. lua_interface->ResetFunctionStack(state);
  11168. if(!spawn || !spawn->IsPlayer())
  11169. {
  11170. 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));
  11171. return 0;
  11172. }
  11173. ((Player*)spawn)->SetCharSheetChanged(value);
  11174. return 0;
  11175. }
  11176. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  11177. if (!lua_interface)
  11178. return 0;
  11179. Spawn* spawn = lua_interface->GetSpawn(state);
  11180. std::string fromName = lua_interface->GetStringValue(state, 2);
  11181. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11182. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11183. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11184. int32 copper = lua_interface->GetInt32Value(state, 6);
  11185. int32 silver = lua_interface->GetInt32Value(state, 7);
  11186. int32 gold = lua_interface->GetInt32Value(state, 8);
  11187. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11188. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11189. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11190. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11191. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11192. lua_interface->ResetFunctionStack(state);
  11193. if(!spawn || !spawn->IsPlayer())
  11194. {
  11195. 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));
  11196. lua_interface->SetBooleanValue(state, false);
  11197. return 1;
  11198. }
  11199. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11200. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11201. lua_interface->SetBooleanValue(state, true);
  11202. return 1;
  11203. }
  11204. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  11205. if (!lua_interface)
  11206. return 0;
  11207. int32 char_id = lua_interface->GetInt32Value(state);
  11208. std::string fromName = lua_interface->GetStringValue(state, 2);
  11209. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11210. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11211. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11212. int32 copper = lua_interface->GetInt32Value(state, 6);
  11213. int32 silver = lua_interface->GetInt32Value(state, 7);
  11214. int32 gold = lua_interface->GetInt32Value(state, 8);
  11215. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11216. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11217. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11218. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11219. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11220. lua_interface->ResetFunctionStack(state);
  11221. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11222. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11223. lua_interface->SetBooleanValue(state, true);
  11224. return 1;
  11225. }
  11226. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  11227. Spawn* widget;
  11228. if (lua_interface) {
  11229. widget = lua_interface->GetSpawn(state);
  11230. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  11231. lua_interface->ResetFunctionStack(state);
  11232. if (widget && widget->IsWidget())
  11233. {
  11234. ((Widget*)widget)->OpenDoor();
  11235. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  11236. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11237. }
  11238. else
  11239. 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));
  11240. }
  11241. return 0;
  11242. }
  11243. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  11244. Spawn* widget;
  11245. if (lua_interface) {
  11246. widget = lua_interface->GetSpawn(state);
  11247. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  11248. lua_interface->ResetFunctionStack(state);
  11249. if (widget && widget->IsWidget())
  11250. {
  11251. ((Widget*)widget)->CloseDoor();
  11252. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  11253. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11254. }
  11255. else
  11256. 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));
  11257. }
  11258. return 0;
  11259. }
  11260. int EQ2Emu_lua_IsOpen(lua_State* state) {
  11261. if (!lua_interface)
  11262. return 0;
  11263. Spawn* widget = lua_interface->GetSpawn(state);
  11264. lua_interface->ResetFunctionStack(state);
  11265. if (widget && widget->IsWidget())
  11266. {
  11267. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  11268. return 1;
  11269. }
  11270. return 0;
  11271. }
  11272. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  11273. if (!lua_interface)
  11274. return 0;
  11275. sint32 min = lua_interface->GetSInt32Value(state);
  11276. sint32 max = lua_interface->GetSInt32Value(state, 2);
  11277. lua_interface->ResetFunctionStack(state);
  11278. sint32 result = MakeRandomInt(min, max);
  11279. lua_interface->SetSInt32Value(state, result);
  11280. return 1;
  11281. }
  11282. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  11283. if (!lua_interface)
  11284. return 0;
  11285. float min = lua_interface->GetFloatValue(state);
  11286. float max = lua_interface->GetFloatValue(state, 2);
  11287. lua_interface->ResetFunctionStack(state);
  11288. float result = MakeRandomFloat(min, max);
  11289. lua_interface->SetFloatValue(state, result);
  11290. return 1;
  11291. }
  11292. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  11293. if (!lua_interface)
  11294. return 0;
  11295. Spawn* spawn = lua_interface->GetSpawn(state);
  11296. int32 value = lua_interface->GetInt32Value(state, 2);
  11297. lua_interface->ResetFunctionStack(state);
  11298. if(!spawn)
  11299. {
  11300. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11301. lua_interface->SetBooleanValue(state, false);
  11302. return 1;
  11303. }
  11304. spawn->AddIconValue(value);
  11305. lua_interface->SetBooleanValue(state, true);
  11306. return 1;
  11307. }
  11308. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  11309. if (!lua_interface)
  11310. return 0;
  11311. Spawn* spawn = lua_interface->GetSpawn(state);
  11312. int32 value = lua_interface->GetInt32Value(state, 2);
  11313. lua_interface->ResetFunctionStack(state);
  11314. if(!spawn)
  11315. {
  11316. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11317. lua_interface->SetBooleanValue(state, false);
  11318. return 1;
  11319. }
  11320. spawn->RemoveIconValue(value);
  11321. lua_interface->SetBooleanValue(state, true);
  11322. return 1;
  11323. }
  11324. int EQ2Emu_lua_GetShardID(lua_State* state) {
  11325. Spawn* npc = lua_interface->GetSpawn(state);
  11326. lua_interface->ResetFunctionStack(state);
  11327. if (npc && npc->IsNPC()) {
  11328. NPC* shard = (NPC*)npc;
  11329. int32 shardid = shard->GetShardID();
  11330. lua_interface->SetInt32Value(state, shardid);
  11331. return 1;
  11332. }
  11333. lua_interface->SetInt32Value(state, 0);
  11334. return 1;
  11335. }
  11336. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  11337. Spawn* npc = lua_interface->GetSpawn(state);
  11338. lua_interface->ResetFunctionStack(state);
  11339. if (npc && npc->IsNPC()) {
  11340. NPC* shard = (NPC*)npc;
  11341. int32 charid = shard->GetShardCharID();
  11342. lua_interface->SetInt32Value(state, charid);
  11343. return 1;
  11344. }
  11345. lua_interface->SetInt32Value(state, 0);
  11346. return 1;
  11347. }
  11348. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  11349. Spawn* npc = lua_interface->GetSpawn(state);
  11350. lua_interface->ResetFunctionStack(state);
  11351. if (npc && npc->IsNPC()) {
  11352. NPC* shard = (NPC*)npc;
  11353. int64 timestamp = shard->GetShardCreatedTimestamp();
  11354. lua_interface->SetSInt64Value(state, timestamp);
  11355. return 1;
  11356. }
  11357. lua_interface->SetSInt64Value(state, 0);
  11358. return 1;
  11359. }
  11360. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  11361. if (!lua_interface)
  11362. return 0;
  11363. int32 shardid = lua_interface->GetInt32Value(state);
  11364. lua_interface->ResetFunctionStack(state);
  11365. if(shardid < 1)
  11366. lua_interface->SetBooleanValue(state, false);
  11367. else
  11368. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  11369. return 1;
  11370. }
  11371. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  11372. if (!lua_interface)
  11373. return 0;
  11374. Spawn* spawn = lua_interface->GetSpawn(state);
  11375. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11376. if (spawn) {
  11377. spawn->PauseMovement(delay_in_ms);
  11378. }
  11379. lua_interface->ResetFunctionStack(state);
  11380. return 0;
  11381. }
  11382. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11383. if (!lua_interface)
  11384. return 0;
  11385. Spawn* spawn = lua_interface->GetSpawn(state);
  11386. if (spawn) {
  11387. spawn->StopMovement();
  11388. }
  11389. lua_interface->ResetFunctionStack(state);
  11390. return 0;
  11391. }
  11392. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11393. Player* player = (Player*)lua_interface->GetSpawn(state);
  11394. int8 level = lua_interface->GetInt8Value(state, 2);
  11395. lua_interface->ResetFunctionStack(state);
  11396. if (player && player->IsPlayer() && level > 0) {
  11397. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11398. return 1;
  11399. }
  11400. return 0;
  11401. }
  11402. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11403. Player* player = (Player*)lua_interface->GetSpawn(state);
  11404. int8 level = lua_interface->GetInt8Value(state, 2);
  11405. lua_interface->ResetFunctionStack(state);
  11406. if (player && player->IsPlayer() && level > 0) {
  11407. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11408. return 1;
  11409. }
  11410. return 0;
  11411. }
  11412. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11413. ZoneServer* zone = lua_interface->GetZone(state);
  11414. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11415. lua_interface->ResetFunctionStack(state);
  11416. if (zone) {
  11417. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11418. if (spawn) {
  11419. lua_interface->SetSpawnValue(state, spawn);
  11420. return 1;
  11421. }
  11422. }
  11423. return 0;
  11424. }
  11425. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11426. if (!lua_interface)
  11427. return 0;
  11428. Spawn* spawn = lua_interface->GetSpawn(state);
  11429. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11430. lua_interface->ResetFunctionStack(state);
  11431. bool res = false;
  11432. if(spawn && spawn->IsTransportSpawn())
  11433. {
  11434. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11435. spawn->SetRailID(rail_id);
  11436. res = true;
  11437. }
  11438. else if (!spawn) {
  11439. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11440. }
  11441. else if(!spawn->IsTransportSpawn()) {
  11442. 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());
  11443. }
  11444. lua_interface->SetBooleanValue(state, res);
  11445. return 1;
  11446. }
  11447. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11448. if (!lua_interface)
  11449. return 0;
  11450. ZoneServer* zone = lua_interface->GetZone(state);
  11451. lua_interface->ResetFunctionStack(state);
  11452. if (zone) {
  11453. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11454. return 1;
  11455. }
  11456. return 0;
  11457. }
  11458. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11459. if (!lua_interface)
  11460. return 0;
  11461. Spawn* spawn = lua_interface->GetSpawn(state);
  11462. lua_interface->ResetFunctionStack(state);
  11463. if (spawn) {
  11464. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11465. return 1;
  11466. }
  11467. return 0;
  11468. }
  11469. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11470. if (!lua_interface)
  11471. return 0;
  11472. Spawn* player = lua_interface->GetSpawn(state);
  11473. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11474. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11475. lua_interface->ResetFunctionStack(state);
  11476. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11477. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11478. }
  11479. else if(!zoneID) {
  11480. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11481. }
  11482. else
  11483. {
  11484. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11485. return 1;
  11486. }
  11487. return 0;
  11488. }
  11489. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11490. if (!lua_interface)
  11491. return 0;
  11492. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11493. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11494. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11495. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11496. lua_interface->ResetFunctionStack(state);
  11497. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11498. world.GetWorldTimeStruct()->year = newYear;
  11499. world.GetWorldTimeStruct()->month = newMonth;
  11500. world.GetWorldTimeStruct()->hour = newHour;
  11501. world.GetWorldTimeStruct()->minute = newMinute;
  11502. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11503. return 0;
  11504. }
  11505. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11506. if (!lua_interface)
  11507. return 0;
  11508. lua_interface->ResetFunctionStack(state);
  11509. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11510. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11511. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11512. return 1;
  11513. }
  11514. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11515. if (!lua_interface)
  11516. return 0;
  11517. lua_interface->ResetFunctionStack(state);
  11518. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11519. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11520. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11521. return 1;
  11522. }
  11523. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11524. if (!lua_interface)
  11525. return 0;
  11526. lua_interface->ResetFunctionStack(state);
  11527. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11528. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11529. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11530. return 1;
  11531. }
  11532. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11533. if (!lua_interface)
  11534. return 0;
  11535. lua_interface->ResetFunctionStack(state);
  11536. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11537. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11538. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11539. return 1;
  11540. }
  11541. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11542. if (!lua_interface)
  11543. return 0;
  11544. lua_interface->ResetFunctionStack(state);
  11545. world.SendTimeUpdate();
  11546. return 0;
  11547. }
  11548. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11549. bool update_result = false;
  11550. Faction* faction = 0;
  11551. Spawn* spawn = lua_interface->GetSpawn(state);
  11552. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11553. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11554. lua_interface->ResetFunctionStack(state);
  11555. if(!spawn || !spawn->IsPlayer()) {
  11556. lua_interface->LogError("LUA ChangeFaction command error: player is not valid");
  11557. return 0;
  11558. }
  11559. Player* player = (Player*)spawn;
  11560. Client* client = player->GetClient();
  11561. if (faction_id > 0) {
  11562. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11563. if(hasfaction == 0) {
  11564. //they do not have the faction. Lets get the default value and feed it in.
  11565. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11566. //add the default faction for the player.
  11567. player->SetFactionValue(faction_id, defaultfaction);
  11568. }
  11569. if(increase >= 0) {
  11570. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11571. faction = master_faction_list.GetFaction(faction_id);
  11572. if(faction && update_result)
  11573. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11574. else if(faction)
  11575. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11576. lua_interface->SetBooleanValue(state, true);
  11577. return 1;
  11578. }
  11579. if(increase < 0){
  11580. //change the negative to a positive, since thats how decreasefaction() likes it.
  11581. increase *= -1;
  11582. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11583. faction = master_faction_list.GetFaction(faction_id);
  11584. if(faction && update_result)
  11585. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11586. else if(faction)
  11587. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11588. lua_interface->SetBooleanValue(state, true);
  11589. return 1;
  11590. }
  11591. }
  11592. lua_interface->SetBooleanValue(state, false);
  11593. return 1;
  11594. }
  11595. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11596. bool hascoin = 0;
  11597. Player* player = (Player*)lua_interface->GetSpawn(state);
  11598. int32 coins = lua_interface->GetInt32Value(state, 2);
  11599. lua_interface->ResetFunctionStack(state);
  11600. if (player && player->IsPlayer()) {
  11601. hascoin = player->HasCoins(coins);
  11602. if(hascoin == 0) {
  11603. lua_interface->SetBooleanValue(state, false);
  11604. return 1;
  11605. }
  11606. if(hascoin == 1) {
  11607. lua_interface->SetBooleanValue(state, true);
  11608. return 1;
  11609. }
  11610. }
  11611. return 0;
  11612. }
  11613. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11614. int32 loot_tier = 0;
  11615. Spawn* spawn = lua_interface->GetSpawn(state);
  11616. lua_interface->ResetFunctionStack(state);
  11617. if (spawn) {
  11618. loot_tier = spawn->GetLootTier();
  11619. lua_interface->SetInt32Value(state, loot_tier);
  11620. return 1;
  11621. }
  11622. return 0;
  11623. }
  11624. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11625. if (!lua_interface)
  11626. return 0;
  11627. Spawn* spawn = lua_interface->GetSpawn(state);
  11628. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11629. lua_interface->ResetFunctionStack(state);
  11630. if (spawn) {
  11631. spawn->SetLootTier(loot_tier);
  11632. lua_interface->SetBooleanValue(state, true);
  11633. return 1;
  11634. }
  11635. lua_interface->SetBooleanValue(state, false);
  11636. return 1;
  11637. }
  11638. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11639. int32 loot_drop_type = 0;
  11640. Spawn* spawn = lua_interface->GetSpawn(state);
  11641. lua_interface->ResetFunctionStack(state);
  11642. if (spawn) {
  11643. loot_drop_type = spawn->GetLootDropType();
  11644. lua_interface->SetInt32Value(state, loot_drop_type);
  11645. return 1;
  11646. }
  11647. return 0;
  11648. }
  11649. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11650. if (!lua_interface)
  11651. return 0;
  11652. Spawn* spawn = lua_interface->GetSpawn(state);
  11653. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11654. lua_interface->ResetFunctionStack(state);
  11655. if (spawn) {
  11656. spawn->SetLootDropType(loot_drop_type);
  11657. lua_interface->SetBooleanValue(state, true);
  11658. return 1;
  11659. }
  11660. lua_interface->SetBooleanValue(state, false);
  11661. return 1;
  11662. }
  11663. int EQ2Emu_lua_DamageEquippedItems(lua_State* state) {
  11664. if (!lua_interface)
  11665. return 0;
  11666. Spawn* spawn = lua_interface->GetSpawn(state);
  11667. int8 damage_amount = lua_interface->GetInt32Value(state, 2);
  11668. if(damage_amount > 100) {
  11669. damage_amount = 100;
  11670. }
  11671. if (!spawn) {
  11672. lua_interface->LogError("%s: LUA DamageEquippedItems command error: spawn is not valid", lua_interface->GetScriptName(state));
  11673. lua_interface->ResetFunctionStack(state);
  11674. return 0;
  11675. }
  11676. lua_interface->ResetFunctionStack(state);
  11677. if (spawn->IsPlayer()) {
  11678. if (((Player*)spawn)->GetClient() && ((Player*)spawn)->DamageEquippedItems(damage_amount, ((Player*)spawn)->GetClient()))
  11679. lua_interface->SetBooleanValue(state, true);
  11680. else
  11681. lua_interface->SetBooleanValue(state, false);
  11682. }
  11683. else {
  11684. lua_interface->SetBooleanValue(state, false);
  11685. }
  11686. return 1;
  11687. }
  11688. int EQ2Emu_lua_CreateWidgetRegion(lua_State* state) {
  11689. ZoneServer* zone = lua_interface->GetZone(state);
  11690. int32 version = lua_interface->GetInt32Value(state, 2);
  11691. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11692. if(region_map == nullptr) {
  11693. lua_interface->LogError("%s: LUA CreateWidgetRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11694. lua_interface->ResetFunctionStack(state);
  11695. return 0;
  11696. }
  11697. string region_name = lua_interface->GetStringValue(state, 3);
  11698. string env_name = lua_interface->GetStringValue(state, 4);
  11699. int32 grid_id = lua_interface->GetInt32Value(state, 5);
  11700. int32 widget_id = lua_interface->GetInt32Value(state, 6);
  11701. float dist = lua_interface->GetFloatValue(state, 7);
  11702. region_map->InsertRegionNode(zone, version, region_name, env_name, grid_id, widget_id, dist);
  11703. lua_interface->ResetFunctionStack(state);
  11704. lua_interface->SetBooleanValue(state, true);
  11705. return 1;
  11706. }
  11707. int EQ2Emu_lua_RemoveRegion(lua_State* state) {
  11708. ZoneServer* zone = lua_interface->GetZone(state);
  11709. int32 version = lua_interface->GetInt32Value(state, 2);
  11710. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11711. if(region_map == nullptr) {
  11712. lua_interface->LogError("%s: LUA RemoveRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11713. lua_interface->ResetFunctionStack(state);
  11714. return 0;
  11715. }
  11716. string region_name = lua_interface->GetStringValue(state, 3);
  11717. region_map->RemoveRegionNode(region_name);
  11718. lua_interface->ResetFunctionStack(state);
  11719. lua_interface->SetBooleanValue(state, true);
  11720. return 1;
  11721. }
  11722. int EQ2Emu_lua_SetPlayerPOVGhost(lua_State* state) {
  11723. Client* client = nullptr;
  11724. Spawn* player = lua_interface->GetSpawn(state);
  11725. if (!player) {
  11726. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not valid");
  11727. lua_interface->SetBooleanValue(state, false);
  11728. lua_interface->ResetFunctionStack(state);
  11729. return 1;
  11730. }
  11731. if (!player->IsPlayer()) {
  11732. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
  11733. lua_interface->SetBooleanValue(state, false);
  11734. lua_interface->ResetFunctionStack(state);
  11735. return 1;
  11736. }
  11737. client = player->GetClient();
  11738. if (!client) {
  11739. lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
  11740. lua_interface->SetBooleanValue(state, false);
  11741. lua_interface->ResetFunctionStack(state);
  11742. return 1;
  11743. }
  11744. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  11745. bool success_sight = client->SetPlayerPOVGhost(spawn);
  11746. lua_interface->ResetFunctionStack(state);
  11747. lua_interface->SetBooleanValue(state, success_sight);
  11748. return 1;
  11749. }
  11750. int EQ2Emu_lua_SetCastOnAggroComplete(lua_State* state) {
  11751. if (!lua_interface)
  11752. return 0;
  11753. bool result = false;
  11754. Spawn* spawn = lua_interface->GetSpawn(state);
  11755. bool cast_completed = (lua_interface->GetInt8Value(state, 2) == 1);
  11756. lua_interface->ResetFunctionStack(state);
  11757. if (!spawn)
  11758. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11759. else if (!spawn->IsNPC())
  11760. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11761. else
  11762. {
  11763. ((NPC*)spawn)->cast_on_aggro_completed = cast_completed;
  11764. result = true;
  11765. }
  11766. lua_interface->SetBooleanValue(state, result);
  11767. return 1;
  11768. }
  11769. int EQ2Emu_lua_IsCastOnAggroComplete(lua_State* state) {
  11770. if (!lua_interface)
  11771. return 0;
  11772. bool result = false;
  11773. Spawn* spawn = lua_interface->GetSpawn(state);
  11774. lua_interface->ResetFunctionStack(state);
  11775. if (!spawn)
  11776. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11777. else if (!spawn->IsNPC())
  11778. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11779. else
  11780. {
  11781. if(((NPC*)spawn)->cast_on_aggro_completed)
  11782. result = true;
  11783. }
  11784. lua_interface->SetBooleanValue(state, result);
  11785. return 1;
  11786. }
  11787. int EQ2Emu_lua_AddRecipeBookToPlayer(lua_State* state) {
  11788. Client* client = nullptr;
  11789. Spawn* player = lua_interface->GetSpawn(state);
  11790. int32 recipe_book_id = lua_interface->GetInt32Value(state, 2);
  11791. lua_interface->ResetFunctionStack(state);
  11792. if (!player) {
  11793. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not valid");
  11794. lua_interface->SetBooleanValue(state, false);
  11795. return 1;
  11796. }
  11797. if (!player->IsPlayer()) {
  11798. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not a player");
  11799. lua_interface->SetBooleanValue(state, false);
  11800. return 1;
  11801. }
  11802. client = player->GetClient();
  11803. if (!client) {
  11804. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: could not find client");
  11805. lua_interface->SetBooleanValue(state, false);
  11806. return 1;
  11807. }
  11808. bool result = client->AddRecipeBookToPlayer(recipe_book_id);
  11809. lua_interface->SetBooleanValue(state, result);
  11810. return 1;
  11811. }
  11812. int EQ2Emu_lua_RemoveRecipeFromPlayer(lua_State* state) {
  11813. Client* client = nullptr;
  11814. Spawn* player = lua_interface->GetSpawn(state);
  11815. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  11816. lua_interface->ResetFunctionStack(state);
  11817. if (!player) {
  11818. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not valid");
  11819. lua_interface->SetBooleanValue(state, false);
  11820. return 1;
  11821. }
  11822. if (!player->IsPlayer()) {
  11823. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not a player");
  11824. lua_interface->SetBooleanValue(state, false);
  11825. return 1;
  11826. }
  11827. client = player->GetClient();
  11828. if (!client) {
  11829. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: could not find client");
  11830. lua_interface->SetBooleanValue(state, false);
  11831. return 1;
  11832. }
  11833. bool result = client->RemoveRecipeFromPlayer(recipe_id);
  11834. lua_interface->SetBooleanValue(state, result);
  11835. return 1;
  11836. }