LuaFunctions.cpp 452 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276
  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() > 561 )
  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. if(spawn->GetSpawnGroupID() == new_group_id) {
  685. lua_interface->SetBooleanValue(state, false);
  686. return 1;
  687. }
  688. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  689. lua_interface->SetBooleanValue(state, true);
  690. return 1;
  691. }
  692. lua_interface->SetBooleanValue(state, false);
  693. return 1;
  694. }
  695. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  696. Spawn* spawn = lua_interface->GetSpawn(state);
  697. lua_interface->ResetFunctionStack(state);
  698. if (spawn) {
  699. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  700. return 1;
  701. }
  702. return 0;
  703. }
  704. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  705. Spawn* spawn = lua_interface->GetSpawn(state);
  706. lua_interface->ResetFunctionStack(state);
  707. if (spawn) {
  708. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  709. return 1;
  710. }
  711. return 0;
  712. }
  713. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  714. Player* player = (Player*)lua_interface->GetSpawn(state);
  715. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  716. lua_interface->ResetFunctionStack(state);
  717. if (player && player->IsPlayer() && faction_id > 0) {
  718. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  719. return 1;
  720. }
  721. return 0;
  722. }
  723. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  724. if (!lua_interface)
  725. return 0;
  726. Spawn* spawn = lua_interface->GetSpawn(state);
  727. int32 value = lua_interface->GetInt32Value(state, 2);
  728. lua_interface->ResetFunctionStack(state);
  729. if (spawn) {
  730. spawn->SetFactionID(value);
  731. }
  732. return 0;
  733. }
  734. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  735. Spawn* spawn = lua_interface->GetSpawn(state);
  736. lua_interface->ResetFunctionStack(state);
  737. if (spawn) {
  738. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  739. return 1;
  740. }
  741. return 0;
  742. }
  743. int EQ2Emu_lua_GetGender(lua_State* state) {
  744. Spawn* spawn = lua_interface->GetSpawn(state);
  745. lua_interface->ResetFunctionStack(state);
  746. if (spawn) {
  747. lua_interface->SetInt32Value(state, spawn->GetGender());
  748. return 1;
  749. }
  750. return 0;
  751. }
  752. int EQ2Emu_lua_GetTarget(lua_State* state) {
  753. Spawn* spawn = lua_interface->GetSpawn(state);
  754. lua_interface->ResetFunctionStack(state);
  755. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  756. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  757. return 1;
  758. }
  759. return 0;
  760. }
  761. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  762. if (!lua_interface)
  763. return 0;
  764. Spawn* spawn = lua_interface->GetSpawn(state);
  765. string mp3_string = lua_interface->GetStringValue(state, 2);
  766. int32 key1 = lua_interface->GetInt32Value(state, 3);
  767. int32 key2 = lua_interface->GetInt32Value(state, 4);
  768. Spawn* player = lua_interface->GetSpawn(state, 5);
  769. lua_interface->ResetFunctionStack(state);
  770. if (spawn && mp3_string.length() > 0) {
  771. Client* client = 0;
  772. if (player && player->IsPlayer())
  773. client = ((Player*)player)->GetClient();
  774. if (client) {
  775. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  776. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  777. }
  778. else
  779. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  780. }
  781. return 0;
  782. }
  783. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  784. if (!lua_interface)
  785. return 0;
  786. Spawn* spawn = lua_interface->GetSpawn(state);
  787. lua_interface->ResetFunctionStack(state);
  788. if (spawn) {
  789. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  790. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  791. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  792. return 3;
  793. }
  794. return 0;
  795. }
  796. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  797. if (!lua_interface)
  798. return 0;
  799. Spawn* spawn = lua_interface->GetSpawn(state);
  800. if (spawn) {
  801. int32 item_id = lua_interface->GetInt32Value(state, 2);
  802. lua_interface->ResetFunctionStack(state);
  803. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  804. return 1;
  805. }
  806. lua_interface->ResetFunctionStack(state);
  807. return 0;
  808. }
  809. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  810. if (!lua_interface)
  811. return 0;
  812. Spawn* spawn = lua_interface->GetSpawn(state);
  813. if (spawn && spawn->IsEntity()) {
  814. int32 item_id = lua_interface->GetInt32Value(state, 2);
  815. int16 charges = lua_interface->GetInt16Value(state, 3);
  816. if (charges == 0)
  817. charges = 1;
  818. ((Entity*)spawn)->AddLootItem(item_id, charges);
  819. }
  820. lua_interface->ResetFunctionStack(state);
  821. return 0;
  822. }
  823. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  824. if (!lua_interface)
  825. return 0;
  826. Spawn* spawn = lua_interface->GetSpawn(state);
  827. if (spawn && spawn->IsEntity()) {
  828. int32 item_id = lua_interface->GetInt32Value(state, 2);
  829. Item* item = spawn->LootItem(item_id);
  830. lua_interface->SetLuaUserDataStale(item);
  831. safe_delete(item);
  832. }
  833. lua_interface->ResetFunctionStack(state);
  834. return 0;
  835. }
  836. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  837. if (!lua_interface)
  838. return 0;
  839. Spawn* spawn = lua_interface->GetSpawn(state);
  840. if (spawn) {
  841. int32 val = lua_interface->GetInt32Value(state, 2);
  842. spawn->AddLootCoins(val);
  843. }
  844. lua_interface->ResetFunctionStack(state);
  845. return 0;
  846. }
  847. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  848. if (!lua_interface)
  849. return 0;
  850. Spawn* entity = lua_interface->GetSpawn(state);
  851. Spawn* player = lua_interface->GetSpawn(state, 2);
  852. if (entity && player && player->IsPlayer()) {
  853. int32 coins = lua_interface->GetInt32Value(state, 3);
  854. vector<Item*>* items = 0;
  855. int i = 0;
  856. int32 item_id = 0;
  857. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  858. if (items == 0)
  859. items = new vector<Item*>;
  860. if (master_item_list.GetItem(item_id))
  861. items->push_back(master_item_list.GetItem(item_id));
  862. i++;
  863. }
  864. Client* client = 0;
  865. client = ((Player*)player)->GetClient();
  866. if (client)
  867. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  868. if(coins > 0)
  869. entity->AddLootCoins(coins);
  870. safe_delete(items);
  871. }
  872. lua_interface->ResetFunctionStack(state);
  873. return 0;
  874. }
  875. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  876. if (!lua_interface)
  877. return 0;
  878. Spawn* entity = lua_interface->GetSpawn(state);
  879. Spawn* player = lua_interface->GetSpawn(state, 2);
  880. int32 item_id = lua_interface->GetInt32Value(state, 3);
  881. lua_interface->ResetFunctionStack(state);
  882. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  883. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  884. return 1;
  885. }
  886. return 0;
  887. }
  888. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  889. if (!lua_interface)
  890. return 0;
  891. Spawn* entity = lua_interface->GetSpawn(state);
  892. Spawn* player = lua_interface->GetSpawn(state, 2);
  893. lua_interface->ResetFunctionStack(state);
  894. if (entity && player && player->IsPlayer()) {
  895. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  896. return 1;
  897. }
  898. return 0;
  899. }
  900. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  901. if (!lua_interface)
  902. return 0;
  903. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  904. lua_interface->SetLuaUserDataStale(conversation);
  905. safe_delete(conversation);
  906. lua_interface->ResetFunctionStack(state);
  907. conversation = new vector<ConversationOption>();
  908. lua_interface->SetConversationValue(state, conversation);
  909. return 1;
  910. }
  911. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  912. if (!lua_interface)
  913. return 0;
  914. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  915. if (conversation) {
  916. ConversationOption conv_option;
  917. conv_option.option = lua_interface->GetStringValue(state, 2);
  918. conv_option.function = lua_interface->GetStringValue(state, 3);
  919. if (conv_option.option.length() > 0)
  920. conversation->push_back(conv_option);
  921. }
  922. lua_interface->ResetFunctionStack(state);
  923. return 0;
  924. }
  925. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  926. if (!lua_interface)
  927. return 0;
  928. Spawn* npc = lua_interface->GetSpawn(state);
  929. Spawn* player = lua_interface->GetSpawn(state, 2);
  930. lua_interface->ResetFunctionStack(state);
  931. if (npc && player && player->IsPlayer() && player->GetZone()) {
  932. Client* client = ((Player*)player)->GetClient();
  933. if (client) {
  934. int32 conversation_id = client->GetConversationID(npc, 0);
  935. client->CloseDialog(conversation_id);
  936. }
  937. }
  938. return 0;
  939. }
  940. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  941. if (!lua_interface)
  942. return 0;
  943. Item* item = lua_interface->GetItem(state);
  944. Spawn* player = lua_interface->GetSpawn(state, 2);
  945. lua_interface->ResetFunctionStack(state);
  946. if (item && player && player->IsPlayer() && player->GetZone()) {
  947. Client* client = ((Player*)player)->GetClient();
  948. if (client) {
  949. int32 conversation_id = client->GetConversationID(0, item);
  950. client->CloseDialog(conversation_id);
  951. }
  952. }
  953. return 0;
  954. }
  955. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  956. if (!lua_interface)
  957. return 0;
  958. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  959. Spawn* spawn = 0;
  960. Item* item = 0;
  961. int8 type = lua_interface->GetInt8Value(state, 2);
  962. if (type == 1 || type == 3)
  963. spawn = lua_interface->GetSpawn(state, 3);
  964. else if (type == 2 || type == 4)
  965. item = lua_interface->GetItem(state, 3);
  966. Spawn* player = lua_interface->GetSpawn(state, 4);
  967. string text = lua_interface->GetStringValue(state, 5);
  968. string mp3 = lua_interface->GetStringValue(state, 6);
  969. int32 key1 = lua_interface->GetInt32Value(state, 7);
  970. int32 key2 = lua_interface->GetInt32Value(state, 8);
  971. int8 language = lua_interface->GetInt8Value(state, 9);
  972. int numargs = lua_interface->GetNumberOfArgs(state);
  973. int8 can_close = 1;
  974. if(numargs > 9)
  975. can_close = lua_interface->GetInt32Value(state, 10);
  976. lua_interface->ResetFunctionStack(state);
  977. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  978. Client* client = ((Player*)player)->GetClient();
  979. if (client) {
  980. if (spawn) {
  981. // Need to do this so the function works the same as it did before
  982. if (type == 1)
  983. type++;
  984. if (mp3.length() > 0)
  985. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2, language, can_close);
  986. else
  987. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), nullptr, 0, 0, language, can_close);
  988. }
  989. else {
  990. if (mp3.length() > 0)
  991. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2, language, can_close);
  992. else
  993. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, nullptr, 0, 0, language, can_close);
  994. }
  995. }
  996. }
  997. lua_interface->SetLuaUserDataStale(conversation);
  998. safe_delete(conversation);
  999. return 0;
  1000. }
  1001. int EQ2Emu_lua_StartConversation(lua_State* state) {
  1002. if (!lua_interface)
  1003. return 0;
  1004. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  1005. Spawn* source = lua_interface->GetSpawn(state, 2);
  1006. Spawn* player = lua_interface->GetSpawn(state, 3);
  1007. string text = lua_interface->GetStringValue(state, 4);
  1008. string mp3 = lua_interface->GetStringValue(state, 5);
  1009. int32 key1 = lua_interface->GetInt32Value(state, 6);
  1010. int32 key2 = lua_interface->GetInt32Value(state, 7);
  1011. int8 language = lua_interface->GetInt32Value(state, 8);
  1012. int numargs = lua_interface->GetNumberOfArgs(state);
  1013. int8 can_close = 1;
  1014. if(numargs > 8)
  1015. can_close = lua_interface->GetInt32Value(state, 9);
  1016. lua_interface->ResetFunctionStack(state);
  1017. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1018. Client* client = ((Player*)player)->GetClient();
  1019. if (mp3.length() > 0)
  1020. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2, language, can_close);
  1021. else
  1022. client->DisplayConversation(source, 1, conversation, text.c_str(), nullptr, 0, 0, language, can_close);
  1023. lua_interface->SetLuaUserDataStale(conversation);
  1024. safe_delete(conversation);
  1025. }
  1026. else
  1027. 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);
  1028. return 0;
  1029. }
  1030. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1031. if (!lua_interface)
  1032. return 0;
  1033. Spawn* spawn = lua_interface->GetSpawn(state);
  1034. float distance = lua_interface->GetFloatValue(state, 2);
  1035. string in_range_function = lua_interface->GetStringValue(state, 3);
  1036. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1037. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1038. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1039. return 0;
  1040. }
  1041. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1042. ZoneServer* zone = lua_interface->GetZone(state);
  1043. float x = lua_interface->GetFloatValue(state, 2);
  1044. float y = lua_interface->GetFloatValue(state, 3);
  1045. float z = lua_interface->GetFloatValue(state, 4);
  1046. float max_variation = lua_interface->GetFloatValue(state, 5);
  1047. string in_range_function = lua_interface->GetStringValue(state, 6);
  1048. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1049. lua_interface->ResetFunctionStack(state);
  1050. if (zone && in_range_function.length() > 0)
  1051. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1052. return 0;
  1053. }
  1054. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1055. if (!lua_interface)
  1056. return 0;
  1057. Spawn* spawn = lua_interface->GetSpawn(state);
  1058. if (spawn && spawn->IsEntity()) {
  1059. int32 val = lua_interface->GetInt32Value(state, 2);
  1060. ((Entity*)spawn)->SetLootCoins(val);
  1061. }
  1062. lua_interface->ResetFunctionStack(state);
  1063. return 0;
  1064. }
  1065. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1066. if (!lua_interface)
  1067. return 0;
  1068. Spawn* spawn = lua_interface->GetSpawn(state);
  1069. lua_interface->ResetFunctionStack(state);
  1070. if (spawn && spawn->IsEntity()) {
  1071. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1072. return 1;
  1073. }
  1074. return 0;
  1075. }
  1076. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1077. if (!lua_interface)
  1078. return 0;
  1079. Spawn* spawn = lua_interface->GetSpawn(state);
  1080. float x = lua_interface->GetFloatValue(state, 2);
  1081. float y = lua_interface->GetFloatValue(state, 3);
  1082. float z = lua_interface->GetFloatValue(state, 4);
  1083. float speed = lua_interface->GetFloatValue(state, 5);
  1084. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1085. string function = lua_interface->GetStringValue(state, 7);
  1086. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1087. float heading = lua_interface->GetFloatValue(state, 8);
  1088. if (spawn) {
  1089. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1090. spawn->GetZone()->AddMovementNPC(spawn);
  1091. }
  1092. lua_interface->ResetFunctionStack(state);
  1093. return 0;
  1094. }
  1095. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1096. if (!lua_interface)
  1097. return 0;
  1098. Spawn* spawn = lua_interface->GetSpawn(state);
  1099. lua_interface->ResetFunctionStack(state);
  1100. if (spawn) {
  1101. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1102. return 1;
  1103. }
  1104. return 0;
  1105. }
  1106. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1107. if (!lua_interface)
  1108. return 0;
  1109. Spawn* spawn = lua_interface->GetSpawn(state);
  1110. lua_interface->ResetFunctionStack(state);
  1111. if (spawn && spawn->IsPlayer()) {
  1112. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1113. return 1;
  1114. }
  1115. lua_interface->SetInt32Value(state, 0);
  1116. return 1;
  1117. }
  1118. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1119. if (!lua_interface)
  1120. return 0;
  1121. Spawn* spawn = lua_interface->GetSpawn(state);
  1122. Spawn* target = lua_interface->GetSpawn(state, 2);
  1123. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1124. bool reset_action_state = true;
  1125. if(num_args > 2)
  1126. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1127. if (spawn && target) {
  1128. if (spawn->IsEntity())
  1129. // ((Entity*)spawn)->FaceTarget(target);
  1130. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1131. }
  1132. lua_interface->ResetFunctionStack(state);
  1133. return 0;
  1134. }
  1135. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1136. if (!lua_interface)
  1137. return 0;
  1138. Spawn* spawn = lua_interface->GetSpawn(state);
  1139. float x = lua_interface->GetFloatValue(state, 2);
  1140. float y = lua_interface->GetFloatValue(state, 3);
  1141. float z = lua_interface->GetFloatValue(state, 4);
  1142. float speed = lua_interface->GetFloatValue(state, 5);
  1143. string lua_function = lua_interface->GetStringValue(state, 6);
  1144. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1145. if (spawn) {
  1146. if (speed == 0)
  1147. speed = spawn->GetSpeed();
  1148. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1149. }
  1150. lua_interface->ResetFunctionStack(state);
  1151. return 0;
  1152. }
  1153. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1154. if (!lua_interface)
  1155. return 0;
  1156. Spawn* spawn = lua_interface->GetSpawn(state);
  1157. lua_interface->ResetFunctionStack(state);
  1158. if (spawn) {
  1159. spawn->ClearRunningLocations();
  1160. }
  1161. return 0;
  1162. }
  1163. int EQ2Emu_lua_Say(lua_State* state) {
  1164. if (!lua_interface)
  1165. return 0;
  1166. Spawn* spawn = lua_interface->GetSpawn(state);
  1167. string message = lua_interface->GetStringValue(state, 2);
  1168. Spawn* player = lua_interface->GetSpawn(state, 3);
  1169. float dist = lua_interface->GetFloatValue(state, 4);
  1170. int32 language = lua_interface->GetInt32Value(state, 5);
  1171. if (spawn && message.length() > 0) {
  1172. Client* client = 0;
  1173. if (player && player->IsPlayer())
  1174. client = ((Player*)player)->GetClient();
  1175. if (client)
  1176. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1177. else
  1178. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1179. }
  1180. lua_interface->ResetFunctionStack(state);
  1181. return 0;
  1182. }
  1183. int EQ2Emu_lua_Shout(lua_State* state) {
  1184. if (!lua_interface)
  1185. return 0;
  1186. Spawn* spawn = lua_interface->GetSpawn(state);
  1187. string message = lua_interface->GetStringValue(state, 2);
  1188. Spawn* player = lua_interface->GetSpawn(state, 3);
  1189. float dist = lua_interface->GetFloatValue(state, 4);
  1190. int32 language = lua_interface->GetInt32Value(state, 5);
  1191. if (spawn && message.length() > 0) {
  1192. Client* client = 0;
  1193. if (player && player->IsPlayer())
  1194. client = ((Player*)player)->GetClient();
  1195. if (client)
  1196. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1197. else
  1198. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1199. }
  1200. lua_interface->ResetFunctionStack(state);
  1201. return 0;
  1202. }
  1203. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1204. if (!lua_interface)
  1205. return 0;
  1206. Spawn* spawn = lua_interface->GetSpawn(state);
  1207. string message = lua_interface->GetStringValue(state, 2);
  1208. Spawn* player = lua_interface->GetSpawn(state, 3);
  1209. float dist = lua_interface->GetFloatValue(state, 4);
  1210. int32 language = lua_interface->GetInt32Value(state, 5);
  1211. if (spawn && message.length() > 0) {
  1212. Client* client = 0;
  1213. if (player && player->IsPlayer())
  1214. client = ((Player*)player)->GetClient();
  1215. if (client)
  1216. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1217. else
  1218. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1219. }
  1220. lua_interface->ResetFunctionStack(state);
  1221. return 0;
  1222. }
  1223. int EQ2Emu_lua_Emote(lua_State* state) {
  1224. if (!lua_interface)
  1225. return 0;
  1226. Spawn* spawn = lua_interface->GetSpawn(state);
  1227. string message = lua_interface->GetStringValue(state, 2);
  1228. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1229. Spawn* player = lua_interface->GetSpawn(state, 4);
  1230. char* to = 0;
  1231. if (spawn2)
  1232. to = spawn2->GetName();
  1233. if (spawn && message.length() > 0) {
  1234. Client* client = 0;
  1235. if (player && player->IsPlayer())
  1236. client = ((Player*)player)->GetClient();
  1237. if (client)
  1238. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1239. else
  1240. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1241. }
  1242. lua_interface->ResetFunctionStack(state);
  1243. return 0;
  1244. }
  1245. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1246. if (!lua_interface)
  1247. return 0;
  1248. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1249. if(!luaspell || luaspell->resisted) {
  1250. lua_interface->ResetFunctionStack(state);
  1251. return 0;
  1252. }
  1253. Spawn* caster = luaspell->caster;
  1254. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1255. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1256. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1257. Spawn* target = lua_interface->GetSpawn(state, 4);
  1258. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1259. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1260. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1261. lua_interface->ResetFunctionStack(state);
  1262. boost::to_lower(heal_type);
  1263. if (caster && caster->IsEntity()) {
  1264. bool success = false;
  1265. luaspell->resisted = false;
  1266. if (target) {
  1267. float distance = caster->GetDistance(target, true);
  1268. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1269. success = true;
  1270. }
  1271. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1272. Spawn* target = 0;
  1273. ZoneServer* zone = luaspell->caster->GetZone();
  1274. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1275. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1276. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1277. float distance = caster->GetDistance(target, true);
  1278. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1279. }
  1280. }
  1281. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1282. success = true;
  1283. }
  1284. if (success) {
  1285. if (caster->GetZone())
  1286. caster->GetZone()->TriggerCharSheetTimer();
  1287. }
  1288. }
  1289. return 0;
  1290. }
  1291. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1292. if (!lua_interface)
  1293. return 0;
  1294. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1295. if(!luaspell || luaspell->resisted) {
  1296. lua_interface->ResetFunctionStack(state);
  1297. return 0;
  1298. }
  1299. Spawn* caster = luaspell->caster;
  1300. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1301. float percentage = lua_interface->GetFloatValue(state, 2);
  1302. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1303. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1304. Spawn* target = lua_interface->GetSpawn(state, 5);
  1305. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1306. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1307. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1308. lua_interface->ResetFunctionStack(state);
  1309. boost::to_lower(heal_type);
  1310. int32 min_heal = 0, max_heal = 0;
  1311. if (caster && caster->IsEntity() && target) {
  1312. if(percentage <= 0.0f)
  1313. {
  1314. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1315. return 0;
  1316. }
  1317. if(heal_type == "power")
  1318. {
  1319. if(current_value)
  1320. {
  1321. if(caster_value)
  1322. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1323. else
  1324. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1325. }
  1326. else
  1327. {
  1328. if(caster_value)
  1329. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1330. else
  1331. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1332. }
  1333. }
  1334. else
  1335. {
  1336. if(current_value)
  1337. {
  1338. if(caster_value)
  1339. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1340. else
  1341. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1342. }
  1343. else
  1344. {
  1345. if(caster_value)
  1346. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1347. else
  1348. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1349. }
  1350. }
  1351. bool success = false;
  1352. luaspell->resisted = false;
  1353. if (target) {
  1354. float distance = caster->GetDistance(target, true);
  1355. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1356. success = true;
  1357. }
  1358. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1359. Spawn* target = 0;
  1360. ZoneServer* zone = luaspell->caster->GetZone();
  1361. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1362. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1363. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1364. float distance = caster->GetDistance(target, true);
  1365. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1366. }
  1367. }
  1368. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1369. success = true;
  1370. }
  1371. if (success) {
  1372. if (caster->GetZone())
  1373. caster->GetZone()->TriggerCharSheetTimer();
  1374. }
  1375. }
  1376. return 0;
  1377. }
  1378. int EQ2Emu_lua_AddItem(lua_State* state) {
  1379. if (!lua_interface)
  1380. return 0;
  1381. Spawn* spawn = lua_interface->GetSpawn(state);
  1382. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1383. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1384. lua_interface->ResetFunctionStack(state);
  1385. // default of 1 quantity to add
  1386. if (quantity == 0)
  1387. quantity = 1;
  1388. if (spawn && spawn->IsPlayer()) {
  1389. Client* client = ((Player*)spawn)->GetClient();
  1390. if (client && item_id > 0) {
  1391. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1392. return 1;
  1393. }
  1394. }
  1395. lua_interface->SetBooleanValue(state, false);
  1396. return 1;
  1397. }
  1398. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1399. if (!lua_interface)
  1400. return 0;
  1401. Spawn* spawn = lua_interface->GetSpawn(state);
  1402. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1403. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1404. string location = lua_interface->GetStringValue(state, 4);
  1405. int16 item_count = lua_interface->GetInt16Value(state,5);
  1406. //devn00b: if we dont have a count, assume 1 item.
  1407. if(!item_count) {
  1408. item_count = 1;
  1409. }
  1410. lua_interface->ResetFunctionStack(state);
  1411. if (spawn && spawn->IsPlayer()) {
  1412. Client* client = ((Player*)spawn)->GetClient();
  1413. if (client && item_id > 0) {
  1414. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1415. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1416. else
  1417. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1418. if (send_messages) {
  1419. Item* item = master_item_list.GetItem(item_id);
  1420. if (item) {
  1421. if(item_count > 1) {
  1422. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1423. string popup_text1 = "You receive "+ item_count;
  1424. string popup_text2 = " " + item->name;
  1425. string popup_text = popup_text1 + popup_text2;
  1426. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1427. // return 1;
  1428. } else {
  1429. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1430. string popup_text = "You receive " + item->name;
  1431. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1432. }
  1433. }
  1434. }
  1435. return 1;
  1436. }
  1437. }
  1438. lua_interface->SetBooleanValue(state, false);
  1439. return 1;
  1440. }
  1441. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1442. Spawn* spawn = lua_interface->GetSpawn(state);
  1443. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1444. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1445. lua_interface->ResetFunctionStack(state);
  1446. // default of 1 to remove
  1447. if (quantity == 0)
  1448. quantity = 1;
  1449. Client* client;
  1450. Item* item;
  1451. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1452. if ((client = ((Player*)spawn)->GetClient())) {
  1453. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1454. if (client->RemoveItem(item, quantity)) {
  1455. lua_interface->SetBooleanValue(state, true);
  1456. return 1;
  1457. }
  1458. }
  1459. }
  1460. }
  1461. lua_interface->SetBooleanValue(state, false);
  1462. return 1;
  1463. }
  1464. int EQ2Emu_lua_HasItem(lua_State* state) {
  1465. Spawn* player = lua_interface->GetSpawn(state);
  1466. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1467. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1468. lua_interface->ResetFunctionStack(state);
  1469. if (player && player->IsPlayer()) {
  1470. bool hasItem = false;
  1471. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1472. if (!hasItem)
  1473. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1474. lua_interface->SetBooleanValue(state, hasItem);
  1475. return 1;
  1476. }
  1477. lua_interface->SetBooleanValue(state, false);
  1478. return 1;
  1479. }
  1480. int EQ2Emu_lua_Spawn(lua_State* state) {
  1481. if (!lua_interface)
  1482. return 0;
  1483. ZoneServer* zone = lua_interface->GetZone(state);
  1484. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1485. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1486. float x = lua_interface->GetFloatValue(state, 4);
  1487. float y = lua_interface->GetFloatValue(state, 5);
  1488. float z = lua_interface->GetFloatValue(state, 6);
  1489. float heading = lua_interface->GetFloatValue(state, 7);
  1490. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1491. Spawn* spawn = zone->GetSpawn(spawn_id);
  1492. if (!spawn)
  1493. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1494. else {
  1495. spawn->SetX(x);
  1496. spawn->SetZ(z);
  1497. spawn->SetY(y,true,true);
  1498. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1499. spawn->SetHeading(heading);
  1500. if (restricted_npc)
  1501. spawn->AddAllowAccessSpawn(spawn);
  1502. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1503. bool scriptActive = false;
  1504. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1505. scriptActive = true;
  1506. spawn->SetSpawnScript(string(spawn_script));
  1507. }
  1508. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1509. zone->AddSpawn(spawn);
  1510. if (scriptActive) {
  1511. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1512. }
  1513. lua_interface->ResetFunctionStack(state);
  1514. lua_interface->SetSpawnValue(state, spawn);
  1515. return 1;
  1516. }
  1517. }
  1518. else {
  1519. string output = "Invalid paramaters to LUA Spawn command: \n";
  1520. if (!zone)
  1521. output = output.append("\t").append("Missing zone reference. \n");
  1522. if (spawn_id == 0)
  1523. output = output.append("\t").append("Missing spawn_id.");
  1524. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1525. }
  1526. lua_interface->ResetFunctionStack(state);
  1527. return 0;
  1528. }
  1529. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1530. if (!lua_interface)
  1531. return 0;
  1532. ZoneServer* zone = lua_interface->GetZone(state);
  1533. lua_interface->ResetFunctionStack(state);
  1534. if (zone) {
  1535. lua_interface->SetStringValue(state, zone->GetZoneName());
  1536. return 1;
  1537. }
  1538. return 0;
  1539. }
  1540. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1541. if (!lua_interface)
  1542. return 0;
  1543. ZoneServer* zone = lua_interface->GetZone(state);
  1544. lua_interface->ResetFunctionStack(state);
  1545. if (zone) {
  1546. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1547. return 1;
  1548. }
  1549. return 0;
  1550. }
  1551. int EQ2Emu_lua_GetZone(lua_State* state) {
  1552. if (!lua_interface)
  1553. return 0;
  1554. int32 zone_id = lua_interface->GetInt32Value(state);
  1555. ZoneServer* zone = 0;
  1556. if (zone_id > 0)
  1557. zone = zone_list.Get(zone_id, true, false, false);
  1558. else {
  1559. string zone_name = lua_interface->GetStringValue(state);
  1560. if (zone_name.length() > 0) {
  1561. zone = zone_list.Get(zone_name.c_str(), true, false, false);
  1562. }
  1563. else {
  1564. Spawn* spawn = lua_interface->GetSpawn(state);
  1565. if (spawn)
  1566. zone = spawn->GetZone();
  1567. }
  1568. }
  1569. lua_interface->ResetFunctionStack(state);
  1570. if (zone) {
  1571. lua_interface->SetZoneValue(state, zone);
  1572. return 1;
  1573. }
  1574. return 0;
  1575. }
  1576. int EQ2Emu_lua_AddHate(lua_State* state) {
  1577. Spawn* entity = lua_interface->GetSpawn(state);
  1578. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1579. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1580. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1581. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1582. lua_interface->ResetFunctionStack(state);
  1583. if(luaspell && luaspell->resisted) {
  1584. return 0;
  1585. }
  1586. if (entity && entity->IsEntity() && amount != 0) {
  1587. if (luaspell && luaspell->caster) {
  1588. ZoneServer* zone = luaspell->caster->GetZone();
  1589. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1590. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1591. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1592. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1593. entity->CheckEncounterState((Entity*)spawn);
  1594. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1595. if (send_packet)
  1596. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1597. }
  1598. }
  1599. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1600. }
  1601. else if (npc && npc->IsNPC() && npc->GetZone()) {
  1602. entity->CheckEncounterState((Entity*)npc);
  1603. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1604. }
  1605. }
  1606. lua_interface->ResetFunctionStack(state);
  1607. return 0;
  1608. }
  1609. int EQ2Emu_lua_Zone(lua_State* state) {
  1610. if (!lua_interface)
  1611. return 0;
  1612. ZoneServer* zone = lua_interface->GetZone(state);
  1613. Spawn* player = lua_interface->GetSpawn(state, 2);
  1614. Client* client = 0;
  1615. if (player && player->IsPlayer())
  1616. client = ((Player*)player)->GetClient();
  1617. float x = lua_interface->GetFloatValue(state, 3);
  1618. float y = lua_interface->GetFloatValue(state, 4);
  1619. float z = lua_interface->GetFloatValue(state, 5);
  1620. float heading = lua_interface->GetFloatValue(state, 6);
  1621. lua_interface->ResetFunctionStack(state);
  1622. if (zone && client) {
  1623. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1624. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1625. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1626. {
  1627. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1628. return 0;
  1629. }
  1630. if (x != 0 || y != 0 || z != 0) {
  1631. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1632. player->SetX(x);
  1633. player->SetY(y);
  1634. player->SetZ(z);
  1635. player->SetHeading(heading);
  1636. client->Zone(zone->GetZoneName(), false);
  1637. }
  1638. else
  1639. client->Zone(zone->GetZoneName());
  1640. }
  1641. else
  1642. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1643. return 0;
  1644. }
  1645. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1646. if (!lua_interface)
  1647. return 0;
  1648. Spawn* spawn = lua_interface->GetSpawn(state);
  1649. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1650. lua_interface->ResetFunctionStack(state);
  1651. if (spawn && spawn2)
  1652. spawn->AddAllowAccessSpawn(spawn2);
  1653. lua_interface->ResetFunctionStack(state);
  1654. return 0;
  1655. }
  1656. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1657. if (!lua_interface)
  1658. return 0;
  1659. Spawn* target = lua_interface->GetSpawn(state);
  1660. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1661. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1662. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1663. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1664. lua_interface->ResetFunctionStack(state);
  1665. if (!target) {
  1666. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1667. return 0;
  1668. }
  1669. if (!target->IsEntity()) {
  1670. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1671. return 0;
  1672. }
  1673. if (spell_id <= 0) {
  1674. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1675. return 0;
  1676. }
  1677. if (caster && !caster->IsEntity()) {
  1678. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1679. return 0;
  1680. }
  1681. if (spell_tier == 0)
  1682. spell_tier = 1;
  1683. if (!caster)
  1684. caster = target;
  1685. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1686. return 0;
  1687. }
  1688. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1689. if (!lua_interface)
  1690. return 0;
  1691. Spawn* target = lua_interface->GetSpawn(state);
  1692. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1693. if(!luaspell || luaspell->resisted) {
  1694. lua_interface->ResetFunctionStack(state);
  1695. lua_interface->SetBooleanValue(state, false);
  1696. return 1;
  1697. }
  1698. Spawn* caster = luaspell->caster;
  1699. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1700. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1701. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1702. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1703. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1704. //lua_interface->ResetFunctionStack(state);
  1705. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1706. vector<int16> faction_req;
  1707. vector<int16> race_req;
  1708. int32 class_req = 0;
  1709. int32 i = 0;
  1710. int8 f = 0;
  1711. int8 r = 0;
  1712. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1713. if (class_id < 100) {
  1714. class_req += pow(2.0, double(class_id - 1));
  1715. }
  1716. else if (class_id > 100 && class_id < 1000) {
  1717. race_req.push_back(class_id);
  1718. r++;
  1719. }
  1720. else {
  1721. faction_req.push_back(class_id);
  1722. f++;
  1723. }
  1724. i++;
  1725. }
  1726. lua_interface->ResetFunctionStack(state);
  1727. if (caster && caster->IsEntity()) {
  1728. bool race_match = false;
  1729. bool success = false;
  1730. luaspell->resisted = false;
  1731. if (luaspell->targets.size() > 0) {
  1732. ZoneServer* zone = luaspell->caster->GetZone();
  1733. Spawn* target = 0;
  1734. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1735. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1736. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1737. if (race_req.size() > 0) {
  1738. for (int8 i = 0; i < race_req.size(); i++) {
  1739. if(race_req[i] == target->GetRace() ||
  1740. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1741. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1742. race_match = true;
  1743. }
  1744. }
  1745. }
  1746. else
  1747. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1748. if (race_match == true) {
  1749. float distance = caster->GetDistance(target, true);
  1750. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1751. }
  1752. }
  1753. }
  1754. success = true;
  1755. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1756. }
  1757. else if (target) {
  1758. //check class and race/faction here
  1759. if (race_req.size() > 0) {
  1760. for (int8 i = 0; i < race_req.size(); i++) {
  1761. if(race_req[i] == target->GetRace() ||
  1762. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1763. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1764. race_match = true;
  1765. }
  1766. }
  1767. }
  1768. else
  1769. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1770. if (race_match == true) {
  1771. float distance = caster->GetDistance(target, true);
  1772. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1773. success = true;
  1774. }
  1775. }
  1776. lua_interface->SetBooleanValue(state, luaspell->has_damaged);
  1777. if (success) {
  1778. Spell* spell = luaspell->spell;
  1779. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1780. ((Player*)caster)->InCombat(true);
  1781. if (caster->GetZone())
  1782. caster->GetZone()->TriggerCharSheetTimer();
  1783. }
  1784. }
  1785. }
  1786. else {
  1787. lua_interface->SetBooleanValue(state, false);
  1788. }
  1789. return 1;
  1790. }
  1791. int EQ2Emu_lua_SpellDamageExt(lua_State* state) {
  1792. if (!lua_interface)
  1793. return 0;
  1794. Spawn* target = lua_interface->GetSpawn(state);
  1795. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1796. if(!luaspell || luaspell->resisted) {
  1797. lua_interface->ResetFunctionStack(state);
  1798. lua_interface->SetBooleanValue(state, false);
  1799. return 1;
  1800. }
  1801. Spawn* caster = luaspell->caster;
  1802. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1803. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1804. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1805. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1806. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1807. int32 override_packet_type = lua_interface->GetInt32Value(state, 7);
  1808. bool take_power = lua_interface->GetInt32Value(state, 8) == 1;
  1809. //lua_interface->ResetFunctionStack(state);
  1810. int32 class_id = lua_interface->GetInt32Value(state, 9);
  1811. vector<int16> faction_req;
  1812. vector<int16> race_req;
  1813. int32 class_req = 0;
  1814. int32 i = 0;
  1815. int8 f = 0;
  1816. int8 r = 0;
  1817. while ((class_id = lua_interface->GetInt32Value(state, 9 + i))) {
  1818. if (class_id < 100) {
  1819. class_req += pow(2.0, double(class_id - 1));
  1820. }
  1821. else if (class_id > 100 && class_id < 1000) {
  1822. race_req.push_back(class_id);
  1823. r++;
  1824. }
  1825. else {
  1826. faction_req.push_back(class_id);
  1827. f++;
  1828. }
  1829. i++;
  1830. }
  1831. lua_interface->ResetFunctionStack(state);
  1832. if (caster && caster->IsEntity()) {
  1833. bool race_match = false;
  1834. bool success = false;
  1835. luaspell->resisted = false;
  1836. if (luaspell->targets.size() > 0) {
  1837. ZoneServer* zone = luaspell->caster->GetZone();
  1838. Spawn* target = 0;
  1839. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1840. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1841. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1842. if (race_req.size() > 0) {
  1843. for (int8 i = 0; i < race_req.size(); i++) {
  1844. if(race_req[i] == target->GetRace() ||
  1845. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1846. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1847. race_match = true;
  1848. }
  1849. }
  1850. }
  1851. else
  1852. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1853. if (race_match == true) {
  1854. float distance = caster->GetDistance(target, true);
  1855. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power);
  1856. }
  1857. }
  1858. }
  1859. success = true;
  1860. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1861. }
  1862. else if (target) {
  1863. //check class and race/faction here
  1864. if (race_req.size() > 0) {
  1865. for (int8 i = 0; i < race_req.size(); i++) {
  1866. if(race_req[i] == target->GetRace() ||
  1867. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1868. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1869. race_match = true;
  1870. }
  1871. }
  1872. }
  1873. else
  1874. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1875. if (race_match == true) {
  1876. float distance = caster->GetDistance(target, true);
  1877. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power))
  1878. success = true;
  1879. }
  1880. }
  1881. lua_interface->SetBooleanValue(state, luaspell->has_damaged);
  1882. if (success) {
  1883. Spell* spell = luaspell->spell;
  1884. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1885. ((Player*)caster)->InCombat(true);
  1886. if (caster->GetZone())
  1887. caster->GetZone()->TriggerCharSheetTimer();
  1888. }
  1889. }
  1890. }
  1891. else {
  1892. lua_interface->SetBooleanValue(state, false);
  1893. }
  1894. return 1;
  1895. }
  1896. int EQ2Emu_lua_ModifyPower(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 && value != 0) {
  1903. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1904. spawn->SetPower(spawn->GetTotalPower());
  1905. else
  1906. spawn->SetPower(spawn->GetPower() + value);
  1907. }
  1908. return 0;
  1909. }
  1910. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1911. if (!lua_interface)
  1912. return 0;
  1913. Spawn* spawn = lua_interface->GetSpawn(state);
  1914. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1915. lua_interface->ResetFunctionStack(state);
  1916. if (spawn && value != 0) {
  1917. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1918. spawn->SetHP(spawn->GetTotalHP());
  1919. else
  1920. spawn->SetHP(spawn->GetHP() + value);
  1921. }
  1922. return 0;
  1923. }
  1924. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1925. if (!lua_interface)
  1926. return 0;
  1927. Spawn* spawn = lua_interface->GetSpawn(state);
  1928. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1929. lua_interface->ResetFunctionStack(state);
  1930. if (spawn && value != 0) {
  1931. spawn->SetTotalPower(value);
  1932. spawn->SetTotalPowerBaseInstance(value);
  1933. }
  1934. return 0;
  1935. }
  1936. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1937. if (!lua_interface)
  1938. return 0;
  1939. Spawn* spawn = lua_interface->GetSpawn(state);
  1940. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1941. lua_interface->ResetFunctionStack(state);
  1942. if (spawn && value != 0) {
  1943. spawn->SetTotalHP(value);
  1944. spawn->SetTotalHPBaseInstance(value);
  1945. }
  1946. return 0;
  1947. }
  1948. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1949. if (!lua_interface)
  1950. return 0;
  1951. Spawn* spawn = lua_interface->GetSpawn(state);
  1952. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1953. lua_interface->ResetFunctionStack(state);
  1954. if (spawn) {
  1955. spawn->SetHP(value);
  1956. if (value > spawn->GetTotalHPBase())
  1957. spawn->SetTotalHP(value);
  1958. }
  1959. return 0;
  1960. }
  1961. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1962. if (!lua_interface)
  1963. return 0;
  1964. Spawn* spawn = lua_interface->GetSpawn(state);
  1965. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1966. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1967. lua_interface->ResetFunctionStack(state);
  1968. if (spawn && spawn->IsEntity() && value > 0)
  1969. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1970. if (spawn && spawn->IsPlayer())
  1971. ((Player*)spawn)->SetCharSheetChanged(true);
  1972. return 0;
  1973. }
  1974. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1975. if (!lua_interface)
  1976. return 0;
  1977. Spawn* spawn = lua_interface->GetSpawn(state);
  1978. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1979. lua_interface->ResetFunctionStack(state);
  1980. if (spawn && spawn->IsEntity() && value > 0)
  1981. ((Entity*)spawn)->SetTotalHPBase(value);
  1982. return 0;
  1983. }
  1984. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1985. if (!lua_interface)
  1986. return 0;
  1987. Spawn* spawn = lua_interface->GetSpawn(state);
  1988. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1989. lua_interface->ResetFunctionStack(state);
  1990. if (spawn && value > 0) {
  1991. spawn->SetPower(value);
  1992. if (value > spawn->GetTotalPowerBase())
  1993. spawn->SetTotalPower(value);
  1994. }
  1995. return 0;
  1996. }
  1997. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1998. if (!lua_interface)
  1999. return 0;
  2000. Spawn* spawn = lua_interface->GetSpawn(state);
  2001. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2002. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2003. lua_interface->ResetFunctionStack(state);
  2004. if (spawn && spawn->IsEntity() && value > 0)
  2005. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  2006. return 0;
  2007. }
  2008. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  2009. if (!lua_interface)
  2010. return 0;
  2011. Spawn* spawn = lua_interface->GetSpawn(state);
  2012. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2013. lua_interface->ResetFunctionStack(state);
  2014. if (spawn && spawn->IsEntity() && value > 0)
  2015. ((Entity*)spawn)->SetTotalPowerBase(value);
  2016. return 0;
  2017. }
  2018. int EQ2Emu_lua_SetPosition(lua_State* state) {
  2019. if (!lua_interface)
  2020. return 0;
  2021. Spawn* spawn = lua_interface->GetSpawn(state);
  2022. float x = lua_interface->GetFloatValue(state, 2);
  2023. float y = lua_interface->GetFloatValue(state, 3);
  2024. float z = lua_interface->GetFloatValue(state, 4);
  2025. float heading = lua_interface->GetFloatValue(state, 5);
  2026. lua_interface->ResetFunctionStack(state);
  2027. if (spawn) {
  2028. spawn->SetX(x);
  2029. spawn->SetY(y);
  2030. spawn->SetZ(z);
  2031. if (heading != 0)
  2032. spawn->SetHeading(heading);
  2033. spawn->SetSpawnOrigX(spawn->GetX());
  2034. spawn->SetSpawnOrigY(spawn->GetY());
  2035. spawn->SetSpawnOrigZ(spawn->GetZ());
  2036. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  2037. if (spawn->IsPlayer()) {
  2038. Client* client = ((Player*)spawn)->GetClient();
  2039. if (client) {
  2040. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  2041. client->QueuePacket(packet);
  2042. }
  2043. }
  2044. }
  2045. return 0;
  2046. }
  2047. int EQ2Emu_lua_SetHeading(lua_State* state) {
  2048. if (!lua_interface)
  2049. return 0;
  2050. Spawn* spawn = lua_interface->GetSpawn(state);
  2051. float value = lua_interface->GetFloatValue(state, 2);
  2052. lua_interface->ResetFunctionStack(state);
  2053. if (spawn) {
  2054. spawn->SetHeading(value);
  2055. if (spawn->IsPlayer()) {
  2056. Client* client = ((Player*)spawn)->GetClient();
  2057. if (client) {
  2058. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  2059. client->QueuePacket(packet);
  2060. }
  2061. }
  2062. }
  2063. return 0;
  2064. }
  2065. int EQ2Emu_lua_SetModelType(lua_State* state) {
  2066. if (!lua_interface)
  2067. return 0;
  2068. Spawn* spawn = lua_interface->GetSpawn(state);
  2069. int16 value = lua_interface->GetInt16Value(state, 2);
  2070. lua_interface->ResetFunctionStack(state);
  2071. if (spawn)
  2072. spawn->SetModelType(value);
  2073. return 0;
  2074. }
  2075. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  2076. if (!lua_interface)
  2077. return 0;
  2078. Spawn* spawn = lua_interface->GetSpawn(state);
  2079. int8 value = lua_interface->GetInt8Value(state, 2);
  2080. lua_interface->ResetFunctionStack(state);
  2081. if (spawn) {
  2082. if (spawn->IsPlayer())
  2083. ((Player*)spawn)->SetPlayerAdventureClass(value);
  2084. else
  2085. spawn->SetAdventureClass(value);
  2086. }
  2087. return 0;
  2088. }
  2089. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  2090. if (!lua_interface)
  2091. return 0;
  2092. Spawn* spawn = lua_interface->GetSpawn(state);
  2093. int8 value = lua_interface->GetInt8Value(state, 2);
  2094. lua_interface->ResetFunctionStack(state);
  2095. if (spawn) {
  2096. spawn->SetTradeskillClass(value);
  2097. if (spawn->IsEntity()) {
  2098. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  2099. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  2100. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  2101. }
  2102. if (spawn->IsPlayer())
  2103. ((Player*)spawn)->SetCharSheetChanged(true);
  2104. }
  2105. return 0;
  2106. }
  2107. int EQ2Emu_lua_SetMount(lua_State* state) {
  2108. if (!lua_interface)
  2109. return 0;
  2110. Spawn* spawn = lua_interface->GetSpawn(state);
  2111. int16 value = lua_interface->GetInt16Value(state, 2);
  2112. lua_interface->ResetFunctionStack(state);
  2113. if (spawn && spawn->IsEntity()) {
  2114. ((Entity*)spawn)->SetMount(value);
  2115. EQ2_Color color;
  2116. color.red = 255;
  2117. color.green = 255;
  2118. color.blue = 255;
  2119. ((Entity*)spawn)->SetMountColor(&color);
  2120. ((Entity*)spawn)->SetMountSaddleColor(&color);
  2121. }
  2122. return 0;
  2123. }
  2124. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  2125. if (!lua_interface)
  2126. return 0;
  2127. Spawn* spawn = lua_interface->GetSpawn(state);
  2128. EQ2_Color mount_color;
  2129. EQ2_Color saddle_color;
  2130. mount_color.red = lua_interface->GetInt8Value(state, 2);
  2131. mount_color.green = lua_interface->GetInt8Value(state, 3);
  2132. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  2133. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  2134. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  2135. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  2136. lua_interface->ResetFunctionStack(state);
  2137. if (spawn && spawn->IsEntity()) {
  2138. ((Entity*)spawn)->SetMountColor(&mount_color);
  2139. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  2140. }
  2141. return 0;
  2142. }
  2143. int EQ2Emu_lua_GetMount(lua_State* state) {
  2144. if (!lua_interface)
  2145. return 0;
  2146. Spawn* spawn = lua_interface->GetSpawn(state);
  2147. lua_interface->ResetFunctionStack(state);
  2148. if (spawn && spawn->IsEntity()) {
  2149. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2150. return 1;
  2151. }
  2152. return 0;
  2153. }
  2154. int EQ2Emu_lua_GetRace(lua_State* state) {
  2155. if (!lua_interface)
  2156. return 0;
  2157. Spawn* spawn = lua_interface->GetSpawn(state);
  2158. lua_interface->ResetFunctionStack(state);
  2159. if (spawn)
  2160. {
  2161. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2162. lua_interface->SetInt32Value(state, spawn->GetRace());
  2163. return 1;
  2164. }
  2165. return 0;
  2166. }
  2167. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2168. if (!lua_interface)
  2169. return 0;
  2170. Spawn* spawn = lua_interface->GetSpawn(state);
  2171. lua_interface->ResetFunctionStack(state);
  2172. if (spawn) {
  2173. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2174. return 1;
  2175. }
  2176. return 0;
  2177. }
  2178. int EQ2Emu_lua_GetClass(lua_State* state) {
  2179. Spawn* spawn = lua_interface->GetSpawn(state);
  2180. lua_interface->ResetFunctionStack(state);
  2181. if (spawn) {
  2182. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2183. return 1;
  2184. }
  2185. return 0;
  2186. }
  2187. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2188. Spawn* spawn = lua_interface->GetSpawn(state);
  2189. lua_interface->ResetFunctionStack(state);
  2190. if (spawn) {
  2191. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2192. return 1;
  2193. }
  2194. return 0;
  2195. }
  2196. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2197. if (!lua_interface)
  2198. return 0;
  2199. Spawn* spawn = lua_interface->GetSpawn(state);
  2200. float value = lua_interface->GetFloatValue(state, 2);
  2201. lua_interface->ResetFunctionStack(state);
  2202. if (spawn) {
  2203. spawn->SetSpeed(value);
  2204. if(spawn->IsEntity())
  2205. ((Entity*)spawn)->SetSpeed(value);
  2206. if (spawn->IsPlayer()) {
  2207. Client* client = ((Player*)spawn)->GetClient();
  2208. if (client) {
  2209. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2210. if (packet) {
  2211. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2212. packet->setDataByName("speed", value);
  2213. packet->setDataByName("size", 0.51);
  2214. EQ2Packet* app = packet->serialize();
  2215. client->QueuePacket(app);
  2216. safe_delete(packet);
  2217. }
  2218. }
  2219. }
  2220. }
  2221. return 0;
  2222. }
  2223. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2224. if (!lua_interface)
  2225. return 0;
  2226. Spawn* spawn = lua_interface->GetSpawn(state);
  2227. const int16 type = lua_interface->GetInt16Value(state, 2);
  2228. const float value = lua_interface->GetFloatValue(state, 3);
  2229. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2230. lua_interface->ResetFunctionStack(state);
  2231. if(!luaspell || luaspell->resisted) {
  2232. return 0;
  2233. }
  2234. int64 class_req = 0;
  2235. int32 class_id = 0;
  2236. vector<int16> faction_req;
  2237. vector<int16> race_req;
  2238. int32 i = 0;
  2239. int8 f = 0;
  2240. int8 r = 0;
  2241. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2242. if (class_id < 100) {
  2243. class_req += pow(2.0, double(class_id - 1));
  2244. }
  2245. else if (class_id > 100 && class_id < 1000) {
  2246. race_req.push_back(class_id);
  2247. r++;
  2248. }
  2249. else {
  2250. faction_req.push_back(class_id);
  2251. f++;
  2252. }
  2253. i++;
  2254. }
  2255. if (value != 0 && type >= 0) {
  2256. if (luaspell && luaspell->spell && luaspell->caster) {
  2257. ZoneServer* zone = luaspell->caster->GetZone();
  2258. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2259. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2260. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2261. if (target) {
  2262. if (target->IsPlayer()) {
  2263. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2264. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2265. if (((Player*)target)->GetGroupMemberInfo())
  2266. ((Player*)target)->UpdateGroupMemberInfo();
  2267. ((Player*)target)->SetCharSheetChanged(true);
  2268. }
  2269. else if (target->IsNPC())
  2270. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2271. else
  2272. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2273. }
  2274. }
  2275. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2276. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2277. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2278. }
  2279. else if (spawn && spawn->IsEntity()) {
  2280. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2281. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2282. if (spawn->IsPlayer())
  2283. ((Player*)spawn)->SetCharSheetChanged(true);
  2284. }
  2285. else
  2286. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2287. }
  2288. else
  2289. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2290. return 0;
  2291. }
  2292. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2293. if (!lua_interface)
  2294. return 0;
  2295. Spawn* spawn = lua_interface->GetSpawn(state);
  2296. int16 type = lua_interface->GetInt16Value(state, 2);
  2297. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2298. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2299. lua_interface->ResetFunctionStack(state);
  2300. if (!spawn) {
  2301. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2302. return 0;
  2303. }
  2304. if (!spawn->IsEntity()) {
  2305. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2306. return 0;
  2307. }
  2308. if (value == 0) {
  2309. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2310. return 0;
  2311. }
  2312. if (!luaspell || !luaspell->spell) {
  2313. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2314. return 0;
  2315. }
  2316. if(luaspell->resisted) {
  2317. return 0;
  2318. }
  2319. int32 class_req = 0;
  2320. vector<int16> faction_req;
  2321. vector<int16> race_req;
  2322. int32 class_id = 0;
  2323. int32 i = 0;
  2324. int8 f = 0;
  2325. int8 r = 0;
  2326. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2327. if (class_id < 100) {
  2328. class_req += pow(2.0, double(class_id - 1));
  2329. }
  2330. else if (class_id > 100 && class_id < 1000) {
  2331. race_req.push_back(class_id);
  2332. r++;
  2333. }
  2334. else {
  2335. faction_req.push_back(class_id);
  2336. f++;
  2337. }
  2338. i++;
  2339. }
  2340. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2341. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2342. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2343. if (spawn->IsPlayer())
  2344. ((Player*)spawn)->SetCharSheetChanged(true);
  2345. return 0;
  2346. }
  2347. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2348. if (!lua_interface)
  2349. return 0;
  2350. Spawn* spawn = lua_interface->GetSpawn(state);
  2351. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2352. if (!spawn) {
  2353. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2354. return 0;
  2355. }
  2356. if (!spawn->IsEntity()) {
  2357. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2358. return 0;
  2359. }
  2360. if (!luaspell || !luaspell->spell) {
  2361. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2362. return 0;
  2363. }
  2364. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2365. if (spawn->IsPlayer())
  2366. ((Player*)spawn)->SetCharSheetChanged(true);
  2367. return 0;
  2368. }
  2369. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2370. if (!lua_interface)
  2371. return 0;
  2372. Spawn* spawn = lua_interface->GetSpawn(state);
  2373. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2374. lua_interface->ResetFunctionStack(state);
  2375. if (luaspell && luaspell->spell) {
  2376. ZoneServer* zone = nullptr;
  2377. if (luaspell->caster != nullptr)
  2378. zone = luaspell->caster->GetZone();
  2379. if(!zone && spawn) {
  2380. zone = spawn->GetZone(); // workaround to try to establish a zone to find the targets and remove the spells
  2381. }
  2382. Spawn* target = 0;
  2383. if(zone) {
  2384. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2385. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2386. target = zone->GetSpawnByID(luaspell->targets[i]);
  2387. if (target && target->IsEntity()) {
  2388. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2389. if (target->IsPlayer())
  2390. ((Player*)target)->SetCharSheetChanged(true);
  2391. }
  2392. }
  2393. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2394. }
  2395. else {
  2396. LogWrite(LUA__ERROR, 0, "LUA", "Error removing spell bonus buff %s called by %s, zone is not available.", luaspell->spell ? luaspell->spell->GetName() : "NotSet", spawn->GetName());
  2397. }
  2398. }
  2399. else if (spawn && spawn->IsEntity()) {
  2400. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2401. if (spawn->IsPlayer())
  2402. ((Player*)spawn)->SetCharSheetChanged(true);
  2403. }
  2404. return 0;
  2405. }
  2406. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2407. if (!lua_interface)
  2408. return 0;
  2409. Spawn* spawn = lua_interface->GetSpawn(state);
  2410. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2411. float value = lua_interface->GetFloatValue(state, 3);
  2412. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2413. if (value != 0) {
  2414. int32 spell_id = 0;
  2415. if (luaspell && luaspell->spell && luaspell->caster) {
  2416. if(luaspell->resisted) {
  2417. lua_interface->ResetFunctionStack(state);
  2418. return 0;
  2419. }
  2420. spell_id = luaspell->spell->GetSpellID();
  2421. ZoneServer* zone = luaspell->caster->GetZone();
  2422. Spawn* target = 0;
  2423. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2424. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2425. target = zone->GetSpawnByID(luaspell->targets[i]);
  2426. if (target && target->Alive()) {
  2427. if (target->IsPlayer()) {
  2428. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2429. Client* client = ((Player*)target)->GetClient();
  2430. if (client) {
  2431. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2432. if (packet)
  2433. client->QueuePacket(packet);
  2434. }
  2435. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2436. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2437. }
  2438. else if (target->IsNPC()) {
  2439. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2440. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2441. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2442. }
  2443. else
  2444. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2445. }
  2446. }
  2447. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2448. }
  2449. else if (spawn) {
  2450. if (spawn->IsPlayer()) {
  2451. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2452. Client* client = ((Player*)spawn)->GetClient();
  2453. if (client) {
  2454. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2455. if (packet)
  2456. client->QueuePacket(packet);
  2457. }
  2458. }
  2459. else if (spawn->IsNPC())
  2460. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2461. else
  2462. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2463. }
  2464. }
  2465. else
  2466. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2467. return 0;
  2468. }
  2469. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2470. if (!lua_interface)
  2471. return 0;
  2472. Spawn* spawn = lua_interface->GetSpawn(state);
  2473. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2474. lua_interface->ResetFunctionStack(state);
  2475. int32 spell_id = 0;
  2476. if (luaspell && luaspell->spell && luaspell->caster) {
  2477. if(luaspell->resisted) {
  2478. return 0;
  2479. }
  2480. spell_id = luaspell->spell->GetSpellID();
  2481. ZoneServer* zone = luaspell->caster->GetZone();
  2482. Spawn* target = 0;
  2483. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2484. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2485. target = zone->GetSpawnByID(luaspell->targets[i]);
  2486. if (target) {
  2487. if (target->IsPlayer()) {
  2488. ((Player*)target)->RemoveSkillBonus(spell_id);
  2489. Client* client = ((Player*)target)->GetClient();
  2490. if (client) {
  2491. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2492. if (packet)
  2493. client->QueuePacket(packet);
  2494. }
  2495. }
  2496. else if (target->IsNPC())
  2497. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2498. else
  2499. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2500. }
  2501. }
  2502. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2503. }
  2504. else if (spawn) {
  2505. if (spawn->IsPlayer()) {
  2506. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2507. Client* client = ((Player*)spawn)->GetClient();
  2508. if (client) {
  2509. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2510. if (packet)
  2511. client->QueuePacket(packet);
  2512. }
  2513. }
  2514. else if (spawn->IsNPC())
  2515. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2516. else
  2517. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2518. }
  2519. return 0;
  2520. }
  2521. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2522. if (!lua_interface)
  2523. return 0;
  2524. Spawn* spawn = lua_interface->GetSpawn(state);
  2525. int8 type = lua_interface->GetInt32Value(state, 2);
  2526. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2527. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2528. lua_interface->ResetFunctionStack(state);
  2529. if(!luaspell || luaspell->resisted) {
  2530. return 0;
  2531. }
  2532. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2533. ZoneServer* zone = luaspell->caster->GetZone();
  2534. Spawn* target = 0;
  2535. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2536. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2537. target = zone->GetSpawnByID(luaspell->targets[i]);
  2538. if (target && target->IsEntity()) {
  2539. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2540. ((Entity*)target)->AddMezSpell(luaspell);
  2541. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2542. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2543. if (target->IsNPC())
  2544. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2545. }
  2546. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2547. ((Entity*)target)->AddStifleSpell(luaspell);
  2548. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2549. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2550. if (target->IsNPC())
  2551. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2552. }
  2553. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2554. ((Entity*)target)->AddDazeSpell(luaspell);
  2555. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2556. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2557. if (target->IsNPC())
  2558. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2559. }
  2560. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2561. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2562. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2563. ((Entity*)target)->AddStunSpell(luaspell);
  2564. if (target->IsNPC())
  2565. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2566. }
  2567. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2568. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2569. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2570. ((Entity*)target)->AddRootSpell(luaspell);
  2571. if (target->IsNPC())
  2572. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2573. }
  2574. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2575. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2576. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2577. ((Entity*)target)->AddFearSpell(luaspell);
  2578. if (target->IsNPC())
  2579. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2580. }
  2581. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2582. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2583. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2584. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2585. }
  2586. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2587. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2588. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2589. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2590. }
  2591. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2592. ((Entity*)target)->AddSnareSpell(luaspell);
  2593. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2594. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2595. if (target->IsNPC())
  2596. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2597. }
  2598. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2599. ((Entity*)target)->AddFlightSpell(luaspell);
  2600. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2601. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2602. }
  2603. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2604. ((Entity*)target)->AddGlideSpell(luaspell);
  2605. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2606. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2607. }
  2608. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2609. ((Entity*)target)->AddSafefallSpell(luaspell);
  2610. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2611. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2612. }
  2613. else
  2614. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2615. }
  2616. else
  2617. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2618. }
  2619. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2620. }
  2621. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2622. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2623. ((Entity*)spawn)->AddMezSpell(luaspell);
  2624. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2625. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2626. }
  2627. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2628. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2629. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2630. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2631. }
  2632. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2633. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2634. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2635. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2636. }
  2637. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2638. ((Entity*)spawn)->AddStunSpell(luaspell);
  2639. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2640. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2641. }
  2642. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2643. ((Entity*)spawn)->AddRootSpell(luaspell);
  2644. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2645. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2646. }
  2647. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2648. ((Entity*)spawn)->AddFearSpell(luaspell);
  2649. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2650. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2651. }
  2652. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2653. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2654. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2655. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2656. }
  2657. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2658. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2659. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2660. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2661. }
  2662. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2663. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2664. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2665. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2666. }
  2667. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2668. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2669. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2670. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2671. }
  2672. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2673. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2674. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2675. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2676. }
  2677. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2678. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2679. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2680. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2681. }
  2682. else
  2683. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2684. }
  2685. else
  2686. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2687. return 0;
  2688. }
  2689. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2690. if (!lua_interface)
  2691. return 0;
  2692. Spawn* spawn = lua_interface->GetSpawn(state);
  2693. int8 type = lua_interface->GetInt8Value(state, 2);
  2694. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2695. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2696. lua_interface->ResetFunctionStack(state);
  2697. if (spawn && spawn->IsEntity()) {
  2698. if (!only_remove_spawn && luaspell && luaspell->spell && luaspell->caster) {
  2699. ZoneServer* zone = luaspell->caster->GetZone();
  2700. Spawn* target = 0;
  2701. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2702. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2703. target = zone->GetSpawnByID(luaspell->targets[i]);
  2704. if (target) {
  2705. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2706. ((Entity*)target)->RemoveMezSpell(luaspell);
  2707. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2708. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2709. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2710. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2711. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2712. ((Entity*)target)->RemoveStunSpell(luaspell);
  2713. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2714. ((Entity*)target)->RemoveRootSpell(luaspell);
  2715. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2716. ((Entity*)target)->RemoveFearSpell(luaspell);
  2717. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2718. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2719. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2720. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2721. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2722. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2723. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2724. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2725. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2726. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2727. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2728. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2729. else
  2730. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2731. }
  2732. }
  2733. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2734. }
  2735. else if (only_remove_spawn) {
  2736. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2737. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2738. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2739. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2740. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2741. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2742. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2743. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2744. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2745. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2746. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2747. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2748. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2749. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2750. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2751. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2752. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2753. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2754. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2755. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2756. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2757. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2758. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2759. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2760. else
  2761. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2762. }
  2763. }
  2764. return 0;
  2765. }
  2766. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2767. if (!lua_interface)
  2768. return 0;
  2769. Spawn* spawn = lua_interface->GetSpawn(state);
  2770. int8 type = lua_interface->GetInt8Value(state, 2);
  2771. lua_interface->ResetFunctionStack(state);
  2772. bool hasEffect = false;
  2773. if (!spawn)
  2774. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2775. else if (!spawn->IsEntity())
  2776. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2777. else if (type < CONTROL_MAX_EFFECTS)
  2778. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2779. else
  2780. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2781. lua_interface->SetBooleanValue(state, hasEffect);
  2782. return 1;
  2783. }
  2784. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2785. if (!lua_interface)
  2786. return 0;
  2787. Spawn* spawn = lua_interface->GetSpawn(state);
  2788. float distance = 0.0f;
  2789. lua_interface->ResetFunctionStack(state);
  2790. if (!spawn)
  2791. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2792. else if (!spawn->IsNPC())
  2793. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2794. else
  2795. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2796. lua_interface->SetFloatValue(state, distance);
  2797. return 1;
  2798. }
  2799. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2800. if (!lua_interface)
  2801. return 0;
  2802. Spawn* spawn = lua_interface->GetSpawn(state);
  2803. float distance = 0.0f;
  2804. lua_interface->ResetFunctionStack(state);
  2805. if (!spawn)
  2806. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2807. else if (!spawn->IsNPC())
  2808. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2809. else
  2810. distance = ((NPC*)spawn)->GetAggroRadius();
  2811. lua_interface->SetFloatValue(state, distance);
  2812. return 1;
  2813. }
  2814. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2815. if (!lua_interface)
  2816. return 0;
  2817. Spawn* spawn = lua_interface->GetSpawn(state);
  2818. float distance = lua_interface->GetFloatValue(state, 2);
  2819. bool override_ = lua_interface->GetBooleanValue(state, 3);
  2820. bool result = false;
  2821. lua_interface->ResetFunctionStack(state);
  2822. if (!spawn)
  2823. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2824. else if (!spawn->IsNPC())
  2825. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2826. else
  2827. {
  2828. ((NPC*)spawn)->SetAggroRadius(distance, override_);
  2829. result = true;
  2830. }
  2831. lua_interface->SetBooleanValue(state, result);
  2832. return 1;
  2833. }
  2834. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2835. if (!lua_interface)
  2836. return 0;
  2837. Spawn* spawn = lua_interface->GetSpawn(state);
  2838. int16 value = lua_interface->GetInt16Value(state, 2);
  2839. lua_interface->ResetFunctionStack(state);
  2840. if (spawn && spawn->IsEntity()) {
  2841. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2842. if (spawn->IsPlayer())
  2843. ((Player*)spawn)->SetCharSheetChanged(true);
  2844. }
  2845. return 0;
  2846. }
  2847. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2848. if (!lua_interface)
  2849. return 0;
  2850. Spawn* spawn = lua_interface->GetSpawn(state);
  2851. int16 value = lua_interface->GetInt16Value(state, 2);
  2852. lua_interface->ResetFunctionStack(state);
  2853. if (spawn && spawn->IsEntity()) {
  2854. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2855. if (spawn->IsPlayer())
  2856. ((Player*)spawn)->SetCharSheetChanged(true);
  2857. }
  2858. return 0;
  2859. }
  2860. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2861. if (!lua_interface)
  2862. return 0;
  2863. Spawn* spawn = lua_interface->GetSpawn(state);
  2864. int16 value = lua_interface->GetInt16Value(state, 2);
  2865. lua_interface->ResetFunctionStack(state);
  2866. if (spawn && spawn->IsEntity()) {
  2867. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2868. if (spawn->IsPlayer())
  2869. ((Player*)spawn)->SetCharSheetChanged(true);
  2870. }
  2871. return 0;
  2872. }
  2873. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2874. if (!lua_interface)
  2875. return 0;
  2876. Spawn* spawn = lua_interface->GetSpawn(state);
  2877. int16 value = lua_interface->GetInt16Value(state, 2);
  2878. lua_interface->ResetFunctionStack(state);
  2879. if (spawn && spawn->IsEntity()) {
  2880. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2881. if (spawn->IsPlayer())
  2882. ((Player*)spawn)->SetCharSheetChanged(true);
  2883. }
  2884. return 0;
  2885. }
  2886. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2887. if (!lua_interface)
  2888. return 0;
  2889. Spawn* spawn = lua_interface->GetSpawn(state);
  2890. int16 value = lua_interface->GetInt16Value(state, 2);
  2891. lua_interface->ResetFunctionStack(state);
  2892. if (spawn && spawn->IsEntity()) {
  2893. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2894. if (spawn->IsPlayer())
  2895. ((Player*)spawn)->SetCharSheetChanged(true);
  2896. }
  2897. return 0;
  2898. }
  2899. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2900. if (!lua_interface)
  2901. return 0;
  2902. Spawn* spawn = lua_interface->GetSpawn(state);
  2903. int8 value = lua_interface->GetInt8Value(state, 2);
  2904. lua_interface->ResetFunctionStack(state);
  2905. if (spawn && spawn->IsEntity()) {
  2906. ((Entity*)spawn)->SetDeity(value);
  2907. if (spawn->IsPlayer())
  2908. ((Player*)spawn)->SetCharSheetChanged(true);
  2909. }
  2910. lua_interface->ResetFunctionStack(state);
  2911. return 0;
  2912. }
  2913. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2914. if (!lua_interface)
  2915. return 0;
  2916. Spawn* spawn = lua_interface->GetSpawn(state);
  2917. lua_interface->ResetFunctionStack(state);
  2918. if (spawn && spawn->IsEntity()) {
  2919. int8 deity = ((Entity*)spawn)->GetDeity();
  2920. lua_interface->SetInt32Value(state, deity);
  2921. return 1;
  2922. }
  2923. return 0;
  2924. }
  2925. int EQ2Emu_lua_SetInt(lua_State* state) {
  2926. if (!lua_interface)
  2927. return 0;
  2928. Spawn* spawn = lua_interface->GetSpawn(state);
  2929. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2930. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2931. lua_interface->ResetFunctionStack(state);
  2932. if (spawn && spawn->IsEntity()) {
  2933. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_INT, value);
  2934. if (spawn->IsPlayer())
  2935. ((Player*)spawn)->SetCharSheetChanged(true);
  2936. }
  2937. return 0;
  2938. }
  2939. int EQ2Emu_lua_SetWis(lua_State* state) {
  2940. if (!lua_interface)
  2941. return 0;
  2942. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2943. Spawn* spawn = lua_interface->GetSpawn(state);
  2944. float value = lua_interface->GetFloatValue(state, 2);
  2945. lua_interface->ResetFunctionStack(state);
  2946. if (spawn && spawn->IsEntity()) {
  2947. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_WIS, value);
  2948. if (spawn->IsPlayer())
  2949. ((Player*)spawn)->SetCharSheetChanged(true);
  2950. }
  2951. return 0;
  2952. }
  2953. int EQ2Emu_lua_SetSta(lua_State* state) {
  2954. if (!lua_interface)
  2955. return 0;
  2956. Spawn* spawn = lua_interface->GetSpawn(state);
  2957. float value = lua_interface->GetFloatValue(state, 2);
  2958. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2959. lua_interface->ResetFunctionStack(state);
  2960. if (spawn && spawn->IsEntity()) {
  2961. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STA, value);
  2962. if (spawn->IsPlayer())
  2963. ((Player*)spawn)->SetCharSheetChanged(true);
  2964. }
  2965. return 0;
  2966. }
  2967. int EQ2Emu_lua_SetStr(lua_State* state) {
  2968. if (!lua_interface)
  2969. return 0;
  2970. Spawn* spawn = lua_interface->GetSpawn(state);
  2971. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2972. float value = lua_interface->GetFloatValue(state, 2);
  2973. lua_interface->ResetFunctionStack(state);
  2974. if (spawn && spawn->IsEntity()) {
  2975. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STR, value);
  2976. if (spawn->IsPlayer())
  2977. ((Player*)spawn)->SetCharSheetChanged(true);
  2978. }
  2979. return 0;
  2980. }
  2981. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2982. if (!lua_interface)
  2983. return 0;
  2984. Spawn* spawn = lua_interface->GetSpawn(state);
  2985. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2986. float value = lua_interface->GetFloatValue(state, 2);
  2987. lua_interface->ResetFunctionStack(state);
  2988. if (spawn && spawn->IsEntity()) {
  2989. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_AGI, value);
  2990. if (spawn->IsPlayer())
  2991. ((Player*)spawn)->SetCharSheetChanged(true);
  2992. }
  2993. return 0;
  2994. }
  2995. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2996. if (!lua_interface)
  2997. return 0;
  2998. Spawn* spawn = lua_interface->GetSpawn(state);
  2999. lua_interface->ResetFunctionStack(state);
  3000. if (spawn) {
  3001. lua_interface->SetInt32Value(state, spawn->GetHP());
  3002. return 1;
  3003. }
  3004. return 0;
  3005. }
  3006. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  3007. if (!lua_interface)
  3008. return 0;
  3009. Spawn* spawn = lua_interface->GetSpawn(state);
  3010. lua_interface->ResetFunctionStack(state);
  3011. if (spawn) {
  3012. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  3013. return 1;
  3014. }
  3015. return 0;
  3016. }
  3017. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  3018. if (!lua_interface)
  3019. return 0;
  3020. Spawn* spawn = lua_interface->GetSpawn(state);
  3021. lua_interface->ResetFunctionStack(state);
  3022. if (spawn) {
  3023. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  3024. return 1;
  3025. }
  3026. return 0;
  3027. }
  3028. int EQ2Emu_lua_GetName(lua_State* state) {
  3029. if (!lua_interface)
  3030. return 0;
  3031. Spawn* spawn = lua_interface->GetSpawn(state);
  3032. lua_interface->ResetFunctionStack(state);
  3033. if (spawn) {
  3034. lua_interface->SetStringValue(state, spawn->GetName());
  3035. return 1;
  3036. }
  3037. return 0;
  3038. }
  3039. int EQ2Emu_lua_GetLevel(lua_State* state) {
  3040. Spawn* spawn = lua_interface->GetSpawn(state);
  3041. lua_interface->ResetFunctionStack(state);
  3042. if (spawn) {
  3043. lua_interface->SetInt32Value(state, spawn->GetLevel());
  3044. return 1;
  3045. }
  3046. return 0;
  3047. }
  3048. int EQ2Emu_lua_GetDifficulty(lua_State* state) {
  3049. Spawn* spawn = lua_interface->GetSpawn(state);
  3050. lua_interface->ResetFunctionStack(state);
  3051. if (spawn) {
  3052. lua_interface->SetInt32Value(state, spawn->GetDifficulty());
  3053. return 1;
  3054. }
  3055. return 0;
  3056. }
  3057. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  3058. if (!lua_interface)
  3059. return 0;
  3060. Spawn* spawn = lua_interface->GetSpawn(state);
  3061. lua_interface->ResetFunctionStack(state);
  3062. if (spawn) {
  3063. lua_interface->SetInt32Value(state, spawn->GetPower());
  3064. return 1;
  3065. }
  3066. return 0;
  3067. }
  3068. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  3069. if (!lua_interface)
  3070. return 0;
  3071. Spawn* spawn = lua_interface->GetSpawn(state);
  3072. lua_interface->ResetFunctionStack(state);
  3073. if (spawn) {
  3074. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  3075. return 1;
  3076. }
  3077. return 0;
  3078. }
  3079. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  3080. if (!lua_interface)
  3081. return 0;
  3082. Spawn* spawn = lua_interface->GetSpawn(state);
  3083. lua_interface->ResetFunctionStack(state);
  3084. if (spawn) {
  3085. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  3086. return 1;
  3087. }
  3088. return 0;
  3089. }
  3090. int EQ2Emu_lua_GetDistance(lua_State* state) {
  3091. if (!lua_interface)
  3092. return 0;
  3093. Spawn* spawn = lua_interface->GetSpawn(state);
  3094. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  3095. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  3096. lua_interface->ResetFunctionStack(state);
  3097. if (spawn && spawn2) {
  3098. float distance = spawn->GetDistance(spawn2, false, include_radius);
  3099. lua_interface->SetFloatValue(state, distance);
  3100. return 1;
  3101. }
  3102. return 0;
  3103. }
  3104. int EQ2Emu_lua_GetX(lua_State* state) {
  3105. if (!lua_interface)
  3106. return 0;
  3107. Spawn* spawn = lua_interface->GetSpawn(state);
  3108. lua_interface->ResetFunctionStack(state);
  3109. if (spawn) {
  3110. lua_interface->SetFloatValue(state, spawn->GetX());
  3111. return 1;
  3112. }
  3113. return 0;
  3114. }
  3115. int EQ2Emu_lua_GetY(lua_State* state) {
  3116. if (!lua_interface)
  3117. return 0;
  3118. Spawn* spawn = lua_interface->GetSpawn(state);
  3119. lua_interface->ResetFunctionStack(state);
  3120. if (spawn) {
  3121. lua_interface->SetFloatValue(state, spawn->GetY());
  3122. return 1;
  3123. }
  3124. return 0;
  3125. }
  3126. int EQ2Emu_lua_GetZ(lua_State* state) {
  3127. if (!lua_interface)
  3128. return 0;
  3129. Spawn* spawn = lua_interface->GetSpawn(state);
  3130. lua_interface->ResetFunctionStack(state);
  3131. if (spawn) {
  3132. lua_interface->SetFloatValue(state, spawn->GetZ());
  3133. return 1;
  3134. }
  3135. return 0;
  3136. }
  3137. int EQ2Emu_lua_GetHeading(lua_State* state) {
  3138. if (!lua_interface)
  3139. return 0;
  3140. Spawn* spawn = lua_interface->GetSpawn(state);
  3141. lua_interface->ResetFunctionStack(state);
  3142. if (spawn) {
  3143. lua_interface->SetFloatValue(state, spawn->GetHeading());
  3144. return 1;
  3145. }
  3146. return 0;
  3147. }
  3148. int EQ2Emu_lua_GetModelType(lua_State* state) {
  3149. if (!lua_interface)
  3150. return 0;
  3151. Spawn* spawn = lua_interface->GetSpawn(state);
  3152. lua_interface->ResetFunctionStack(state);
  3153. if (spawn) {
  3154. lua_interface->SetInt32Value(state, spawn->GetModelType());
  3155. return 1;
  3156. }
  3157. return 0;
  3158. }
  3159. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  3160. if (!lua_interface)
  3161. return 0;
  3162. Spawn* spawn = lua_interface->GetSpawn(state);
  3163. lua_interface->ResetFunctionStack(state);
  3164. if (spawn) {
  3165. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  3166. return 1;
  3167. }
  3168. return 0;
  3169. }
  3170. int EQ2Emu_lua_HasMoved(lua_State* state) {
  3171. if (!lua_interface)
  3172. return 0;
  3173. Spawn* spawn = lua_interface->GetSpawn(state);
  3174. lua_interface->ResetFunctionStack(state);
  3175. if (spawn && spawn->IsEntity()) {
  3176. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  3177. return 1;
  3178. }
  3179. return 0;
  3180. }
  3181. int EQ2Emu_lua_GetInt(lua_State* state) {
  3182. if (!lua_interface)
  3183. return 0;
  3184. Spawn* spawn = lua_interface->GetSpawn(state);
  3185. lua_interface->ResetFunctionStack(state);
  3186. if (spawn && spawn->IsEntity()) {
  3187. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  3188. return 1;
  3189. }
  3190. return 0;
  3191. }
  3192. int EQ2Emu_lua_GetWis(lua_State* state) {
  3193. if (!lua_interface)
  3194. return 0;
  3195. Spawn* spawn = lua_interface->GetSpawn(state);
  3196. lua_interface->ResetFunctionStack(state);
  3197. if (spawn && spawn->IsEntity()) {
  3198. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  3199. return 1;
  3200. }
  3201. return 0;
  3202. }
  3203. int EQ2Emu_lua_GetSta(lua_State* state) {
  3204. if (!lua_interface)
  3205. return 0;
  3206. Spawn* spawn = lua_interface->GetSpawn(state);
  3207. lua_interface->ResetFunctionStack(state);
  3208. if (spawn && spawn->IsEntity()) {
  3209. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  3210. return 1;
  3211. }
  3212. return 0;
  3213. }
  3214. int EQ2Emu_lua_GetStr(lua_State* state) {
  3215. if (!lua_interface)
  3216. return 0;
  3217. Spawn* spawn = lua_interface->GetSpawn(state);
  3218. lua_interface->ResetFunctionStack(state);
  3219. if (spawn && spawn->IsEntity()) {
  3220. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3221. return 1;
  3222. }
  3223. return 0;
  3224. }
  3225. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3226. if (!lua_interface)
  3227. return 0;
  3228. Spawn* spawn = lua_interface->GetSpawn(state);
  3229. lua_interface->ResetFunctionStack(state);
  3230. if (spawn && spawn->IsEntity()) {
  3231. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3232. return 1;
  3233. }
  3234. return 0;
  3235. }
  3236. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3237. if (!lua_interface)
  3238. return 0;
  3239. Spawn* spawn = lua_interface->GetSpawn(state);
  3240. lua_interface->ResetFunctionStack(state);
  3241. if (spawn && spawn->IsEntity()) {
  3242. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3243. return 1;
  3244. }
  3245. return 0;
  3246. }
  3247. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3248. if (!lua_interface)
  3249. return 0;
  3250. Spawn* spawn = lua_interface->GetSpawn(state);
  3251. lua_interface->ResetFunctionStack(state);
  3252. if (spawn && spawn->IsEntity()) {
  3253. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3254. return 1;
  3255. }
  3256. return 0;
  3257. }
  3258. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3259. if (!lua_interface)
  3260. return 0;
  3261. Spawn* spawn = lua_interface->GetSpawn(state);
  3262. lua_interface->ResetFunctionStack(state);
  3263. if (spawn && spawn->IsEntity()) {
  3264. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3265. return 1;
  3266. }
  3267. return 0;
  3268. }
  3269. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3270. if (!lua_interface)
  3271. return 0;
  3272. Spawn* spawn = lua_interface->GetSpawn(state);
  3273. lua_interface->ResetFunctionStack(state);
  3274. if (spawn && spawn->IsEntity()) {
  3275. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3276. return 1;
  3277. }
  3278. return 0;
  3279. }
  3280. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3281. if (!lua_interface)
  3282. return 0;
  3283. Spawn* spawn = lua_interface->GetSpawn(state);
  3284. lua_interface->ResetFunctionStack(state);
  3285. if (spawn && spawn->IsEntity()) {
  3286. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3287. return 1;
  3288. }
  3289. return 0;
  3290. }
  3291. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3292. if (!lua_interface)
  3293. return 0;
  3294. Spawn* player = lua_interface->GetSpawn(state);
  3295. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3296. int32 step = lua_interface->GetInt32Value(state, 3);
  3297. lua_interface->ResetFunctionStack(state);
  3298. if (!player || !player->IsPlayer()) {
  3299. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3300. return 0;
  3301. }
  3302. if (quest_id <= 0) {
  3303. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3304. return 0;
  3305. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3306. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3307. return 0;
  3308. }
  3309. if (step > 0) {
  3310. Client* client = ((Player*)player)->GetClient();
  3311. if (client)
  3312. client->AddPendingQuestUpdate(quest_id, step);
  3313. } else {
  3314. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3315. }
  3316. return 0;
  3317. }
  3318. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3319. Spawn* player = lua_interface->GetSpawn(state);
  3320. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3321. int32 step = lua_interface->GetInt32Value(state, 3);
  3322. int32 progress = lua_interface->GetInt32Value(state, 4);
  3323. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3324. Client* client = ((Player*)player)->GetClient();
  3325. if (client)
  3326. client->AddPendingQuestUpdate(quest_id, step, progress);
  3327. }
  3328. return 0;
  3329. }
  3330. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3331. if (!lua_interface)
  3332. return 0;
  3333. Spawn* player = lua_interface->GetSpawn(state);
  3334. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3335. if (player && player->IsPlayer() && quest_id > 0) {
  3336. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3337. return 1;
  3338. }
  3339. return 0;
  3340. }
  3341. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3342. if (!lua_interface)
  3343. return 0;
  3344. Spawn* player = lua_interface->GetSpawn(state);
  3345. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3346. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3347. lua_interface->ResetFunctionStack(state);
  3348. if (player && player->IsPlayer() && quest_id > 0) {
  3349. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3350. return 1;
  3351. }
  3352. return 0;
  3353. }
  3354. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3355. if (!lua_interface)
  3356. return 0;
  3357. Spawn* player = lua_interface->GetSpawn(state);
  3358. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3359. lua_interface->ResetFunctionStack(state);
  3360. if (player && player->IsPlayer() && quest_id > 0) {
  3361. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3362. return 1;
  3363. }
  3364. return 0;
  3365. }
  3366. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3367. if (!lua_interface)
  3368. return 0;
  3369. Quest* quest = lua_interface->GetQuest(state);
  3370. string name = lua_interface->GetStringValue(state, 2);
  3371. string type = lua_interface->GetStringValue(state, 3);
  3372. string zone = lua_interface->GetStringValue(state, 4);
  3373. int16 level = lua_interface->GetInt16Value(state, 5);
  3374. string description = lua_interface->GetStringValue(state, 6);
  3375. lua_interface->ResetFunctionStack(state);
  3376. bool load = true;
  3377. if (!quest) {
  3378. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3379. load = false;
  3380. }
  3381. if (load && name.length() == 0) {
  3382. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3383. load = false;
  3384. }
  3385. if (load && type.length() == 0) {
  3386. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3387. load = false;
  3388. }
  3389. if (load && zone.length() == 0) {
  3390. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3391. load = false;
  3392. }
  3393. if (load && description.length() == 0) {
  3394. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3395. load = false;
  3396. }
  3397. if (load && level == 0) {
  3398. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3399. load = false;
  3400. }
  3401. if (load)
  3402. quest->RegisterQuest(name, type, zone, level, description);
  3403. return 0;
  3404. }
  3405. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3406. if (!lua_interface)
  3407. return 0;
  3408. Quest* quest = lua_interface->GetQuest(state);
  3409. int8 level = lua_interface->GetInt16Value(state, 2);
  3410. lua_interface->ResetFunctionStack(state);
  3411. if (quest) {
  3412. quest->SetPrereqLevel(level);
  3413. }
  3414. return 0;
  3415. }
  3416. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3417. if (!lua_interface)
  3418. return 0;
  3419. Quest* quest = lua_interface->GetQuest(state);
  3420. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3421. lua_interface->ResetFunctionStack(state);
  3422. if (quest) {
  3423. quest->AddPrereqQuest(quest_id);
  3424. }
  3425. return 0;
  3426. }
  3427. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3428. if (!lua_interface)
  3429. return 0;
  3430. Quest* quest = lua_interface->GetQuest(state);
  3431. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3432. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3433. lua_interface->ResetFunctionStack(state);
  3434. if (quest) {
  3435. if (quantity == 0)
  3436. quantity = 1;
  3437. Item* master_item = master_item_list.GetItem(item_id);
  3438. if (master_item) {
  3439. Item* item = new Item(master_item);
  3440. item->details.count = quantity;
  3441. quest->AddPrereqItem(item);
  3442. }
  3443. }
  3444. return 0;
  3445. }
  3446. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3447. if (!lua_interface)
  3448. return 0;
  3449. Spawn* player = lua_interface->GetSpawn(state);
  3450. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3451. lua_interface->ResetFunctionStack(state);
  3452. if(!player || !player->IsPlayer()) {
  3453. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3454. return 0;
  3455. }
  3456. if (quest_id > 0) {
  3457. lua_interface->SetBooleanValue(state, (((Player*)player)->HasActiveQuest(quest_id) == TRUE));
  3458. return 1;
  3459. } else {
  3460. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3461. }
  3462. return 0;
  3463. }
  3464. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3465. if (!lua_interface)
  3466. return 0;
  3467. Quest* quest = lua_interface->GetQuest(state);
  3468. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3469. lua_interface->ResetFunctionStack(state);
  3470. if (quest && spawn_id > 0)
  3471. quest->SetQuestReturnNPC(spawn_id);
  3472. return 0;
  3473. }
  3474. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3475. if (!lua_interface)
  3476. return 0;
  3477. Spawn* spawn = lua_interface->GetSpawn(state);
  3478. int32 time = lua_interface->GetInt32Value(state, 2);
  3479. string function = lua_interface->GetStringValue(state, 3);
  3480. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3481. Spawn* player = lua_interface->GetSpawn(state, 5);
  3482. lua_interface->ResetFunctionStack(state);
  3483. if (!spawn) {
  3484. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3485. return 0;
  3486. }
  3487. if (time <= 0) {
  3488. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3489. return 0;
  3490. }
  3491. if (function.length() == 0) {
  3492. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3493. return 0;
  3494. }
  3495. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3496. if ( time < 10)
  3497. time = 10;
  3498. timer->timer = Timer::GetCurrentTime2() + time;
  3499. timer->function = function;
  3500. timer->spawn = spawn->GetID();
  3501. timer->player = player ? player->GetID() : 0;
  3502. if (max_count == 0)
  3503. max_count = 1;
  3504. timer->max_count = max_count;
  3505. timer->current_count = 0;
  3506. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3507. return 0;
  3508. }
  3509. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3510. if (!lua_interface)
  3511. return 0;
  3512. Spawn* spawn = lua_interface->GetSpawn(state);
  3513. string function = lua_interface->GetStringValue(state, 2);
  3514. lua_interface->ResetFunctionStack(state);
  3515. if (!spawn) {
  3516. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3517. return 0;
  3518. }
  3519. if(!spawn->GetZone()) {
  3520. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3521. return 0;
  3522. }
  3523. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3524. return 0;
  3525. }
  3526. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3527. if (!lua_interface)
  3528. return 0;
  3529. Spawn* player = lua_interface->GetSpawn(state);
  3530. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3531. lua_interface->ResetFunctionStack(state);
  3532. if (player && player->IsPlayer() && quest_id > 0) {
  3533. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3534. return 1;
  3535. }
  3536. return 0;
  3537. }
  3538. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3539. if (!lua_interface)
  3540. return 0;
  3541. Spawn* player = lua_interface->GetSpawn(state);
  3542. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3543. lua_interface->ResetFunctionStack(state);
  3544. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3545. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3546. if (quest)
  3547. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3548. return 1;
  3549. }
  3550. return 0;
  3551. }
  3552. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3553. if (!lua_interface)
  3554. return 0;
  3555. Spawn* player = lua_interface->GetSpawn(state);
  3556. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3557. lua_interface->ResetFunctionStack(state);
  3558. if (player && player->IsPlayer() && quest_id > 0) {
  3559. lua_interface->SetBooleanValue(state, (((Player*)player)->HasQuestBeenCompleted(quest_id) != 0));
  3560. return 1;
  3561. }
  3562. return 0;
  3563. }
  3564. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3565. if (!lua_interface)
  3566. return 0;
  3567. Spawn* npc = lua_interface->GetSpawn(state);
  3568. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3569. lua_interface->ResetFunctionStack(state);
  3570. if (npc && !npc->IsPlayer() && quest_id > 0)
  3571. npc->AddProvidedQuest(quest_id);
  3572. return 0;
  3573. }
  3574. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3575. if (!lua_interface)
  3576. return 0;
  3577. Spawn* npc = lua_interface->GetSpawn(state);
  3578. Spawn* player = lua_interface->GetSpawn(state, 2);
  3579. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3580. bool forced = lua_interface->GetBooleanValue(state, 4);
  3581. lua_interface->ResetFunctionStack(state);
  3582. /* NPC is allowed to be null */
  3583. if (player && player->IsPlayer() && quest_id > 0) {
  3584. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3585. if (master_quest) {
  3586. Client* client = ((Player*)player)->GetClient();
  3587. if (!client) {
  3588. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3589. }
  3590. Quest* quest = new Quest(master_quest);
  3591. if (!quest) {
  3592. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3593. }
  3594. if (client && quest) {
  3595. if (npc)
  3596. quest->SetQuestGiver(npc->GetDatabaseID());
  3597. else
  3598. quest->SetQuestGiver(0);
  3599. client->AddPendingQuest(quest, forced);
  3600. }
  3601. }
  3602. else {
  3603. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3604. }
  3605. }
  3606. else {
  3607. 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);
  3608. }
  3609. return 0;
  3610. }
  3611. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3612. if (!lua_interface)
  3613. return 0;
  3614. Quest* quest = lua_interface->GetQuest(state);
  3615. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3616. lua_interface->ResetFunctionStack(state);
  3617. if (quest) {
  3618. quest->AddPrereqClass(class_id);
  3619. }
  3620. return 0;
  3621. }
  3622. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3623. if (!lua_interface)
  3624. return 0;
  3625. Quest* quest = lua_interface->GetQuest(state);
  3626. int8 race = lua_interface->GetInt8Value(state, 2);
  3627. lua_interface->ResetFunctionStack(state);
  3628. if (quest) {
  3629. quest->AddPrereqRace(race);
  3630. }
  3631. return 0;
  3632. }
  3633. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3634. if (!lua_interface)
  3635. return 0;
  3636. Quest* quest = lua_interface->GetQuest(state);
  3637. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3638. lua_interface->ResetFunctionStack(state);
  3639. if (quest) {
  3640. quest->AddPrereqModelType(model_type);
  3641. }
  3642. return 0;
  3643. }
  3644. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3645. if (!lua_interface)
  3646. return 0;
  3647. Quest* quest = lua_interface->GetQuest(state);
  3648. int8 level = lua_interface->GetInt8Value(state, 2);
  3649. lua_interface->ResetFunctionStack(state);
  3650. if (!quest) {
  3651. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3652. return 0;
  3653. }
  3654. quest->SetPrereqTSLevel(level);
  3655. return 0;
  3656. }
  3657. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3658. if (!lua_interface)
  3659. return 0;
  3660. Quest* quest = lua_interface->GetQuest(state);
  3661. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3662. lua_interface->ResetFunctionStack(state);
  3663. if (!quest) {
  3664. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3665. return 0;
  3666. }
  3667. quest->AddPrereqTradeskillClass(class_id);
  3668. return 0;
  3669. }
  3670. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3671. if (!lua_interface)
  3672. return 0;
  3673. Quest* quest = lua_interface->GetQuest(state);
  3674. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3675. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3676. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3677. lua_interface->ResetFunctionStack(state);
  3678. if (quest) {
  3679. quest->AddPrereqFaction(faction_id, min, max);
  3680. }
  3681. return 0;
  3682. }
  3683. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3684. if (!lua_interface)
  3685. return 0;
  3686. Quest* quest = lua_interface->GetQuest(state);
  3687. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3688. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3689. lua_interface->ResetFunctionStack(state);
  3690. if (quest) {
  3691. if (quantity == 0)
  3692. quantity = 1;
  3693. Item* master_item = master_item_list.GetItem(item_id);
  3694. if (master_item) {
  3695. Item* item = new Item(master_item);
  3696. item->details.count = quantity;
  3697. quest->AddSelectableRewardItem(item);
  3698. }
  3699. }
  3700. return 0;
  3701. }
  3702. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3703. if (!lua_interface)
  3704. return 0;
  3705. Quest* quest = lua_interface->GetQuest(state);
  3706. if (quest) {
  3707. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3708. vector<Item*>* items = quest->GetRewardItems();
  3709. if (items) {
  3710. vector<Item*>::iterator itr;
  3711. for (itr = items->begin(); itr != items->end(); itr++) {
  3712. if (*itr && (*itr)->details.item_id == item_id) {
  3713. lua_interface->SetBooleanValue(state, true);
  3714. return 1;
  3715. }
  3716. }
  3717. }
  3718. }
  3719. lua_interface->SetBooleanValue(state, false);
  3720. return 1;
  3721. }
  3722. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3723. if (!lua_interface)
  3724. return 0;
  3725. Quest* quest = lua_interface->GetQuest(state);
  3726. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3727. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3728. lua_interface->ResetFunctionStack(state);
  3729. if (quest) {
  3730. if (quantity == 0)
  3731. quantity = 1;
  3732. Item* master_item = master_item_list.GetItem(item_id);
  3733. if (master_item) {
  3734. Item* item = new Item(master_item);
  3735. item->details.count = quantity;
  3736. quest->AddRewardItem(item);
  3737. }
  3738. }
  3739. return 0;
  3740. }
  3741. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3742. if (!lua_interface)
  3743. return 0;
  3744. Quest* quest = lua_interface->GetQuest(state);
  3745. int32 copper = lua_interface->GetInt32Value(state, 2);
  3746. int32 silver = lua_interface->GetInt32Value(state, 3);
  3747. int32 gold = lua_interface->GetInt32Value(state, 4);
  3748. int32 plat = lua_interface->GetInt32Value(state, 5);
  3749. lua_interface->ResetFunctionStack(state);
  3750. if (quest) {
  3751. quest->AddRewardCoins(copper, silver, gold, plat);
  3752. }
  3753. return 0;
  3754. }
  3755. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3756. if (!lua_interface)
  3757. return 0;
  3758. Quest* quest = lua_interface->GetQuest(state);
  3759. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3760. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3761. lua_interface->ResetFunctionStack(state);
  3762. if (quest && faction_id > 0 && amount != 0)
  3763. quest->AddRewardFaction(faction_id, amount);
  3764. return 0;
  3765. }
  3766. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3767. if (!lua_interface)
  3768. return 0;
  3769. Quest* quest = lua_interface->GetQuest(state);
  3770. int32 status = lua_interface->GetInt32Value(state, 2);
  3771. lua_interface->ResetFunctionStack(state);
  3772. if (quest) {
  3773. quest->SetRewardStatus(status);
  3774. }
  3775. return 0;
  3776. }
  3777. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3778. if (!lua_interface)
  3779. return 0;
  3780. Quest* quest = lua_interface->GetQuest(state);
  3781. int32 status = lua_interface->GetInt32Value(state, 2);
  3782. lua_interface->ResetFunctionStack(state);
  3783. if (quest) {
  3784. quest->SetStatusTmpReward(status);
  3785. }
  3786. return 0;
  3787. }
  3788. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3789. if (!lua_interface)
  3790. return 0;
  3791. Quest* quest = lua_interface->GetQuest(state);
  3792. int64 coins = lua_interface->GetInt64Value(state, 2);
  3793. lua_interface->ResetFunctionStack(state);
  3794. if (quest) {
  3795. quest->SetCoinTmpReward(coins);
  3796. }
  3797. return 0;
  3798. }
  3799. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3800. if (!lua_interface)
  3801. return 0;
  3802. Quest* quest = lua_interface->GetQuest(state);
  3803. string comment = lua_interface->GetStringValue(state, 2);
  3804. lua_interface->ResetFunctionStack(state);
  3805. if (quest) {
  3806. quest->SetRewardComment(comment);
  3807. }
  3808. return 0;
  3809. }
  3810. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3811. if (!lua_interface)
  3812. return 0;
  3813. Quest* quest = lua_interface->GetQuest(state);
  3814. int32 exp = lua_interface->GetInt32Value(state, 2);
  3815. lua_interface->ResetFunctionStack(state);
  3816. if (quest) {
  3817. quest->SetRewardXP(exp);
  3818. }
  3819. return 0;
  3820. }
  3821. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3822. Quest* quest = lua_interface->GetQuest(state);
  3823. int32 step = lua_interface->GetInt32Value(state, 2);
  3824. string description = lua_interface->GetStringValue(state, 3);
  3825. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3826. float percentage = lua_interface->GetFloatValue(state, 5);
  3827. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3828. int16 icon = lua_interface->GetInt16Value(state, 7);
  3829. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3830. if (quest) {
  3831. const char* taskgroup = 0;
  3832. if (str_taskgroup.length() > 0)
  3833. taskgroup = str_taskgroup.c_str();
  3834. int32 id = 0;
  3835. vector<int32>* ids = 0;
  3836. int i = 0;
  3837. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3838. if (ids == 0)
  3839. ids = new vector<int32>;
  3840. ids->push_back(id);
  3841. i++;
  3842. }
  3843. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3844. if (quest_step && icon && quantity > 0)
  3845. quest_step->SetIcon(icon);
  3846. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3847. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3848. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3849. }
  3850. }
  3851. lua_interface->ResetFunctionStack(state);
  3852. return 0;
  3853. }
  3854. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3855. {
  3856. if (!lua_interface)
  3857. return 0;
  3858. Quest* quest = lua_interface->GetQuest(state);
  3859. int32 step = lua_interface->GetInt32Value(state, 2);
  3860. string description = lua_interface->GetStringValue(state, 3);
  3861. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3862. float percentage = lua_interface->GetFloatValue(state, 5);
  3863. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3864. int16 icon = lua_interface->GetInt16Value(state, 7);
  3865. if (quest) {
  3866. const char* taskgroup = 0;
  3867. if (str_taskgroup.length() > 0)
  3868. taskgroup = str_taskgroup.c_str();
  3869. int32 id = 0;
  3870. vector<int32>* ids = 0;
  3871. int i = 0;
  3872. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3873. if (ids == 0)
  3874. ids = new vector<int32>;
  3875. ids->push_back(id);
  3876. i++;
  3877. }
  3878. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3879. if (quest_step && icon > 0 && quantity > 0)
  3880. quest_step->SetIcon(icon);
  3881. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3882. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3883. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3884. }
  3885. safe_delete(ids);
  3886. }
  3887. lua_interface->ResetFunctionStack(state);
  3888. return 0;
  3889. }
  3890. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3891. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3892. }
  3893. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3894. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3895. }
  3896. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3897. if (!lua_interface)
  3898. return 0;
  3899. Quest* quest = lua_interface->GetQuest(state);
  3900. int32 step = lua_interface->GetInt32Value(state, 2);
  3901. string description = lua_interface->GetStringValue(state, 3);
  3902. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3903. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3904. int16 icon = lua_interface->GetInt16Value(state, 6);
  3905. if (quest) {
  3906. const char* taskgroup = 0;
  3907. if (str_taskgroup.length() > 0)
  3908. taskgroup = str_taskgroup.c_str();
  3909. int32 npc_id = 0;
  3910. vector<int32>* ids = 0;
  3911. int i = 0;
  3912. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3913. if (ids == 0)
  3914. ids = new vector<int32>;
  3915. ids->push_back(npc_id);
  3916. i++;
  3917. }
  3918. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3919. if (quest_step && icon > 0)
  3920. quest_step->SetIcon(icon);
  3921. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3922. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3923. if(client)
  3924. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3925. }
  3926. safe_delete(ids);
  3927. }
  3928. lua_interface->ResetFunctionStack(state);
  3929. return 0;
  3930. }
  3931. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3932. if (!lua_interface)
  3933. return 0;
  3934. Quest* quest = lua_interface->GetQuest(state);
  3935. int32 step = lua_interface->GetInt32Value(state, 2);
  3936. string description = lua_interface->GetStringValue(state, 3);
  3937. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3938. float percentage = lua_interface->GetFloatValue(state, 5);
  3939. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3940. int16 icon = lua_interface->GetInt16Value(state, 7);
  3941. if (quest) {
  3942. const char* taskgroup = 0;
  3943. if (str_taskgroup.length() > 0)
  3944. taskgroup = str_taskgroup.c_str();
  3945. int32 item_id = 0;
  3946. vector<int32>* ids = 0;
  3947. int i = 0;
  3948. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3949. if (ids == 0)
  3950. ids = new vector<int32>;
  3951. ids->push_back(item_id);
  3952. i++;
  3953. }
  3954. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3955. if (quest_step && icon > 0 && quantity > 0)
  3956. quest_step->SetIcon(icon);
  3957. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3958. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3959. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3960. }
  3961. safe_delete(ids);
  3962. }
  3963. lua_interface->ResetFunctionStack(state);
  3964. return 0;
  3965. }
  3966. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3967. if (!lua_interface)
  3968. return 0;
  3969. Quest* quest = lua_interface->GetQuest(state);
  3970. int32 step = lua_interface->GetInt32Value(state, 2);
  3971. string description = lua_interface->GetStringValue(state, 3);
  3972. float max_variation = lua_interface->GetFloatValue(state, 4);
  3973. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3974. int16 icon = lua_interface->GetInt16Value(state, 6);
  3975. if (quest) {
  3976. const char* taskgroup = 0;
  3977. if (str_taskgroup.length() > 0)
  3978. taskgroup = str_taskgroup.c_str();
  3979. vector<Location>* locations = 0;
  3980. int8 i = 7;
  3981. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3982. while (true) {
  3983. Location loc;
  3984. loc.x = lua_interface->GetFloatValue(state, i);
  3985. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3986. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3987. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3988. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3989. break;
  3990. if (locations == 0)
  3991. locations = new vector<Location>;
  3992. locations->push_back(loc);
  3993. i += 4;
  3994. }
  3995. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3996. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3997. if (quest_step && icon > 0)
  3998. quest_step->SetIcon(icon);
  3999. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4000. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4001. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4002. }
  4003. }
  4004. lua_interface->ResetFunctionStack(state);
  4005. return 0;
  4006. }
  4007. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  4008. if (!lua_interface)
  4009. return 0;
  4010. Quest* quest = lua_interface->GetQuest(state);
  4011. int32 step = lua_interface->GetInt32Value(state, 2);
  4012. string description = lua_interface->GetStringValue(state, 3);
  4013. float max_variation = lua_interface->GetFloatValue(state, 4);
  4014. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  4015. int16 icon = lua_interface->GetInt16Value(state, 6);
  4016. if (quest) {
  4017. const char* taskgroup = 0;
  4018. if (str_taskgroup.length() > 0)
  4019. taskgroup = str_taskgroup.c_str();
  4020. vector<Location>* locations = 0;
  4021. int8 i = 7;
  4022. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4023. while (true) {
  4024. Location loc;
  4025. loc.x = lua_interface->GetFloatValue(state, i);
  4026. loc.y = lua_interface->GetFloatValue(state, i + 1);
  4027. loc.z = lua_interface->GetFloatValue(state, i + 2);
  4028. loc.zone_id = 0;
  4029. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  4030. break;
  4031. if (locations == 0)
  4032. locations = new vector<Location>;
  4033. locations->push_back(loc);
  4034. i += 3;
  4035. }
  4036. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  4037. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  4038. if (quest_step && icon > 0)
  4039. quest_step->SetIcon(icon);
  4040. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4041. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4042. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4043. }
  4044. }
  4045. lua_interface->ResetFunctionStack(state);
  4046. return 0;
  4047. }
  4048. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  4049. if (!lua_interface)
  4050. return 0;
  4051. Quest* quest = lua_interface->GetQuest(state);
  4052. int32 step = lua_interface->GetInt32Value(state, 2);
  4053. string description = lua_interface->GetStringValue(state, 3);
  4054. float max_variation = lua_interface->GetFloatValue(state, 4);
  4055. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  4056. int16 icon = lua_interface->GetInt16Value(state, 6);
  4057. if (quest) {
  4058. const char* taskgroup = 0;
  4059. if (str_taskgroup.length() > 0)
  4060. taskgroup = str_taskgroup.c_str();
  4061. vector<Location>* locations = 0;
  4062. int i = 7;
  4063. while (true) {
  4064. Location loc;
  4065. loc.x = lua_interface->GetFloatValue(state, i);
  4066. loc.y = lua_interface->GetFloatValue(state, i + 1);
  4067. loc.z = lua_interface->GetFloatValue(state, i + 2);
  4068. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  4069. break;
  4070. if (locations == 0)
  4071. locations = new vector<Location>;
  4072. locations->push_back(loc);
  4073. i += 3;
  4074. }
  4075. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  4076. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  4077. if (quest_step && icon > 0)
  4078. quest_step->SetIcon(icon);
  4079. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4080. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4081. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4082. }
  4083. }
  4084. lua_interface->ResetFunctionStack(state);
  4085. return 0;
  4086. }
  4087. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  4088. Quest* quest = lua_interface->GetQuest(state);
  4089. int32 step = lua_interface->GetInt32Value(state, 2);
  4090. string description = lua_interface->GetStringValue(state, 3);
  4091. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4092. float percentage = lua_interface->GetFloatValue(state, 5);
  4093. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4094. int16 icon = lua_interface->GetInt16Value(state, 7);
  4095. if (quest) {
  4096. const char* taskgroup = 0;
  4097. if (str_taskgroup.length() > 0)
  4098. taskgroup = str_taskgroup.c_str();
  4099. int32 spell_id = 0;
  4100. vector<int32>* ids = 0;
  4101. int i = 0;
  4102. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4103. if (ids == 0)
  4104. ids = new vector<int32>;
  4105. ids->push_back(spell_id);
  4106. i++;
  4107. }
  4108. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4109. if (quest_step && icon > 0 && quantity > 0)
  4110. quest_step->SetIcon(icon);
  4111. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4112. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4113. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4114. }
  4115. safe_delete(ids);
  4116. }
  4117. lua_interface->ResetFunctionStack(state);
  4118. return 0;
  4119. }
  4120. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  4121. if (!lua_interface)
  4122. return 0;
  4123. Quest* quest = lua_interface->GetQuest(state);
  4124. int32 step = lua_interface->GetInt32Value(state, 2);
  4125. string description = lua_interface->GetStringValue(state, 3);
  4126. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4127. float percentage = lua_interface->GetFloatValue(state, 5);
  4128. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4129. int16 icon = lua_interface->GetInt16Value(state, 7);
  4130. if (quest) {
  4131. const char* taskgroup = 0;
  4132. if (str_taskgroup.length() > 0)
  4133. taskgroup = str_taskgroup.c_str();
  4134. int32 item_id = 0;
  4135. vector<int32>* ids = 0;
  4136. int i = 0;
  4137. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4138. if (ids == 0)
  4139. ids = new vector<int32>;
  4140. ids->push_back(item_id);
  4141. i++;
  4142. }
  4143. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4144. if (quest_step && icon > 0 && quantity > 0)
  4145. quest_step->SetIcon(icon);
  4146. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4147. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4148. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4149. }
  4150. safe_delete(ids);
  4151. }
  4152. lua_interface->ResetFunctionStack(state);
  4153. return 0;
  4154. }
  4155. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  4156. if (!lua_interface)
  4157. return 0;
  4158. Quest* quest = lua_interface->GetQuest(state);
  4159. int32 step = lua_interface->GetInt32Value(state, 2);
  4160. string description = lua_interface->GetStringValue(state, 3);
  4161. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4162. float percentage = lua_interface->GetFloatValue(state, 5);
  4163. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4164. int16 icon = lua_interface->GetInt16Value(state, 7);
  4165. if (quest) {
  4166. const char* taskgroup = 0;
  4167. if (str_taskgroup.length() > 0)
  4168. taskgroup = str_taskgroup.c_str();
  4169. int32 item_id = 0;
  4170. vector<int32>* ids = 0;
  4171. int i = 0;
  4172. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4173. if (ids == 0)
  4174. ids = new vector<int32>;
  4175. ids->push_back(item_id);
  4176. i++;
  4177. }
  4178. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4179. if (quest_step && icon > 0 && quantity > 0)
  4180. quest_step->SetIcon(icon);
  4181. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4182. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4183. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4184. }
  4185. safe_delete(ids);
  4186. }
  4187. lua_interface->ResetFunctionStack(state);
  4188. return 0;
  4189. }
  4190. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  4191. if (!lua_interface)
  4192. return 0;
  4193. Quest* quest = lua_interface->GetQuest(state);
  4194. string action = lua_interface->GetStringValue(state, 2);
  4195. lua_interface->ResetFunctionStack(state);
  4196. if (quest) {
  4197. if (action.length() > 0)
  4198. quest->SetCompleteAction(action);
  4199. }
  4200. return 0;
  4201. }
  4202. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  4203. if (!lua_interface)
  4204. return 0;
  4205. Quest* quest = lua_interface->GetQuest(state);
  4206. int32 step = lua_interface->GetInt32Value(state, 2);
  4207. string action = lua_interface->GetStringValue(state, 3);
  4208. lua_interface->ResetFunctionStack(state);
  4209. if (quest) {
  4210. if (step > 0 && action.length() > 0)
  4211. quest->AddCompleteAction(step, action);
  4212. }
  4213. return 0;
  4214. }
  4215. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  4216. if (!lua_interface)
  4217. return 0;
  4218. Quest* quest = lua_interface->GetQuest(state);
  4219. int32 step = lua_interface->GetInt32Value(state, 2);
  4220. string action = lua_interface->GetStringValue(state, 3);
  4221. lua_interface->ResetFunctionStack(state);
  4222. if (quest) {
  4223. if (step > 0 && action.length() > 0)
  4224. quest->AddProgressAction(step, action);
  4225. }
  4226. return 0;
  4227. }
  4228. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  4229. if (!lua_interface)
  4230. return 0;
  4231. Quest* quest = lua_interface->GetQuest(state);
  4232. string description = lua_interface->GetStringValue(state, 2);
  4233. lua_interface->ResetFunctionStack(state);
  4234. if (quest && description.length() > 0)
  4235. quest->SetDescription(description);
  4236. return 0;
  4237. }
  4238. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4239. if (!lua_interface)
  4240. return 0;
  4241. Quest* quest = lua_interface->GetQuest(state);
  4242. string description = lua_interface->GetStringValue(state, 2);
  4243. lua_interface->ResetFunctionStack(state);
  4244. if (quest && description.length() > 0)
  4245. quest->SetCompletedDescription(description);
  4246. return 0;
  4247. }
  4248. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4249. if (!lua_interface)
  4250. return 0;
  4251. Quest* quest = lua_interface->GetQuest(state);
  4252. int32 step = lua_interface->GetInt32Value(state, 2);
  4253. string description = lua_interface->GetStringValue(state, 3);
  4254. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4255. lua_interface->ResetFunctionStack(state);
  4256. if (quest && step > 0 && description.length() > 0) {
  4257. quest->SetTaskGroupDescription(step, description, display_bullets);
  4258. }
  4259. return 0;
  4260. }
  4261. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4262. if (!lua_interface)
  4263. return 0;
  4264. Quest* quest = lua_interface->GetQuest(state);
  4265. int32 step = lua_interface->GetInt32Value(state, 2);
  4266. string description = lua_interface->GetStringValue(state, 3);
  4267. lua_interface->ResetFunctionStack(state);
  4268. if (quest && step > 0 && description.length() > 0) {
  4269. quest->SetStepDescription(step, description);
  4270. }
  4271. return 0;
  4272. }
  4273. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4274. Quest* quest = lua_interface->GetQuest(state);
  4275. string zone = lua_interface->GetStringValue(state, 2);
  4276. lua_interface->ResetFunctionStack(state);
  4277. if (quest && zone.length() > 0)
  4278. quest->SetZone(zone);
  4279. return 0;
  4280. }
  4281. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4282. if (!lua_interface)
  4283. return 0;
  4284. Quest* quest = lua_interface->GetQuest(state);
  4285. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4286. lua_interface->ResetFunctionStack(state);
  4287. if (quest && spawn) {
  4288. if (spawn->IsPlayer()) {
  4289. Client* client = ((Player*)spawn)->GetClient();
  4290. if (client) {
  4291. client->AddPendingQuestReward(quest);
  4292. }
  4293. }
  4294. }
  4295. return 0;
  4296. }
  4297. int EQ2Emu_lua_Harvest(lua_State* state) {
  4298. if (!lua_interface)
  4299. return 0;
  4300. Spawn* player = lua_interface->GetSpawn(state);
  4301. Spawn* node = lua_interface->GetSpawn(state, 2);
  4302. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4303. Client* client = ((Player*)player)->GetClient();
  4304. if (client) {
  4305. ((GroundSpawn*)node)->ProcessHarvest(client);
  4306. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4307. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4308. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4309. }
  4310. }
  4311. }
  4312. else if (player && player->IsPlayer()) {
  4313. Client* client = ((Player*)player)->GetClient();
  4314. if (client)
  4315. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4316. }
  4317. lua_interface->ResetFunctionStack(state);
  4318. return 0;
  4319. }
  4320. int EQ2Emu_lua_Bind(lua_State* state) {
  4321. if (!lua_interface)
  4322. return 0;
  4323. Spawn* spawn = lua_interface->GetSpawn(state);
  4324. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4325. float x = lua_interface->GetFloatValue(state, 3);
  4326. float y = lua_interface->GetFloatValue(state, 4);
  4327. float z = lua_interface->GetFloatValue(state, 5);
  4328. float h = lua_interface->GetFloatValue(state, 6);
  4329. lua_interface->ResetFunctionStack(state);
  4330. if (!spawn) {
  4331. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4332. return 0;
  4333. }
  4334. if (!spawn->IsPlayer()) {
  4335. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4336. return 0;
  4337. }
  4338. if (zone_id == 0) {
  4339. Client* client = ((Player*)spawn)->GetClient();
  4340. if (!client) {
  4341. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4342. return 0;
  4343. }
  4344. if (!client->Bind())
  4345. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4346. }
  4347. else {
  4348. Player* player = (Player*)spawn;
  4349. player->GetPlayerInfo()->SetBindZone(zone_id);
  4350. player->GetPlayerInfo()->SetBindX(x);
  4351. player->GetPlayerInfo()->SetBindY(y);
  4352. player->GetPlayerInfo()->SetBindZ(z);
  4353. player->GetPlayerInfo()->SetBindHeading(h);
  4354. }
  4355. return 0;
  4356. }
  4357. int EQ2Emu_lua_Gate(lua_State* state) {
  4358. if (!lua_interface)
  4359. return 0;
  4360. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4361. Spawn* spawn = lua_interface->GetSpawn(state);
  4362. lua_interface->ResetFunctionStack(state);
  4363. if (spawn) {
  4364. if (spawn->IsPlayer()) {
  4365. Client* client = ((Player*)spawn)->GetClient();
  4366. if (client) {
  4367. if (!client->Gate((spell != nullptr) ? true : false))
  4368. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4369. }
  4370. }
  4371. }
  4372. return 0;
  4373. }
  4374. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4375. if (!lua_interface)
  4376. return 0;
  4377. bool ret = false;
  4378. Spawn* spawn = lua_interface->GetSpawn(state);
  4379. lua_interface->ResetFunctionStack(state);
  4380. if (spawn) {
  4381. if (spawn->IsPlayer()) {
  4382. Client* client = ((Player*)spawn)->GetClient();
  4383. if (client)
  4384. ret = client->BindAllowed();
  4385. }
  4386. }
  4387. lua_interface->SetBooleanValue(state, ret);
  4388. return 1;
  4389. }
  4390. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4391. if (!lua_interface)
  4392. return 0;
  4393. bool ret = false;
  4394. Spawn* spawn = lua_interface->GetSpawn(state);
  4395. lua_interface->ResetFunctionStack(state);
  4396. if (spawn) {
  4397. if (spawn->IsPlayer()) {
  4398. Client* client = ((Player*)spawn)->GetClient();
  4399. ZoneServer* zone = lua_interface->GetZone(state);
  4400. if (client && zone){
  4401. ret = zone->GetCanGate();
  4402. }
  4403. }
  4404. }
  4405. lua_interface->SetBooleanValue(state, ret);
  4406. return 1;
  4407. }
  4408. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4409. Spawn* spawn = lua_interface->GetSpawn(state);
  4410. lua_interface->ResetFunctionStack(state);
  4411. if (spawn) {
  4412. lua_interface->SetBooleanValue(state, spawn->Alive());
  4413. return 1;
  4414. }
  4415. return 0;
  4416. }
  4417. int EQ2Emu_lua_IsSpawnGroupAlive(lua_State* state) {
  4418. ZoneServer* zone = lua_interface->GetZone(state);
  4419. int32 group_id = lua_interface->GetInt32Value(state, 2);
  4420. lua_interface->ResetFunctionStack(state);
  4421. if (zone) {
  4422. lua_interface->SetBooleanValue(state, zone->IsSpawnGroupAlive(group_id));
  4423. return 1;
  4424. }
  4425. return 0;
  4426. }
  4427. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4428. if (!lua_interface)
  4429. return 0;
  4430. Spawn* spawn = lua_interface->GetSpawn(state);
  4431. lua_interface->ResetFunctionStack(state);
  4432. if (spawn && spawn->IsEntity()) {
  4433. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4434. return 1;
  4435. }
  4436. return 0;
  4437. }
  4438. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4439. Spawn* spawn = lua_interface->GetSpawn(state);
  4440. string message = lua_interface->GetStringValue(state, 2);
  4441. string color_str = lua_interface->GetStringValue(state, 3);
  4442. lua_interface->ResetFunctionStack(state);
  4443. int8 color = CHANNEL_NARRATIVE;
  4444. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4445. Client* client = ((Player*)spawn)->GetClient();
  4446. if (client) {
  4447. if (color_str.length() > 0) {
  4448. // leave for backwards compat, but all future should just use the number
  4449. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4450. color = CHANNEL_COLOR_RED;
  4451. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4452. color = CHANNEL_COLOR_YELLOW;
  4453. else
  4454. {
  4455. // use a number to specify the channel as per Commands/Commands.h defines
  4456. color = (int8)atoul(color_str.c_str());
  4457. }
  4458. }
  4459. client->SimpleMessage(color, message.c_str());
  4460. }
  4461. }
  4462. return 0;
  4463. }
  4464. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4465. Spawn* spawn = lua_interface->GetSpawn(state);
  4466. string message = lua_interface->GetStringValue(state, 2);
  4467. int8 red = lua_interface->GetInt8Value(state, 3);
  4468. int8 green = lua_interface->GetInt8Value(state, 4);
  4469. int8 blue = lua_interface->GetInt8Value(state, 5);
  4470. lua_interface->ResetFunctionStack(state);
  4471. if (!spawn) {
  4472. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4473. return 0;
  4474. }
  4475. if (!spawn->IsPlayer()) {
  4476. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not a player.", lua_interface->GetScriptName(state));
  4477. return 0;
  4478. }
  4479. int32 words = ::CountWordsInString(message.c_str());
  4480. if (words < 5)
  4481. words = 5;
  4482. Client* client = ((Player*)spawn)->GetClient();
  4483. if (client)
  4484. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4485. return 0;
  4486. }
  4487. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4488. Spawn* spawn = lua_interface->GetSpawn(state);
  4489. int8 param = lua_interface->GetInt8Value(state, 2);
  4490. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4491. int8 value = lua_interface->GetInt8Value(state, 4);
  4492. lua_interface->ResetFunctionStack(state);
  4493. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4494. Client* client = ((Player*)spawn)->GetClient();
  4495. if (client) {
  4496. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4497. switch (param) {
  4498. case 1: {
  4499. packet->setDataByName("parameter1", param_value);
  4500. break;
  4501. }
  4502. case 2: {
  4503. packet->setDataByName("parameter2", param_value);
  4504. break;
  4505. }
  4506. case 3: {
  4507. packet->setDataByName("parameter3", param_value);
  4508. break;
  4509. }
  4510. case 4: {
  4511. packet->setDataByName("parameter4", param_value);
  4512. break;
  4513. }
  4514. case 5: {
  4515. packet->setDataByName("parameter5", param_value);
  4516. break;
  4517. }
  4518. }
  4519. packet->setDataByName("value", value);
  4520. client->QueuePacket(packet->serialize());
  4521. safe_delete(packet);
  4522. }
  4523. }
  4524. return 0;
  4525. }
  4526. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4527. Spawn* spawn = lua_interface->GetSpawn(state);
  4528. lua_interface->ResetFunctionStack(state);
  4529. if (spawn && spawn->IsPlayer()) {
  4530. if (((Player*)spawn)->GetIsTracking())
  4531. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4532. else
  4533. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4534. }
  4535. return 0;
  4536. }
  4537. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4538. Spawn* player = lua_interface->GetSpawn(state);
  4539. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4540. string name = lua_interface->GetStringValue(state, 3);
  4541. float distance = lua_interface->GetFloatValue(state, 4);
  4542. string command = lua_interface->GetStringValue(state, 5);
  4543. string error_text = lua_interface->GetStringValue(state, 6);
  4544. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4545. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4546. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4547. lua_interface->ResetFunctionStack(state);
  4548. if (spawn) {
  4549. if (distance == 0)
  4550. distance = 10.0f;
  4551. if (command.length() == 0)
  4552. command = name;
  4553. if (command.length() < 1 && name.length() < 1)
  4554. {
  4555. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4556. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4557. spawn->RemovePrimaryCommands();
  4558. }
  4559. else
  4560. {
  4561. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4562. }
  4563. }
  4564. return 0;
  4565. }
  4566. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4567. if (!lua_interface)
  4568. return 0;
  4569. Spawn* player = lua_interface->GetSpawn(state);
  4570. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4571. int16 tier = lua_interface->GetInt16Value(state, 3);
  4572. lua_interface->ResetFunctionStack(state);
  4573. if (player && player->IsPlayer()) {
  4574. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4575. return 1;
  4576. }
  4577. return 0;
  4578. }
  4579. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4580. if (!lua_interface)
  4581. return 0;
  4582. Spawn* player = lua_interface->GetSpawn(state);
  4583. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4584. int16 tier = lua_interface->GetInt16Value(state, 3);
  4585. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4586. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4587. bool add_to_hotbar = true;
  4588. if (num_args > 4) {
  4589. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4590. }
  4591. lua_interface->ResetFunctionStack(state);
  4592. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4593. if (player && spell && player->IsPlayer()) {
  4594. Client* client = player->GetClient();
  4595. if (client) {
  4596. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4597. {
  4598. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4599. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4600. client->GetPlayer()->UnlockSpell(spell);
  4601. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4602. }
  4603. else
  4604. {
  4605. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4606. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4607. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4608. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4609. client->GetPlayer()->UnlockSpell(spell);
  4610. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4611. }
  4612. //if (client ) {
  4613. // ((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);
  4614. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4615. if (outapp)
  4616. client->QueuePacket(outapp);
  4617. }
  4618. }
  4619. return 0;
  4620. }
  4621. int EQ2Emu_lua_DeleteSpellBook(lua_State* state) {
  4622. if (!lua_interface)
  4623. return 0;
  4624. Spawn* player = lua_interface->GetSpawn(state);
  4625. int8 type_selection = lua_interface->GetInt8Value(state, 2);
  4626. lua_interface->ResetFunctionStack(state);
  4627. if (player && player->IsPlayer()) {
  4628. Client* client = player->GetClient();
  4629. if (client) {
  4630. ((Player*)player)->DeleteSpellBook(type_selection);
  4631. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4632. if (outapp)
  4633. client->QueuePacket(outapp);
  4634. }
  4635. }
  4636. return 0;
  4637. }
  4638. int EQ2Emu_lua_SendNewAdventureSpells(lua_State* state) {
  4639. if (!lua_interface)
  4640. return 0;
  4641. Spawn* player = lua_interface->GetSpawn(state);
  4642. lua_interface->ResetFunctionStack(state);
  4643. if (player && player->IsPlayer()) {
  4644. Client* client = player->GetClient();
  4645. if (client) {
  4646. client->SendNewAdventureSpells();
  4647. }
  4648. }
  4649. return 0;
  4650. }
  4651. int EQ2Emu_lua_SendNewTradeskillSpells(lua_State* state) {
  4652. if (!lua_interface)
  4653. return 0;
  4654. Spawn* player = lua_interface->GetSpawn(state);
  4655. lua_interface->ResetFunctionStack(state);
  4656. if (player && player->IsPlayer()) {
  4657. Client* client = player->GetClient();
  4658. if (client) {
  4659. client->SendNewTradeskillSpells();
  4660. }
  4661. }
  4662. return 0;
  4663. }
  4664. int EQ2Emu_lua_RemoveSpellBookEntry(lua_State* state) {
  4665. if (!lua_interface)
  4666. return 0;
  4667. Spawn* player = lua_interface->GetSpawn(state);
  4668. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4669. lua_interface->ResetFunctionStack(state);
  4670. if (player && player->IsPlayer()) {
  4671. SpellBookEntry* sbe = ((Player*)player)->GetSpellBookSpell(spellid);
  4672. Client* client = player->GetClient();
  4673. if (sbe && client) {
  4674. ((Player*)player)->RemoveSpellBookEntry(spellid);
  4675. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4676. if (outapp)
  4677. client->QueuePacket(outapp);
  4678. }
  4679. }
  4680. return 0;
  4681. }
  4682. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4683. if (!lua_interface)
  4684. return 0;
  4685. Spawn* player = lua_interface->GetSpawn(state);
  4686. lua_interface->ResetFunctionStack(state);
  4687. if (player && player->IsPlayer()) {
  4688. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4689. return 1;
  4690. }
  4691. return 0;
  4692. }
  4693. int EQ2Emu_lua_Attack(lua_State* state) {
  4694. if (lua_interface) {
  4695. Spawn* npc = lua_interface->GetSpawn(state);
  4696. Spawn* player = lua_interface->GetSpawn(state, 2);
  4697. lua_interface->ResetFunctionStack(state);
  4698. if (npc && player && npc->IsNPC() && player->IsEntity())
  4699. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4700. }
  4701. return 0;
  4702. }
  4703. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4704. if (lua_interface) {
  4705. Spawn* target = lua_interface->GetSpawn(state);
  4706. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4707. lua_interface->ResetFunctionStack(state);
  4708. if (target && target->GetZone())
  4709. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4710. }
  4711. return 0;
  4712. }
  4713. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4714. Spawn* player;
  4715. if (lua_interface) {
  4716. player = lua_interface->GetSpawn(state);
  4717. lua_interface->ResetFunctionStack(state);
  4718. if (player && player->IsPlayer()) {
  4719. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4720. return 1;
  4721. }
  4722. }
  4723. return 0;
  4724. }
  4725. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4726. Spawn* player;
  4727. Client* client;
  4728. if (lua_interface) {
  4729. player = lua_interface->GetSpawn(state);
  4730. lua_interface->ResetFunctionStack(state);
  4731. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4732. if ((client = ((Player*)player)->GetClient()))
  4733. client->HandInCollections();
  4734. }
  4735. return 0;
  4736. }
  4737. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4738. Spawn* widget;
  4739. if (lua_interface) {
  4740. widget = lua_interface->GetSpawn(state);
  4741. lua_interface->ResetFunctionStack(state);
  4742. if (widget && widget->IsWidget())
  4743. ((Widget*)widget)->HandleUse(nullptr, "");
  4744. }
  4745. return 0;
  4746. }
  4747. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4748. Spawn* spawn = 0;
  4749. int32 primary_list = 0;
  4750. int32 secondary_list = 0;
  4751. if (lua_interface) {
  4752. spawn = lua_interface->GetSpawn(state);
  4753. primary_list = lua_interface->GetInt32Value(state, 2);
  4754. secondary_list = lua_interface->GetInt32Value(state, 3);
  4755. lua_interface->ResetFunctionStack(state);
  4756. if (!spawn->IsNPC()) {
  4757. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4758. return 0;
  4759. }
  4760. NPC* npc = (NPC*)spawn;
  4761. npc->SetPrimarySpellList(primary_list);
  4762. npc->SetSecondarySpellList(secondary_list);
  4763. npc->SetSpells(world.GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4764. }
  4765. return 0;
  4766. }
  4767. int EQ2Emu_lua_GetPet(lua_State* state) {
  4768. if (!lua_interface)
  4769. return 0;
  4770. Spawn* spawn = lua_interface->GetSpawn(state);
  4771. lua_interface->ResetFunctionStack(state);
  4772. if (spawn) {
  4773. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4774. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4775. return 1;
  4776. }
  4777. }
  4778. return 0;
  4779. }
  4780. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4781. if (!lua_interface)
  4782. return 0;
  4783. Spawn* spawn = lua_interface->GetSpawn(state);
  4784. lua_interface->ResetFunctionStack(state);
  4785. if (spawn) {
  4786. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4787. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4788. return 1;
  4789. }
  4790. }
  4791. return 0;
  4792. }
  4793. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4794. if (!lua_interface)
  4795. return 0;
  4796. Spawn* spawn = lua_interface->GetSpawn(state);
  4797. lua_interface->ResetFunctionStack(state);
  4798. if (spawn) {
  4799. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4800. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4801. return 1;
  4802. }
  4803. }
  4804. return 0;
  4805. }
  4806. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4807. if (!lua_interface)
  4808. return 0;
  4809. Spawn* spawn = lua_interface->GetSpawn(state);
  4810. lua_interface->ResetFunctionStack(state);
  4811. if (spawn) {
  4812. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4813. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4814. return 1;
  4815. }
  4816. }
  4817. return 0;
  4818. }
  4819. int EQ2Emu_lua_Charm(lua_State* state) {
  4820. if (!lua_interface)
  4821. return 0;
  4822. Spawn* owner = lua_interface->GetSpawn(state);
  4823. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4824. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4825. lua_interface->ResetFunctionStack(state);
  4826. if (!luaspell) {
  4827. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4828. return 0;
  4829. }
  4830. if(luaspell->resisted) {
  4831. return 0;
  4832. }
  4833. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4834. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4835. pet->SetPet(true);
  4836. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4837. ((NPC*)pet)->SetOwner((Entity*)owner);
  4838. // If owner is player and player does not have a summoned pet set the players charsheet
  4839. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4840. Player* player = (Player*)owner;
  4841. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4842. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4843. player->GetInfoStruct()->set_pet_movement(2);
  4844. player->GetInfoStruct()->set_pet_behavior(3);
  4845. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4846. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4847. // Make sure the values get sent to the client
  4848. player->SetCharSheetChanged(true);
  4849. }
  4850. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4851. pet->SetSpawnScript("");
  4852. // Set faction to the same as the owner
  4853. pet->SetFactionID(owner->GetFactionID());
  4854. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4855. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4856. // Clear hate list
  4857. ((NPC*)pet)->Brain()->ClearHate();
  4858. // Set the brain to a pet brain
  4859. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4860. }
  4861. return 0;
  4862. }
  4863. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4864. if (!lua_interface)
  4865. return 0;
  4866. Spawn* spawn = lua_interface->GetSpawn(state);
  4867. lua_interface->ResetFunctionStack(state);
  4868. if (!spawn) {
  4869. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4870. return 0;
  4871. }
  4872. vector<Spawn*> groupMembers;
  4873. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4874. groupMembers = *spawn->GetSpawnGroup();
  4875. }
  4876. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4877. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4878. deque<GroupMemberInfo*>::iterator itr;
  4879. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4880. if (group)
  4881. {
  4882. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4883. deque<GroupMemberInfo*>* members = group->GetMembers();
  4884. GroupMemberInfo* info = 0;
  4885. for (itr = members->begin(); itr != members->end(); itr++) {
  4886. info = *itr;
  4887. if (info->client)
  4888. groupMembers.push_back(info->client->GetPlayer());
  4889. }
  4890. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4891. }
  4892. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4893. }
  4894. else
  4895. return 0;
  4896. lua_createtable(state, groupMembers.size(), 0);
  4897. int newTable = lua_gettop(state);
  4898. for (int32 i = 0; i < groupMembers.size(); i++) {
  4899. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4900. lua_rawseti(state, newTable, i + 1);
  4901. }
  4902. return 1;
  4903. }
  4904. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4905. if (!lua_interface)
  4906. return 0;
  4907. lua_interface->ResetFunctionStack(state);
  4908. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4909. lua_interface->SetOptionWindowValue(state, option_window);
  4910. return 1;
  4911. }
  4912. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4913. if (!lua_interface)
  4914. return 0;
  4915. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4916. if (option_window) {
  4917. OptionWindowOption option_window_option;
  4918. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4919. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4920. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4921. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4922. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4923. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4924. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4925. option_window->push_back(option_window_option);
  4926. }
  4927. lua_interface->ResetFunctionStack(state);
  4928. return 0;
  4929. }
  4930. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4931. if (!lua_interface)
  4932. return 0;
  4933. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4934. Spawn* player = lua_interface->GetSpawn(state, 2);
  4935. string window_title = lua_interface->GetStringValue(state, 3);
  4936. string cancel_command = lua_interface->GetStringValue(state, 4);
  4937. lua_interface->ResetFunctionStack(state);
  4938. if (!player->IsPlayer()) {
  4939. lua_interface->LogError("%s: LUA SendOptionWindow command error: spawn is not a player", lua_interface->GetScriptName(state));
  4940. return 0;
  4941. }
  4942. Client* client = ((Player*)player)->GetClient();
  4943. if (option_window && window_title.length() > 0 && client) {
  4944. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4945. if (!packet)
  4946. return 0;
  4947. packet->setDataByName("title_text", window_title.c_str());
  4948. if (cancel_command.length() > 0)
  4949. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4950. packet->setArrayLengthByName("num_selections", option_window->size());
  4951. vector<OptionWindowOption>::iterator itr;
  4952. int8 i = 0;
  4953. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4954. OptionWindowOption opt = *itr;
  4955. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4956. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4957. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4958. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4959. if (opt.optionCommand.length() > 0)
  4960. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4961. if (opt.optionConfirmTitle.length() > 0)
  4962. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4963. i++;
  4964. }
  4965. client->QueuePacket(packet->serialize());
  4966. lua_interface->SetLuaUserDataStale(option_window);
  4967. safe_delete(option_window);
  4968. safe_delete(packet);
  4969. }
  4970. return 0;
  4971. }
  4972. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4973. if (!lua_interface)
  4974. return 0;
  4975. Spawn* spawn = lua_interface->GetSpawn(state);
  4976. lua_interface->ResetFunctionStack(state);
  4977. if (spawn) {
  4978. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4979. return 1;
  4980. }
  4981. else
  4982. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4983. return 0;
  4984. }
  4985. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4986. if (!lua_interface)
  4987. return 0;
  4988. Spawn* spawn = lua_interface->GetSpawn(state);
  4989. lua_interface->ResetFunctionStack(state);
  4990. if (spawn) {
  4991. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4992. return 1;
  4993. }
  4994. else
  4995. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4996. return 0;
  4997. }
  4998. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4999. if (!lua_interface)
  5000. return 0;
  5001. Spawn* spawn = lua_interface->GetSpawn(state);
  5002. lua_interface->ResetFunctionStack(state);
  5003. if (spawn) {
  5004. int8 class_id = spawn->GetTradeskillClass();
  5005. // Need to add 42 for the offset in the array
  5006. class_id += 44;
  5007. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  5008. return 1;
  5009. }
  5010. else
  5011. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  5012. return 0;
  5013. }
  5014. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  5015. if (!lua_interface)
  5016. return 0;
  5017. Spawn* spawn = lua_interface->GetSpawn(state);
  5018. int16 level = lua_interface->GetInt8Value(state, 2);
  5019. lua_interface->ResetFunctionStack(state);
  5020. if (spawn) {
  5021. if (spawn->IsPlayer() && ((Player*)spawn)->GetClient())
  5022. ((Player*)spawn)->GetClient()->ChangeTSLevel(spawn->GetTSLevel(), level);
  5023. else
  5024. spawn->SetTSLevel(level);
  5025. }
  5026. else
  5027. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  5028. return 0;
  5029. }
  5030. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  5031. if (!lua_interface)
  5032. return 0;
  5033. Spawn* spawn = lua_interface->GetSpawn(state);
  5034. int8 attackable = lua_interface->GetInt8Value(state, 2);
  5035. lua_interface->ResetFunctionStack(state);
  5036. if (spawn) {
  5037. spawn->SetAttackable(attackable);
  5038. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  5039. }
  5040. return 0;
  5041. }
  5042. int EQ2Emu_lua_SummonPet(lua_State* state) {
  5043. // Check to see if we have a valid lua_interface
  5044. if (!lua_interface)
  5045. return 0;
  5046. // Get the spawn that is getting the pet
  5047. Spawn* spawn = lua_interface->GetSpawn(state);
  5048. // Get the DB ID of the pet
  5049. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5050. // The max level the pet can gain
  5051. int8 max_level = lua_interface->GetInt8Value(state, 3);
  5052. // Get the spell that this command was called from
  5053. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5054. lua_interface->ResetFunctionStack(state);
  5055. // Check to make sure the spawn pointer is valid
  5056. if (!spawn) {
  5057. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5058. return 0;
  5059. }
  5060. // Check to make sure the spawn is an entity
  5061. if (!spawn->IsEntity()) {
  5062. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5063. return 0;
  5064. }
  5065. // Check to make sure the spawn doesn't already have a pet of this type
  5066. if (((Entity*)spawn)->GetPet()) {
  5067. if (spawn->IsPlayer()) {
  5068. Client* client = ((Player*)spawn)->GetClient();
  5069. if (client)
  5070. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  5071. }
  5072. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5073. return 0;
  5074. }
  5075. // Check to see if the DB ID for the pet is set
  5076. if (pet_id == 0) {
  5077. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5078. return 0;
  5079. }
  5080. // Check to see if the pointer to the spell is valid
  5081. if (!luaspell) {
  5082. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5083. return 0;
  5084. }
  5085. if(luaspell->resisted) {
  5086. return 0;
  5087. }
  5088. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  5089. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5090. if (!pet) {
  5091. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5092. return 0;
  5093. }
  5094. // Check to make sure the pet is an npc
  5095. if (!pet->IsNPC()) {
  5096. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  5097. return 0;
  5098. }
  5099. // Spawn the pet at the same location as the owner
  5100. pet->SetX(spawn->GetX());
  5101. pet->SetY(spawn->GetY());
  5102. pet->SetZ(spawn->GetZ());
  5103. pet->SetLocation(spawn->GetLocation());
  5104. pet->SetHeading(spawn->GetHeading());
  5105. std::string petName = std::string("");
  5106. if(spawn->IsEntity()) {
  5107. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  5108. }
  5109. if(petName.size() < 1) {
  5110. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5111. petName = spawn->GetZone()->pet_names.at(rand_index);
  5112. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  5113. }
  5114. // If player set various values for the char sheet (pet window)
  5115. if (spawn->IsPlayer()) {
  5116. Player* player = (Player*)spawn;
  5117. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  5118. player->GetInfoStruct()->set_pet_name(petName);
  5119. player->GetInfoStruct()->set_pet_movement(2);
  5120. player->GetInfoStruct()->set_pet_behavior(3);
  5121. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  5122. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  5123. // Make sure the values get sent to the client
  5124. player->SetCharSheetChanged(true);
  5125. }
  5126. // Set the pets name
  5127. pet->SetName(petName.c_str());
  5128. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  5129. if (max_level > 0)
  5130. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  5131. else
  5132. pet->SetLevel(spawn->GetLevel());
  5133. // Set the max level this pet can reach
  5134. ((NPC*)pet)->SetMaxPetLevel(max_level);
  5135. ((NPC*)pet)->UpdateWeapons();
  5136. // Set the faction of the pet to the same faction as the owner
  5137. pet->SetFactionID(spawn->GetFactionID());
  5138. // Set the spawn as a pet
  5139. pet->SetPet(true);
  5140. // Give a pointer of the owner to the pet
  5141. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5142. // Give a pointer of the pet to the owner
  5143. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  5144. // Set the pet type
  5145. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  5146. // Set the spell id used to create this pet
  5147. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5148. // Set the spell tier used to create this pet
  5149. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5150. // Set the pets spawn type to 6
  5151. pet->SetSpawnType(6);
  5152. // Set the pets brain
  5153. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  5154. // Check to see if the pet has a subtitle
  5155. if (strlen(pet->GetSubTitle()) > 0) {
  5156. // Add the players name to the front of the sub title
  5157. string pet_subtitle;
  5158. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5159. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5160. // Set the pets subtitle to the new one
  5161. pet->SetSubTitle(pet_subtitle.c_str());
  5162. }
  5163. // Add the "Pet Options" entity command to the pet
  5164. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5165. const char* spawn_script = world.GetSpawnScript(pet_id);
  5166. bool runScript = false;
  5167. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  5168. runScript = true;
  5169. pet->SetSpawnScript(string(spawn_script));
  5170. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_PRESPAWN);
  5171. }
  5172. spawn->GetZone()->AddSpawn(pet);
  5173. if(runScript){
  5174. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_SPAWN);
  5175. }
  5176. // Set the pet as the return value for this function
  5177. lua_interface->SetSpawnValue(state, pet);
  5178. return 1;
  5179. }
  5180. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  5181. if (!lua_interface)
  5182. return 0;
  5183. Spawn* spawn = lua_interface->GetSpawn(state);
  5184. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5185. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5186. lua_interface->ResetFunctionStack(state);
  5187. if (!spawn) {
  5188. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5189. return 0;
  5190. }
  5191. if (!spawn->IsEntity()) {
  5192. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5193. return 0;
  5194. }
  5195. if (((Entity*)spawn)->GetDeityPet()) {
  5196. if (spawn->IsPlayer()) {
  5197. Client* client = ((Player*)spawn)->GetClient();
  5198. if (client)
  5199. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  5200. }
  5201. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5202. return 0;
  5203. }
  5204. if (pet_id == 0) {
  5205. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5206. return 0;
  5207. }
  5208. if (!luaspell) {
  5209. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5210. return 0;
  5211. }
  5212. if(luaspell->resisted) {
  5213. return 0;
  5214. }
  5215. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5216. if (!pet) {
  5217. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5218. return 0;
  5219. }
  5220. if (!pet->IsNPC()) {
  5221. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5222. return 0;
  5223. }
  5224. pet->SetX(spawn->GetX());
  5225. pet->SetY(spawn->GetY());
  5226. pet->SetZ(spawn->GetZ());
  5227. pet->SetLocation(spawn->GetLocation());
  5228. pet->SetHeading(spawn->GetHeading());
  5229. spawn->GetZone()->AddSpawn(pet);
  5230. string random_pet_name;
  5231. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5232. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5233. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5234. pet->SetName(random_pet_name.c_str());
  5235. pet->SetLevel(spawn->GetLevel());
  5236. pet->SetFactionID(spawn->GetFactionID());
  5237. pet->SetPet(true);
  5238. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  5239. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5240. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  5241. pet->SetSpawnType(6);
  5242. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5243. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5244. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5245. if (strlen(pet->GetSubTitle()) > 0) {
  5246. string pet_subtitle;
  5247. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5248. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5249. pet->SetSubTitle(pet_subtitle.c_str());
  5250. }
  5251. // deity and cosmetic pets are not attackable
  5252. pet->SetAttackable(false);
  5253. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5254. lua_interface->SetSpawnValue(state, pet);
  5255. return 1;
  5256. }
  5257. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  5258. if (!lua_interface)
  5259. return 0;
  5260. Spawn* spawn = lua_interface->GetSpawn(state);
  5261. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5262. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5263. lua_interface->ResetFunctionStack(state);
  5264. if (!spawn) {
  5265. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5266. return 0;
  5267. }
  5268. if (!spawn->IsEntity()) {
  5269. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5270. return 0;
  5271. }
  5272. if (((Entity*)spawn)->GetCosmeticPet()) {
  5273. if (spawn->IsPlayer()) {
  5274. Client* client = ((Player*)spawn)->GetClient();
  5275. if (client)
  5276. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  5277. }
  5278. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5279. return 0;
  5280. }
  5281. if (pet_id == 0) {
  5282. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5283. return 0;
  5284. }
  5285. if (!luaspell) {
  5286. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5287. return 0;
  5288. }
  5289. if(luaspell->resisted) {
  5290. return 0;
  5291. }
  5292. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5293. if (!pet) {
  5294. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5295. return 0;
  5296. }
  5297. if (!pet->IsNPC()) {
  5298. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5299. return 0;
  5300. }
  5301. pet->SetX(spawn->GetX());
  5302. pet->SetY(spawn->GetY());
  5303. pet->SetZ(spawn->GetZ());
  5304. pet->SetLocation(spawn->GetLocation());
  5305. pet->SetHeading(spawn->GetHeading());
  5306. spawn->GetZone()->AddSpawn(pet);
  5307. string random_pet_name;
  5308. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5309. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5310. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5311. pet->SetName(random_pet_name.c_str());
  5312. pet->SetLevel(spawn->GetLevel());
  5313. pet->SetFactionID(spawn->GetFactionID());
  5314. pet->SetPet(true);
  5315. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  5316. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5317. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5318. pet->SetSpawnType(6);
  5319. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5320. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5321. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5322. if (strlen(pet->GetSubTitle()) > 0) {
  5323. string pet_subtitle;
  5324. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5325. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5326. pet->SetSubTitle(pet_subtitle.c_str());
  5327. }
  5328. pet->SetAttackable(false);
  5329. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5330. lua_interface->SetSpawnValue(state, pet);
  5331. return 1;
  5332. }
  5333. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5334. if (!lua_interface)
  5335. return 0;
  5336. Spawn* spawn = lua_interface->GetSpawn(state);
  5337. lua_interface->ResetFunctionStack(state);
  5338. if (!spawn) {
  5339. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5340. return 0;
  5341. }
  5342. if (!spawn->IsPet()) {
  5343. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5344. return 0;
  5345. }
  5346. if (!((NPC*)spawn)->IsDismissing() && ((NPC*)spawn)->GetOwner())
  5347. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5348. return 0;
  5349. }
  5350. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5351. if (!lua_interface)
  5352. return 0;
  5353. Quest* quest = lua_interface->GetQuest(state);
  5354. if (!quest) {
  5355. 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));
  5356. lua_interface->ResetFunctionStack(state);
  5357. return 0;
  5358. }
  5359. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5360. lua_interface->ResetFunctionStack(state);
  5361. if (feather_color > 0)
  5362. quest->SetFeatherColor(feather_color);
  5363. return 0;
  5364. }
  5365. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5366. if (!lua_interface)
  5367. return 0;
  5368. Spawn* spawn = lua_interface->GetSpawn(state);
  5369. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5370. lua_interface->ResetFunctionStack(state);
  5371. if (!spawn) {
  5372. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5373. return 0;
  5374. }
  5375. if (!spawn2) {
  5376. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5377. return 0;
  5378. }
  5379. spawn->RemoveSpawnAccess(spawn2);
  5380. return 0;
  5381. }
  5382. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5383. if (!lua_interface)
  5384. return 0;
  5385. ZoneServer* zone = lua_interface->GetZone(state);
  5386. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5387. lua_interface->ResetFunctionStack(state);
  5388. if (!zone) {
  5389. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5390. return 0;
  5391. }
  5392. if (location_id == 0) {
  5393. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5394. return 0;
  5395. }
  5396. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5397. if (!location) {
  5398. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5399. return 0;
  5400. }
  5401. int32 rand_number = MakeRandomInt(0, location->entities.size() - 1);
  5402. Spawn* spawn = 0;
  5403. if (location->entities[rand_number]) {
  5404. if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5405. spawn = zone->AddNPCSpawn(location, location->entities[rand_number]);
  5406. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5407. spawn = zone->AddGroundSpawn(location, location->entities[rand_number]);
  5408. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5409. spawn = zone->AddObjectSpawn(location, location->entities[rand_number]);
  5410. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5411. spawn = zone->AddWidgetSpawn(location, location->entities[rand_number]);
  5412. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5413. spawn = zone->AddSignSpawn(location, location->entities[rand_number]);
  5414. if(spawn && spawn->IsOmittedByDBFlag())
  5415. {
  5416. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5417. safe_delete(spawn);
  5418. spawn = 0;
  5419. return 0;
  5420. }
  5421. if (spawn) {
  5422. const char* script = 0;
  5423. for (int x = 0; x < 3; x++) {
  5424. switch (x) {
  5425. case 0:
  5426. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5427. break;
  5428. case 1:
  5429. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5430. break;
  5431. case 2:
  5432. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5433. break;
  5434. }
  5435. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5436. spawn->SetSpawnScript(string(script));
  5437. break;
  5438. }
  5439. }
  5440. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5441. lua_interface->SetSpawnValue(state, spawn);
  5442. return 1;
  5443. }
  5444. else {
  5445. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5446. safe_delete(spawn);
  5447. }
  5448. }
  5449. return 0;
  5450. }
  5451. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5452. if (!lua_interface)
  5453. return 0;
  5454. Spawn* caster = lua_interface->GetSpawn(state);
  5455. Spawn* target = lua_interface->GetSpawn(state, 2);
  5456. int32 id = lua_interface->GetInt32Value(state, 3);
  5457. string command = lua_interface->GetStringValue(state, 4);
  5458. lua_interface->ResetFunctionStack(state);
  5459. if (!caster) {
  5460. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5461. return 0;
  5462. }
  5463. if (!target) {
  5464. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5465. return 0;
  5466. }
  5467. if (!caster->IsPlayer()) {
  5468. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5469. return 0;
  5470. }
  5471. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5472. if (!entity_command) {
  5473. 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());
  5474. return 0;
  5475. }
  5476. Client* client = ((Player*)caster)->GetClient();
  5477. if (!client) {
  5478. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5479. return 0;
  5480. }
  5481. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5482. return 0;
  5483. }
  5484. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5485. if (!lua_interface)
  5486. return 0;
  5487. Spawn* spawn = lua_interface->GetSpawn(state);
  5488. lua_interface->ResetFunctionStack(state);
  5489. if (!spawn) {
  5490. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5491. return 0;
  5492. }
  5493. if (!spawn->IsNPC()) {
  5494. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5495. return 0;
  5496. }
  5497. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5498. return 0;
  5499. }
  5500. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5501. if (!lua_interface)
  5502. return 0;
  5503. Spawn* spawn = lua_interface->GetSpawn(state);
  5504. int16 tick = lua_interface->GetInt16Value(state, 2);
  5505. lua_interface->ResetFunctionStack(state);
  5506. if (!spawn) {
  5507. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5508. return 0;
  5509. }
  5510. if (!spawn->IsNPC()) {
  5511. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5512. return 0;
  5513. }
  5514. if (tick < 20) {
  5515. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5516. return 0;
  5517. }
  5518. ((NPC*)spawn)->Brain()->SetTick(tick);
  5519. return 0;
  5520. }
  5521. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5522. if (!lua_interface)
  5523. return 0;
  5524. Spawn* spawn = lua_interface->GetSpawn(state);
  5525. Spawn* target = lua_interface->GetSpawn(state, 2);
  5526. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5527. lua_interface->ResetFunctionStack(state);
  5528. if (!spawn) {
  5529. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5530. return 0;
  5531. }
  5532. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5533. spawn->SetFollowTarget(target, follow_distance);
  5534. return 0;
  5535. }
  5536. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5537. if (!lua_interface)
  5538. return 0;
  5539. Spawn* spawn = lua_interface->GetSpawn(state);
  5540. lua_interface->ResetFunctionStack(state);
  5541. if (!spawn) {
  5542. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5543. return 0;
  5544. }
  5545. Spawn* target = spawn->GetFollowTarget();
  5546. if (target) {
  5547. lua_interface->SetSpawnValue(state, target);
  5548. return 1;
  5549. }
  5550. return 0;
  5551. }
  5552. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5553. if (!lua_interface)
  5554. return 0;
  5555. Spawn* spawn = lua_interface->GetSpawn(state);
  5556. lua_interface->ResetFunctionStack(state);
  5557. if (!spawn) {
  5558. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5559. return 0;
  5560. }
  5561. if (spawn->following)
  5562. spawn->following = false;
  5563. else
  5564. spawn->following = true;
  5565. return 0;
  5566. }
  5567. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5568. if (!lua_interface)
  5569. return 0;
  5570. Spawn* spawn = lua_interface->GetSpawn(state);
  5571. lua_interface->ResetFunctionStack(state);
  5572. if (!spawn) {
  5573. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5574. return 0;
  5575. }
  5576. lua_interface->SetBooleanValue(state, spawn->following);
  5577. return 1;
  5578. }
  5579. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5580. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5581. // I will attempt to explain how this function works for future refrence
  5582. // Fist lets make sure lua_interface is valid, if not return out
  5583. if (!lua_interface)
  5584. return 0;
  5585. // Next we grab the first 2 params same as we usually would
  5586. Spawn* spawn = lua_interface->GetSpawn(state);
  5587. string var = lua_interface->GetStringValue(state, 2);
  5588. // 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
  5589. // 1 = Spawn
  5590. // 2 = Zone
  5591. // 3 = Item
  5592. // 4 = Quest
  5593. // 5 = String
  5594. // 6 = nil (null)
  5595. int8 dataType = 0;
  5596. // Define pointers for each potential type
  5597. Spawn* spawnVal = 0;
  5598. ZoneServer* zone = 0;
  5599. Item* item = 0;
  5600. Quest* quest = 0;
  5601. string val;
  5602. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5603. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5604. // options window are also light user data be we do not handle those.
  5605. // We check with lua_islightuserdata(lua_State*, index)
  5606. if (lua_islightuserdata(state, 3)) {
  5607. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5608. // and convert it to LUAUserData*
  5609. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5610. // Check to make sure the data we got is valid, if not give an error
  5611. if (!data || !data->IsCorrectlyInitialized()) {
  5612. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5613. }
  5614. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5615. else if (data->IsSpawn()) {
  5616. spawnVal = data->spawn;
  5617. dataType = 1;
  5618. }
  5619. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5620. else if (data->IsZone()) {
  5621. zone = data->zone;
  5622. dataType = 2;
  5623. }
  5624. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5625. else if (data->IsItem()) {
  5626. item = data->item;
  5627. dataType = 3;
  5628. }
  5629. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5630. else if (data->IsQuest()) {
  5631. quest = data->quest;
  5632. dataType = 4;
  5633. }
  5634. }
  5635. // Wasn't light user data, check if it is nil(null)
  5636. else if (lua_isnil(state, 3)) {
  5637. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5638. dataType = 6;
  5639. }
  5640. // Wasn't light user data or nil (null), must be a string
  5641. else {
  5642. // Set the string and dataType variable
  5643. val = lua_interface->GetStringValue(state, 3);
  5644. dataType = 5;
  5645. }
  5646. lua_interface->ResetFunctionStack(state);
  5647. // We now have all the params, lets check to make sure they are valid
  5648. if (!spawn) {
  5649. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5650. return 0;
  5651. }
  5652. if (var.length() == 0) {
  5653. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5654. return 0;
  5655. }
  5656. if (dataType == 0) {
  5657. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5658. return 0;
  5659. }
  5660. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5661. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5662. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5663. switch (dataType) {
  5664. case 1:
  5665. // 1 = Spawn
  5666. spawn->AddTempVariable(var, spawnVal);
  5667. break;
  5668. case 2:
  5669. // 2 = Zone
  5670. spawn->AddTempVariable(var, zone);
  5671. break;
  5672. case 3:
  5673. // 3 = Item
  5674. spawn->AddTempVariable(var, item);
  5675. break;
  5676. case 4:
  5677. // 4 = Quest
  5678. spawn->AddTempVariable(var, quest);
  5679. break;
  5680. case 5:
  5681. // 5 = String
  5682. spawn->AddTempVariable(var, val);
  5683. break;
  5684. case 6:
  5685. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5686. spawn->DeleteTempVariable(var);
  5687. break;
  5688. }
  5689. // And we are done so return out
  5690. return 0;
  5691. }
  5692. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5693. if (!lua_interface)
  5694. return 0;
  5695. Spawn* spawn = lua_interface->GetSpawn(state);
  5696. string var = lua_interface->GetStringValue(state, 2);
  5697. lua_interface->ResetFunctionStack(state);
  5698. if (!spawn) {
  5699. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5700. return 0;
  5701. }
  5702. if (var.length() == 0) {
  5703. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5704. return 0;
  5705. }
  5706. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5707. int8 type = spawn->GetTempVariableType(var);
  5708. Spawn* spawn2 = 0;
  5709. ZoneServer* zone = 0;
  5710. Item* item = 0;
  5711. Quest* quest = 0;
  5712. // Set the lua function return value based on the type of data the variable contains
  5713. switch (type) {
  5714. case 1:
  5715. spawn2 = spawn->GetTempVariableSpawn(var);
  5716. if (!spawn2)
  5717. return 0;
  5718. lua_interface->SetSpawnValue(state, spawn2);
  5719. break;
  5720. case 2:
  5721. zone = spawn->GetTempVariableZone(var);
  5722. if (!zone)
  5723. return 0;
  5724. lua_interface->SetZoneValue(state, zone);
  5725. break;
  5726. case 3:
  5727. item = spawn->GetTempVariableItem(var);
  5728. if (!item)
  5729. return 0;
  5730. lua_interface->SetItemValue(state, item);
  5731. break;
  5732. case 4:
  5733. quest = spawn->GetTempVariableQuest(var);
  5734. if (!quest)
  5735. return 0;
  5736. lua_interface->SetQuestValue(state, quest);
  5737. break;
  5738. case 5:
  5739. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5740. break;
  5741. default:
  5742. // Not a valid type then the variable was not set so return out
  5743. return 0;
  5744. }
  5745. // Return value was set so return out
  5746. return 1;
  5747. }
  5748. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5749. {
  5750. if (!lua_interface)
  5751. return 0;
  5752. Quest* quest = lua_interface->GetQuest(state);
  5753. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5754. string description = lua_interface->GetStringValue(state, 3);
  5755. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5756. if (!quest) {
  5757. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5758. lua_interface->ResetFunctionStack(state);
  5759. lua_interface->SetBooleanValue(state, false);
  5760. return 1;
  5761. }
  5762. if (!spawn) {
  5763. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5764. lua_interface->ResetFunctionStack(state);
  5765. lua_interface->SetBooleanValue(state, false);
  5766. return 1;
  5767. }
  5768. if (!spawn->IsPlayer()) {
  5769. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5770. lua_interface->ResetFunctionStack(state);
  5771. lua_interface->SetBooleanValue(state, false);
  5772. return 1;
  5773. }
  5774. if (item_id == 0) {
  5775. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5776. lua_interface->ResetFunctionStack(state);
  5777. lua_interface->SetBooleanValue(state, false);
  5778. return 1;
  5779. }
  5780. Client* client = ((Player*)spawn)->GetClient();
  5781. if (!client) {
  5782. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given player spawn", lua_interface->GetScriptName(state));
  5783. lua_interface->ResetFunctionStack(state);
  5784. lua_interface->SetBooleanValue(state, false);
  5785. return 1;
  5786. }
  5787. Item* item = master_item_list.GetItem(item_id);
  5788. if (!item) {
  5789. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5790. lua_interface->ResetFunctionStack(state);
  5791. lua_interface->SetBooleanValue(state, false);
  5792. return 1;
  5793. }
  5794. Item* firstItem = new Item(item);
  5795. quest->AddTmpRewardItem(firstItem);
  5796. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5797. bool itemsAddedSuccessfully = true;
  5798. if(num_args > 4)
  5799. {
  5800. for(int8 n=5;n<num_args+1;n++)
  5801. {
  5802. int32 new_item = lua_interface->GetInt32Value(state, n);
  5803. Item* tmpItem = master_item_list.GetItem(new_item);
  5804. if(tmpItem)
  5805. {
  5806. Item* newTmpItem = new Item(tmpItem);
  5807. quest->AddTmpRewardItem(newTmpItem);
  5808. }
  5809. else
  5810. itemsAddedSuccessfully = false;
  5811. }
  5812. }
  5813. client->AddPendingQuestReward(quest, true, true, description); // queue for display
  5814. lua_interface->ResetFunctionStack(state);
  5815. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5816. return 1;
  5817. }
  5818. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5819. if (!lua_interface)
  5820. return 0;
  5821. Quest* quest = lua_interface->GetQuest(state);
  5822. lua_interface->ResetFunctionStack(state);
  5823. if (!quest) {
  5824. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5825. return 0;
  5826. }
  5827. quest->SetRepeatable(true);
  5828. return 0;
  5829. }
  5830. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5831. if (!lua_interface)
  5832. return 0;
  5833. Spawn* spawn = lua_interface->GetSpawn(state);
  5834. lua_interface->ResetFunctionStack(state);
  5835. if (!spawn) {
  5836. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5837. return 0;
  5838. }
  5839. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5840. string ret = classes.GetClassNameCase(base_class);
  5841. if (ret.length() > 0) {
  5842. lua_interface->SetStringValue(state, ret.c_str());
  5843. return 1;
  5844. }
  5845. return 0;
  5846. }
  5847. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5848. if (!lua_interface)
  5849. return 0;
  5850. Spawn* player = lua_interface->GetSpawn(state);
  5851. lua_interface->ResetFunctionStack(state);
  5852. if (player && player->IsPlayer()) {
  5853. Client* client = player->GetClient();
  5854. if (client)
  5855. client->SendWaypoints();
  5856. }
  5857. return 0;
  5858. }
  5859. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5860. if (!lua_interface)
  5861. return 0;
  5862. Spawn* player = lua_interface->GetSpawn(state);
  5863. string name = lua_interface->GetStringValue(state, 2);
  5864. int32 type = lua_interface->GetInt32Value(state, 3);
  5865. lua_interface->ResetFunctionStack(state);
  5866. if (type == 0)
  5867. type = 2;
  5868. if (name.length() > 0) {
  5869. if (player && player->IsPlayer()) {
  5870. Client* client = player->GetClient();
  5871. if (client)
  5872. client->AddWaypoint(name, type);
  5873. }
  5874. }
  5875. return 0;
  5876. }
  5877. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5878. if (!lua_interface)
  5879. return 0;
  5880. Spawn* player = lua_interface->GetSpawn(state);
  5881. string name = lua_interface->GetStringValue(state, 2);
  5882. lua_interface->ResetFunctionStack(state);
  5883. if (name.length() > 0) {
  5884. if (player && player->IsPlayer()) {
  5885. Client* client = player->GetClient();
  5886. if (client)
  5887. client->RemoveWaypoint(name);
  5888. }
  5889. }
  5890. return 0;
  5891. }
  5892. int EQ2Emu_lua_AddWard(lua_State* state) {
  5893. if (!lua_interface)
  5894. return 0;
  5895. int32 damage = lua_interface->GetInt32Value(state);
  5896. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5897. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5898. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5899. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5900. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5901. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5902. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5903. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5904. lua_interface->ResetFunctionStack(state);
  5905. if(!spell || spell->resisted) {
  5906. return 0;
  5907. }
  5908. bool ward_was_added = false;
  5909. ZoneServer* zone = spell->caster->GetZone();
  5910. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5911. for (int32 i = 0; i < spell->targets.size(); i++) {
  5912. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5913. if (!target)
  5914. continue;
  5915. if (target->IsEntity()) {
  5916. // If the ward is already active remove it
  5917. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5918. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5919. // Create new ward info
  5920. WardInfo* ward = new WardInfo;
  5921. ward->Spell = spell;
  5922. ward->BaseDamage = damage;
  5923. ward->DamageLeft = damage;
  5924. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5925. ward->keepWard = keepWard;
  5926. ward->WardType = wardType;
  5927. if (damageAbsorptionPercent > 100)
  5928. damageAbsorptionPercent = 100;
  5929. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5930. if (damageAbsorptionMaxHealthPercent > 100)
  5931. damageAbsorptionMaxHealthPercent = 100;
  5932. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5933. ward->RedirectDamagePercent = redirectDamagePercent;
  5934. ward->LastRedirectDamage = 0;
  5935. ward->LastAbsorbedDamage = 0;
  5936. ward->HitCount = 0;
  5937. spell->num_triggers = maxHitCount;
  5938. spell->had_triggers = true;
  5939. spell->cancel_after_all_triggers = false;
  5940. ward->MaxHitCount = maxHitCount;
  5941. ward->RoundTriggered = false;
  5942. if (wardType == WARD_TYPE_MAGICAL)
  5943. ward->DamageType = damageTypes;
  5944. // Add the ward to the entity
  5945. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5946. ward_was_added = true;
  5947. }
  5948. }
  5949. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5950. if (ward_was_added && spell->caster->IsPlayer()) {
  5951. spell->had_dmg_remaining = true;
  5952. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, damage, 1);
  5953. }
  5954. return 0;
  5955. }
  5956. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5957. if (!lua_interface)
  5958. return 0;
  5959. int32 amount = lua_interface->GetInt32Value(state);
  5960. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5961. lua_interface->ResetFunctionStack(state);
  5962. WardInfo* ward = 0;
  5963. if(!spell || spell->resisted) {
  5964. return 0;
  5965. }
  5966. ZoneServer* zone = spell->caster->GetZone();
  5967. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5968. if (spell->targets.size() > 0 && zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5969. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5970. ward = target->GetWard(spell->spell->GetSpellID());
  5971. if (target && ward) {
  5972. ward->DamageLeft += amount;
  5973. if (ward->DamageLeft > ward->BaseDamage)
  5974. ward->DamageLeft = ward->BaseDamage;
  5975. for (int32 i = 0; i < spell->targets.size(); i++) {
  5976. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5977. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5978. }
  5979. }
  5980. }
  5981. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5982. if (ward && spell->caster->IsPlayer())
  5983. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
  5984. return 0;
  5985. }
  5986. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5987. if (!lua_interface)
  5988. return 0;
  5989. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5990. lua_interface->ResetFunctionStack(state);
  5991. if (!spell) {
  5992. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5993. return 0;
  5994. }
  5995. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5996. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5997. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5998. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5999. if (ward) {
  6000. lua_interface->SetInt32Value(state, ward->DamageLeft);
  6001. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6002. return 1;
  6003. }
  6004. }
  6005. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6006. return 0;
  6007. }
  6008. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  6009. if (!lua_interface)
  6010. return 0;
  6011. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6012. if (!spell) {
  6013. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  6014. lua_interface->ResetFunctionStack(state);
  6015. return 0;
  6016. }
  6017. string type = lua_interface->GetStringValue(state, 2);
  6018. lua_interface->ResetFunctionStack(state);
  6019. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6020. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  6021. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  6022. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  6023. if (ward) {
  6024. if (boost::iequals(type, "damageleft"))
  6025. lua_interface->SetInt32Value(state, ward->DamageLeft);
  6026. else if (boost::iequals(type, "basedamage"))
  6027. lua_interface->SetInt32Value(state, ward->BaseDamage);
  6028. else if (boost::iequals(type, "keepward"))
  6029. lua_interface->SetBooleanValue(state, ward->keepWard);
  6030. else if (boost::iequals(type, "wardtype"))
  6031. lua_interface->SetInt32Value(state, ward->WardType);
  6032. else if (boost::iequals(type, "dmgabsorptionpct"))
  6033. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  6034. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  6035. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  6036. else if (boost::iequals(type, "redirectdamagepercent"))
  6037. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  6038. else if (boost::iequals(type, "lastredirectdamage"))
  6039. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  6040. else if (boost::iequals(type, "lastabsorbeddamage"))
  6041. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  6042. else if (boost::iequals(type, "hitcount"))
  6043. lua_interface->SetInt32Value(state, ward->HitCount);
  6044. else if (boost::iequals(type, "maxhitcount"))
  6045. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  6046. else
  6047. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  6048. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6049. return 1;
  6050. }
  6051. }
  6052. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6053. return 0;
  6054. }
  6055. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  6056. if (!lua_interface)
  6057. return 0;
  6058. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6059. lua_interface->ResetFunctionStack(state);
  6060. if(!spell) {
  6061. return 0;
  6062. }
  6063. ZoneServer* zone = spell->caster->GetZone();
  6064. Spawn* target = 0;
  6065. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6066. for (int32 i = 0; i < spell->targets.size(); i++) {
  6067. target = zone->GetSpawnByID(spell->targets.at(i));
  6068. if (target && target->IsEntity()) {
  6069. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  6070. }
  6071. }
  6072. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6073. return 0;
  6074. }
  6075. int EQ2Emu_lua_Interrupt(lua_State* state)
  6076. {
  6077. if (!lua_interface)
  6078. return 0;
  6079. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  6080. Spawn* target = lua_interface->GetSpawn(state, 2);
  6081. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6082. lua_interface->ResetFunctionStack(state);
  6083. if (!caster)
  6084. {
  6085. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6086. return 0;
  6087. }
  6088. if (!target)
  6089. {
  6090. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6091. return 0;
  6092. }
  6093. if (!spell) {
  6094. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  6095. return 0;
  6096. }
  6097. if (!target->IsEntity() && !spell)
  6098. {
  6099. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  6100. return 0;
  6101. }
  6102. if (!target && spell) {
  6103. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6104. for (int8 i = 0; i < spell->targets.size(); i++) {
  6105. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6106. if (!target || !target->IsEntity())
  6107. continue;
  6108. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  6109. }
  6110. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6111. }
  6112. else
  6113. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  6114. return 0;
  6115. }
  6116. int EQ2Emu_lua_Stealth(lua_State* state) {
  6117. if (!lua_interface)
  6118. return 0;
  6119. int8 type = lua_interface->GetInt8Value(state);
  6120. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6121. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6122. lua_interface->ResetFunctionStack(state);
  6123. if (!spell) {
  6124. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  6125. return 0;
  6126. }
  6127. ZoneServer* zone = spell->caster->GetZone();
  6128. if (spawn) {
  6129. if (spawn->IsEntity()) {
  6130. if (type == 1) {
  6131. ((Entity*)spawn)->AddStealthSpell(spell);
  6132. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  6133. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  6134. }
  6135. else if (type == 2) {
  6136. ((Entity*)spawn)->AddInvisSpell(spell);
  6137. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  6138. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  6139. }
  6140. return 0;
  6141. }
  6142. else {
  6143. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  6144. return 0;
  6145. }
  6146. }
  6147. else {
  6148. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6149. for (int32 i = 0; i < spell->targets.size(); i++) {
  6150. spawn = zone->GetSpawnByID(spell->targets.at(i));
  6151. if (!spawn || !spawn->IsEntity())
  6152. continue;
  6153. if (type == 1) {
  6154. ((Entity*)spawn)->AddStealthSpell(spell);
  6155. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  6156. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  6157. }
  6158. else if (type == 2) {
  6159. ((Entity*)spawn)->AddInvisSpell(spell);
  6160. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  6161. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  6162. }
  6163. else {
  6164. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  6165. break;
  6166. }
  6167. }
  6168. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6169. }
  6170. return 0;
  6171. }
  6172. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  6173. if (!lua_interface)
  6174. return 0;
  6175. Spawn* spawn = lua_interface->GetSpawn(state);
  6176. lua_interface->ResetFunctionStack(state);
  6177. if (!spawn) {
  6178. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6179. return 0;
  6180. }
  6181. if (spawn->IsEntity()) {
  6182. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  6183. return 1;
  6184. }
  6185. else
  6186. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  6187. return 0;
  6188. }
  6189. int EQ2Emu_lua_IsInvis(lua_State* state) {
  6190. if (!lua_interface)
  6191. return 0;
  6192. Spawn* spawn = lua_interface->GetSpawn(state);
  6193. lua_interface->ResetFunctionStack(state);
  6194. if (!spawn) {
  6195. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  6196. return 0;
  6197. }
  6198. if (spawn->IsEntity()) {
  6199. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  6200. return 1;
  6201. }
  6202. else
  6203. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  6204. return 0;
  6205. }
  6206. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  6207. if (!lua_interface)
  6208. return 0;
  6209. Spawn* player = lua_interface->GetSpawn(state);
  6210. int32 item_id = lua_interface->GetInt32Value(state, 2);
  6211. lua_interface->ResetFunctionStack(state);
  6212. if (!player->IsPlayer()) {
  6213. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  6214. return 0;
  6215. }
  6216. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  6217. return 1;
  6218. }
  6219. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  6220. if (!lua_interface)
  6221. return 0;
  6222. Spawn* spawn = lua_interface->GetSpawn(state);
  6223. int8 slot = lua_interface->GetInt8Value(state, 2);
  6224. lua_interface->ResetFunctionStack(state);
  6225. if (!spawn) {
  6226. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6227. return 0;
  6228. }
  6229. if (!spawn->IsEntity()) {
  6230. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6231. return 0;
  6232. }
  6233. Item* item = ((Entity*)spawn)->GetEquipmentList()->GetItem(slot);
  6234. if (!item) {
  6235. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  6236. return 0;
  6237. }
  6238. lua_interface->SetItemValue(state, item);
  6239. return 1;
  6240. }
  6241. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  6242. if (!lua_interface)
  6243. return 0;
  6244. Spawn* player = lua_interface->GetSpawn(state);
  6245. int32 id = lua_interface->GetInt32Value(state, 2);
  6246. lua_interface->ResetFunctionStack(state);
  6247. if (!player) {
  6248. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6249. return 0;
  6250. }
  6251. if (!player->IsPlayer()) {
  6252. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6253. return 0;
  6254. }
  6255. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  6256. if (!item) {
  6257. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  6258. return 0;
  6259. }
  6260. lua_interface->SetItemValue(state, item);
  6261. return 1;
  6262. }
  6263. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  6264. if (!lua_interface)
  6265. return 0;
  6266. Spawn* spawn = lua_interface->GetSpawn(state);
  6267. int8 slot = lua_interface->GetInt8Value(state, 2);
  6268. int32 item_id = lua_interface->GetInt32Value(state, 3);
  6269. lua_interface->ResetFunctionStack(state);
  6270. if (!spawn) {
  6271. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6272. return 0;
  6273. }
  6274. if (!spawn->IsEntity()) {
  6275. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6276. return 0;
  6277. }
  6278. Item* item = master_item_list.GetItem(item_id);
  6279. if (!item) {
  6280. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  6281. return 0;
  6282. }
  6283. Item* copy = new Item(item);
  6284. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  6285. if(result)
  6286. {
  6287. ((Entity*)spawn)->SetEquipment(copy, slot);
  6288. spawn->vis_changed = true;
  6289. if(spawn->IsPlayer())
  6290. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6291. }
  6292. else
  6293. {
  6294. safe_delete(copy);
  6295. }
  6296. lua_interface->SetBooleanValue(state, result);
  6297. return 1;
  6298. }
  6299. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  6300. if (!lua_interface)
  6301. return 0;
  6302. Spawn* spawn = lua_interface->GetSpawn(state);
  6303. int8 slot = lua_interface->GetInt8Value(state, 2);
  6304. Item* item = lua_interface->GetItem(state, 3);
  6305. lua_interface->ResetFunctionStack(state);
  6306. if (!spawn) {
  6307. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  6308. return 0;
  6309. }
  6310. if (!spawn->IsEntity()) {
  6311. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6312. return 0;
  6313. }
  6314. if (!item) {
  6315. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  6316. return 0;
  6317. }
  6318. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  6319. if(result)
  6320. {
  6321. ((Entity*)spawn)->SetEquipment(item, slot);
  6322. spawn->vis_changed = true;
  6323. if(spawn->IsPlayer())
  6324. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6325. }
  6326. lua_interface->SetBooleanValue(state, result);
  6327. return 1;
  6328. }
  6329. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  6330. if (!lua_interface)
  6331. return 0;
  6332. Spawn* spawn = lua_interface->GetSpawn(state);
  6333. int8 slot = lua_interface->GetInt8Value(state, 2);
  6334. 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
  6335. lua_interface->ResetFunctionStack(state);
  6336. if (!spawn) {
  6337. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6338. return 0;
  6339. }
  6340. if (!spawn->IsEntity()) {
  6341. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6342. return 0;
  6343. }
  6344. if(slot >= NUM_SLOTS) {
  6345. lua_interface->LogError("%s: LUA UnequipSlot command error: wrong slot id given %u, max %u", lua_interface->GetScriptName(state), slot, NUM_SLOTS);
  6346. return 0;
  6347. }
  6348. if(spawn->IsPlayer() && ((Player*)spawn)->GetClient()) {
  6349. Item* item = ((Player*)spawn)->GetEquipmentList()->GetItem(slot);
  6350. if(item) {
  6351. item->save_needed = true;
  6352. if(no_delete_item) {
  6353. database.DeleteItem(((Player*)spawn)->GetClient()->GetCharacterID(), item, 0);
  6354. ((Player*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6355. }
  6356. else{
  6357. Client* client = ((Player*)spawn)->GetClient();
  6358. client->UnequipItem(item->details.index);
  6359. }
  6360. }
  6361. }
  6362. else
  6363. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6364. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  6365. spawn->vis_changed = true;
  6366. if(spawn->IsPlayer())
  6367. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6368. lua_interface->SetBooleanValue(state, true);
  6369. return 1;
  6370. }
  6371. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  6372. if (!lua_interface)
  6373. return 0;
  6374. Spawn* spawn = lua_interface->GetSpawn(state);
  6375. int8 slot = lua_interface->GetInt8Value(state, 2);
  6376. int16 type = lua_interface->GetInt16Value(state, 3);
  6377. int8 r = lua_interface->GetInt8Value(state, 4);
  6378. int8 g = lua_interface->GetInt8Value(state, 5);
  6379. int8 b = lua_interface->GetInt8Value(state, 6);
  6380. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6381. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6382. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6383. lua_interface->ResetFunctionStack(state);
  6384. if (!spawn) {
  6385. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6386. return 0;
  6387. }
  6388. if (!spawn->IsEntity()) {
  6389. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6390. return 0;
  6391. }
  6392. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6393. spawn->vis_changed = true;
  6394. lua_interface->SetBooleanValue(state, true);
  6395. return 1;
  6396. }
  6397. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6398. if (!lua_interface)
  6399. return 0;
  6400. Spawn* player = lua_interface->GetSpawn(state);
  6401. int32 id = lua_interface->GetInt32Value(state, 2);
  6402. int8 count = lua_interface->GetInt8Value(state, 3);
  6403. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6404. lua_interface->ResetFunctionStack(state);
  6405. if (!player) {
  6406. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6407. return 0;
  6408. }
  6409. if (!player->IsPlayer()) {
  6410. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6411. return 0;
  6412. }
  6413. if (!count)
  6414. count = 1;
  6415. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6416. if (!item) {
  6417. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6418. return 0;
  6419. }
  6420. lua_interface->SetItemValue(state, item);
  6421. return 1;
  6422. }
  6423. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6424. if (!lua_interface)
  6425. return 0;
  6426. Spawn* spawn = lua_interface->GetSpawn(state);
  6427. int32 anim = lua_interface->GetInt32Value(state, 2);
  6428. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6429. int8 type = lua_interface->GetInt8Value(state, 4);
  6430. lua_interface->ResetFunctionStack(state);
  6431. if (!spawn) {
  6432. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6433. return 0;
  6434. }
  6435. if (spawn2) {
  6436. if (spawn2->IsPlayer()) {
  6437. if (type != 1 && type != 2)
  6438. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6439. else
  6440. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6441. return 0;
  6442. }
  6443. else {
  6444. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6445. return 0;
  6446. }
  6447. }
  6448. else
  6449. spawn->GetZone()->PlayAnimation(spawn, anim);
  6450. return 0;
  6451. }
  6452. int EQ2Emu_lua_IsPet(lua_State* state) {
  6453. if (!lua_interface)
  6454. return 0;
  6455. Spawn* spawn = lua_interface->GetSpawn(state);
  6456. lua_interface->ResetFunctionStack(state);
  6457. if (!spawn) {
  6458. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6459. return 0;
  6460. }
  6461. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6462. return 1;
  6463. }
  6464. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6465. if (!lua_interface)
  6466. return 0;
  6467. Spawn* spawn = lua_interface->GetSpawn(state);
  6468. lua_interface->ResetFunctionStack(state);
  6469. if (!spawn) {
  6470. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6471. return 0;
  6472. }
  6473. if (!spawn->IsNPC()) {
  6474. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6475. return 0;
  6476. }
  6477. if (((NPC*)spawn)->GetOwner()) {
  6478. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6479. return 1;
  6480. }
  6481. return 0;
  6482. }
  6483. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6484. if (!lua_interface)
  6485. return 0;
  6486. Spawn* spawn = lua_interface->GetSpawn(state);
  6487. Spawn* target = lua_interface->GetSpawn(state, 2);
  6488. lua_interface->ResetFunctionStack(state);
  6489. if (!spawn) {
  6490. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6491. return 0;
  6492. }
  6493. if (!spawn) {
  6494. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6495. return 0;
  6496. }
  6497. spawn->SetTarget(target);
  6498. return 0;
  6499. }
  6500. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6501. if (!lua_interface)
  6502. return 0;
  6503. Spawn* spawn = lua_interface->GetSpawn(state);
  6504. bool val = lua_interface->GetBooleanValue(state, 2);
  6505. lua_interface->ResetFunctionStack(state);
  6506. if (!spawn) {
  6507. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6508. return 0;
  6509. }
  6510. if (!spawn->IsEntity()) {
  6511. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6512. return 0;
  6513. }
  6514. ((Entity*)spawn)->InCombat(val);
  6515. if (val) {
  6516. spawn->ClearRunningLocations();
  6517. spawn->CalculateRunningLocation(true);
  6518. }
  6519. return 0;
  6520. }
  6521. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6522. if (!lua_interface)
  6523. return 0;
  6524. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6525. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6526. lua_interface->ResetFunctionStack(state);
  6527. if (!spawn1) {
  6528. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6529. return 0;
  6530. }
  6531. if (!spawn2) {
  6532. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6533. return 0;
  6534. }
  6535. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6536. return 1;
  6537. }
  6538. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6539. if (!lua_interface)
  6540. return 0;
  6541. Spawn* spawn = lua_interface->GetSpawn(state);
  6542. lua_interface->ResetFunctionStack(state);
  6543. if (!spawn) {
  6544. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6545. return 0;
  6546. }
  6547. if (!spawn->IsNPC()) {
  6548. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6549. return 0;
  6550. }
  6551. ((NPC*)spawn)->ClearRunback();
  6552. return 0;
  6553. }
  6554. int EQ2Emu_lua_Runback(lua_State* state) {
  6555. if (!lua_interface)
  6556. return 0;
  6557. Spawn* spawn = lua_interface->GetSpawn(state);
  6558. lua_interface->ResetFunctionStack(state);
  6559. if (!spawn) {
  6560. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6561. return 0;
  6562. }
  6563. if (!spawn->IsNPC()) {
  6564. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6565. return 0;
  6566. }
  6567. ((NPC*)spawn)->Runback();
  6568. return 0;
  6569. }
  6570. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6571. if (!lua_interface)
  6572. return 0;
  6573. Spawn* spawn = lua_interface->GetSpawn(state);
  6574. lua_interface->ResetFunctionStack(state);
  6575. if (!spawn) {
  6576. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6577. return 0;
  6578. }
  6579. if (!spawn->IsNPC()) {
  6580. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6581. return 0;
  6582. }
  6583. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6584. return 1;
  6585. }
  6586. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6587. if (!lua_interface)
  6588. return 0;
  6589. Spawn* spawn = lua_interface->GetSpawn(state);
  6590. lua_interface->ResetFunctionStack(state);
  6591. if (!spawn) {
  6592. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6593. return 0;
  6594. }
  6595. if (!spawn->IsEntity()) {
  6596. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6597. return 0;
  6598. }
  6599. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6600. return 1;
  6601. }
  6602. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6603. if (!lua_interface)
  6604. return 0;
  6605. Spawn* spawn = lua_interface->GetSpawn(state);
  6606. lua_interface->ResetFunctionStack(state);
  6607. if (!spawn) {
  6608. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6609. return 0;
  6610. }
  6611. if (!spawn->IsEntity()) {
  6612. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6613. return 0;
  6614. }
  6615. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6616. return 1;
  6617. }
  6618. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6619. if (!lua_interface)
  6620. return 0;
  6621. Spawn* spawn = lua_interface->GetSpawn(state);
  6622. lua_interface->ResetFunctionStack(state);
  6623. if (!spawn) {
  6624. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6625. return 0;
  6626. }
  6627. if (!spawn->IsEntity()) {
  6628. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6629. return 0;
  6630. }
  6631. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6632. return 1;
  6633. }
  6634. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6635. if (!lua_interface)
  6636. return 0;
  6637. Spawn* spawn = lua_interface->GetSpawn(state);
  6638. lua_interface->ResetFunctionStack(state);
  6639. if (!spawn) {
  6640. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6641. return 0;
  6642. }
  6643. if (!spawn->IsEntity()) {
  6644. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6645. return 0;
  6646. }
  6647. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6648. return 1;
  6649. }
  6650. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6651. if (!lua_interface)
  6652. return 0;
  6653. Spawn* spawn = lua_interface->GetSpawn(state);
  6654. Spawn* target = lua_interface->GetSpawn(state, 2);
  6655. float distance = lua_interface->GetFloatValue(state, 3);
  6656. lua_interface->ResetFunctionStack(state);
  6657. if (!spawn) {
  6658. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6659. return 0;
  6660. }
  6661. if (!target) {
  6662. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6663. return 0;
  6664. }
  6665. if (!spawn->IsNPC()) {
  6666. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6667. return 0;
  6668. }
  6669. if (!target->IsEntity()) {
  6670. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6671. return 0;
  6672. }
  6673. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6674. return 1;
  6675. }
  6676. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6677. if (!lua_interface)
  6678. return 0;
  6679. Spawn* spawn = lua_interface->GetSpawn(state);
  6680. Spawn* target = lua_interface->GetSpawn(state, 2);
  6681. float distance = lua_interface->GetFloatValue(state, 3);
  6682. lua_interface->ResetFunctionStack(state);
  6683. if (!spawn) {
  6684. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6685. return 0;
  6686. }
  6687. if (!target) {
  6688. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6689. return 0;
  6690. }
  6691. if (!spawn->IsNPC()) {
  6692. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6693. return 0;
  6694. }
  6695. if (!target->IsEntity()) {
  6696. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6697. return 0;
  6698. }
  6699. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6700. return 0;
  6701. }
  6702. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6703. if (!lua_interface)
  6704. return 0;
  6705. Spawn* spawn = lua_interface->GetSpawn(state);
  6706. lua_interface->ResetFunctionStack(state);
  6707. if (!spawn) {
  6708. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6709. return 0;
  6710. }
  6711. if (!spawn->IsNPC()) {
  6712. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6713. return 0;
  6714. }
  6715. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6716. return 1;
  6717. }
  6718. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6719. if (!lua_interface)
  6720. return 0;
  6721. Spawn* spawn = lua_interface->GetSpawn(state);
  6722. lua_interface->ResetFunctionStack(state);
  6723. if (!spawn) {
  6724. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6725. return 0;
  6726. }
  6727. if (!spawn->IsNPC()) {
  6728. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6729. return 0;
  6730. }
  6731. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6732. return 1;
  6733. }
  6734. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6735. if (!lua_interface)
  6736. return 0;
  6737. Spawn* spawn = lua_interface->GetSpawn(state);
  6738. lua_interface->ResetFunctionStack(state);
  6739. if (!spawn) {
  6740. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6741. return 0;
  6742. }
  6743. if (!spawn->IsNPC()) {
  6744. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6745. return 0;
  6746. }
  6747. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6748. if (hated) {
  6749. lua_interface->SetSpawnValue(state, hated);
  6750. return 1;
  6751. }
  6752. return 0;
  6753. }
  6754. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6755. if (!lua_interface)
  6756. return 0;
  6757. Spawn* spawn = lua_interface->GetSpawn(state);
  6758. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6759. lua_interface->ResetFunctionStack(state);
  6760. if (!spawn) {
  6761. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6762. return 0;
  6763. }
  6764. if (!spawn->IsNPC()) {
  6765. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6766. return 0;
  6767. }
  6768. if (!hated) {
  6769. ((NPC*)spawn)->Brain()->ClearHate();
  6770. return 0;
  6771. }
  6772. else
  6773. {
  6774. if (!hated->IsEntity()) {
  6775. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6776. return 0;
  6777. }
  6778. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6779. return 0;
  6780. }
  6781. return 0;
  6782. }
  6783. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6784. if (!lua_interface)
  6785. return 0;
  6786. Spawn* spawn = lua_interface->GetSpawn(state);
  6787. lua_interface->ResetFunctionStack(state);
  6788. if (!spawn) {
  6789. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6790. return 0;
  6791. }
  6792. if (!spawn->IsNPC()) {
  6793. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6794. return 0;
  6795. }
  6796. ((NPC*)spawn)->Brain()->ClearEncounter();
  6797. return 0;
  6798. }
  6799. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6800. if (!lua_interface)
  6801. return 0;
  6802. Spawn* spawn = lua_interface->GetSpawn(state);
  6803. lua_interface->ResetFunctionStack(state);
  6804. if (!spawn) {
  6805. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6806. return 0;
  6807. }
  6808. if (!spawn->IsNPC()) {
  6809. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6810. return 0;
  6811. }
  6812. // Temp list to store hate list
  6813. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6814. if (encounterList->size() == 0) {
  6815. safe_delete(encounterList);
  6816. return 0;
  6817. }
  6818. lua_createtable(state, encounterList->size(), 0);
  6819. int newTable = lua_gettop(state);
  6820. for (int32 i = 0; i < encounterList->size(); i++) {
  6821. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6822. if (temp)
  6823. lua_interface->SetSpawnValue(state, temp);
  6824. lua_rawseti(state, newTable, i + 1);
  6825. }
  6826. safe_delete(encounterList);
  6827. return 1;
  6828. }
  6829. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6830. if (!lua_interface)
  6831. return 0;
  6832. Spawn* spawn = lua_interface->GetSpawn(state);
  6833. lua_interface->ResetFunctionStack(state);
  6834. if (!spawn) {
  6835. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6836. return 0;
  6837. }
  6838. if (!spawn->IsNPC()) {
  6839. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6840. return 0;
  6841. }
  6842. // Temp list to store hate list
  6843. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6844. if (hateList->size() == 0) {
  6845. safe_delete(hateList);
  6846. return 0;
  6847. }
  6848. lua_createtable(state, hateList->size(), 0);
  6849. int newTable = lua_gettop(state);
  6850. for (int32 i = 0; i < hateList->size(); i++) {
  6851. lua_interface->SetSpawnValue(state, hateList->at(i));
  6852. lua_rawseti(state, newTable, i + 1);
  6853. }
  6854. safe_delete(hateList);
  6855. return 1;
  6856. }
  6857. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6858. if (!lua_interface)
  6859. return 0;
  6860. Spawn* spawn = lua_interface->GetSpawn(state);
  6861. lua_interface->ResetFunctionStack(state);
  6862. if (!spawn) {
  6863. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6864. return 0;
  6865. }
  6866. if (spawn->IsPlayer()) {
  6867. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6868. lua_interface->SetBooleanValue(state, true);
  6869. else
  6870. lua_interface->SetBooleanValue(state, false);
  6871. return 1;
  6872. }
  6873. else {
  6874. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6875. return 1;
  6876. }
  6877. }
  6878. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6879. if (!lua_interface)
  6880. return 0;
  6881. Quest* quest = lua_interface->GetQuest(state);
  6882. lua_interface->ResetFunctionStack(state);
  6883. if (!quest) {
  6884. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6885. return 0;
  6886. }
  6887. quest->SetCompletedFlag(true);
  6888. return 0;
  6889. }
  6890. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6891. if (!lua_interface)
  6892. return 0;
  6893. Spawn* spawn = lua_interface->GetSpawn(state);
  6894. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6895. int8 tier = lua_interface->GetInt8Value(state, 3);
  6896. lua_interface->ResetFunctionStack(state);
  6897. if (!spawn) {
  6898. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6899. return 0;
  6900. }
  6901. if (!spawn->IsEntity()) {
  6902. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6903. return 0;
  6904. }
  6905. if (spellID == 0) {
  6906. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6907. return 0;
  6908. }
  6909. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6910. if (effect) {
  6911. if (tier > 0) {
  6912. // If a tier was passed chec to see if it is the same as the effect
  6913. if (tier == effect->tier)
  6914. lua_interface->SetBooleanValue(state, true);
  6915. else
  6916. lua_interface->SetBooleanValue(state, false);
  6917. return 1;
  6918. }
  6919. else {
  6920. // Have an effect but no tier was passed so return true
  6921. lua_interface->SetBooleanValue(state, true);
  6922. }
  6923. return 1;
  6924. }
  6925. // no effect so return false
  6926. lua_interface->SetBooleanValue(state, false);
  6927. return 1;
  6928. }
  6929. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6930. if (!lua_interface)
  6931. return 0;
  6932. Spawn* spawn = lua_interface->GetSpawn(state);
  6933. int32 id = lua_interface->GetInt32Value(state, 2);
  6934. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6935. lua_interface->ResetFunctionStack(state);
  6936. Spawn* spawn2 = 0;
  6937. vector<Spawn*> list;
  6938. if (!spawn) {
  6939. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6940. return 0;
  6941. }
  6942. //If zone not provided, use spawn's zone
  6943. if (!zone)
  6944. zone = spawn->GetZone();
  6945. list = zone->GetSpawnsByID(id);
  6946. if (list.size() == 0) {
  6947. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6948. return 0;
  6949. }
  6950. vector<Spawn*>::iterator itr = list.begin();
  6951. for (int8 i = 0; i < list.size(); i++) {
  6952. spawn2 = itr[i];
  6953. if (spawn2)
  6954. spawn2->AddAllowAccessSpawn(spawn);
  6955. }
  6956. return 0;
  6957. }
  6958. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6959. if (!lua_interface)
  6960. return 0;
  6961. Spawn* spawn = lua_interface->GetSpawn(state);
  6962. int32 id = lua_interface->GetInt32Value(state, 2);
  6963. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6964. lua_interface->ResetFunctionStack(state);
  6965. Spawn* spawn2 = 0;
  6966. if (!spawn) {
  6967. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6968. return 0;
  6969. }
  6970. //If zone not provided, use spawn's zone
  6971. if (!zone)
  6972. zone = spawn->GetZone();
  6973. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6974. vector<Spawn*>::iterator itr = list.begin();
  6975. if (list.size() == 0) {
  6976. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6977. return 0;
  6978. }
  6979. for (int8 i = 0; i < list.size(); i++) {
  6980. spawn2 = itr[i];
  6981. if (spawn2)
  6982. spawn2->RemoveSpawnAccess(spawn);
  6983. }
  6984. return 0;
  6985. }
  6986. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6987. if (!lua_interface)
  6988. return 0;
  6989. Quest* quest = lua_interface->GetQuest(state);
  6990. lua_interface->ResetFunctionStack(state);
  6991. if (!quest) {
  6992. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6993. return 0;
  6994. }
  6995. quest->SetYellowName(true);
  6996. return 0;
  6997. }
  6998. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6999. if (!lua_interface)
  7000. return 0;
  7001. Spawn* spawn = lua_interface->GetSpawn(state);
  7002. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  7003. lua_interface->ResetFunctionStack(state);
  7004. if (!spawn) {
  7005. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  7006. return 0;
  7007. }
  7008. if (!spawn->IsPlayer()) {
  7009. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  7010. return 0;
  7011. }
  7012. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  7013. return 1;
  7014. }
  7015. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  7016. if (!lua_interface)
  7017. return 0;
  7018. Spawn* spawn = lua_interface->GetSpawn(state);
  7019. lua_interface->ResetFunctionStack(state);
  7020. if (!spawn) {
  7021. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7022. return 0;
  7023. }
  7024. if (!spawn->IsPlayer()) {
  7025. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  7026. return 0;
  7027. }
  7028. ZoneServer* zone = spawn->GetZone();
  7029. if (!zone) {
  7030. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  7031. return 0;
  7032. }
  7033. Instance_Type iType = zone->GetInstanceType();
  7034. if (iType == SOLO_LOCKOUT_INSTANCE ||
  7035. iType == GROUP_LOCKOUT_INSTANCE ||
  7036. iType == RAID_LOCKOUT_INSTANCE ||
  7037. iType == SOLO_PERSIST_INSTANCE ||
  7038. iType == GROUP_PERSIST_INSTANCE ||
  7039. iType == RAID_PERSIST_INSTANCE) {
  7040. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  7041. if (data) {
  7042. // Check to see if the timer has already been set, if it has return out.
  7043. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  7044. return 0;
  7045. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  7046. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  7047. if(spawn->IsPlayer()) {
  7048. Client* client = ((Player*)spawn)->GetClient();
  7049. if (client) {
  7050. string time_msg = "";
  7051. int32 time = data->success_lockout_time;
  7052. int16 hour;
  7053. int8 min;
  7054. int8 sec;
  7055. hour = time / 3600;
  7056. time = time % 3600;
  7057. min = time / 60;
  7058. time = time % 60;
  7059. sec = time;
  7060. if (hour > 0) {
  7061. char temp[10];
  7062. sprintf(temp, " %i", hour);
  7063. time_msg.append(temp);
  7064. time_msg.append(" hour");
  7065. time_msg.append((hour > 1) ? "s" : "");
  7066. }
  7067. if (min > 0) {
  7068. char temp[5];
  7069. sprintf(temp, " %i", min);
  7070. time_msg.append(temp);
  7071. time_msg.append(" minute");
  7072. time_msg.append((min > 1) ? "s" : "");
  7073. }
  7074. // Only add seconds if minutes and hours are 0
  7075. if (hour == 0 && min == 0 && sec > 0) {
  7076. char temp[5];
  7077. sprintf(temp, " %i", sec);
  7078. time_msg.append(temp);
  7079. time_msg.append(" second");
  7080. time_msg.append((sec > 1) ? "s" : "");
  7081. }
  7082. 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());
  7083. }
  7084. else {
  7085. lua_interface->LogError("LUA SetSuccessTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7086. }
  7087. }
  7088. }
  7089. else
  7090. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7091. }
  7092. else
  7093. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  7094. return 0;
  7095. }
  7096. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  7097. if (!lua_interface)
  7098. return 0;
  7099. Spawn* spawn = lua_interface->GetSpawn(state);
  7100. lua_interface->ResetFunctionStack(state);
  7101. if (!spawn) {
  7102. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7103. return 0;
  7104. }
  7105. if (!spawn->IsPlayer()) {
  7106. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  7107. return 0;
  7108. }
  7109. ZoneServer* zone = spawn->GetZone();
  7110. if (!zone) {
  7111. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  7112. return 0;
  7113. }
  7114. Instance_Type iType = zone->GetInstanceType();
  7115. if (iType == SOLO_LOCKOUT_INSTANCE ||
  7116. iType == GROUP_LOCKOUT_INSTANCE ||
  7117. iType == RAID_LOCKOUT_INSTANCE ||
  7118. iType == SOLO_PERSIST_INSTANCE ||
  7119. iType == GROUP_PERSIST_INSTANCE ||
  7120. iType == RAID_PERSIST_INSTANCE) {
  7121. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  7122. if (data) {
  7123. // Check to see if the timer has already been set, if it has return out.
  7124. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  7125. return 0;
  7126. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  7127. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  7128. if(spawn->IsPlayer()) {
  7129. Client* client = ((Player*)spawn)->GetClient();
  7130. if (client) {
  7131. string time_msg = "";
  7132. int32 time = data->failure_lockout_time;
  7133. int16 hour;
  7134. int8 min;
  7135. int8 sec;
  7136. hour = time / 3600;
  7137. time = time % 3600;
  7138. min = time / 60;
  7139. time = time % 60;
  7140. sec = time;
  7141. if (hour > 0) {
  7142. char temp[10];
  7143. sprintf(temp, " %i", hour);
  7144. time_msg.append(temp);
  7145. time_msg.append(" hour");
  7146. time_msg.append((hour > 1) ? "s" : "");
  7147. }
  7148. if (min > 0) {
  7149. char temp[5];
  7150. sprintf(temp, " %i", min);
  7151. time_msg.append(temp);
  7152. time_msg.append(" minute");
  7153. time_msg.append((min > 1) ? "s" : "");
  7154. }
  7155. // Only add seconds if minutes and hours are 0
  7156. if (hour == 0 && min == 0 && sec > 0) {
  7157. char temp[5];
  7158. sprintf(temp, " %i", sec);
  7159. time_msg.append(temp);
  7160. time_msg.append(" second");
  7161. time_msg.append((sec > 1) ? "s" : "");
  7162. }
  7163. 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());
  7164. }
  7165. }
  7166. else {
  7167. lua_interface->LogError("LUA SetFailureTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7168. }
  7169. }
  7170. else
  7171. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7172. }
  7173. else
  7174. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  7175. return 0;
  7176. }
  7177. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  7178. if (!lua_interface)
  7179. return 0;
  7180. Spawn* spawn = lua_interface->GetSpawn(state);
  7181. lua_interface->ResetFunctionStack(state);
  7182. if (!spawn) {
  7183. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  7184. return 0;
  7185. }
  7186. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  7187. return 1;
  7188. }
  7189. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  7190. if (!lua_interface)
  7191. return 0;
  7192. Spawn* player = lua_interface->GetSpawn(state);
  7193. Spawn* ground = lua_interface->GetSpawn(state, 2);
  7194. if (!player) {
  7195. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7196. lua_interface->ResetFunctionStack(state);
  7197. return 0;
  7198. }
  7199. if (!player->IsPlayer()) {
  7200. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  7201. lua_interface->ResetFunctionStack(state);
  7202. return 0;
  7203. }
  7204. if (!ground) {
  7205. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7206. lua_interface->ResetFunctionStack(state);
  7207. return 0;
  7208. }
  7209. if (!ground->IsGroundSpawn()) {
  7210. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  7211. lua_interface->ResetFunctionStack(state);
  7212. return 0;
  7213. }
  7214. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7215. if (!groundspawn_entries) {
  7216. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7217. lua_interface->ResetFunctionStack(state);
  7218. return 0;
  7219. }
  7220. Skill* skill = 0;
  7221. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  7222. if (collection_skill == "Collecting")
  7223. skill = ((Player*)player)->GetSkillByName("Gathering");
  7224. else
  7225. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  7226. if (!skill) {
  7227. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  7228. lua_interface->ResetFunctionStack(state);
  7229. return 0;
  7230. }
  7231. vector<GroundSpawnEntry*>::iterator itr;
  7232. GroundSpawnEntry* entry = 0;
  7233. bool can_harvest = false;
  7234. sint32 min_skill = -1;
  7235. int16 totalSkill = skill->current_val;
  7236. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  7237. if(skillID != 0xFFFFFFFF)
  7238. {
  7239. ((Entity*)player)->MStats.lock();
  7240. totalSkill += ((Entity*)player)->stats[skillID];
  7241. ((Entity*)player)->MStats.unlock();
  7242. }
  7243. // first, iterate through groundspawn_entries, discard tables player cannot use
  7244. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  7245. {
  7246. entry = *itr;
  7247. if (min_skill == -1 || entry->min_skill_level < min_skill)
  7248. min_skill = entry->min_skill_level;
  7249. // if player lacks skill, skip table
  7250. if (entry->min_skill_level > totalSkill)
  7251. continue;
  7252. // if bonus, but player lacks level, skip table
  7253. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  7254. continue;
  7255. can_harvest = true;
  7256. break;
  7257. }
  7258. lua_interface->SetBooleanValue(state, can_harvest);
  7259. // If false, send the message to the client
  7260. if (!can_harvest) {
  7261. Client* client = ((Player*)player)->GetClient();
  7262. if (client) {
  7263. string msg = "You do not have enough skill to ";
  7264. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  7265. msg.append("gather");
  7266. else if (collection_skill == "Mining")
  7267. msg.append("mine");
  7268. else if (collection_skill == "Trapping")
  7269. msg.append("trap");
  7270. else if (collection_skill == "Foresting")
  7271. msg.append("forest");
  7272. else if (collection_skill == "Fishing")
  7273. msg.append("catch");
  7274. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  7275. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  7276. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  7277. }
  7278. }
  7279. lua_interface->ResetFunctionStack(state);
  7280. return 1;
  7281. }
  7282. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  7283. if (!lua_interface)
  7284. return 0;
  7285. Spawn* player = lua_interface->GetSpawn(state);
  7286. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  7287. lua_interface->ResetFunctionStack(state);
  7288. if (!player) {
  7289. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  7290. return 0;
  7291. }
  7292. if (!player->IsPlayer()) {
  7293. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  7294. return 0;
  7295. }
  7296. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  7297. lua_interface->SetBooleanValue(state, ret);
  7298. return 1;
  7299. }
  7300. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  7301. // Check to see if we have a valid lua_interface
  7302. if (!lua_interface)
  7303. return 0;
  7304. // Get the spawn that is getting the pet
  7305. Spawn* spawn = lua_interface->GetSpawn(state);
  7306. Spawn* target = lua_interface->GetSpawn(state, 2);
  7307. // Get the DB ID of the pet
  7308. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  7309. float x = lua_interface->GetFloatValue(state, 4);
  7310. float y = lua_interface->GetFloatValue(state, 5);
  7311. float z = lua_interface->GetFloatValue(state, 6);
  7312. // Get the spell that this command was called from
  7313. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7314. lua_interface->ResetFunctionStack(state);
  7315. // Check to make sure the spawn pointer is valid
  7316. if (!spawn) {
  7317. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  7318. return 0;
  7319. }
  7320. // Check to make sure the spawn is an entity
  7321. if (!spawn->IsEntity()) {
  7322. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  7323. return 0;
  7324. }
  7325. if (!target) {
  7326. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  7327. return 0;
  7328. }
  7329. if (!target->IsEntity()) {
  7330. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  7331. return 0;
  7332. }
  7333. // Check to see if the DB ID for the pet is set
  7334. if (pet_id == 0) {
  7335. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  7336. return 0;
  7337. }
  7338. // Check to see if the pointer to the spell is valid
  7339. if (!luaspell) {
  7340. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  7341. return 0;
  7342. }
  7343. if(luaspell->resisted) {
  7344. return 0;
  7345. }
  7346. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  7347. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  7348. if (!pet) {
  7349. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  7350. return 0;
  7351. }
  7352. // Check to make sure the pet is an npc
  7353. if (!pet->IsNPC()) {
  7354. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  7355. return 0;
  7356. }
  7357. if (x == 0)
  7358. x = spawn->GetX();
  7359. if (y == 0)
  7360. y = spawn->GetY();
  7361. if (z == 0)
  7362. z = spawn->GetZ();
  7363. // Spawn the pet at the same location as the owner
  7364. pet->SetX(x);
  7365. pet->SetY(y);
  7366. pet->SetZ(z);
  7367. pet->SetLocation(spawn->GetLocation());
  7368. pet->SetHeading(spawn->GetHeading());
  7369. spawn->GetZone()->AddSpawn(pet);
  7370. const char* spawn_script = world.GetSpawnScript(pet_id);
  7371. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  7372. spawn->SetSpawnScript(string(spawn_script));
  7373. spawn->GetZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7374. }
  7375. std::string petName = std::string("");
  7376. if(spawn->IsEntity()) {
  7377. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  7378. }
  7379. if(petName.size() < 1) {
  7380. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  7381. petName = spawn->GetZone()->pet_names.at(rand_index);
  7382. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  7383. }
  7384. // Set the pets name
  7385. pet->SetName(petName.c_str());
  7386. // Set the level of the pet to the owners level
  7387. pet->SetLevel(spawn->GetLevel());
  7388. // Set the faction of the pet to the same faction as the owner
  7389. pet->SetFactionID(spawn->GetFactionID());
  7390. // Set the spawn as a pet
  7391. pet->SetPet(true);
  7392. // Give a pointer of the owner to the pet
  7393. ((NPC*)pet)->SetOwner((Entity*)spawn);
  7394. // Set the pet type
  7395. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  7396. // Set the spell id used to create this pet
  7397. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  7398. // Set the spell tier used to create this pet
  7399. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  7400. // Set the pets spawn type to 6
  7401. pet->SetSpawnType(6);
  7402. // Set the pets brain
  7403. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  7404. // Check to see if the pet has a subtitle
  7405. if (strlen(pet->GetSubTitle()) > 0) {
  7406. // Add the players name to the front of the sub title
  7407. string pet_subtitle;
  7408. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  7409. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  7410. // Set the pets subtitle to the new one
  7411. pet->SetSubTitle(pet_subtitle.c_str());
  7412. }
  7413. // Set the pet as the return value for this function
  7414. lua_interface->SetSpawnValue(state, pet);
  7415. return 1;
  7416. }
  7417. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  7418. if (!lua_interface)
  7419. return 0;
  7420. Spawn* spawn = lua_interface->GetSpawn(state);
  7421. Spawn* player = lua_interface->GetSpawn(state, 2);
  7422. float max_distance = lua_interface->GetFloatValue(state, 3);
  7423. string type = lua_interface->GetStringValue(state, 4);
  7424. lua_interface->ResetFunctionStack(state);
  7425. if (!spawn || (spawn && spawn->IsPlayer())) {
  7426. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  7427. return 0;
  7428. }
  7429. if (!player || !player->IsPlayer()) {
  7430. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  7431. return 0;
  7432. }
  7433. Client* client = ((Player*)player)->GetClient();
  7434. if (!client) {
  7435. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7436. return 0;
  7437. }
  7438. //Set max_distance to default if not set or not proper value
  7439. if (max_distance <= 0)
  7440. max_distance = 500;
  7441. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7442. if (packet) {
  7443. float unknown2_3 = 0;
  7444. int8 placement_mode = 0;
  7445. if (type == "wall") {
  7446. placement_mode = 2;
  7447. unknown2_3 = 150;
  7448. }
  7449. else if (type == "ceiling")
  7450. placement_mode = 1;
  7451. packet->setDataByName("placement_mode", placement_mode);
  7452. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7453. packet->setDataByName("model_type", spawn->GetModelType());
  7454. packet->setDataByName("unknown", 1); //size
  7455. packet->setDataByName("unknown2", 1); //size 2
  7456. packet->setDataByName("unknown2", .5, 1); //size 3
  7457. packet->setDataByName("unknown2", 3, 2);
  7458. packet->setDataByName("unknown2", unknown2_3, 3);
  7459. packet->setDataByName("max_distance", max_distance);
  7460. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7461. client->QueuePacket(packet->serialize());
  7462. safe_delete(packet);
  7463. }
  7464. return 0;
  7465. }
  7466. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7467. if (!lua_interface)
  7468. return 0;
  7469. Item* item = lua_interface->GetItem(state);
  7470. lua_interface->ResetFunctionStack(state);
  7471. if (!item) {
  7472. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7473. return 0;
  7474. }
  7475. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7476. return 1;
  7477. }
  7478. int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
  7479. if (!lua_interface)
  7480. return 0;
  7481. Item* item = lua_interface->GetItem(state);
  7482. lua_interface->ResetFunctionStack(state);
  7483. if (!item) {
  7484. lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7485. return 0;
  7486. }
  7487. lua_interface->SetInt32Value(state, item->effect_type);
  7488. return 1;
  7489. }
  7490. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7491. if (!lua_interface)
  7492. return 0;
  7493. Spawn* spawn = lua_interface->GetSpawn(state);
  7494. lua_interface->ResetFunctionStack(state);
  7495. if (!spawn) {
  7496. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7497. return 0;
  7498. }
  7499. if (spawn->GetZone())
  7500. spawn->GetZone()->AddTransportSpawn(spawn);
  7501. return 0;
  7502. }
  7503. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7504. if (!lua_interface)
  7505. return 0;
  7506. Spawn* spawn = lua_interface->GetSpawn(state);
  7507. lua_interface->ResetFunctionStack(state);
  7508. if (!spawn) {
  7509. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7510. return 0;
  7511. }
  7512. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7513. return 1;
  7514. }
  7515. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7516. if (!lua_interface)
  7517. return 0;
  7518. Skill* skill = lua_interface->GetSkill(state);
  7519. lua_interface->ResetFunctionStack(state);
  7520. if (!skill) {
  7521. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7522. return 0;
  7523. }
  7524. lua_interface->SetInt32Value(state, skill->current_val);
  7525. return 1;
  7526. }
  7527. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7528. if (!lua_interface)
  7529. return 0;
  7530. Skill* skill = lua_interface->GetSkill(state);
  7531. lua_interface->ResetFunctionStack(state);
  7532. if (!skill) {
  7533. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7534. return 0;
  7535. }
  7536. lua_interface->SetInt32Value(state, skill->max_val);
  7537. return 1;
  7538. }
  7539. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7540. if (!lua_interface)
  7541. return 0;
  7542. Skill* skill = lua_interface->GetSkill(state);
  7543. lua_interface->ResetFunctionStack(state);
  7544. if (!skill) {
  7545. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7546. return 0;
  7547. }
  7548. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7549. return 1;
  7550. }
  7551. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7552. if (!lua_interface)
  7553. return 0;
  7554. Skill* skill = lua_interface->GetSkill(state);
  7555. int16 value = lua_interface->GetInt16Value(state, 2);
  7556. lua_interface->ResetFunctionStack(state);
  7557. if (!skill) {
  7558. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7559. return 0;
  7560. }
  7561. skill->max_val = value;
  7562. if (skill->max_val < skill->current_val)
  7563. skill->current_val = skill->max_val;
  7564. return 0;
  7565. }
  7566. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7567. if (!lua_interface)
  7568. return 0;
  7569. Skill* skill = lua_interface->GetSkill(state);
  7570. int16 value = lua_interface->GetInt16Value(state, 2);
  7571. lua_interface->ResetFunctionStack(state);
  7572. if (!skill) {
  7573. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7574. return 0;
  7575. }
  7576. if (value > skill->max_val)
  7577. skill->current_val = skill->max_val;
  7578. else
  7579. skill->current_val = value;
  7580. return 0;
  7581. }
  7582. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7583. if (!lua_interface)
  7584. return 0;
  7585. Spawn* player = lua_interface->GetSpawn(state);
  7586. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7587. lua_interface->ResetFunctionStack(state);
  7588. if (skill_id > 0 && player && player->IsPlayer()) {
  7589. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7590. return 1;
  7591. }
  7592. return 0;
  7593. }
  7594. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7595. if (!lua_interface)
  7596. return 0;
  7597. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7598. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7599. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7600. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7601. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7602. lua_interface->ResetFunctionStack(state);
  7603. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7604. if (player_spawn && player_spawn->IsPlayer()) {
  7605. Player* player = (Player*)player_spawn;
  7606. bool added = false;
  7607. if (!player->skill_list.HasSkill(skill_id)) {
  7608. player->AddSkill(skill_id, current_val, max_val, true);
  7609. added = true;
  7610. }
  7611. 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
  7612. Client* client = player->GetClient();
  7613. if (client) {
  7614. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7615. if (packet)
  7616. client->QueuePacket(packet);
  7617. }
  7618. }
  7619. if (added) {
  7620. lua_interface->SetBooleanValue(state, true);
  7621. return 1;
  7622. }
  7623. }
  7624. else {
  7625. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7626. }
  7627. }
  7628. else {
  7629. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7630. }
  7631. lua_interface->SetBooleanValue(state, false);
  7632. return 1;
  7633. }
  7634. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7635. if (!lua_interface)
  7636. return 0;
  7637. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7638. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7639. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7640. lua_interface->ResetFunctionStack(state);
  7641. if (skill_id > 0) {
  7642. if (player_spawn && player_spawn->IsPlayer()) {
  7643. Player* player = (Player*)player_spawn;
  7644. if (player->skill_list.HasSkill(skill_id)) {
  7645. player->RemovePlayerSkill(skill_id, true);
  7646. if (!more_to_remove) {
  7647. Client* client = player->GetClient();
  7648. if (client) {
  7649. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7650. if (packet)
  7651. client->QueuePacket(packet);
  7652. }
  7653. }
  7654. }
  7655. }
  7656. else {
  7657. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7658. }
  7659. }
  7660. else {
  7661. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7662. }
  7663. return 0;
  7664. }
  7665. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7666. if (!lua_interface)
  7667. return 0;
  7668. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7669. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7670. int16 amount = lua_interface->GetInt8Value(state, 3);
  7671. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7672. lua_interface->ResetFunctionStack(state);
  7673. if (amount > 0 && skill_type < 100) {
  7674. if (player_spawn && player_spawn->IsPlayer()) {
  7675. Player* player = (Player*)player_spawn;
  7676. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7677. if (!more_to_increase) {
  7678. Client* client = player->GetClient();
  7679. if (client) {
  7680. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7681. if (packet)
  7682. client->QueuePacket(packet);
  7683. }
  7684. }
  7685. }
  7686. else {
  7687. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7688. }
  7689. }
  7690. else {
  7691. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7692. }
  7693. return 0;
  7694. }
  7695. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7696. if (!lua_interface)
  7697. return 0;
  7698. Spawn* spawn = lua_interface->GetSpawn(state);
  7699. string name = lua_interface->GetStringValue(state, 2);
  7700. lua_interface->ResetFunctionStack(state);
  7701. if (!spawn) {
  7702. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7703. return 0;
  7704. }
  7705. if (!spawn->IsEntity()) {
  7706. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7707. return 0;
  7708. }
  7709. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7710. if (skill) {
  7711. lua_interface->SetSkillValue(state, skill);
  7712. return 1;
  7713. }
  7714. return 0;
  7715. }
  7716. int EQ2Emu_lua_AddProc(lua_State* state) {
  7717. if (!lua_interface)
  7718. return 0;
  7719. Spawn* spawn = lua_interface->GetSpawn(state);
  7720. int8 type = lua_interface->GetInt8Value(state, 2);
  7721. float chance = lua_interface->GetFloatValue(state, 3);
  7722. Item* item = lua_interface->GetItem(state, 4);
  7723. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7724. LuaSpell* spell = 0;
  7725. if (!item)
  7726. spell = lua_interface->GetCurrentSpell(state);
  7727. if (!spawn && (!spell || !use_all_spelltargets)) {
  7728. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7729. return 0;
  7730. }
  7731. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7732. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7733. return 0;
  7734. }
  7735. if (!item && !spell) {
  7736. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7737. return 0;
  7738. }
  7739. if(spell && spell->resisted) {
  7740. return 0;
  7741. }
  7742. if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
  7743. Spawn* target;
  7744. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7745. for (int8 i = 0; i < spell->targets.size(); i++) {
  7746. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7747. if (!target || !target->IsEntity())
  7748. continue;
  7749. ((Entity*)target)->AddProc(type, chance, item, spell);
  7750. }
  7751. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7752. }
  7753. else
  7754. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7755. return 0;
  7756. }
  7757. int EQ2Emu_lua_AddProcExt(lua_State* state) {
  7758. if (!lua_interface)
  7759. return 0;
  7760. Spawn* spawn = lua_interface->GetSpawn(state);
  7761. int8 type = lua_interface->GetInt8Value(state, 2);
  7762. int8 damage_type = lua_interface->GetInt8Value(state, 3);
  7763. float chance = lua_interface->GetFloatValue(state, 4);
  7764. int8 hp_ratio = lua_interface->GetInt8Value(state, 5);
  7765. bool below_health = lua_interface->GetBooleanValue(state, 6);
  7766. bool target_health = lua_interface->GetBooleanValue(state, 7);
  7767. Item* item = lua_interface->GetItem(state, 8);
  7768. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 9) == 1);
  7769. bool extended_version = true;
  7770. LuaSpell* spell = 0;
  7771. if (!item)
  7772. spell = lua_interface->GetCurrentSpell(state);
  7773. if (!spawn && (!spell || !use_all_spelltargets)) {
  7774. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7775. return 0;
  7776. }
  7777. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7778. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7779. return 0;
  7780. }
  7781. if (!item && !spell) {
  7782. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7783. return 0;
  7784. }
  7785. if(spell && spell->resisted) {
  7786. return 0;
  7787. }
  7788. if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
  7789. Spawn* target;
  7790. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7791. for (int8 i = 0; i < spell->targets.size(); i++) {
  7792. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7793. if (!target || !target->IsEntity())
  7794. continue;
  7795. ((Entity*)target)->AddProc(type, chance, item, spell, damage_type, hp_ratio, below_health, target_health, extended_version);
  7796. }
  7797. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7798. }
  7799. else
  7800. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7801. return 0;
  7802. }
  7803. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7804. if (!lua_interface)
  7805. return 0;
  7806. Spawn* spawn = lua_interface->GetSpawn(state);
  7807. Item* item = lua_interface->GetItem(state, 2);
  7808. LuaSpell* spell = 0;
  7809. if (!spawn) {
  7810. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7811. lua_interface->ResetFunctionStack(state);
  7812. return 0;
  7813. }
  7814. if (!spawn->IsEntity()) {
  7815. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7816. lua_interface->ResetFunctionStack(state);
  7817. return 0;
  7818. }
  7819. if (!item)
  7820. spell = lua_interface->GetCurrentSpell(state);
  7821. lua_interface->ResetFunctionStack(state);
  7822. if (!item && !spell) {
  7823. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7824. return 0;
  7825. }
  7826. if (spell && spell->caster && spell->caster->GetZone()) {
  7827. Spawn* target;
  7828. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7829. for (int8 i = 0; i < spell->targets.size(); i++) {
  7830. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7831. if (!target || !target->IsEntity())
  7832. continue;
  7833. ((Entity*)target)->RemoveProc(item, spell);
  7834. }
  7835. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7836. spell->caster->RemoveProc(item, spell);
  7837. }
  7838. else
  7839. ((Entity*)spawn)->RemoveProc(item, spell);
  7840. return 0;
  7841. }
  7842. int EQ2Emu_lua_Knockback(lua_State* state) {
  7843. if (!lua_interface)
  7844. return 0;
  7845. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7846. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7847. int32 duration = lua_interface->GetInt32Value(state, 3);
  7848. float vertical = lua_interface->GetFloatValue(state, 4);
  7849. float horizontal = lua_interface->GetFloatValue(state, 5);
  7850. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7851. lua_interface->ResetFunctionStack(state);
  7852. if (!target_spawn) {
  7853. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7854. return 0;
  7855. }
  7856. if (!spawn) {
  7857. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7858. return 0;
  7859. }
  7860. if ((vertical != 0 || horizontal != 0)) {
  7861. if(spawn->IsPlayer()) {
  7862. Client* client = ((Player*)spawn)->GetClient();
  7863. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7864. if (packet) {
  7865. packet->setDataByName("target_x", target_spawn->GetX());
  7866. packet->setDataByName("target_y", target_spawn->GetY());
  7867. packet->setDataByName("target_z", target_spawn->GetZ());
  7868. packet->setDataByName("vertical_movement", vertical);
  7869. packet->setDataByName("horizontal_movement", horizontal);
  7870. if (use_heading)
  7871. packet->setDataByName("use_player_heading", 1);
  7872. client->QueuePacket(packet->serialize());
  7873. }
  7874. safe_delete(packet);
  7875. }
  7876. else {
  7877. spawn->SetKnockback(target_spawn, duration, vertical, horizontal);
  7878. }
  7879. }
  7880. return 0;
  7881. }
  7882. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7883. if (!lua_interface)
  7884. return 0;
  7885. Spawn* spawn = lua_interface->GetSpawn(state);
  7886. lua_interface->ResetFunctionStack(state);
  7887. if (!spawn) {
  7888. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7889. return 0;
  7890. }
  7891. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7892. return 1;
  7893. }
  7894. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7895. if (!lua_interface)
  7896. return 0;
  7897. Spawn* caster = lua_interface->GetSpawn(state);
  7898. Spawn* target = lua_interface->GetSpawn(state, 2);
  7899. string name = lua_interface->GetStringValue(state, 3);
  7900. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7901. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7902. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7903. string success_msg = lua_interface->GetStringValue(state, 7);
  7904. string effect_msg = lua_interface->GetStringValue(state, 8);
  7905. lua_interface->ResetFunctionStack(state);
  7906. if (!caster) {
  7907. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7908. return 0;
  7909. }
  7910. if (!caster->IsEntity()) {
  7911. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7912. return 0;
  7913. }
  7914. if (!target) {
  7915. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7916. return 0;
  7917. }
  7918. if (!target->IsEntity()) {
  7919. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7920. return 0;
  7921. }
  7922. if (name.length() == 0) {
  7923. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7924. return 0;
  7925. }
  7926. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7927. return 0;
  7928. }
  7929. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7930. if (!lua_interface)
  7931. return 0;
  7932. string name = lua_interface->GetStringValue(state);
  7933. lua_interface->ResetFunctionStack(state);
  7934. if (name.length() == 0) {
  7935. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7936. return 0;
  7937. }
  7938. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7939. if (!skill) {
  7940. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7941. return 0;
  7942. }
  7943. lua_interface->SetInt32Value(state, skill->skill_id);
  7944. return 1;
  7945. }
  7946. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7947. if (!lua_interface)
  7948. return 0;
  7949. Spawn* spawn = lua_interface->GetSpawn(state);
  7950. lua_interface->ResetFunctionStack(state);
  7951. if (!spawn) {
  7952. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7953. return 0;
  7954. }
  7955. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7956. return 1;
  7957. }
  7958. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7959. if (!lua_interface)
  7960. return 0;
  7961. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7962. lua_interface->ResetFunctionStack(state);
  7963. if (!luaspell) {
  7964. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7965. return 0;
  7966. }
  7967. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7968. return 1;
  7969. }
  7970. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7971. if (!lua_interface)
  7972. return 0;
  7973. Spawn* spawn = lua_interface->GetSpawn(state);
  7974. Spawn* target = lua_interface->GetSpawn(state, 2);
  7975. lua_interface->ResetFunctionStack(state);
  7976. if (!spawn) {
  7977. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7978. return 0;
  7979. }
  7980. if (!spawn->IsEntity()) {
  7981. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7982. return 0;
  7983. }
  7984. if (!target) {
  7985. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7986. return 0;
  7987. }
  7988. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7989. return 1;
  7990. }
  7991. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7992. if (!lua_interface)
  7993. return 0;
  7994. Spawn* spawn = lua_interface->GetSpawn(state);
  7995. Spawn* target = lua_interface->GetSpawn(state, 2);
  7996. lua_interface->ResetFunctionStack(state);
  7997. if (!spawn) {
  7998. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7999. return 0;
  8000. }
  8001. if (!spawn->IsEntity()) {
  8002. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8003. return 0;
  8004. }
  8005. if (!target) {
  8006. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  8007. return 0;
  8008. }
  8009. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  8010. return 1;
  8011. }
  8012. int EQ2Emu_lua_InFront(lua_State* state) {
  8013. if (!lua_interface)
  8014. return 0;
  8015. Spawn* spawn = lua_interface->GetSpawn(state);
  8016. Spawn* target = lua_interface->GetSpawn(state, 2);
  8017. lua_interface->ResetFunctionStack(state);
  8018. if (!spawn) {
  8019. lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  8020. return 0;
  8021. }
  8022. if (!target) {
  8023. lua_interface->LogError("%s: LUA InFrontSpawn command error: target is not valid", lua_interface->GetScriptName(state));
  8024. return 0;
  8025. }
  8026. lua_interface->SetBooleanValue(state, spawn->InFrontSpawn(target, spawn->GetX(), spawn->GetZ()));
  8027. return 1;
  8028. }
  8029. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  8030. if (!lua_interface)
  8031. return 0;
  8032. Item* item = lua_interface->GetItem(state);
  8033. lua_interface->ResetFunctionStack(state);
  8034. if (!item) {
  8035. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  8036. return 0;
  8037. }
  8038. lua_interface->SetInt32Value(state, item->details.count);
  8039. return 1;
  8040. }
  8041. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  8042. if (!lua_interface)
  8043. return 0;
  8044. Item* item = lua_interface->GetItem(state);
  8045. Spawn* owner = lua_interface->GetSpawn(state, 2);
  8046. int16 new_count = lua_interface->GetInt32Value(state, 3);
  8047. lua_interface->ResetFunctionStack(state);
  8048. if (!item) {
  8049. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  8050. return 0;
  8051. }
  8052. if (!owner) {
  8053. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  8054. return 0;
  8055. }
  8056. if (!owner->IsPlayer()) {
  8057. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8058. return 0;
  8059. }
  8060. if (item->stack_count < new_count) {
  8061. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  8062. return 0;
  8063. }
  8064. if (new_count > 0) {
  8065. item->details.count = new_count;
  8066. item->save_needed = true;
  8067. }
  8068. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  8069. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  8070. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  8071. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  8072. else
  8073. {
  8074. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  8075. return 0;
  8076. }
  8077. Client* client = ((Player*)owner)->GetClient();
  8078. if (!client)
  8079. return 0;
  8080. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  8081. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  8082. if (app)
  8083. client->QueuePacket(app);
  8084. return 0;
  8085. }
  8086. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  8087. if (!lua_interface)
  8088. return 0;
  8089. int32 time = lua_interface->GetInt32Value(state);
  8090. string function = lua_interface->GetStringValue(state, 2);
  8091. Spawn* caster = lua_interface->GetSpawn(state, 3);
  8092. Spawn* target = lua_interface->GetSpawn(state, 4);
  8093. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8094. lua_interface->ResetFunctionStack(state);
  8095. if (time == 0) {
  8096. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  8097. return 0;
  8098. }
  8099. if (function.length() == 0) {
  8100. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  8101. return 0;
  8102. }
  8103. if (!spell || (!spell->caster || !spell->caster->GetZone())) {
  8104. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  8105. return 0;
  8106. }
  8107. SpellScriptTimer* timer = new SpellScriptTimer;
  8108. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  8109. #ifdef WIN32
  8110. ZeroMemory(timer, sizeof(SpellScriptTimer));
  8111. #else
  8112. bzero(timer, sizeof(SpellScriptTimer));
  8113. #endif*/
  8114. timer->caster = 0;
  8115. timer->deleteWhenDone = false;
  8116. timer->target = 0;
  8117. timer->time = Timer::GetCurrentTime2() + time;
  8118. timer->customFunction = function;
  8119. timer->spell = spell;
  8120. if (caster)
  8121. timer->caster = caster->GetID();
  8122. if (target)
  8123. timer->target = target->GetID();
  8124. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  8125. return 0;
  8126. }
  8127. int EQ2Emu_lua_Resurrect(lua_State* state) {
  8128. if (!lua_interface)
  8129. return 0;
  8130. float hp_perc = lua_interface->GetFloatValue(state);
  8131. float power_perc = lua_interface->GetFloatValue(state, 2);
  8132. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  8133. Spawn* target = lua_interface->GetSpawn(state, 4);
  8134. string heal_name = lua_interface->GetStringValue(state, 5);
  8135. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  8136. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  8137. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8138. lua_interface->ResetFunctionStack(state);
  8139. if (!spell) {
  8140. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  8141. return 0;
  8142. }
  8143. Entity* caster = spell->caster;
  8144. if (!caster) {
  8145. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  8146. return 0;
  8147. }
  8148. Client* client = 0;
  8149. PendingResurrection* rez = 0;
  8150. ZoneServer* zone = spell->caster->GetZone();
  8151. if (!target) {
  8152. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8153. if (spell->targets.size() > 0) {
  8154. vector<int32> spell_targets = spell->targets;
  8155. for (int8 i = 0; i < spell_targets.size(); i++) {
  8156. target = zone->GetSpawnByID(spell_targets.at(i));
  8157. if (!target)
  8158. continue;
  8159. if (!target->IsPlayer())
  8160. continue;
  8161. client = ((Player*)target)->GetClient();
  8162. if (!client)
  8163. continue;
  8164. rez = client->GetCurrentRez();
  8165. if (rez->active)
  8166. continue;
  8167. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  8168. rez->active = true;
  8169. rez->caster = caster;
  8170. rez->expire_timer = new Timer;
  8171. int32 duration = spell->spell->GetSpellDuration();
  8172. rez->expire_timer->Start(duration * 100);
  8173. rez->hp_perc = hp_perc;
  8174. rez->mp_perc = power_perc;
  8175. rez->range = spell->spell->GetSpellData()->range;
  8176. rez->spell_name = spell->spell->GetName();
  8177. if (heal_name.length() > 0)
  8178. rez->heal_name = heal_name;
  8179. else
  8180. rez->heal_name = rez->spell_name;
  8181. rez->no_calcs = no_calcs;
  8182. rez->crit_mod = crit_mod;
  8183. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  8184. if (send_window)
  8185. client->SendResurrectionWindow();
  8186. else {
  8187. target->GetZone()->ResurrectSpawn(target, client);
  8188. rez->should_delete = true;
  8189. }
  8190. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  8191. }
  8192. }
  8193. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8194. }
  8195. else {
  8196. if(!target->IsPlayer())
  8197. return 0;
  8198. client = ((Player*)target)->GetClient();
  8199. if (!client)
  8200. return 0;
  8201. rez = client->GetCurrentRez();
  8202. if (rez->active)
  8203. return 0;
  8204. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  8205. rez->active = true;
  8206. rez->caster = caster;
  8207. rez->expire_timer = new Timer;
  8208. int32 duration = spell->spell->GetSpellDuration();
  8209. rez->expire_timer->Start(duration * 100);
  8210. rez->hp_perc = hp_perc;
  8211. rez->mp_perc = power_perc;
  8212. rez->range = spell->spell->GetSpellData()->range;
  8213. rez->spell_name = spell->spell->GetName();
  8214. if (heal_name.length() > 0)
  8215. rez->heal_name = heal_name;
  8216. else
  8217. rez->heal_name = rez->spell_name;
  8218. rez->no_calcs = no_calcs;
  8219. rez->crit_mod = crit_mod;
  8220. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  8221. if (send_window)
  8222. client->SendResurrectionWindow();
  8223. else {
  8224. target->GetZone()->ResurrectSpawn(target, client);
  8225. rez->should_delete = true;
  8226. }
  8227. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  8228. }
  8229. return 0;
  8230. }
  8231. int EQ2Emu_lua_SetVision(lua_State* state) {
  8232. if (!lua_interface)
  8233. return 0;
  8234. Spawn* spawn = lua_interface->GetSpawn(state);
  8235. int32 vision = lua_interface->GetInt32Value(state, 2);
  8236. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8237. lua_interface->ResetFunctionStack(state);
  8238. if (!spawn) {
  8239. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8240. return 0;
  8241. }
  8242. if (!spawn->IsEntity()) {
  8243. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8244. return 0;
  8245. }
  8246. if (spell && spell->targets.size() > 0) {
  8247. ZoneServer* zone = spell->caster->GetZone();
  8248. for (int8 i = 0; i < spell->targets.size(); i++) {
  8249. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8250. if (target && target->IsEntity()) {
  8251. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  8252. if (target->IsPlayer())
  8253. ((Player*)target)->SetCharSheetChanged(true);
  8254. }
  8255. }
  8256. }
  8257. else {
  8258. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  8259. if (spawn->IsPlayer())
  8260. ((Player*)spawn)->SetCharSheetChanged(true);
  8261. }
  8262. return 0;
  8263. }
  8264. int EQ2Emu_lua_BlurVision(lua_State* state) {
  8265. if (!lua_interface)
  8266. return 0;
  8267. Spawn* spawn = lua_interface->GetSpawn(state);
  8268. float intensity = lua_interface->GetFloatValue(state, 2);
  8269. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8270. lua_interface->ResetFunctionStack(state);
  8271. if (!spawn) {
  8272. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8273. return 0;
  8274. }
  8275. if (!spawn->IsEntity()) {
  8276. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8277. return 0;
  8278. }
  8279. if (spell && spell->targets.size() > 0) {
  8280. ZoneServer* zone = spell->caster->GetZone();
  8281. for (int8 i = 0; i < spell->targets.size(); i++) {
  8282. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8283. if (target && target->IsEntity()) {
  8284. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  8285. if (target->IsPlayer())
  8286. ((Player*)target)->SetCharSheetChanged(true);
  8287. }
  8288. }
  8289. }
  8290. else {
  8291. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  8292. if (spawn->IsPlayer())
  8293. ((Player*)spawn)->SetCharSheetChanged(true);
  8294. }
  8295. return 0;
  8296. }
  8297. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  8298. if (!lua_interface)
  8299. return 0;
  8300. Spawn* spawn = lua_interface->GetSpawn(state);
  8301. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  8302. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8303. lua_interface->ResetFunctionStack(state);
  8304. if (!spawn) {
  8305. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  8306. return 0;
  8307. }
  8308. if (!spawn->IsEntity()) {
  8309. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  8310. return 0;
  8311. }
  8312. if (spell && spell->targets.size() > 0) {
  8313. ZoneServer* zone = spell->caster->GetZone();
  8314. for (int8 i = 0; i < spell->targets.size(); i++) {
  8315. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8316. if (target && target->IsEntity()) {
  8317. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8318. if (target->IsPlayer())
  8319. ((Player*)target)->SetCharSheetChanged(true);
  8320. }
  8321. }
  8322. }
  8323. else {
  8324. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8325. if (spawn->IsPlayer())
  8326. ((Player*)spawn)->SetCharSheetChanged(true);
  8327. }
  8328. return 0;
  8329. }
  8330. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  8331. if (!lua_interface)
  8332. return 0;
  8333. Item* item = lua_interface->GetItem(state);
  8334. int8 type = lua_interface->GetInt32Value(state, 2);
  8335. lua_interface->ResetFunctionStack(state);
  8336. if (!item) {
  8337. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  8338. return 0;
  8339. }
  8340. if (type == 1)
  8341. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  8342. else if (type == 2)
  8343. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  8344. return 1;
  8345. }
  8346. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  8347. if (!lua_interface)
  8348. return 0;
  8349. Spawn* target = lua_interface->GetSpawn(state);
  8350. float val = lua_interface->GetFloatValue(state, 2);
  8351. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8352. lua_interface->ResetFunctionStack(state);
  8353. // Added from Gangrenous post
  8354. if (spell && spell->resisted)
  8355. return 0;
  8356. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  8357. if (val > 1.0f)
  8358. val = 1.0f - (val / 100.0f);
  8359. if (spell && spell->spell && spell->targets.size() > 0) {
  8360. ZoneServer* zone = spell->caster->GetZone();
  8361. for (int32 i = 0; i != spell->targets.size(); i++) {
  8362. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  8363. if (spawn && spawn->IsEntity()) {
  8364. ((Entity*)spawn)->SetSpeedMultiplier(val);
  8365. if (spawn->IsPlayer())
  8366. ((Player*)spawn)->SetCharSheetChanged(true);
  8367. }
  8368. }
  8369. }
  8370. else {
  8371. if (target && target->IsEntity()) {
  8372. ((Entity*)target)->SetSpeedMultiplier(val);
  8373. if (target->IsPlayer())
  8374. ((Player*)target)->SetCharSheetChanged(true);
  8375. }
  8376. }
  8377. return 0;
  8378. }
  8379. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  8380. if (!lua_interface)
  8381. return 0;
  8382. Spawn* spawn = lua_interface->GetSpawn(state);
  8383. int16 model = lua_interface->GetInt16Value(state, 2);
  8384. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8385. lua_interface->ResetFunctionStack(state);
  8386. if (spell && spell->spell && spell->targets.size() > 0) {
  8387. ZoneServer* zone = spell->caster->GetZone();
  8388. for (int32 i = 0; i < spell->targets.size(); i++) {
  8389. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8390. if (target)
  8391. target->SetIllusionModel(model);
  8392. }
  8393. }
  8394. else {
  8395. if (!spawn) {
  8396. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8397. return 0;
  8398. }
  8399. spawn->SetIllusionModel(model);
  8400. }
  8401. return 0;
  8402. }
  8403. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  8404. if (!lua_interface)
  8405. return 0;
  8406. Spawn* spawn = lua_interface->GetSpawn(state);
  8407. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8408. lua_interface->ResetFunctionStack(state);
  8409. if (spell && spell->spell && spell->targets.size() > 0) {
  8410. ZoneServer* zone = spell->caster->GetZone();
  8411. for (int32 i = 0; i < spell->targets.size(); i++) {
  8412. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8413. if (target)
  8414. target->SetIllusionModel(0);
  8415. }
  8416. }
  8417. else {
  8418. if (!spawn) {
  8419. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8420. return 0;
  8421. }
  8422. spawn->SetIllusionModel(0);
  8423. }
  8424. return 0;
  8425. }
  8426. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  8427. if (!lua_interface)
  8428. return 0;
  8429. Spawn* caster = lua_interface->GetSpawn(state);
  8430. Spawn* target = lua_interface->GetSpawn(state, 2);
  8431. float chance = lua_interface->GetFloatValue(state, 3);
  8432. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8433. lua_interface->ResetFunctionStack(state);
  8434. if (!caster) {
  8435. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8436. return 0;
  8437. }
  8438. if (!caster->IsEntity()) {
  8439. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  8440. return 0;
  8441. }
  8442. if (!target) {
  8443. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8444. return 0;
  8445. }
  8446. if (!target->IsEntity()) {
  8447. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  8448. return 0;
  8449. }
  8450. if (chance <= 0) {
  8451. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  8452. return 0;
  8453. }
  8454. if (!spell) {
  8455. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8456. return 0;
  8457. }
  8458. if(spell->resisted) {
  8459. return 0;
  8460. }
  8461. if (((Entity*)caster)->GetThreatTransfer()) {
  8462. return 0;
  8463. }
  8464. ThreatTransfer* transfer = new ThreatTransfer;
  8465. transfer->Target = target->GetID();
  8466. transfer->Amount = chance;
  8467. transfer->Spell = spell;
  8468. ((Entity*)caster)->SetThreatTransfer(transfer);
  8469. return 0;
  8470. }
  8471. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  8472. if (!lua_interface)
  8473. return 0;
  8474. Spawn* spawn = lua_interface->GetSpawn(state);
  8475. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8476. lua_interface->ResetFunctionStack(state);
  8477. if (!spawn || !spawn->IsEntity()) {
  8478. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  8479. return 0;
  8480. }
  8481. if (!spawn->IsEntity()) {
  8482. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8483. return 0;
  8484. }
  8485. if (!spell) {
  8486. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8487. return 0;
  8488. }
  8489. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  8490. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  8491. if(transfer && transfer->Spell != spell) {
  8492. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  8493. return 0;
  8494. }
  8495. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  8496. }
  8497. return 0;
  8498. }
  8499. int EQ2Emu_lua_CureByType(lua_State* state) {
  8500. if (!lua_interface)
  8501. return 0;
  8502. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8503. int8 cure_count = lua_interface->GetInt8Value(state);
  8504. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8505. string cure_name = lua_interface->GetStringValue(state, 3);
  8506. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8507. Spawn* target = lua_interface->GetSpawn(state, 5);
  8508. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  8509. lua_interface->ResetFunctionStack(state);
  8510. if(spell && spell->resisted) {
  8511. return 0;
  8512. }
  8513. if (target) {
  8514. if (!target->IsEntity()) {
  8515. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8516. return 0;
  8517. }
  8518. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8519. std::string alternate_name = "item";
  8520. if(spell)
  8521. alternate_name = std::string(spell->spell->GetName());
  8522. if(!caster && spell)
  8523. caster = (Spawn*)spell->caster;
  8524. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  8525. }
  8526. }
  8527. else {
  8528. ZoneServer* zone = spell->caster->GetZone();
  8529. vector<int32> targets = spell->targets;
  8530. vector<Entity*> targets_to_cure;
  8531. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8532. for (int8 i = 0; i < targets.size(); i++) {
  8533. target = zone->GetSpawnByID(targets.at(i));
  8534. if (!target || !target->IsEntity())
  8535. continue;
  8536. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8537. targets_to_cure.push_back((Entity*)target);
  8538. }
  8539. }
  8540. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8541. vector<Entity*>::iterator itr;
  8542. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  8543. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8544. }
  8545. }
  8546. return 0;
  8547. }
  8548. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  8549. if (!lua_interface)
  8550. return 0;
  8551. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8552. if(spell->resisted) {
  8553. lua_interface->ResetFunctionStack(state);
  8554. return 0;
  8555. }
  8556. int8 cure_count = lua_interface->GetInt8Value(state);
  8557. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8558. string cure_name = lua_interface->GetStringValue(state, 3);
  8559. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8560. Spawn* target = lua_interface->GetSpawn(state, 5);
  8561. lua_interface->ResetFunctionStack(state);
  8562. if (target) {
  8563. if (!target->IsEntity()) {
  8564. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8565. return 0;
  8566. }
  8567. if (((Entity*)target)->GetDetCount() > 0)
  8568. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8569. }
  8570. else {
  8571. ZoneServer* zone = spell->caster->GetZone();
  8572. vector<int32> targets = spell->targets;
  8573. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8574. for (int8 i = 0; i < targets.size(); i++) {
  8575. target = zone->GetSpawnByID(targets.at(i));
  8576. if (!target || !target->IsEntity())
  8577. continue;
  8578. if (((Entity*)target)->GetDetCount() > 0)
  8579. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8580. }
  8581. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8582. }
  8583. return 0;
  8584. }
  8585. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8586. if (!lua_interface)
  8587. return 0;
  8588. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8589. lua_interface->ResetFunctionStack(state);
  8590. if (!spell) {
  8591. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8592. return 0;
  8593. }
  8594. if (!spell->caster) {
  8595. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8596. return 0;
  8597. }
  8598. if (!spell->caster->GetZone()) {
  8599. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8600. return 0;
  8601. }
  8602. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8603. return 0;
  8604. }
  8605. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8606. if (!lua_interface)
  8607. return 0;
  8608. Spawn* spawn = lua_interface->GetSpawn(state);
  8609. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8610. lua_interface->ResetFunctionStack(state);
  8611. if (!spell) {
  8612. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8613. return 0;
  8614. }
  8615. if (spawn && spawn->IsEntity())
  8616. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8617. else {
  8618. ZoneServer* zone = spell->caster->GetZone();
  8619. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8620. for (int32 i = 0; i < spell->targets.size(); i++) {
  8621. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8622. if (!spawn || !spawn->IsEntity())
  8623. continue;
  8624. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8625. }
  8626. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8627. }
  8628. return 0;
  8629. }
  8630. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8631. if (!lua_interface)
  8632. return 0;
  8633. Spawn* spawn = lua_interface->GetSpawn(state);
  8634. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8635. lua_interface->ResetFunctionStack(state);
  8636. if (!spell) {
  8637. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8638. return 0;
  8639. }
  8640. if (spawn && spawn->IsEntity())
  8641. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8642. else {
  8643. ZoneServer* zone = spell->caster->GetZone();
  8644. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8645. for (int32 i = 0; i < spell->targets.size(); i++) {
  8646. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8647. if (!spawn || !spawn->IsEntity())
  8648. continue;
  8649. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8650. }
  8651. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8652. }
  8653. return 0;
  8654. }
  8655. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8656. if (!lua_interface)
  8657. return 0;
  8658. Spawn* caster = lua_interface->GetSpawn(state);
  8659. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8660. lua_interface->ResetFunctionStack(state);
  8661. if (!caster) {
  8662. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8663. return 0;
  8664. }
  8665. if (!caster->IsPlayer()) {
  8666. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8667. return 0;
  8668. }
  8669. Spawn* target = caster->GetTarget();
  8670. if (!target) {
  8671. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8672. return 0;
  8673. }
  8674. Client* client = ((Player*)caster)->GetClient();
  8675. if (!client) {
  8676. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8677. return 0;
  8678. }
  8679. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8680. if (ho) {
  8681. ho->SetTarget(target->GetID());
  8682. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8683. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8684. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8685. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8686. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8687. deque<GroupMemberInfo*>::iterator itr;
  8688. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8689. if (group)
  8690. {
  8691. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8692. deque<GroupMemberInfo*>* members = group->GetMembers();
  8693. for (itr = members->begin(); itr != members->end(); itr++) {
  8694. if ((*itr)->client)
  8695. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8696. }
  8697. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8698. }
  8699. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8700. }
  8701. else
  8702. safe_delete(ho);
  8703. }
  8704. else {
  8705. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8706. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8707. }
  8708. else
  8709. safe_delete(ho);
  8710. }
  8711. }
  8712. return 0;
  8713. }
  8714. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8715. if (!lua_interface)
  8716. return 0;
  8717. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8718. if (!spell) {
  8719. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8720. return 0;
  8721. }
  8722. int16 triggerCount = lua_interface->GetInt16Value(state);
  8723. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8724. if (!triggerCount) {
  8725. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8726. return 0;
  8727. }
  8728. spell->num_triggers = triggerCount;
  8729. spell->had_triggers = true;
  8730. spell->cancel_after_all_triggers = cancel_after_triggers;
  8731. return 0;
  8732. }
  8733. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8734. if (!lua_interface)
  8735. return 0;
  8736. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8737. lua_interface->ResetFunctionStack(state);
  8738. if (!spell) {
  8739. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8740. return 0;
  8741. }
  8742. lua_interface->SetInt32Value(state, spell->num_triggers);
  8743. return 1;
  8744. }
  8745. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8746. if (!lua_interface)
  8747. return 0;
  8748. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8749. if (!spell) {
  8750. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8751. lua_interface->ResetFunctionStack(state);
  8752. return 0;
  8753. }
  8754. if (!spell->caster || !spell->caster->GetZone()) {
  8755. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: caster / caster zone must be set!", lua_interface->GetScriptName(state));
  8756. lua_interface->ResetFunctionStack(state);
  8757. return 0;
  8758. }
  8759. int16 remove_count = lua_interface->GetInt16Value(state);
  8760. lua_interface->ResetFunctionStack(state);
  8761. if (!remove_count)
  8762. remove_count = 1;
  8763. if (remove_count >= spell->num_triggers) {
  8764. spell->num_triggers = 0;
  8765. if (spell->cancel_after_all_triggers)
  8766. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8767. }
  8768. else {
  8769. spell->num_triggers -= remove_count;
  8770. Client* client = spell->caster->IsPlayer() ? ((Player*)spell->caster)->GetClient() : nullptr;
  8771. ClientPacketFunctions::SendMaintainedExamineUpdate(client, spell->slot_pos, spell->num_triggers, 0);
  8772. }
  8773. return 0;
  8774. }
  8775. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8776. if (!lua_interface)
  8777. return 0;
  8778. Spawn* spawn = lua_interface->GetSpawn(state);
  8779. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8780. lua_interface->ResetFunctionStack(state);
  8781. if (!spawn) {
  8782. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8783. return 0;
  8784. }
  8785. if (!copy_spawn) {
  8786. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8787. return 0;
  8788. }
  8789. spawn->CopySpawnAppearance(copy_spawn);
  8790. return 0;
  8791. }
  8792. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8793. Spawn* spawn = lua_interface->GetSpawn(state);
  8794. int8 type = lua_interface->GetInt8Value(state, 2);
  8795. lua_interface->ResetFunctionStack(state);
  8796. if (!spawn) {
  8797. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8798. return 0;
  8799. }
  8800. else if (!spawn->IsEntity()) {
  8801. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8802. return 0;
  8803. }
  8804. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8805. return 1;
  8806. }
  8807. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8808. if (!lua_interface)
  8809. return 0;
  8810. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8811. int8 type = lua_interface->GetInt8Value(state);
  8812. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8813. lua_interface->ResetFunctionStack(state);
  8814. if (!spell) {
  8815. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8816. return 0;
  8817. }
  8818. if(spell->resisted) {
  8819. return 0;
  8820. }
  8821. if (spawn) {
  8822. if (!spawn->IsEntity()) {
  8823. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8824. return 0;
  8825. }
  8826. Entity* entity = ((Entity*)spawn);
  8827. entity->AddImmunity(spell, type);
  8828. }
  8829. else if(spell->caster && spell->caster->GetZone()) {
  8830. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8831. for (int8 i = 0; i < spell->targets.size(); i++) {
  8832. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8833. if (!spawn || !spawn->IsEntity())
  8834. continue;
  8835. Entity* entity = ((Entity*)spawn);
  8836. entity->AddImmunity(spell, type);
  8837. }
  8838. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8839. }
  8840. return 0;
  8841. }
  8842. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8843. if (!lua_interface)
  8844. return 0;
  8845. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8846. int8 type = lua_interface->GetInt8Value(state);
  8847. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8848. lua_interface->ResetFunctionStack(state);
  8849. if (!spell) {
  8850. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8851. return 0;
  8852. }
  8853. if (spawn) {
  8854. if (!spawn->IsEntity()) {
  8855. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8856. return 0;
  8857. }
  8858. Entity* entity = ((Entity*)spawn);
  8859. entity->RemoveImmunity(spell, type);
  8860. }
  8861. else if(spell->caster && spell->caster->GetZone()) {
  8862. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8863. for (int8 i = 0; i < spell->targets.size(); i++) {
  8864. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8865. if (!spawn || !spawn->IsEntity())
  8866. continue;
  8867. Entity* entity = ((Entity*)spawn);
  8868. entity->RemoveImmunity(spell, type);
  8869. }
  8870. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8871. }
  8872. return 0;
  8873. }
  8874. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8875. if (!lua_interface)
  8876. return 0;
  8877. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8878. if(spell && spell->resisted) {
  8879. lua_interface->ResetFunctionStack(state);
  8880. return 0;
  8881. }
  8882. float snare = lua_interface->GetFloatValue(state);
  8883. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8884. lua_interface->ResetFunctionStack(state);
  8885. // convert the val to the speed multipler value (100 - val)
  8886. float val = 100.0 - snare;
  8887. val /= 100.0;
  8888. if (spawn) {
  8889. if (!spawn->IsEntity()) {
  8890. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8891. return 0;
  8892. }
  8893. ((Entity*)spawn)->SetSnareValue(spell, val);
  8894. }
  8895. else if(spell && spell->caster && spell->caster->GetZone()) {
  8896. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8897. for (int8 i = 0; i < spell->targets.size(); i++) {
  8898. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8899. if (!spawn || !spawn->IsEntity())
  8900. continue;
  8901. ((Entity*)spawn)->SetSnareValue(spell, val);
  8902. }
  8903. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8904. }
  8905. return 0;
  8906. }
  8907. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8908. if (!lua_interface)
  8909. return 0;
  8910. Spawn* spawn = lua_interface->GetSpawn(state);
  8911. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8912. lua_interface->ResetFunctionStack(state);
  8913. if (!spawn) {
  8914. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8915. return 0;
  8916. }
  8917. if (race_id == 0) {
  8918. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8919. return 0;
  8920. }
  8921. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8922. return 1;
  8923. }
  8924. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8925. if (!lua_interface)
  8926. return 0;
  8927. Spawn* spawn = lua_interface->GetSpawn(state);
  8928. lua_interface->ResetFunctionStack(state);
  8929. if (!spawn) {
  8930. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8931. return 0;
  8932. }
  8933. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8934. return 1;
  8935. }
  8936. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8937. if (!lua_interface)
  8938. return 0;
  8939. Spawn* spawn = lua_interface->GetSpawn(state);
  8940. lua_interface->ResetFunctionStack(state);
  8941. if (!spawn) {
  8942. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8943. return 0;
  8944. }
  8945. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8946. return 1;
  8947. }
  8948. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8949. if (!lua_interface)
  8950. return 0;
  8951. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8952. lua_interface->ResetFunctionStack(state);
  8953. if (!spell) {
  8954. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8955. return 0;
  8956. }
  8957. lua_interface->SetStringValue(state, spell->spell->GetName());
  8958. return 1;
  8959. }
  8960. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8961. if (!lua_interface)
  8962. return 0;
  8963. Quest* quest = lua_interface->GetQuest(state);
  8964. lua_interface->ResetFunctionStack(state);
  8965. if (!quest) {
  8966. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8967. return 0;
  8968. }
  8969. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8970. return 1;
  8971. }
  8972. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8973. if (!lua_interface)
  8974. return 0;
  8975. Quest* quest = lua_interface->GetQuest(state);
  8976. int32 flags = lua_interface->GetInt32Value(state, 2);
  8977. lua_interface->ResetFunctionStack(state);
  8978. if (!quest) {
  8979. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8980. return 0;
  8981. }
  8982. quest->SetQuestFlags(flags);
  8983. return 0;
  8984. }
  8985. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8986. if (!lua_interface)
  8987. return 0;
  8988. Quest* quest = lua_interface->GetQuest(state);
  8989. Spawn* player = lua_interface->GetSpawn(state, 2);
  8990. int32 step = lua_interface->GetInt32Value(state, 3);
  8991. int32 duration = lua_interface->GetInt32Value(state, 4);
  8992. string action = lua_interface->GetStringValue(state, 5);
  8993. lua_interface->ResetFunctionStack(state);
  8994. if (!quest) {
  8995. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8996. return 0;
  8997. }
  8998. if (!player) {
  8999. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  9000. return 0;
  9001. }
  9002. if (!player->IsPlayer()) {
  9003. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9004. return 0;
  9005. }
  9006. if (step == 0) {
  9007. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  9008. return 0;
  9009. }
  9010. if (duration == 0) {
  9011. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  9012. return 0;
  9013. }
  9014. if (action.length() == 0) {
  9015. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  9016. return 0;
  9017. }
  9018. Client* client = ((Player*)player)->GetClient();
  9019. if (!client) {
  9020. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  9021. return 0;
  9022. }
  9023. quest->SetTimerStep(step);
  9024. quest->AddFailedAction(step, action);
  9025. quest->SetStepTimer(duration);
  9026. client->AddQuestTimer(quest->GetQuestID());
  9027. return 0;
  9028. }
  9029. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  9030. if (!lua_interface)
  9031. return 0;
  9032. Quest* quest = lua_interface->GetQuest(state);
  9033. Spawn* player = lua_interface->GetSpawn(state, 2);
  9034. lua_interface->ResetFunctionStack(state);
  9035. if (!quest) {
  9036. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  9037. return 0;
  9038. }
  9039. if (!player) {
  9040. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  9041. return 0;
  9042. }
  9043. if (!player->IsPlayer()) {
  9044. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9045. return 0;
  9046. }
  9047. Client* client = ((Player*)player)->GetClient();
  9048. if (!client) {
  9049. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  9050. return 0;
  9051. }
  9052. quest->SetTimerStep(0);
  9053. quest->SetStepTimer(0);
  9054. client->RemoveQuestTimer(quest->GetQuestID());
  9055. return 0;
  9056. }
  9057. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  9058. if (!lua_interface)
  9059. return 0;
  9060. Spawn* player = lua_interface->GetSpawn(state);
  9061. Quest* quest = lua_interface->GetQuest(state, 2);
  9062. int32 step = lua_interface->GetInt32Value(state, 3);
  9063. lua_interface->ResetFunctionStack(state);
  9064. if (!player) {
  9065. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  9066. return 0;
  9067. }
  9068. if (!player->IsPlayer()) {
  9069. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9070. return 0;
  9071. }
  9072. if (!quest) {
  9073. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  9074. return 0;
  9075. }
  9076. if (step == 0) {
  9077. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  9078. return 0;
  9079. }
  9080. Client* client = ((Player*)player)->GetClient();
  9081. if (!client) {
  9082. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  9083. return 0;
  9084. }
  9085. if (quest->RemoveQuestStep(step, client)) {
  9086. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  9087. client->GetCurrentZone()->SendQuestUpdates(client);
  9088. }
  9089. else
  9090. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  9091. return 0;
  9092. }
  9093. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  9094. if (!lua_interface)
  9095. return 0;
  9096. Quest* quest = lua_interface->GetQuest(state, 1);
  9097. int32 step = lua_interface->GetInt32Value(state, 2);
  9098. string desc = lua_interface->GetStringValue(state, 3);
  9099. string task_group = lua_interface->GetStringValue(state, 4);
  9100. lua_interface->ResetFunctionStack(state);
  9101. if (!quest) {
  9102. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  9103. return 0;
  9104. }
  9105. if (step == 0) {
  9106. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  9107. return 0;
  9108. }
  9109. QuestStep* quest_step = quest->GetQuestStep(step);
  9110. if (!quest_step) {
  9111. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  9112. return 0;
  9113. }
  9114. quest_step->SetStepProgress(0);
  9115. quest_step->SetTaskGroup(task_group);
  9116. quest_step->SetDescription(desc);
  9117. return 0;
  9118. }
  9119. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  9120. if (!lua_interface)
  9121. return 0;
  9122. Quest* quest = lua_interface->GetQuest(state);
  9123. int32 step = lua_interface->GetInt32Value(state, 2);
  9124. string action = lua_interface->GetStringValue(state, 3);
  9125. lua_interface->ResetFunctionStack(state);
  9126. if (!quest) {
  9127. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  9128. return 0;
  9129. }
  9130. if (step == 0) {
  9131. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  9132. return 0;
  9133. }
  9134. if (action.length() == 0) {
  9135. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  9136. return 0;
  9137. }
  9138. quest->AddFailedAction(step, action);
  9139. return 0;
  9140. }
  9141. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  9142. if (!lua_interface)
  9143. return 0;
  9144. Spawn* player = lua_interface->GetSpawn(state);
  9145. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9146. int32 step = lua_interface->GetInt32Value(state, 3);
  9147. lua_interface->ResetFunctionStack(state);
  9148. if (!player) {
  9149. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  9150. return 0;
  9151. }
  9152. if (!player->IsPlayer()) {
  9153. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9154. return 0;
  9155. }
  9156. if (quest_id == 0) {
  9157. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  9158. return 0;
  9159. }
  9160. if (step == 0) {
  9161. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  9162. return 0;
  9163. }
  9164. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  9165. if (!quest) {
  9166. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  9167. return 0;
  9168. }
  9169. quest->StepFailed(step);
  9170. return 0;
  9171. }
  9172. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  9173. if (!lua_interface)
  9174. return 0;
  9175. Spawn* player = lua_interface->GetSpawn(state);
  9176. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9177. lua_interface->ResetFunctionStack(state);
  9178. if (!player) {
  9179. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  9180. return 0;
  9181. }
  9182. if (!player->IsPlayer()) {
  9183. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  9184. return 0;
  9185. }
  9186. if (quest_id == 0) {
  9187. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  9188. return 0;
  9189. }
  9190. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestCompletedCount(quest_id));
  9191. return 1;
  9192. }
  9193. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  9194. if (!lua_interface)
  9195. return 0;
  9196. string name = lua_interface->GetStringValue(state);
  9197. string value = lua_interface->GetStringValue(state, 2);
  9198. string comment = lua_interface->GetStringValue(state, 3);
  9199. lua_interface->ResetFunctionStack(state);
  9200. if (name.length() == 0) {
  9201. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  9202. return 0;
  9203. }
  9204. if (value.length() == 0) {
  9205. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  9206. return 0;
  9207. }
  9208. string varname = string("lua_").append(name);
  9209. Variable* var = variables.FindVariable(varname);
  9210. if (var)
  9211. var->SetValue(value.c_str());
  9212. else {
  9213. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  9214. variables.AddVariable(var);
  9215. }
  9216. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  9217. return 0;
  9218. }
  9219. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  9220. if (!lua_interface)
  9221. return 0;
  9222. string name = lua_interface->GetStringValue(state);
  9223. lua_interface->ResetFunctionStack(state);
  9224. if (name.length() == 0) {
  9225. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  9226. return 0;
  9227. }
  9228. string varname = string("lua_").append(name);
  9229. Variable* var = variables.FindVariable(varname);
  9230. if (var)
  9231. lua_interface->SetStringValue(state, var->GetValue());
  9232. else
  9233. lua_interface->SetStringValue(state, "NULL");
  9234. return 1;
  9235. }
  9236. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  9237. if (!lua_interface)
  9238. return 0;
  9239. Spawn* player = lua_interface->GetSpawn(state);
  9240. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9241. lua_interface->ResetFunctionStack(state);
  9242. if (!player) {
  9243. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9244. return 0;
  9245. }
  9246. if (!player->IsPlayer()) {
  9247. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9248. return 0;
  9249. }
  9250. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  9251. return 1;
  9252. }
  9253. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  9254. if (!lua_interface)
  9255. return 0;
  9256. Spawn* player = lua_interface->GetSpawn(state);
  9257. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9258. lua_interface->ResetFunctionStack(state);
  9259. if (!player) {
  9260. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9261. return 0;
  9262. }
  9263. if (!player->IsPlayer()) {
  9264. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9265. return 0;
  9266. }
  9267. Language* language = master_languages_list.GetLanguage(language_id);
  9268. if (language)
  9269. {
  9270. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  9271. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID(), 0);
  9272. }
  9273. return 0;
  9274. }
  9275. int EQ2Emu_lua_IsNight(lua_State* state) {
  9276. if (!lua_interface)
  9277. return 0;
  9278. ZoneServer* zone = lua_interface->GetZone(state);
  9279. lua_interface->ResetFunctionStack(state);
  9280. if (!zone) {
  9281. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  9282. return 0;
  9283. }
  9284. lua_interface->SetBooleanValue(state, zone->IsDusk());
  9285. return 1;
  9286. }
  9287. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  9288. if (!lua_interface)
  9289. return 0;
  9290. Spawn* spawn = lua_interface->GetSpawn(state);
  9291. lua_interface->ResetFunctionStack(state);
  9292. if (!spawn) {
  9293. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  9294. return 0;
  9295. }
  9296. if (!spawn->IsWidget()) {
  9297. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  9298. return 0;
  9299. }
  9300. ((Widget*)spawn)->SetMultiFloorLift(true);
  9301. if (spawn->GetZone())
  9302. spawn->GetZone()->AddTransportSpawn(spawn);
  9303. return 0;
  9304. }
  9305. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  9306. if (!lua_interface)
  9307. return 0;
  9308. Spawn* player = lua_interface->GetSpawn(state);
  9309. int32 path = lua_interface->GetInt32Value(state, 2);
  9310. lua_interface->ResetFunctionStack(state);
  9311. if (!player) {
  9312. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9313. return 0;
  9314. }
  9315. if (!player->IsPlayer()) {
  9316. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9317. return 0;
  9318. }
  9319. if (path == 0) {
  9320. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  9321. return 0;
  9322. }
  9323. Client* client = ((Player*)player)->GetClient();
  9324. if (!client) {
  9325. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9326. return 0;
  9327. }
  9328. client->SendFlightAutoMount(path);
  9329. return 0;
  9330. }
  9331. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  9332. if (!lua_interface)
  9333. return 0;
  9334. Spawn* player = lua_interface->GetSpawn(state);
  9335. if (!player) {
  9336. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9337. return 0;
  9338. }
  9339. if (!player->IsPlayer()) {
  9340. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9341. return 0;
  9342. }
  9343. Client* client = ((Player*)player)->GetClient();
  9344. if (!client) {
  9345. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9346. return 0;
  9347. }
  9348. client->EndAutoMount();
  9349. return 0;
  9350. }
  9351. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  9352. if (!lua_interface)
  9353. return 0;
  9354. Spawn* player = lua_interface->GetSpawn(state);
  9355. lua_interface->ResetFunctionStack(state);
  9356. if (!player) {
  9357. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  9358. return 0;
  9359. }
  9360. if (!player->IsPlayer()) {
  9361. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9362. return 0;
  9363. }
  9364. Client* client = ((Player*)player)->GetClient();
  9365. if (!client) {
  9366. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9367. return 0;
  9368. }
  9369. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  9370. return 1;
  9371. }
  9372. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  9373. if (!lua_interface)
  9374. return 0;
  9375. Spawn* player = lua_interface->GetSpawn(state);
  9376. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9377. int32 value = lua_interface->GetInt32Value(state, 3);
  9378. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9379. lua_interface->ResetFunctionStack(state);
  9380. if (!player) {
  9381. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9382. return 0;
  9383. }
  9384. if (!player->IsPlayer()) {
  9385. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9386. return 0;
  9387. }
  9388. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  9389. return 0;
  9390. }
  9391. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  9392. if (!lua_interface)
  9393. return 0;
  9394. Spawn* player = lua_interface->GetSpawn(state);
  9395. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9396. lua_interface->ResetFunctionStack(state);
  9397. if (!player) {
  9398. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9399. return 0;
  9400. }
  9401. if (!player->IsPlayer()) {
  9402. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9403. return 0;
  9404. }
  9405. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  9406. if (!hd)
  9407. return 0;
  9408. lua_interface->SetInt32Value(state, hd->Value);
  9409. lua_interface->SetInt32Value(state, hd->Value2);
  9410. return 2;
  9411. }
  9412. int EQ2Emu_lua_SetGridID(lua_State* state) {
  9413. if (!lua_interface)
  9414. return 0;
  9415. Spawn* spawn = lua_interface->GetSpawn(state);
  9416. int32 grid = lua_interface->GetInt32Value(state, 2);
  9417. lua_interface->ResetFunctionStack(state);
  9418. if (!spawn) {
  9419. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9420. return 0;
  9421. }
  9422. if (grid == 0) {
  9423. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  9424. return 0;
  9425. }
  9426. spawn->SetLocation(grid);
  9427. return 0;
  9428. }
  9429. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  9430. if (!lua_interface)
  9431. return 0;
  9432. Spawn* spawn = lua_interface->GetSpawn(state);
  9433. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9434. int32 value1 = lua_interface->GetInt32Value(state, 3);
  9435. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9436. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  9437. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  9438. lua_interface->ResetFunctionStack(state);
  9439. if (!spawn) {
  9440. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9441. return 0;
  9442. }
  9443. //Add this quest to the list of required quests for this spawn
  9444. spawn->SetRequiredHistory(event_id, value1, value2);
  9445. //If private spawn value set
  9446. if (private_spawn) {
  9447. //Set the spawn to be private when not granted access via history
  9448. spawn->AddAllowAccessSpawn(spawn);
  9449. spawn->SetPrivateQuestSpawn(true);
  9450. }
  9451. //This value will override vis_flags in the vis packet
  9452. if (flag_override > 0)
  9453. spawn->SetQuestsRequiredOverride(flag_override);
  9454. return 0;
  9455. }
  9456. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  9457. if (!lua_interface)
  9458. return 0;
  9459. Spawn* player = lua_interface->GetSpawn(state);
  9460. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9461. int32 step_id = lua_interface->GetInt32Value(state, 3);
  9462. lua_interface->ResetFunctionStack(state);
  9463. if (!player) {
  9464. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  9465. return 0;
  9466. }
  9467. if (!player->IsPlayer()) {
  9468. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  9469. return 0;
  9470. }
  9471. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  9472. return 1;
  9473. }
  9474. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  9475. if (!lua_interface)
  9476. return 0;
  9477. Spawn* player = lua_interface->GetSpawn(state);
  9478. int8 level = lua_interface->GetInt8Value(state, 2);
  9479. lua_interface->ResetFunctionStack(state);
  9480. if (!player) {
  9481. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  9482. return 0;
  9483. }
  9484. if (!player->IsPlayer()) {
  9485. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  9486. return 0;
  9487. }
  9488. if (level == 0) {
  9489. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  9490. return 0;
  9491. }
  9492. Client* client = ((Player*)player)->GetClient();
  9493. if (!client) {
  9494. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  9495. return 0;
  9496. }
  9497. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  9498. return 0;
  9499. }
  9500. int EQ2Emu_lua_AddCoin(lua_State* state) {
  9501. if (!lua_interface)
  9502. return 0;
  9503. Spawn* player = lua_interface->GetSpawn(state);
  9504. int32 amount = lua_interface->GetInt32Value(state, 2);
  9505. lua_interface->ResetFunctionStack(state);
  9506. if (!player) {
  9507. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9508. return 0;
  9509. }
  9510. if (!player->IsPlayer()) {
  9511. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9512. return 0;
  9513. }
  9514. if (amount == 0) {
  9515. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9516. return 0;
  9517. }
  9518. ((Player*)player)->AddCoins(amount);
  9519. return 0;
  9520. }
  9521. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  9522. if (!lua_interface)
  9523. return 0;
  9524. Spawn* player = lua_interface->GetSpawn(state);
  9525. int32 amount = lua_interface->GetInt32Value(state, 2);
  9526. lua_interface->ResetFunctionStack(state);
  9527. if (!player) {
  9528. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9529. return 0;
  9530. }
  9531. if (!player->IsPlayer()) {
  9532. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9533. return 0;
  9534. }
  9535. if (amount == 0) {
  9536. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9537. return 0;
  9538. }
  9539. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  9540. return 1;
  9541. }
  9542. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  9543. if (!lua_interface)
  9544. return 0;
  9545. ZoneServer* zone = lua_interface->GetZone(state);
  9546. lua_interface->ResetFunctionStack(state);
  9547. if (!zone) {
  9548. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9549. return 0;
  9550. }
  9551. vector<Entity*> players = zone->GetPlayers();
  9552. if (players.size() == 0)
  9553. return 0;
  9554. lua_createtable(state, players.size(), 0);
  9555. int newTable = lua_gettop(state);
  9556. for (int32 i = 0; i < players.size(); i++) {
  9557. lua_interface->SetSpawnValue(state, players.at(i));
  9558. lua_rawseti(state, newTable, i + 1);
  9559. }
  9560. return 1;
  9561. }
  9562. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  9563. if (!lua_interface)
  9564. return 0;
  9565. ZoneServer* zone = lua_interface->GetZone(state, 1);
  9566. if (!zone) {
  9567. lua_interface->LogError("%s: LUA SpawnGroupByID command error: zone is not valid", lua_interface->GetScriptName(state));
  9568. return 0;
  9569. }
  9570. int32 group_id = lua_interface->GetInt32Value(state, 2);
  9571. int16 custom_level = lua_interface->GetInt32Value(state, 3);
  9572. lua_interface->ResetFunctionStack(state);
  9573. //Map of <placement_id, location_id>
  9574. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  9575. map<int32, int32>::iterator itr;
  9576. vector<Spawn*> group;
  9577. Spawn* leader = 0;
  9578. if(locs == nullptr)
  9579. return 0;
  9580. for (itr = locs->begin(); itr != locs->end(); itr++) {
  9581. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  9582. if (!location) {
  9583. lua_interface->LogError("%s: LUA SpawnGroupByID command error: no location found for group id %u and the given ID (%u)", lua_interface->GetScriptName(state), group_id, itr->second);
  9584. return 0;
  9585. }
  9586. int32 rand_number = MakeRandomInt(0, location->entities.size() - 1);
  9587. Spawn* spawn = 0;
  9588. if (location->entities[rand_number]) {
  9589. if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  9590. spawn = zone->AddNPCSpawn(location, location->entities[rand_number]);
  9591. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  9592. spawn = zone->AddGroundSpawn(location, location->entities[rand_number]);
  9593. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  9594. spawn = zone->AddObjectSpawn(location, location->entities[rand_number]);
  9595. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  9596. spawn = zone->AddWidgetSpawn(location, location->entities[rand_number]);
  9597. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9598. spawn = zone->AddSignSpawn(location, location->entities[rand_number]);
  9599. if(spawn && spawn->IsOmittedByDBFlag())
  9600. {
  9601. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met (LUA SpawnGroupByID).", location->entities[rand_number]->spawn_id);
  9602. safe_delete(spawn);
  9603. continue;
  9604. }
  9605. if (spawn) {
  9606. if(!leader)
  9607. leader = spawn;
  9608. if(leader)
  9609. leader->AddSpawnToGroup(spawn);
  9610. spawn->SetSpawnGroupID(group_id);
  9611. if(custom_level > 0 && custom_level != 0xFFFF) {
  9612. spawn->SetLevel(custom_level);
  9613. }
  9614. const char* script = 0;
  9615. for (int x = 0; x < 3; x++) {
  9616. switch (x) {
  9617. case 0:
  9618. script = world.GetSpawnEntryScript(location->entities[rand_number]->spawn_entry_id);
  9619. break;
  9620. case 1:
  9621. script = world.GetSpawnLocationScript(location->entities[rand_number]->spawn_location_id);
  9622. break;
  9623. case 2:
  9624. script = world.GetSpawnScript(location->entities[rand_number]->spawn_id);
  9625. break;
  9626. }
  9627. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9628. spawn->SetSpawnScript(string(script));
  9629. break;
  9630. }
  9631. }
  9632. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9633. lua_interface->SetSpawnValue(state, spawn);
  9634. group.push_back(spawn);
  9635. }
  9636. else {
  9637. LogWrite(ZONE__ERROR, 0, "Zone", "%s: Error adding spawn by group id to zone %s with location id %u.", lua_interface->GetScriptName(state), zone->GetZoneName(), group_id);
  9638. safe_delete(spawn);
  9639. }
  9640. }
  9641. }
  9642. if (!group.empty()) {
  9643. lua_createtable(state, group.size(), 0);
  9644. int newTable = lua_gettop(state);
  9645. for (int32 i = 0; i < group.size(); i++) {
  9646. lua_interface->SetSpawnValue(state, group[i]);
  9647. lua_rawseti(state, newTable, i + 1);
  9648. }
  9649. }
  9650. else
  9651. lua_pushnil(state);
  9652. return 1;
  9653. }
  9654. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9655. if (!lua_interface)
  9656. return 0;
  9657. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9658. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9659. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9660. lua_interface->ResetFunctionStack(state);
  9661. if (!spawn) {
  9662. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9663. return 0;
  9664. }
  9665. if (anim_id == 0) {
  9666. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9667. return 0;
  9668. }
  9669. if (leeway == 0)
  9670. leeway = 5000;
  9671. spawn->SetSpawnAnim(anim_id);
  9672. spawn->SetSpawnAnimLeeway(leeway);
  9673. return 0;
  9674. }
  9675. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9676. if (!lua_interface)
  9677. return 0;
  9678. Spawn* player = lua_interface->GetSpawn(state);
  9679. lua_interface->ResetFunctionStack(state);
  9680. if (!player || !player->IsPlayer()) {
  9681. return 0;
  9682. }
  9683. Client* client = ((Player*)player)->GetClient();
  9684. if (!client) {
  9685. return 0;
  9686. }
  9687. lua_interface->SetInt32Value(state, client->GetVersion());
  9688. return 1;
  9689. }
  9690. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9691. if (!lua_interface)
  9692. return 0;
  9693. Item* item = lua_interface->GetItem(state);
  9694. lua_interface->ResetFunctionStack(state);
  9695. if (!item) {
  9696. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9697. return 0;
  9698. }
  9699. lua_interface->SetInt32Value(state, item->details.item_id);
  9700. return 1;
  9701. }
  9702. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9703. if (!lua_interface)
  9704. return 0;
  9705. Spawn* spawn = lua_interface->GetSpawn(state);
  9706. lua_interface->ResetFunctionStack(state);
  9707. if (!spawn) {
  9708. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9709. return 0;
  9710. }
  9711. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9712. return 1;
  9713. }
  9714. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9715. if (!lua_interface)
  9716. return 0;
  9717. Spawn* spawn = lua_interface->GetSpawn(state);
  9718. lua_interface->ResetFunctionStack(state);
  9719. if (!spawn) {
  9720. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9721. return 0;
  9722. }
  9723. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9724. return 1;
  9725. }
  9726. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9727. if (!lua_interface)
  9728. return 0;
  9729. Spawn* spawn = lua_interface->GetSpawn(state);
  9730. lua_interface->ResetFunctionStack(state);
  9731. if (!spawn) {
  9732. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9733. return 0;
  9734. }
  9735. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9736. return 1;
  9737. }
  9738. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9739. if (!lua_interface)
  9740. return 0;
  9741. Spawn* spawn = lua_interface->GetSpawn(state);
  9742. lua_interface->ResetFunctionStack(state);
  9743. if (!spawn) {
  9744. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9745. return 0;
  9746. }
  9747. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9748. return 1;
  9749. }
  9750. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9751. if (!lua_interface)
  9752. return 0;
  9753. Spawn* spawn = lua_interface->GetSpawn(state);
  9754. float pct = lua_interface->GetFloatValue(state, 2);
  9755. lua_interface->ResetFunctionStack(state);
  9756. if (!spawn) {
  9757. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9758. return 0;
  9759. }
  9760. if (pct == 0) {
  9761. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9762. return 0;
  9763. }
  9764. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9765. lua_interface->SetInt32Value(state, amount);
  9766. return 1;
  9767. }
  9768. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9769. if (!lua_interface)
  9770. return 0;
  9771. Spawn* spawn = lua_interface->GetSpawn(state);
  9772. float pct = lua_interface->GetFloatValue(state, 2);
  9773. lua_interface->ResetFunctionStack(state);
  9774. if (!spawn) {
  9775. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9776. return 0;
  9777. }
  9778. if (pct == 0) {
  9779. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9780. return 0;
  9781. }
  9782. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9783. lua_interface->SetInt32Value(state, amount);
  9784. return 1;
  9785. }
  9786. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9787. if (!lua_interface)
  9788. return 0;
  9789. Spawn* spawn = lua_interface->GetSpawn(state);
  9790. lua_interface->ResetFunctionStack(state);
  9791. if (!spawn) {
  9792. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9793. return 0;
  9794. }
  9795. if (!spawn->IsPlayer()) {
  9796. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9797. return 0;
  9798. }
  9799. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9800. return 1;
  9801. }
  9802. int EQ2Emu_lua_Evac(lua_State* state) {
  9803. if (!lua_interface)
  9804. return 0;
  9805. Spawn* target = lua_interface->GetSpawn(state);
  9806. if (target) {
  9807. float x = target->GetZone()->GetSafeX();
  9808. float y = target->GetZone()->GetSafeY();
  9809. float z = target->GetZone()->GetSafeZ();
  9810. float h = target->GetZone()->GetSafeHeading();
  9811. target->SetX(x);
  9812. target->SetY(y);
  9813. target->SetZ(z);
  9814. target->SetHeading(h);
  9815. target->SetSpawnOrigX(x);
  9816. target->SetSpawnOrigY(y);
  9817. target->SetSpawnOrigZ(z);
  9818. target->SetSpawnOrigHeading(h);
  9819. if (target->IsPlayer()) {
  9820. Client* client = ((Player*)target)->GetClient();
  9821. if (client) {
  9822. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9823. int numargs = lua_interface->GetNumberOfArgs(state);
  9824. if(numargs == 4) {
  9825. x = lua_interface->GetFloatValue(state,1);
  9826. y = lua_interface->GetFloatValue(state,2);
  9827. z = lua_interface->GetFloatValue(state,3);
  9828. h = lua_interface->GetFloatValue(state,4);
  9829. }
  9830. client->SetReloadingZone(true);
  9831. target->SetX(x);
  9832. target->SetY(y);
  9833. target->SetZ(z);
  9834. target->SetHeading(h);
  9835. target->SetSpawnOrigX(x);
  9836. target->SetSpawnOrigY(y);
  9837. target->SetSpawnOrigZ(z);
  9838. target->SetSpawnOrigHeading(h);
  9839. target->SetAppearancePosition(x,y,z);
  9840. client->SetZoningCoords(x,y,z,h);
  9841. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9842. if (packet)
  9843. {
  9844. packet->setDataByName("x", x);
  9845. packet->setDataByName("y", y);
  9846. packet->setDataByName("z", z);
  9847. client->QueuePacket(packet->serialize());
  9848. safe_delete(packet);
  9849. }
  9850. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9851. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9852. }
  9853. }
  9854. lua_interface->ResetFunctionStack(state);
  9855. }
  9856. else {
  9857. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9858. if(!spell || !spell->caster || !spell->caster->GetZone()) {
  9859. lua_interface->ResetFunctionStack(state);
  9860. return 0;
  9861. }
  9862. ZoneServer* zone = spell->caster->GetZone();
  9863. float x = spell->caster->GetZone()->GetSafeX();
  9864. float y = spell->caster->GetZone()->GetSafeY();
  9865. float z = spell->caster->GetZone()->GetSafeZ();
  9866. float h = spell->caster->GetZone()->GetSafeHeading();
  9867. int numargs = lua_interface->GetNumberOfArgs(state);
  9868. if(numargs == 4) {
  9869. x = lua_interface->GetFloatValue(state,1);
  9870. y = lua_interface->GetFloatValue(state,2);
  9871. z = lua_interface->GetFloatValue(state,3);
  9872. h = lua_interface->GetFloatValue(state,4);
  9873. }
  9874. lua_interface->ResetFunctionStack(state);
  9875. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9876. for (int32 i = 0; i < spell->targets.size(); i++) {
  9877. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9878. if (!target2)
  9879. continue;
  9880. if (target2->IsPlayer()) {
  9881. Client* client = ((Player*)target2)->GetClient();
  9882. if (client) {
  9883. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9884. client->SetReloadingZone(true);
  9885. target2->SetX(x);
  9886. target2->SetY(y);
  9887. target2->SetZ(z);
  9888. target2->SetHeading(h);
  9889. target2->SetSpawnOrigX(x);
  9890. target2->SetSpawnOrigY(y);
  9891. target2->SetSpawnOrigZ(z);
  9892. target2->SetSpawnOrigHeading(h);
  9893. target2->SetAppearancePosition(x,y,z);
  9894. client->SetZoningCoords(x,y,z,h);
  9895. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9896. if (packet)
  9897. {
  9898. packet->setDataByName("x", x);
  9899. packet->setDataByName("y", y);
  9900. packet->setDataByName("z", z);
  9901. client->QueuePacket(packet->serialize());
  9902. safe_delete(packet);
  9903. }
  9904. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9905. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9906. }
  9907. }
  9908. }
  9909. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9910. }
  9911. return 0;
  9912. }
  9913. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9914. if (!lua_interface)
  9915. return 0;
  9916. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9917. lua_interface->ResetFunctionStack(state);
  9918. if (!luaspell || !luaspell->spell) {
  9919. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9920. return 0;
  9921. }
  9922. int8 tier = luaspell->spell->GetSpellTier();
  9923. lua_interface->SetInt32Value(state, tier);
  9924. return 1;
  9925. }
  9926. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9927. if (!lua_interface)
  9928. return 0;
  9929. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9930. lua_interface->ResetFunctionStack(state);
  9931. if (!luaspell || !luaspell->spell) {
  9932. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9933. return 0;
  9934. }
  9935. int32 spell_id = luaspell->spell->GetSpellID();
  9936. lua_interface->SetInt32Value(state, spell_id);
  9937. return 1;
  9938. }
  9939. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9940. if (!lua_interface)
  9941. return 0;
  9942. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9943. lua_interface->ResetFunctionStack(state);
  9944. if (!spawn) {
  9945. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9946. return 0;
  9947. }
  9948. if (!spawn->IsPlayer()) {
  9949. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9950. return 0;
  9951. }
  9952. ZoneServer* zone = spawn->GetZone();
  9953. if (!zone) {
  9954. return 0;
  9955. }
  9956. Client* client = ((Player*)spawn)->GetClient();
  9957. if (!client) {
  9958. return 0;
  9959. }
  9960. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9961. return 0;
  9962. }
  9963. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9964. if (!lua_interface)
  9965. return 0;
  9966. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9967. lua_interface->ResetFunctionStack(state);
  9968. if (!spawn) {
  9969. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9970. return 0;
  9971. }
  9972. if (!spawn->IsPlayer()) {
  9973. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9974. return 0;
  9975. }
  9976. ZoneServer* zone = spawn->GetZone();
  9977. if (!zone) {
  9978. return 0;
  9979. }
  9980. Client* client = ((Player*)spawn)->GetClient();
  9981. if (!client) {
  9982. return 0;
  9983. }
  9984. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9985. return 0;
  9986. }
  9987. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9988. if (!lua_interface)
  9989. return 0;
  9990. Spawn* caster = lua_interface->GetSpawn(state);
  9991. Spawn* target = lua_interface->GetSpawn(state, 2);
  9992. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9993. string spell_name = lua_interface->GetStringValue(state, 4);
  9994. lua_interface->ResetFunctionStack(state);
  9995. if (!caster) {
  9996. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9997. return 0;
  9998. }
  9999. if (!caster->IsEntity()) {
  10000. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  10001. return 0;
  10002. }
  10003. if (!target) {
  10004. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10005. return 0;
  10006. }
  10007. if (!target->IsEntity()) {
  10008. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  10009. return 0;
  10010. }
  10011. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  10012. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  10013. return 0;
  10014. }
  10015. int EQ2Emu_lua_GiveExp(lua_State* state) {
  10016. if (!lua_interface)
  10017. return 0;
  10018. Spawn* player = lua_interface->GetSpawn(state);
  10019. int32 amount = lua_interface->GetInt32Value(state, 2);
  10020. lua_interface->ResetFunctionStack(state);
  10021. if (player && player->IsPlayer() && amount > 0) {
  10022. ((Player*)player)->AddXP(amount);
  10023. }
  10024. return 0;
  10025. }
  10026. int EQ2Emu_lua_DisplayText(lua_State* state) {
  10027. if (!lua_interface)
  10028. return 0;
  10029. Spawn* player = lua_interface->GetSpawn(state);
  10030. int8 type = lua_interface->GetInt8Value(state, 2);
  10031. string text = lua_interface->GetStringValue(state, 3);
  10032. lua_interface->ResetFunctionStack(state);
  10033. Client* client = 0;
  10034. if (player && player->IsPlayer())
  10035. client = ((Player*)player)->GetClient();
  10036. if (!client || text.length() == 0) {
  10037. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  10038. return 0;
  10039. }
  10040. client->SimpleMessage(type, text.c_str());
  10041. return 0;
  10042. }
  10043. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  10044. if (!lua_interface)
  10045. return 0;
  10046. Spawn* player = lua_interface->GetSpawn(state);
  10047. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10048. lua_interface->ResetFunctionStack(state);
  10049. Client* client = 0;
  10050. if (player && player->IsPlayer())
  10051. client = ((Player*)player)->GetClient();
  10052. if (!client || !spawn) {
  10053. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  10054. return 0;
  10055. }
  10056. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  10057. if (!items) {
  10058. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  10059. return 0;
  10060. }
  10061. client->SendLootResponsePacket(spawn->GetLootCoins(), items, spawn, true);
  10062. return 0;
  10063. }
  10064. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  10065. if (!lua_interface)
  10066. return 0;
  10067. Spawn* spawnref = lua_interface->GetSpawn(state);
  10068. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  10069. lua_interface->ResetFunctionStack(state);
  10070. if (spawn_id > 0 && spawnref) {
  10071. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  10072. if (spawns.size() == 0) {
  10073. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  10074. return 0;
  10075. }
  10076. Spawn* spawn = 0;
  10077. int16 index = MakeRandomInt(0, spawns.size());
  10078. if (index >= spawns.size() || index < 0)
  10079. index = 0;
  10080. spawn = spawns[index];
  10081. lua_interface->SetSpawnValue(state, spawn);
  10082. return 1;
  10083. }
  10084. else {
  10085. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  10086. }
  10087. return 0;
  10088. }
  10089. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  10090. Spawn* player = lua_interface->GetSpawn(state);
  10091. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  10092. string name = lua_interface->GetStringValue(state, 3);
  10093. float distance = lua_interface->GetFloatValue(state, 4);
  10094. string command = lua_interface->GetStringValue(state, 5);
  10095. string error_text = lua_interface->GetStringValue(state, 6);
  10096. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  10097. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  10098. lua_interface->ResetFunctionStack(state);
  10099. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  10100. if (distance == 0)
  10101. distance = 10.0f;
  10102. if (command.length() == 0)
  10103. command = name;
  10104. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  10105. if (spawns.size() == 0) {
  10106. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  10107. return 0;
  10108. }
  10109. Spawn* spawn = 0;
  10110. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  10111. spawn = *itr;
  10112. if (spawn) {
  10113. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  10114. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  10115. }
  10116. }
  10117. }
  10118. return 0;
  10119. }
  10120. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  10121. if (!lua_interface)
  10122. return 0;
  10123. Client* client = 0;
  10124. Spawn* player = lua_interface->GetSpawn(state);
  10125. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  10126. lua_interface->ResetFunctionStack(state);
  10127. if (player && player->IsPlayer() && player->GetZone())
  10128. client = ((Player*)player)->GetClient();
  10129. else{
  10130. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  10131. return 0;
  10132. }
  10133. if (client) {
  10134. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  10135. if (packet) {
  10136. packet->setDataByName("goal_num", goal_num);
  10137. client->QueuePacket(packet->serialize());
  10138. safe_delete(packet);
  10139. }
  10140. }
  10141. return 0;
  10142. }
  10143. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  10144. if (!lua_interface)
  10145. return 0;
  10146. Client* client = 0;
  10147. Spawn* player = lua_interface->GetSpawn(state);
  10148. lua_interface->ResetFunctionStack(state);
  10149. if (player && player->IsPlayer() && player->GetZone())
  10150. client = ((Player*)player)->GetClient();
  10151. else {
  10152. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  10153. return 0;
  10154. }
  10155. if (client && client->GetVersion() >= 374) {
  10156. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  10157. }
  10158. return 0;
  10159. }
  10160. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  10161. if (!lua_interface)
  10162. return 0;
  10163. Client* client = 0;
  10164. Spawn* player = lua_interface->GetSpawn(state);
  10165. float duration = lua_interface->GetFloatValue(state, 2);
  10166. string text = lua_interface->GetStringValue(state, 3);
  10167. string voice = lua_interface->GetStringValue(state, 4);
  10168. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  10169. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  10170. string signal = lua_interface->GetStringValue(state, 7);
  10171. string goal1 = lua_interface->GetStringValue(state, 8);
  10172. string task1 = lua_interface->GetStringValue(state, 9);
  10173. string goal2 = lua_interface->GetStringValue(state, 10);
  10174. string task2 = lua_interface->GetStringValue(state, 11);
  10175. string goal3 = lua_interface->GetStringValue(state, 12);
  10176. string task3 = lua_interface->GetStringValue(state, 13);
  10177. string goal4 = lua_interface->GetStringValue(state, 14);
  10178. string task4 = lua_interface->GetStringValue(state, 15);
  10179. lua_interface->ResetFunctionStack(state);
  10180. if (!player) {
  10181. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  10182. return 0;
  10183. }
  10184. if (!player->IsPlayer()) {
  10185. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  10186. return 0;
  10187. }
  10188. else
  10189. client = ((Player*)player)->GetClient();
  10190. if (!client) {
  10191. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  10192. return 0;
  10193. }
  10194. if (text.length() == 0) {
  10195. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  10196. return 0;
  10197. }
  10198. if (duration >= 0 && duration < 2)
  10199. duration = 2;
  10200. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  10201. if (packet) {
  10202. packet->setDataByName("open_seconds_max", duration);
  10203. packet->setDataByName("text", text.c_str());
  10204. packet->setDataByName("voice", voice.c_str());
  10205. int8 num_goals = 1;
  10206. if (task2.length() > 0)
  10207. num_goals++;
  10208. if (task3.length() > 0)
  10209. num_goals++;
  10210. if (task4.length() > 0)
  10211. num_goals++;
  10212. packet->setArrayLengthByName("num_goals", num_goals);
  10213. for (int8 i = 0; i < num_goals; i++) {
  10214. packet->setSubArrayLengthByName("num_tasks", 1, i);
  10215. }
  10216. if (goal1.length() > 0)
  10217. packet->setArrayDataByName("goal_text", goal1.c_str());
  10218. if (goal2.length() > 0)
  10219. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  10220. if (goal3.length() > 0)
  10221. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  10222. if (goal4.length() > 0)
  10223. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  10224. packet->setSubArrayDataByName("task_text", task1.c_str());
  10225. if (task2.length() > 0)
  10226. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  10227. if (task3.length() > 0)
  10228. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  10229. if (task4.length() > 0)
  10230. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  10231. packet->setDataByName("complete_sound", "click");
  10232. packet->setDataByName("signal", signal.c_str());
  10233. packet->setDataByName("voice_key1", voice_key1);
  10234. packet->setDataByName("voice_key2", voice_key2);
  10235. client->QueuePacket(packet->serialize());
  10236. safe_delete(packet);
  10237. }
  10238. return 0;
  10239. }
  10240. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  10241. if (!lua_interface)
  10242. return 0;
  10243. Client* client = 0;
  10244. Spawn* player = lua_interface->GetSpawn(state);
  10245. string window = lua_interface->GetStringValue(state, 2);
  10246. int8 show = lua_interface->GetInt8Value(state, 3);
  10247. lua_interface->ResetFunctionStack(state);
  10248. if (!player) {
  10249. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  10250. return 0;
  10251. }
  10252. if (!player->IsPlayer()) {
  10253. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  10254. return 0;
  10255. }
  10256. else
  10257. client = ((Player*)player)->GetClient();
  10258. if (!client) {
  10259. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  10260. return 0;
  10261. }
  10262. if (window.length() == 0) {
  10263. lua_interface->LogError("LUA ShowWindow required parameters not given");
  10264. return 0;
  10265. }
  10266. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  10267. if (packet) {
  10268. packet->setDataByName("window", window.c_str());
  10269. packet->setDataByName("show", show);
  10270. client->QueuePacket(packet->serialize());
  10271. safe_delete(packet);
  10272. }
  10273. return 0;
  10274. }
  10275. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  10276. //See GameEvents.txt for options that can be used for this function
  10277. if (!lua_interface)
  10278. return 0;
  10279. Client* client = 0;
  10280. Spawn* player = lua_interface->GetSpawn(state);
  10281. string event_name = lua_interface->GetStringValue(state, 2);
  10282. int8 enabled = lua_interface->GetInt8Value(state, 3);
  10283. lua_interface->ResetFunctionStack(state);
  10284. if (!player || !player->IsPlayer()) {
  10285. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  10286. return 0;
  10287. }
  10288. client = ((Player*)player)->GetClient();
  10289. if (!client) {
  10290. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  10291. return 0;
  10292. }
  10293. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  10294. if (packet) {
  10295. packet->setDataByName("event_name", event_name.c_str());
  10296. packet->setDataByName("enabled", enabled);
  10297. client->QueuePacket(packet->serialize());
  10298. safe_delete(packet);
  10299. }
  10300. return 0;
  10301. }
  10302. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  10303. if (!lua_interface)
  10304. return 0;
  10305. Spawn* player = lua_interface->GetSpawn(state);
  10306. lua_interface->ResetFunctionStack(state);
  10307. if (player && player->IsPlayer()) {
  10308. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  10309. return 1;
  10310. }
  10311. return 0;
  10312. }
  10313. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  10314. if (!lua_interface)
  10315. return 0;
  10316. Spawn* player = lua_interface->GetSpawn(state);
  10317. int8 step = lua_interface->GetInt8Value(state, 2);
  10318. lua_interface->ResetFunctionStack(state);
  10319. if (player && player->IsPlayer() && step > 0) {
  10320. ((Player*)player)->SetTutorialStep(step);
  10321. }
  10322. return 0;
  10323. }
  10324. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  10325. if (!lua_interface)
  10326. return 0;
  10327. Client* client = 0;
  10328. Spawn* player = lua_interface->GetSpawn(state);
  10329. string window = lua_interface->GetStringValue(state, 2);
  10330. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  10331. lua_interface->ResetFunctionStack(state);
  10332. if (!player) {
  10333. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  10334. return 0;
  10335. }
  10336. if (!player->IsPlayer()) {
  10337. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  10338. return 0;
  10339. }
  10340. else
  10341. client = ((Player*)player)->GetClient();
  10342. if (!client) {
  10343. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  10344. return 0;
  10345. }
  10346. if (window.length() == 0) {
  10347. lua_interface->LogError("LUA FlashWindow required parameters not given");
  10348. return 0;
  10349. }
  10350. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  10351. if (packet) {
  10352. packet->setDataByName("window", window.c_str());
  10353. packet->setDataByName("flash_seconds", flash_seconds);
  10354. client->QueuePacket(packet->serialize());
  10355. safe_delete(packet);
  10356. }
  10357. return 0;
  10358. }
  10359. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  10360. if (!lua_interface)
  10361. return 0;
  10362. Spawn* spawn = lua_interface->GetSpawn(state);
  10363. Spawn* target = lua_interface->GetSpawn(state, 2);
  10364. lua_interface->ResetFunctionStack(state);
  10365. if (spawn && target)
  10366. return spawn->CheckLoS(target);
  10367. return 0;
  10368. }
  10369. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  10370. if (!lua_interface)
  10371. return 0;
  10372. Spawn* spawn = lua_interface->GetSpawn(state);
  10373. float x = lua_interface->GetFloatValue(state, 2);
  10374. float y = lua_interface->GetFloatValue(state, 3);
  10375. float z = lua_interface->GetFloatValue(state, 4);
  10376. lua_interface->ResetFunctionStack(state);
  10377. if (spawn)
  10378. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  10379. return 0;
  10380. }
  10381. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  10382. if (!lua_interface)
  10383. return 0;
  10384. ZoneServer* zone = lua_interface->GetZone(state);
  10385. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  10386. lua_interface->ResetFunctionStack(state);
  10387. if (zone)
  10388. zone->SetExpansionFlag(xpackFlag);
  10389. return 0;
  10390. }
  10391. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  10392. if (!lua_interface)
  10393. return 0;
  10394. ZoneServer* zone = lua_interface->GetZone(state);
  10395. lua_interface->ResetFunctionStack(state);
  10396. if (zone) {
  10397. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  10398. return 1;
  10399. }
  10400. return 0;
  10401. }
  10402. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  10403. if (!lua_interface)
  10404. return 0;
  10405. ZoneServer* zone = lua_interface->GetZone(state);
  10406. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  10407. lua_interface->ResetFunctionStack(state);
  10408. if (zone)
  10409. zone->SetHolidayFlag(holidayFlag);
  10410. return 0;
  10411. }
  10412. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  10413. if (!lua_interface)
  10414. return 0;
  10415. ZoneServer* zone = lua_interface->GetZone(state);
  10416. lua_interface->ResetFunctionStack(state);
  10417. if (zone) {
  10418. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  10419. return 1;
  10420. }
  10421. return 0;
  10422. }
  10423. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  10424. if (!lua_interface)
  10425. return 0;
  10426. Spawn* spawn = lua_interface->GetSpawn(state);
  10427. bool canbind = lua_interface->GetInt32Value(state, 2);
  10428. lua_interface->ResetFunctionStack(state);
  10429. if(!spawn) {
  10430. lua_interface->LogError("%s: LUA SetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10431. return 0;
  10432. }
  10433. ZoneServer* zone = spawn->GetZone();
  10434. if (zone)
  10435. zone->SetCanBind(canbind);
  10436. return 0;
  10437. }
  10438. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  10439. if (!lua_interface)
  10440. return 0;
  10441. Spawn* spawn = lua_interface->GetSpawn(state);
  10442. lua_interface->ResetFunctionStack(state);
  10443. if(!spawn) {
  10444. lua_interface->LogError("%s: LUA GetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10445. return 0;
  10446. }
  10447. ZoneServer* zone = spawn->GetZone();
  10448. if (zone) {
  10449. lua_interface->SetInt32Value(state, zone->GetCanBind());
  10450. return 1;
  10451. }
  10452. return 0;
  10453. }
  10454. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  10455. if (!lua_interface)
  10456. return 0;
  10457. Spawn* spawn = lua_interface->GetSpawn(state);
  10458. bool cangate = lua_interface->GetInt32Value(state, 2);
  10459. lua_interface->ResetFunctionStack(state);
  10460. if(!spawn) {
  10461. lua_interface->LogError("%s: LUA SetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10462. return 0;
  10463. }
  10464. ZoneServer* zone = spawn->GetZone();
  10465. if (zone)
  10466. zone->SetCanGate(cangate);
  10467. return 0;
  10468. }
  10469. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  10470. if (!lua_interface)
  10471. return 0;
  10472. Spawn* spawn = lua_interface->GetSpawn(state);
  10473. lua_interface->ResetFunctionStack(state);
  10474. if(!spawn) {
  10475. lua_interface->LogError("%s: LUA GetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10476. return 0;
  10477. }
  10478. ZoneServer* zone = spawn->GetZone();
  10479. if (zone) {
  10480. lua_interface->SetInt32Value(state, zone->GetCanGate());
  10481. return 1;
  10482. }
  10483. return 0;
  10484. }
  10485. int EQ2Emu_lua_SetCanEvac(lua_State* state) {
  10486. if (!lua_interface)
  10487. return 0;
  10488. Spawn* spawn = lua_interface->GetSpawn(state);
  10489. bool canevac = lua_interface->GetInt32Value(state, 2);
  10490. lua_interface->ResetFunctionStack(state);
  10491. if(!spawn) {
  10492. lua_interface->LogError("%s: LUA SetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10493. return 0;
  10494. }
  10495. ZoneServer* zone = spawn->GetZone();
  10496. if (zone)
  10497. zone->SetCanEvac(canevac);
  10498. return 0;
  10499. }
  10500. int EQ2Emu_lua_GetCanEvac(lua_State* state) {
  10501. if (!lua_interface)
  10502. return 0;
  10503. Spawn* spawn = lua_interface->GetSpawn(state);
  10504. lua_interface->ResetFunctionStack(state);
  10505. if(!spawn) {
  10506. lua_interface->LogError("%s: LUA GetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10507. return 0;
  10508. }
  10509. ZoneServer* zone = spawn->GetZone();
  10510. if (zone) {
  10511. lua_interface->SetInt32Value(state, zone->GetCanEvac());
  10512. return 1;
  10513. }
  10514. return 0;
  10515. }
  10516. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  10517. if (!lua_interface)
  10518. return 0;
  10519. Spawn* spawn = lua_interface->GetSpawn(state);
  10520. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  10521. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  10522. float distance = lua_interface->GetFloatValue(state, 4);
  10523. string in_range_function = lua_interface->GetStringValue(state, 5);
  10524. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  10525. lua_interface->ResetFunctionStack(state);
  10526. if (spawn && distance > 0 && in_range_function.length() > 0)
  10527. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  10528. return 0;
  10529. }
  10530. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  10531. if (!lua_interface)
  10532. return 0;
  10533. Spawn* spawn = lua_interface->GetSpawn(state);
  10534. Spawn* target = lua_interface->GetSpawn(state, 2);
  10535. lua_interface->ResetFunctionStack(state);
  10536. if (spawn && target)
  10537. {
  10538. if (spawn->IsPlayer() && target->IsEntity())
  10539. {
  10540. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  10541. return 1;
  10542. }
  10543. else if (spawn->IsEntity() && target->IsEntity())
  10544. {
  10545. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  10546. return 1;
  10547. }
  10548. }
  10549. return 0;
  10550. }
  10551. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  10552. if (!lua_interface)
  10553. return 0;
  10554. Spawn* spawn = lua_interface->GetSpawn(state);
  10555. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10556. lua_interface->ResetFunctionStack(state);
  10557. if (spawn && spawn->IsEntity())
  10558. {
  10559. ((Entity*)spawn)->SetSeeInvisSpell(val);
  10560. if (spawn->IsPlayer())
  10561. {
  10562. Client* client = ((Player*)spawn)->GetClient();
  10563. if (client)
  10564. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  10565. }
  10566. }
  10567. return 0;
  10568. }
  10569. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  10570. if (!lua_interface)
  10571. return 0;
  10572. Spawn* spawn = lua_interface->GetSpawn(state);
  10573. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10574. lua_interface->ResetFunctionStack(state);
  10575. if (spawn && spawn->IsEntity())
  10576. {
  10577. ((Entity*)spawn)->SetSeeHideSpell(val);
  10578. if (spawn->IsPlayer())
  10579. {
  10580. Client* client = ((Player*)spawn)->GetClient();
  10581. if (client)
  10582. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  10583. }
  10584. }
  10585. return 0;
  10586. }
  10587. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  10588. {
  10589. if (!lua_interface)
  10590. return 0;
  10591. Spawn* player = lua_interface->GetSpawn(state);
  10592. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10593. string command = lua_interface->GetStringValue(state, 3);
  10594. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10595. lua_interface->ResetFunctionStack(state);
  10596. if (spawn && player && player->IsPlayer())
  10597. {
  10598. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10599. bool res = false;
  10600. if (cmd)
  10601. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  10602. lua_interface->SetBooleanValue(state, res);
  10603. return 1;
  10604. }
  10605. return 0;
  10606. }
  10607. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  10608. {
  10609. if (!lua_interface)
  10610. return 0;
  10611. Spawn* spawn = lua_interface->GetSpawn(state);
  10612. int32 charID = lua_interface->GetInt32Value(state, 2);
  10613. string command = lua_interface->GetStringValue(state, 3);
  10614. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10615. lua_interface->ResetFunctionStack(state);
  10616. if (spawn && charID)
  10617. {
  10618. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10619. bool res = false;
  10620. if (cmd)
  10621. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  10622. lua_interface->SetBooleanValue(state, res);
  10623. return 1;
  10624. }
  10625. return 0;
  10626. }
  10627. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  10628. {
  10629. if (!lua_interface)
  10630. return 0;
  10631. Spawn* spawn = lua_interface->GetSpawn(state);
  10632. string command = lua_interface->GetStringValue(state, 2);
  10633. lua_interface->ResetFunctionStack(state);
  10634. if (spawn && command.length() > 0)
  10635. spawn->RemovePrimaryEntityCommand(command.c_str());
  10636. return 0;
  10637. }
  10638. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  10639. if (!lua_interface)
  10640. return 0;
  10641. Spawn* spawn = lua_interface->GetSpawn(state);
  10642. float distance = lua_interface->GetFloatValue(state, 2);
  10643. string command = lua_interface->GetStringValue(state, 3);
  10644. Spawn* player = lua_interface->GetSpawn(state, 4);
  10645. lua_interface->ResetFunctionStack(state);
  10646. if (spawn) {
  10647. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  10648. }
  10649. return 0;
  10650. }
  10651. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  10652. if (!lua_interface)
  10653. return 0;
  10654. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10655. Spawn* spawn = lua_interface->GetSpawn(state);
  10656. Spawn* player = lua_interface->GetSpawn(state, 2);
  10657. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  10658. lua_interface->ResetFunctionStack(state);
  10659. if (spawn && player && transport_id && player->IsPlayer()) {
  10660. Client* client = 0;
  10661. if (player && player->IsPlayer())
  10662. client = ((Player*)player)->GetClient();
  10663. if (!client)
  10664. return 0;
  10665. vector<TransportDestination*> destinations;
  10666. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  10667. if (destinations.size())
  10668. {
  10669. client->SetTemporaryTransportID(transport_id);
  10670. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  10671. }
  10672. else
  10673. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  10674. }
  10675. return 0;
  10676. }
  10677. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  10678. if (!lua_interface)
  10679. return 0;
  10680. Spawn* player = lua_interface->GetSpawn(state);
  10681. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  10682. lua_interface->ResetFunctionStack(state);
  10683. if (player && player->IsPlayer()) {
  10684. Client* client = 0;
  10685. if (player && player->IsPlayer())
  10686. client = ((Player*)player)->GetClient();
  10687. if (!client)
  10688. return 0;
  10689. client->SetTemporaryTransportID(transport_id);
  10690. }
  10691. return 0;
  10692. }
  10693. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10694. if (!lua_interface)
  10695. return 0;
  10696. Spawn* player = lua_interface->GetSpawn(state);
  10697. lua_interface->ResetFunctionStack(state);
  10698. if (player && player->IsPlayer()) {
  10699. Client* client = 0;
  10700. if (player && player->IsPlayer())
  10701. client = ((Player*)player)->GetClient();
  10702. if (!client)
  10703. return 0;
  10704. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10705. return 1;
  10706. }
  10707. return 0;
  10708. }
  10709. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10710. if (!lua_interface)
  10711. return 0;
  10712. Spawn* spawn = lua_interface->GetSpawn(state);
  10713. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10714. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10715. if (!spawn) {
  10716. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10717. return 0;
  10718. }
  10719. if (!spawn->IsEntity()) {
  10720. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10721. return 0;
  10722. }
  10723. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10724. {
  10725. 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);
  10726. return 0;
  10727. }
  10728. lua_interface->ResetFunctionStack(state);
  10729. if (spell && spell->targets.size() > 0) {
  10730. ZoneServer* zone = spell->caster->GetZone();
  10731. for (int8 i = 0; i < spell->targets.size(); i++) {
  10732. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10733. if (target && target->IsEntity()) {
  10734. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10735. if (target->IsPlayer())
  10736. ((Player*)target)->SetCharSheetChanged(true);
  10737. }
  10738. }
  10739. }
  10740. else {
  10741. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10742. if (spawn->IsPlayer())
  10743. ((Player*)spawn)->SetCharSheetChanged(true);
  10744. }
  10745. return 0;
  10746. }
  10747. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10748. if (!lua_interface)
  10749. return 0;
  10750. Spawn* spawn = lua_interface->GetSpawn(state);
  10751. lua_interface->ResetFunctionStack(state);
  10752. if (!spawn) {
  10753. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10754. return 0;
  10755. }
  10756. if (!spawn->IsEntity()) {
  10757. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10758. return 0;
  10759. }
  10760. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10761. return 1;
  10762. }
  10763. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10764. if (!lua_interface)
  10765. return 0;
  10766. int32 spell_id = lua_interface->GetInt32Value(state);
  10767. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10768. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10769. if (spell_id > 0) {
  10770. if (spell_tier == 0)
  10771. spell_tier = 1;
  10772. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10773. if(!spell) {
  10774. lua_interface->LogError("%s: GetSpell: Failed, spell id %u spell tier %u does not exist.", lua_interface->GetScriptName(state), spell_id, spell_tier);
  10775. lua_interface->ResetFunctionStack(state);
  10776. return 0;
  10777. }
  10778. LuaSpell* lua_spell = 0;
  10779. if(custom_lua_script.size() > 0)
  10780. {
  10781. // attempt to load the custom script since it isn't already loaded
  10782. // we will re-obtain the lua_spell further below
  10783. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10784. {
  10785. 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());
  10786. }
  10787. }
  10788. else
  10789. custom_lua_script = spell->GetSpellData()->lua_script;
  10790. if (!lua_spell && lua_interface)
  10791. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10792. lua_interface->ResetFunctionStack(state);
  10793. if (!lua_spell)
  10794. {
  10795. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10796. return 0;
  10797. }
  10798. lua_spell->spell = new Spell(spell);
  10799. lua_interface->AddCustomSpell(lua_spell);
  10800. lua_interface->SetSpellValue(state, lua_spell);
  10801. return 1;
  10802. }
  10803. return 0;
  10804. }
  10805. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10806. if (!lua_interface)
  10807. return 0;
  10808. LuaSpell* spell = lua_interface->GetSpell(state);
  10809. string field = lua_interface->GetStringValue(state, 2);
  10810. lua_interface->ResetFunctionStack(state);
  10811. if (!spell) {
  10812. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10813. return 0;
  10814. }
  10815. if (!spell->spell || !spell->spell->GetSpellData()) {
  10816. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10817. return 0;
  10818. }
  10819. boost::to_lower(field);
  10820. return spell->spell->GetSpellData(state, field);
  10821. }
  10822. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10823. if (!lua_interface)
  10824. return 0;
  10825. LuaSpell* spell = lua_interface->GetSpell(state);
  10826. string field = lua_interface->GetStringValue(state, 2);
  10827. int8 fieldArg = 3; // field value after the initial set
  10828. if (!spell) {
  10829. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10830. lua_interface->ResetFunctionStack(state);
  10831. return 0;
  10832. }
  10833. if (!spell->spell || !spell->spell->GetSpellData()) {
  10834. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10835. lua_interface->ResetFunctionStack(state);
  10836. return 0;
  10837. }
  10838. boost::to_lower(field);
  10839. bool valSet = false;
  10840. spell->spell->SetSpellData(state, field, fieldArg);
  10841. lua_interface->ResetFunctionStack(state);
  10842. return valSet;
  10843. }
  10844. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10845. if (!lua_interface)
  10846. return 0;
  10847. LuaSpell* spell = lua_interface->GetSpell(state);
  10848. int8 idx = lua_interface->GetInt32Value(state, 2);
  10849. if (!spell) {
  10850. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10851. lua_interface->ResetFunctionStack(state);
  10852. return 0;
  10853. }
  10854. if (!spell->spell || !spell->spell->GetSpellData()) {
  10855. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10856. lua_interface->ResetFunctionStack(state);
  10857. return 0;
  10858. }
  10859. if (spell->spell->lua_data.size() <= idx)
  10860. {
  10861. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10862. lua_interface->ResetFunctionStack(state);
  10863. return 0;
  10864. }
  10865. bool setVal = true;
  10866. LUAData* data = spell->spell->lua_data[idx];
  10867. switch (data->type)
  10868. {
  10869. case 0:
  10870. {
  10871. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10872. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10873. data->int_value = value;
  10874. data->int_value2 = value2;
  10875. break;
  10876. }
  10877. case 1:
  10878. {
  10879. float value = lua_interface->GetFloatValue(state, 3);
  10880. float value2 = lua_interface->GetFloatValue(state, 4);
  10881. data->float_value = value;
  10882. data->float_value2 = value2;
  10883. break;
  10884. }
  10885. case 2:
  10886. {
  10887. bool value = lua_interface->GetBooleanValue(state, 3);
  10888. data->bool_value = value;
  10889. break;
  10890. }
  10891. case 3:
  10892. {
  10893. string value = lua_interface->GetStringValue(state, 3);
  10894. string value2 = lua_interface->GetStringValue(state, 4);
  10895. data->string_value = value;
  10896. data->string_value2 = value2;
  10897. break;
  10898. }
  10899. default:
  10900. setVal = false;
  10901. }
  10902. lua_interface->ResetFunctionStack(state);
  10903. return setVal;
  10904. }
  10905. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10906. if (!lua_interface)
  10907. return 0;
  10908. LuaSpell* spell = lua_interface->GetSpell(state);
  10909. int8 idx = lua_interface->GetInt32Value(state, 2);
  10910. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10911. lua_interface->ResetFunctionStack(state);
  10912. if (!spell) {
  10913. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10914. return 0;
  10915. }
  10916. if (!spell->spell || !spell->spell->GetSpellData()) {
  10917. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10918. return 0;
  10919. }
  10920. if (spell->spell->lua_data.size() <= idx)
  10921. {
  10922. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10923. return 0;
  10924. }
  10925. bool setVal = true;
  10926. LUAData* data = spell->spell->lua_data[idx];
  10927. switch (data->type)
  10928. {
  10929. case 0:
  10930. {
  10931. if(!secondfield)
  10932. lua_interface->SetSInt32Value(state, data->int_value);
  10933. else
  10934. lua_interface->SetSInt32Value(state, data->int_value2);
  10935. break;
  10936. }
  10937. case 1:
  10938. {
  10939. if (!secondfield)
  10940. lua_interface->SetFloatValue(state, data->float_value);
  10941. else
  10942. lua_interface->SetFloatValue(state, data->float_value2);
  10943. break;
  10944. }
  10945. case 2:
  10946. {
  10947. lua_interface->SetBooleanValue(state, data->bool_value);
  10948. break;
  10949. }
  10950. case 3:
  10951. {
  10952. if (!secondfield)
  10953. lua_interface->SetStringValue(state, data->string_value.c_str());
  10954. else
  10955. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10956. break;
  10957. }
  10958. default:
  10959. setVal = false;
  10960. }
  10961. return setVal;
  10962. }
  10963. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10964. if (!lua_interface)
  10965. return 0;
  10966. LuaSpell* spell = lua_interface->GetSpell(state);
  10967. int8 idx = lua_interface->GetInt32Value(state, 2);
  10968. string field = lua_interface->GetStringValue(state, 3);
  10969. boost::to_lower(field);
  10970. if (!spell) {
  10971. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10972. lua_interface->ResetFunctionStack(state);
  10973. return 0;
  10974. }
  10975. if (!spell->spell || !spell->spell->GetSpellData()) {
  10976. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10977. lua_interface->ResetFunctionStack(state);
  10978. return 0;
  10979. }
  10980. if (spell->spell->effects.size() <= idx)
  10981. {
  10982. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10983. lua_interface->ResetFunctionStack(state);
  10984. return 0;
  10985. }
  10986. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10987. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10988. if (field == "description")
  10989. effect->description = string(lua_interface->GetStringValue(state, 4));
  10990. else if (field == "bullet")
  10991. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10992. else if (field == "percentage")
  10993. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10994. else { // no match
  10995. lua_interface->ResetFunctionStack(state);
  10996. return 0;
  10997. }
  10998. lua_interface->ResetFunctionStack(state);
  10999. return 1;
  11000. }
  11001. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  11002. if (!lua_interface)
  11003. return 0;
  11004. LuaSpell* spell = lua_interface->GetSpell(state);
  11005. int8 idx = lua_interface->GetInt32Value(state, 2);
  11006. string field = lua_interface->GetStringValue(state, 3);
  11007. lua_interface->ResetFunctionStack(state);
  11008. boost::to_lower(field);
  11009. if (!spell) {
  11010. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  11011. return 0;
  11012. }
  11013. if (!spell->spell || !spell->spell->GetSpellData()) {
  11014. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  11015. return 0;
  11016. }
  11017. if (spell->spell->effects.size() <= idx)
  11018. {
  11019. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  11020. return 0;
  11021. }
  11022. // do we need to lock? eh probably not this should only be used before use of the custom spell
  11023. SpellDisplayEffect* effect = spell->spell->effects[idx];
  11024. if (field == "description")
  11025. lua_interface->SetStringValue(state, effect->description.c_str());
  11026. else if (field == "bullet")
  11027. lua_interface->SetInt32Value(state, effect->subbullet);
  11028. else if (field == "percentage")
  11029. lua_interface->SetInt32Value(state, effect->percentage);
  11030. else // no match
  11031. return 0;
  11032. return 1;
  11033. }
  11034. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  11035. if (!lua_interface)
  11036. return 0;
  11037. LuaSpell* spell = lua_interface->GetSpell(state);
  11038. Spawn* caster = lua_interface->GetSpawn(state, 2);
  11039. Spawn* target = lua_interface->GetSpawn(state, 3);
  11040. lua_interface->ResetFunctionStack(state);
  11041. if (!target) {
  11042. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  11043. return 0;
  11044. }
  11045. if (!target->IsEntity()) {
  11046. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  11047. return 0;
  11048. }
  11049. if (!spell) {
  11050. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  11051. return 0;
  11052. }
  11053. if (caster && !caster->IsEntity()) {
  11054. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  11055. return 0;
  11056. }
  11057. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  11058. return 0;
  11059. }
  11060. int EQ2Emu_lua_InWater(lua_State* state) {
  11061. if (!lua_interface)
  11062. return 0;
  11063. Spawn* spawn = lua_interface->GetSpawn(state);
  11064. lua_interface->ResetFunctionStack(state);
  11065. if (spawn) {
  11066. lua_interface->SetBooleanValue(state, spawn->InWater());
  11067. return 1;
  11068. }
  11069. return 0;
  11070. }
  11071. int EQ2Emu_lua_InLava(lua_State* state) {
  11072. if (!lua_interface)
  11073. return 0;
  11074. Spawn* spawn = lua_interface->GetSpawn(state);
  11075. lua_interface->ResetFunctionStack(state);
  11076. if (spawn) {
  11077. lua_interface->SetBooleanValue(state, spawn->InLava());
  11078. return 1;
  11079. }
  11080. return 0;
  11081. }
  11082. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  11083. if (!lua_interface)
  11084. return 0;
  11085. Spawn* attacker = lua_interface->GetSpawn(state);
  11086. Spawn* victim = lua_interface->GetSpawn(state, 2);
  11087. int8 type = lua_interface->GetInt8Value(state, 3);
  11088. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  11089. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  11090. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  11091. string spell_name = lua_interface->GetStringValue(state, 7);
  11092. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  11093. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  11094. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  11095. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  11096. bool take_power = (lua_interface->GetInt8Value(state, 12) == 1);
  11097. lua_interface->ResetFunctionStack(state);
  11098. if (!attacker) {
  11099. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  11100. lua_interface->SetBooleanValue(state, false);
  11101. return 1;
  11102. }
  11103. if (!attacker->IsEntity()) {
  11104. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  11105. lua_interface->SetBooleanValue(state, false);
  11106. return 1;
  11107. }
  11108. if (!victim) {
  11109. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  11110. lua_interface->SetBooleanValue(state, false);
  11111. return 1;
  11112. }
  11113. if (!victim->IsEntity()) {
  11114. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  11115. lua_interface->SetBooleanValue(state, false);
  11116. return 1;
  11117. }
  11118. bool has_damaged = ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker, take_power);
  11119. lua_interface->SetBooleanValue(state, has_damaged);
  11120. return 1;
  11121. }
  11122. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  11123. if (!lua_interface)
  11124. return 0;
  11125. Spawn* spawn = lua_interface->GetSpawn(state);
  11126. lua_interface->ResetFunctionStack(state);
  11127. if (spawn) {
  11128. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  11129. return 1;
  11130. }
  11131. return 0;
  11132. }
  11133. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  11134. if (!lua_interface)
  11135. return 0;
  11136. Spawn* spawn = lua_interface->GetSpawn(state);
  11137. bool invul = lua_interface->GetBooleanValue(state, 2);
  11138. lua_interface->ResetFunctionStack(state);
  11139. if (spawn) {
  11140. spawn->SetInvulnerable(invul);
  11141. }
  11142. return 0;
  11143. }
  11144. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  11145. if (!lua_interface)
  11146. return 0;
  11147. string category = lua_interface->GetStringValue(state);
  11148. string name = lua_interface->GetStringValue(state, 2);
  11149. lua_interface->ResetFunctionStack(state);
  11150. Rule *ret = 0;
  11151. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11152. lua_interface->SetBooleanValue(state, ret->GetBool());
  11153. return 1;
  11154. }
  11155. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11156. return 0;
  11157. }
  11158. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  11159. if (!lua_interface)
  11160. return 0;
  11161. string category = lua_interface->GetStringValue(state);
  11162. string name = lua_interface->GetStringValue(state, 2);
  11163. lua_interface->ResetFunctionStack(state);
  11164. Rule *ret = 0;
  11165. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11166. lua_interface->SetInt32Value(state, ret->GetInt32());
  11167. return 1;
  11168. }
  11169. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11170. return 0;
  11171. }
  11172. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  11173. if (!lua_interface)
  11174. return 0;
  11175. string category = lua_interface->GetStringValue(state);
  11176. string name = lua_interface->GetStringValue(state, 2);
  11177. lua_interface->ResetFunctionStack(state);
  11178. Rule *ret = 0;
  11179. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11180. lua_interface->SetFloatValue(state, ret->GetFloat());
  11181. return 1;
  11182. }
  11183. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11184. return 0;
  11185. }
  11186. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  11187. if (!lua_interface)
  11188. return 0;
  11189. Spawn* spawn = lua_interface->GetSpawn(state);
  11190. string type = lua_interface->GetStringValue(state, 2);
  11191. lua_interface->ResetFunctionStack(state);
  11192. if (spawn) {
  11193. int res = 1;
  11194. boost::to_lower(type);
  11195. if(type == "assigned_aa")
  11196. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  11197. else if ( type == "unassigned_aa")
  11198. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  11199. else if ( type == "assigned_tradeskill_aa")
  11200. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  11201. else if ( type == "unassigned_tradeskill_aa")
  11202. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  11203. else if ( type == "assigned_prestige_aa")
  11204. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  11205. else if ( type == "unassigned_prestige_aa")
  11206. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  11207. else if ( type == "assigned_tradeskill_prestige_aa")
  11208. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  11209. else if ( type == "unassigned_tradeskill_prestige_aa")
  11210. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  11211. else
  11212. res = 0;
  11213. return res;
  11214. }
  11215. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  11216. return 0;
  11217. }
  11218. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  11219. if (!lua_interface)
  11220. return 0;
  11221. Spawn* spawn = lua_interface->GetSpawn(state);
  11222. string type = lua_interface->GetStringValue(state, 2);
  11223. sint32 value = lua_interface->GetSInt32Value(state, 3);
  11224. lua_interface->ResetFunctionStack(state);
  11225. if (spawn) {
  11226. boost::to_lower(type);
  11227. if(type == "assigned_aa")
  11228. spawn->SetAssignedAA((sint16)value);
  11229. else if ( type == "unassigned_aa")
  11230. spawn->SetUnassignedAA((sint16)value);
  11231. else if ( type == "assigned_tradeskill_aa")
  11232. spawn->SetTradeskillAA((sint16)value);
  11233. else if ( type == "unassigned_tradeskill_aa")
  11234. spawn->SetUnassignedTradeskillAA((sint16)value);
  11235. else if ( type == "assigned_prestige_aa")
  11236. spawn->SetPrestigeAA((sint16)value);
  11237. else if ( type == "unassigned_prestige_aa")
  11238. spawn->SetUnassignedPrestigeAA((sint16)value);
  11239. else if ( type == "assigned_tradeskill_prestige_aa")
  11240. spawn->SetTradeskillPrestigeAA((sint16)value);
  11241. else if ( type == "unassigned_tradeskill_prestige_aa")
  11242. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  11243. if(spawn->IsPlayer())
  11244. ((Player*)spawn)->SetCharSheetChanged(true);
  11245. }
  11246. return 0;
  11247. }
  11248. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  11249. if (!lua_interface)
  11250. return 0;
  11251. string titleName = lua_interface->GetStringValue(state);
  11252. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  11253. lua_interface->ResetFunctionStack(state);
  11254. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  11255. lua_interface->SetSInt32Value(state, index);
  11256. return 1;
  11257. }
  11258. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  11259. if (!lua_interface)
  11260. return 0;
  11261. Spawn* spawn = lua_interface->GetSpawn(state);
  11262. string titleName = lua_interface->GetStringValue(state, 2);
  11263. lua_interface->ResetFunctionStack(state);
  11264. if(!spawn->IsPlayer())
  11265. {
  11266. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  11267. lua_interface->SetSInt32Value(state, -1);
  11268. return 1;
  11269. }
  11270. Player* player = (Player*)spawn;
  11271. // check if player already has the title, don't need to add twice
  11272. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11273. if ( playerHasTitle)
  11274. {
  11275. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  11276. return 1;
  11277. }
  11278. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  11279. if(!title)
  11280. {
  11281. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11282. lua_interface->SetSInt32Value(state, -1);
  11283. return 1;
  11284. }
  11285. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  11286. if(returnIdx < 0)
  11287. {
  11288. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11289. }
  11290. lua_interface->SetSInt32Value(state, returnIdx);
  11291. player->GetClient()->SendTitleUpdate();
  11292. return 1;
  11293. }
  11294. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  11295. if (!lua_interface)
  11296. return 0;
  11297. Spawn* spawn = lua_interface->GetSpawn(state);
  11298. string titleName = lua_interface->GetStringValue(state, 2);
  11299. lua_interface->ResetFunctionStack(state);
  11300. if(!spawn->IsPlayer())
  11301. {
  11302. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11303. return 0;
  11304. }
  11305. Player* player = (Player*)spawn;
  11306. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11307. if(!title)
  11308. {
  11309. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11310. return 0;
  11311. }
  11312. if(title->GetPrefix())
  11313. {
  11314. 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());
  11315. return 0;
  11316. }
  11317. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  11318. player->GetClient()->SendTitleUpdate();
  11319. return 1;
  11320. }
  11321. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  11322. if (!lua_interface)
  11323. return 0;
  11324. Spawn* spawn = lua_interface->GetSpawn(state);
  11325. string titleName = lua_interface->GetStringValue(state, 2);
  11326. lua_interface->ResetFunctionStack(state);
  11327. if(!spawn->IsPlayer())
  11328. {
  11329. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11330. return 0;
  11331. }
  11332. Player* player = (Player*)spawn;
  11333. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11334. if(!title)
  11335. {
  11336. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11337. return 0;
  11338. }
  11339. if(!title->GetPrefix())
  11340. {
  11341. 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());
  11342. return 0;
  11343. }
  11344. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  11345. player->GetClient()->SendTitleUpdate();
  11346. return 1;
  11347. }
  11348. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  11349. if (!lua_interface)
  11350. return 0;
  11351. Spawn* spawn = lua_interface->GetSpawn(state);
  11352. lua_interface->ResetFunctionStack(state);
  11353. if(!spawn)
  11354. {
  11355. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: spawn is null", lua_interface->GetScriptName(state));
  11356. return 0;
  11357. }
  11358. if(!spawn->IsPlayer())
  11359. {
  11360. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11361. return 0;
  11362. }
  11363. Player* player = (Player*)spawn;
  11364. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  11365. player->GetClient()->SendTitleUpdate();
  11366. return 1;
  11367. }
  11368. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  11369. if (!lua_interface)
  11370. return 0;
  11371. Spawn* spawn = lua_interface->GetSpawn(state);
  11372. lua_interface->ResetFunctionStack(state);
  11373. if(!spawn)
  11374. {
  11375. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: spawn is null", lua_interface->GetScriptName(state));
  11376. return 0;
  11377. }
  11378. if(!spawn->IsPlayer())
  11379. {
  11380. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11381. return 0;
  11382. }
  11383. Player* player = (Player*)spawn;
  11384. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  11385. player->GetClient()->SendTitleUpdate();
  11386. return 1;
  11387. }
  11388. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  11389. if (!lua_interface)
  11390. return 0;
  11391. Spawn* spawn = lua_interface->GetSpawn(state);
  11392. string field = lua_interface->GetStringValue(state, 2);
  11393. lua_interface->ResetFunctionStack(state);
  11394. if(!spawn || !spawn->IsEntity())
  11395. {
  11396. 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));
  11397. return 0;
  11398. }
  11399. Entity* ent = (Entity*)spawn;
  11400. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  11401. return 1;
  11402. }
  11403. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  11404. if (!lua_interface)
  11405. return 0;
  11406. Spawn* spawn = lua_interface->GetSpawn(state);
  11407. string field = lua_interface->GetStringValue(state, 2);
  11408. lua_interface->ResetFunctionStack(state);
  11409. if(!spawn || !spawn->IsEntity())
  11410. {
  11411. 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));
  11412. return 0;
  11413. }
  11414. Entity* ent = (Entity*)spawn;
  11415. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  11416. return 1;
  11417. }
  11418. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  11419. if (!lua_interface)
  11420. return 0;
  11421. Spawn* spawn = lua_interface->GetSpawn(state);
  11422. string field = lua_interface->GetStringValue(state, 2);
  11423. lua_interface->ResetFunctionStack(state);
  11424. if(!spawn || !spawn->IsEntity())
  11425. {
  11426. 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));
  11427. return 0;
  11428. }
  11429. Entity* ent = (Entity*)spawn;
  11430. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  11431. return 1;
  11432. }
  11433. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  11434. if (!lua_interface)
  11435. return 0;
  11436. Spawn* spawn = lua_interface->GetSpawn(state);
  11437. string field = lua_interface->GetStringValue(state, 2);
  11438. lua_interface->ResetFunctionStack(state);
  11439. if(!spawn || !spawn->IsEntity())
  11440. {
  11441. 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));
  11442. return 0;
  11443. }
  11444. Entity* ent = (Entity*)spawn;
  11445. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  11446. return 1;
  11447. }
  11448. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  11449. if (!lua_interface)
  11450. return 0;
  11451. Spawn* spawn = lua_interface->GetSpawn(state);
  11452. string field = lua_interface->GetStringValue(state, 2);
  11453. string value = lua_interface->GetStringValue(state, 3);
  11454. lua_interface->ResetFunctionStack(state);
  11455. if(!spawn || !spawn->IsEntity())
  11456. {
  11457. 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));
  11458. return 0;
  11459. }
  11460. Entity* ent = (Entity*)spawn;
  11461. bool set_ = ent->SetInfoStructString(field, value);
  11462. lua_interface->SetBooleanValue(state, set_);
  11463. return 1;
  11464. }
  11465. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  11466. if (!lua_interface)
  11467. return 0;
  11468. Spawn* spawn = lua_interface->GetSpawn(state);
  11469. string field = lua_interface->GetStringValue(state, 2);
  11470. int64 value = lua_interface->GetInt64Value(state, 3);
  11471. lua_interface->ResetFunctionStack(state);
  11472. if(!spawn || !spawn->IsEntity())
  11473. {
  11474. 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));
  11475. return 0;
  11476. }
  11477. Entity* ent = (Entity*)spawn;
  11478. bool set_ = ent->SetInfoStructUInt(field, value);
  11479. lua_interface->SetBooleanValue(state, set_);
  11480. return 1;
  11481. }
  11482. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  11483. if (!lua_interface)
  11484. return 0;
  11485. Spawn* spawn = lua_interface->GetSpawn(state);
  11486. string field = lua_interface->GetStringValue(state, 2);
  11487. sint64 value = lua_interface->GetSInt64Value(state, 3);
  11488. lua_interface->ResetFunctionStack(state);
  11489. if(!spawn || !spawn->IsEntity())
  11490. {
  11491. 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));
  11492. return 0;
  11493. }
  11494. Entity* ent = (Entity*)spawn;
  11495. bool set_ = ent->SetInfoStructSInt(field, value);
  11496. lua_interface->SetBooleanValue(state, set_);
  11497. return 1;
  11498. }
  11499. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  11500. if (!lua_interface)
  11501. return 0;
  11502. Spawn* spawn = lua_interface->GetSpawn(state);
  11503. string field = lua_interface->GetStringValue(state, 2);
  11504. float value = lua_interface->GetFloatValue(state, 3);
  11505. lua_interface->ResetFunctionStack(state);
  11506. if(!spawn || !spawn->IsEntity())
  11507. {
  11508. 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));
  11509. return 0;
  11510. }
  11511. Entity* ent = (Entity*)spawn;
  11512. bool set_ = ent->SetInfoStructFloat(field, value);
  11513. lua_interface->SetBooleanValue(state, set_);
  11514. return 1;
  11515. }
  11516. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  11517. if (!lua_interface)
  11518. return 0;
  11519. Spawn* spawn = lua_interface->GetSpawn(state);
  11520. bool value = lua_interface->GetBooleanValue(state, 2);
  11521. lua_interface->ResetFunctionStack(state);
  11522. if(!spawn || !spawn->IsPlayer())
  11523. {
  11524. 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));
  11525. return 0;
  11526. }
  11527. ((Player*)spawn)->SetCharSheetChanged(value);
  11528. return 0;
  11529. }
  11530. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  11531. if (!lua_interface)
  11532. return 0;
  11533. Spawn* spawn = lua_interface->GetSpawn(state);
  11534. std::string fromName = lua_interface->GetStringValue(state, 2);
  11535. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11536. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11537. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11538. int32 copper = lua_interface->GetInt32Value(state, 6);
  11539. int32 silver = lua_interface->GetInt32Value(state, 7);
  11540. int32 gold = lua_interface->GetInt32Value(state, 8);
  11541. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11542. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11543. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11544. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11545. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11546. lua_interface->ResetFunctionStack(state);
  11547. if(!spawn || !spawn->IsPlayer())
  11548. {
  11549. 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));
  11550. lua_interface->SetBooleanValue(state, false);
  11551. return 1;
  11552. }
  11553. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11554. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11555. lua_interface->SetBooleanValue(state, true);
  11556. return 1;
  11557. }
  11558. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  11559. if (!lua_interface)
  11560. return 0;
  11561. int32 char_id = lua_interface->GetInt32Value(state);
  11562. std::string fromName = lua_interface->GetStringValue(state, 2);
  11563. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11564. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11565. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11566. int32 copper = lua_interface->GetInt32Value(state, 6);
  11567. int32 silver = lua_interface->GetInt32Value(state, 7);
  11568. int32 gold = lua_interface->GetInt32Value(state, 8);
  11569. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11570. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11571. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11572. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11573. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11574. lua_interface->ResetFunctionStack(state);
  11575. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11576. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11577. lua_interface->SetBooleanValue(state, true);
  11578. return 1;
  11579. }
  11580. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  11581. Spawn* widget;
  11582. if (lua_interface) {
  11583. widget = lua_interface->GetSpawn(state);
  11584. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  11585. lua_interface->ResetFunctionStack(state);
  11586. if (widget && widget->IsWidget())
  11587. {
  11588. ((Widget*)widget)->OpenDoor();
  11589. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  11590. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11591. }
  11592. else
  11593. 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));
  11594. }
  11595. return 0;
  11596. }
  11597. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  11598. Spawn* widget;
  11599. if (lua_interface) {
  11600. widget = lua_interface->GetSpawn(state);
  11601. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  11602. lua_interface->ResetFunctionStack(state);
  11603. if (widget && widget->IsWidget())
  11604. {
  11605. ((Widget*)widget)->CloseDoor();
  11606. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  11607. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11608. }
  11609. else
  11610. 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));
  11611. }
  11612. return 0;
  11613. }
  11614. int EQ2Emu_lua_IsOpen(lua_State* state) {
  11615. if (!lua_interface)
  11616. return 0;
  11617. Spawn* widget = lua_interface->GetSpawn(state);
  11618. lua_interface->ResetFunctionStack(state);
  11619. if (widget && widget->IsWidget())
  11620. {
  11621. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  11622. return 1;
  11623. }
  11624. return 0;
  11625. }
  11626. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  11627. if (!lua_interface)
  11628. return 0;
  11629. sint32 min = lua_interface->GetSInt32Value(state);
  11630. sint32 max = lua_interface->GetSInt32Value(state, 2);
  11631. lua_interface->ResetFunctionStack(state);
  11632. sint32 result = MakeRandomInt(min, max);
  11633. lua_interface->SetSInt32Value(state, result);
  11634. return 1;
  11635. }
  11636. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  11637. if (!lua_interface)
  11638. return 0;
  11639. float min = lua_interface->GetFloatValue(state);
  11640. float max = lua_interface->GetFloatValue(state, 2);
  11641. lua_interface->ResetFunctionStack(state);
  11642. float result = MakeRandomFloat(min, max);
  11643. lua_interface->SetFloatValue(state, result);
  11644. return 1;
  11645. }
  11646. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  11647. if (!lua_interface)
  11648. return 0;
  11649. Spawn* spawn = lua_interface->GetSpawn(state);
  11650. int32 value = lua_interface->GetInt32Value(state, 2);
  11651. lua_interface->ResetFunctionStack(state);
  11652. if(!spawn)
  11653. {
  11654. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11655. lua_interface->SetBooleanValue(state, false);
  11656. return 1;
  11657. }
  11658. spawn->AddIconValue(value);
  11659. lua_interface->SetBooleanValue(state, true);
  11660. return 1;
  11661. }
  11662. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  11663. if (!lua_interface)
  11664. return 0;
  11665. Spawn* spawn = lua_interface->GetSpawn(state);
  11666. int32 value = lua_interface->GetInt32Value(state, 2);
  11667. lua_interface->ResetFunctionStack(state);
  11668. if(!spawn)
  11669. {
  11670. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11671. lua_interface->SetBooleanValue(state, false);
  11672. return 1;
  11673. }
  11674. spawn->RemoveIconValue(value);
  11675. lua_interface->SetBooleanValue(state, true);
  11676. return 1;
  11677. }
  11678. int EQ2Emu_lua_GetShardID(lua_State* state) {
  11679. Spawn* npc = lua_interface->GetSpawn(state);
  11680. lua_interface->ResetFunctionStack(state);
  11681. if (npc && npc->IsNPC()) {
  11682. NPC* shard = (NPC*)npc;
  11683. int32 shardid = shard->GetShardID();
  11684. lua_interface->SetInt32Value(state, shardid);
  11685. return 1;
  11686. }
  11687. lua_interface->SetInt32Value(state, 0);
  11688. return 1;
  11689. }
  11690. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  11691. Spawn* npc = lua_interface->GetSpawn(state);
  11692. lua_interface->ResetFunctionStack(state);
  11693. if (npc && npc->IsNPC()) {
  11694. NPC* shard = (NPC*)npc;
  11695. int32 charid = shard->GetShardCharID();
  11696. lua_interface->SetInt32Value(state, charid);
  11697. return 1;
  11698. }
  11699. lua_interface->SetInt32Value(state, 0);
  11700. return 1;
  11701. }
  11702. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  11703. Spawn* npc = lua_interface->GetSpawn(state);
  11704. lua_interface->ResetFunctionStack(state);
  11705. if (npc && npc->IsNPC()) {
  11706. NPC* shard = (NPC*)npc;
  11707. int64 timestamp = shard->GetShardCreatedTimestamp();
  11708. lua_interface->SetSInt64Value(state, timestamp);
  11709. return 1;
  11710. }
  11711. lua_interface->SetSInt64Value(state, 0);
  11712. return 1;
  11713. }
  11714. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  11715. if (!lua_interface)
  11716. return 0;
  11717. int32 shardid = lua_interface->GetInt32Value(state);
  11718. lua_interface->ResetFunctionStack(state);
  11719. if(shardid < 1)
  11720. lua_interface->SetBooleanValue(state, false);
  11721. else
  11722. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  11723. return 1;
  11724. }
  11725. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  11726. if (!lua_interface)
  11727. return 0;
  11728. Spawn* spawn = lua_interface->GetSpawn(state);
  11729. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11730. if (spawn) {
  11731. spawn->PauseMovement(delay_in_ms);
  11732. }
  11733. lua_interface->ResetFunctionStack(state);
  11734. return 0;
  11735. }
  11736. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11737. if (!lua_interface)
  11738. return 0;
  11739. Spawn* spawn = lua_interface->GetSpawn(state);
  11740. if (spawn) {
  11741. spawn->ResetMovement();
  11742. }
  11743. lua_interface->ResetFunctionStack(state);
  11744. return 0;
  11745. }
  11746. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11747. Player* player = (Player*)lua_interface->GetSpawn(state);
  11748. int8 level = lua_interface->GetInt8Value(state, 2);
  11749. lua_interface->ResetFunctionStack(state);
  11750. if (player && player->IsPlayer() && level > 0) {
  11751. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11752. return 1;
  11753. }
  11754. return 0;
  11755. }
  11756. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11757. Player* player = (Player*)lua_interface->GetSpawn(state);
  11758. int8 level = lua_interface->GetInt8Value(state, 2);
  11759. lua_interface->ResetFunctionStack(state);
  11760. if (player && player->IsPlayer() && level > 0) {
  11761. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11762. return 1;
  11763. }
  11764. return 0;
  11765. }
  11766. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11767. ZoneServer* zone = lua_interface->GetZone(state);
  11768. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11769. lua_interface->ResetFunctionStack(state);
  11770. if (zone) {
  11771. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11772. if (spawn) {
  11773. lua_interface->SetSpawnValue(state, spawn);
  11774. return 1;
  11775. }
  11776. }
  11777. return 0;
  11778. }
  11779. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11780. if (!lua_interface)
  11781. return 0;
  11782. Spawn* spawn = lua_interface->GetSpawn(state);
  11783. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11784. lua_interface->ResetFunctionStack(state);
  11785. bool res = false;
  11786. if(spawn && spawn->IsTransportSpawn())
  11787. {
  11788. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11789. spawn->SetRailID(rail_id);
  11790. res = true;
  11791. }
  11792. else if (!spawn) {
  11793. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11794. }
  11795. else if(!spawn->IsTransportSpawn()) {
  11796. 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());
  11797. }
  11798. lua_interface->SetBooleanValue(state, res);
  11799. return 1;
  11800. }
  11801. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11802. if (!lua_interface)
  11803. return 0;
  11804. ZoneServer* zone = lua_interface->GetZone(state);
  11805. lua_interface->ResetFunctionStack(state);
  11806. if (zone) {
  11807. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11808. return 1;
  11809. }
  11810. return 0;
  11811. }
  11812. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11813. if (!lua_interface)
  11814. return 0;
  11815. Spawn* spawn = lua_interface->GetSpawn(state);
  11816. lua_interface->ResetFunctionStack(state);
  11817. if (spawn) {
  11818. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11819. return 1;
  11820. }
  11821. return 0;
  11822. }
  11823. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11824. if (!lua_interface)
  11825. return 0;
  11826. Spawn* player = lua_interface->GetSpawn(state);
  11827. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11828. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11829. lua_interface->ResetFunctionStack(state);
  11830. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11831. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11832. }
  11833. else if(!zoneID) {
  11834. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11835. }
  11836. else
  11837. {
  11838. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11839. return 1;
  11840. }
  11841. return 0;
  11842. }
  11843. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11844. if (!lua_interface)
  11845. return 0;
  11846. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11847. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11848. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11849. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11850. lua_interface->ResetFunctionStack(state);
  11851. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11852. world.GetWorldTimeStruct()->year = newYear;
  11853. world.GetWorldTimeStruct()->month = newMonth;
  11854. world.GetWorldTimeStruct()->hour = newHour;
  11855. world.GetWorldTimeStruct()->minute = newMinute;
  11856. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11857. return 0;
  11858. }
  11859. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11860. if (!lua_interface)
  11861. return 0;
  11862. lua_interface->ResetFunctionStack(state);
  11863. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11864. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11865. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11866. return 1;
  11867. }
  11868. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11869. if (!lua_interface)
  11870. return 0;
  11871. lua_interface->ResetFunctionStack(state);
  11872. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11873. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11874. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11875. return 1;
  11876. }
  11877. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11878. if (!lua_interface)
  11879. return 0;
  11880. lua_interface->ResetFunctionStack(state);
  11881. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11882. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11883. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11884. return 1;
  11885. }
  11886. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11887. if (!lua_interface)
  11888. return 0;
  11889. lua_interface->ResetFunctionStack(state);
  11890. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11891. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11892. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11893. return 1;
  11894. }
  11895. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11896. if (!lua_interface)
  11897. return 0;
  11898. lua_interface->ResetFunctionStack(state);
  11899. world.SendTimeUpdate();
  11900. return 0;
  11901. }
  11902. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11903. bool update_result = false;
  11904. Faction* faction = 0;
  11905. Spawn* spawn = lua_interface->GetSpawn(state);
  11906. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11907. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11908. lua_interface->ResetFunctionStack(state);
  11909. if(!spawn || !spawn->IsPlayer()) {
  11910. lua_interface->LogError("LUA ChangeFaction command error: player is not valid");
  11911. return 0;
  11912. }
  11913. Player* player = (Player*)spawn;
  11914. Client* client = player->GetClient();
  11915. if (faction_id > 0) {
  11916. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11917. if(hasfaction == 0) {
  11918. //they do not have the faction. Lets get the default value and feed it in.
  11919. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11920. //add the default faction for the player.
  11921. player->SetFactionValue(faction_id, defaultfaction);
  11922. }
  11923. if(increase >= 0) {
  11924. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11925. faction = master_faction_list.GetFaction(faction_id);
  11926. if(faction && update_result)
  11927. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11928. else if(faction)
  11929. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11930. lua_interface->SetBooleanValue(state, true);
  11931. return 1;
  11932. }
  11933. if(increase < 0){
  11934. //change the negative to a positive, since thats how decreasefaction() likes it.
  11935. increase *= -1;
  11936. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11937. faction = master_faction_list.GetFaction(faction_id);
  11938. if(faction && update_result)
  11939. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11940. else if(faction)
  11941. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11942. lua_interface->SetBooleanValue(state, true);
  11943. return 1;
  11944. }
  11945. }
  11946. lua_interface->SetBooleanValue(state, false);
  11947. return 1;
  11948. }
  11949. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11950. bool hascoin = 0;
  11951. Spawn* player = lua_interface->GetSpawn(state);
  11952. int32 coins = lua_interface->GetInt32Value(state, 2);
  11953. lua_interface->ResetFunctionStack(state);
  11954. if (player && player->IsPlayer()) {
  11955. hascoin = ((Player*)player)->HasCoins(coins);
  11956. if(hascoin == 0) {
  11957. lua_interface->SetBooleanValue(state, false);
  11958. return 1;
  11959. }
  11960. if(hascoin == 1) {
  11961. lua_interface->SetBooleanValue(state, true);
  11962. return 1;
  11963. }
  11964. }
  11965. return 0;
  11966. }
  11967. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11968. int32 loot_tier = 0;
  11969. Spawn* spawn = lua_interface->GetSpawn(state);
  11970. lua_interface->ResetFunctionStack(state);
  11971. if (spawn) {
  11972. loot_tier = spawn->GetLootTier();
  11973. lua_interface->SetInt32Value(state, loot_tier);
  11974. return 1;
  11975. }
  11976. return 0;
  11977. }
  11978. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11979. if (!lua_interface)
  11980. return 0;
  11981. Spawn* spawn = lua_interface->GetSpawn(state);
  11982. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11983. lua_interface->ResetFunctionStack(state);
  11984. if (spawn) {
  11985. spawn->SetLootTier(loot_tier);
  11986. lua_interface->SetBooleanValue(state, true);
  11987. return 1;
  11988. }
  11989. lua_interface->SetBooleanValue(state, false);
  11990. return 1;
  11991. }
  11992. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11993. int32 loot_drop_type = 0;
  11994. Spawn* spawn = lua_interface->GetSpawn(state);
  11995. lua_interface->ResetFunctionStack(state);
  11996. if (spawn) {
  11997. loot_drop_type = spawn->GetLootDropType();
  11998. lua_interface->SetInt32Value(state, loot_drop_type);
  11999. return 1;
  12000. }
  12001. return 0;
  12002. }
  12003. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  12004. if (!lua_interface)
  12005. return 0;
  12006. Spawn* spawn = lua_interface->GetSpawn(state);
  12007. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  12008. lua_interface->ResetFunctionStack(state);
  12009. if (spawn) {
  12010. spawn->SetLootDropType(loot_drop_type);
  12011. lua_interface->SetBooleanValue(state, true);
  12012. return 1;
  12013. }
  12014. lua_interface->SetBooleanValue(state, false);
  12015. return 1;
  12016. }
  12017. int EQ2Emu_lua_DamageEquippedItems(lua_State* state) {
  12018. if (!lua_interface)
  12019. return 0;
  12020. Spawn* spawn = lua_interface->GetSpawn(state);
  12021. int8 damage_amount = lua_interface->GetInt32Value(state, 2);
  12022. if(damage_amount > 100) {
  12023. damage_amount = 100;
  12024. }
  12025. if (!spawn) {
  12026. lua_interface->LogError("%s: LUA DamageEquippedItems command error: spawn is not valid", lua_interface->GetScriptName(state));
  12027. lua_interface->ResetFunctionStack(state);
  12028. return 0;
  12029. }
  12030. lua_interface->ResetFunctionStack(state);
  12031. if (spawn->IsPlayer()) {
  12032. if (((Player*)spawn)->GetClient() && ((Player*)spawn)->DamageEquippedItems(damage_amount, ((Player*)spawn)->GetClient()))
  12033. lua_interface->SetBooleanValue(state, true);
  12034. else
  12035. lua_interface->SetBooleanValue(state, false);
  12036. }
  12037. else {
  12038. lua_interface->SetBooleanValue(state, false);
  12039. }
  12040. return 1;
  12041. }
  12042. int EQ2Emu_lua_CreateWidgetRegion(lua_State* state) {
  12043. ZoneServer* zone = lua_interface->GetZone(state);
  12044. int32 version = lua_interface->GetInt32Value(state, 2);
  12045. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  12046. if(region_map == nullptr) {
  12047. lua_interface->LogError("%s: LUA CreateWidgetRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  12048. lua_interface->ResetFunctionStack(state);
  12049. return 0;
  12050. }
  12051. string region_name = lua_interface->GetStringValue(state, 3);
  12052. string env_name = lua_interface->GetStringValue(state, 4);
  12053. int32 grid_id = lua_interface->GetInt32Value(state, 5);
  12054. int32 widget_id = lua_interface->GetInt32Value(state, 6);
  12055. float dist = lua_interface->GetFloatValue(state, 7);
  12056. region_map->InsertRegionNode(zone, version, region_name, env_name, grid_id, widget_id, dist);
  12057. lua_interface->ResetFunctionStack(state);
  12058. lua_interface->SetBooleanValue(state, true);
  12059. return 1;
  12060. }
  12061. int EQ2Emu_lua_RemoveRegion(lua_State* state) {
  12062. ZoneServer* zone = lua_interface->GetZone(state);
  12063. int32 version = lua_interface->GetInt32Value(state, 2);
  12064. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  12065. if(region_map == nullptr) {
  12066. lua_interface->LogError("%s: LUA RemoveRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  12067. lua_interface->ResetFunctionStack(state);
  12068. return 0;
  12069. }
  12070. string region_name = lua_interface->GetStringValue(state, 3);
  12071. region_map->RemoveRegionNode(region_name);
  12072. lua_interface->ResetFunctionStack(state);
  12073. lua_interface->SetBooleanValue(state, true);
  12074. return 1;
  12075. }
  12076. int EQ2Emu_lua_SetPlayerPOVGhost(lua_State* state) {
  12077. Client* client = nullptr;
  12078. Spawn* player = lua_interface->GetSpawn(state);
  12079. if (!player) {
  12080. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not valid");
  12081. lua_interface->SetBooleanValue(state, false);
  12082. lua_interface->ResetFunctionStack(state);
  12083. return 1;
  12084. }
  12085. if (!player->IsPlayer()) {
  12086. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
  12087. lua_interface->SetBooleanValue(state, false);
  12088. lua_interface->ResetFunctionStack(state);
  12089. return 1;
  12090. }
  12091. client = player->GetClient();
  12092. if (!client) {
  12093. lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
  12094. lua_interface->SetBooleanValue(state, false);
  12095. lua_interface->ResetFunctionStack(state);
  12096. return 1;
  12097. }
  12098. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  12099. bool success_sight = client->SetPlayerPOVGhost(spawn);
  12100. lua_interface->ResetFunctionStack(state);
  12101. lua_interface->SetBooleanValue(state, success_sight);
  12102. return 1;
  12103. }
  12104. int EQ2Emu_lua_SetCastOnAggroComplete(lua_State* state) {
  12105. if (!lua_interface)
  12106. return 0;
  12107. bool result = false;
  12108. Spawn* spawn = lua_interface->GetSpawn(state);
  12109. bool cast_completed = (lua_interface->GetInt8Value(state, 2) == 1);
  12110. lua_interface->ResetFunctionStack(state);
  12111. if (!spawn)
  12112. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  12113. else if (!spawn->IsNPC())
  12114. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  12115. else
  12116. {
  12117. ((NPC*)spawn)->cast_on_aggro_completed = cast_completed;
  12118. result = true;
  12119. }
  12120. lua_interface->SetBooleanValue(state, result);
  12121. return 1;
  12122. }
  12123. int EQ2Emu_lua_IsCastOnAggroComplete(lua_State* state) {
  12124. if (!lua_interface)
  12125. return 0;
  12126. bool result = false;
  12127. Spawn* spawn = lua_interface->GetSpawn(state);
  12128. lua_interface->ResetFunctionStack(state);
  12129. if (!spawn)
  12130. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  12131. else if (!spawn->IsNPC())
  12132. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  12133. else
  12134. {
  12135. if(((NPC*)spawn)->cast_on_aggro_completed)
  12136. result = true;
  12137. }
  12138. lua_interface->SetBooleanValue(state, result);
  12139. return 1;
  12140. }
  12141. int EQ2Emu_lua_AddRecipeBookToPlayer(lua_State* state) {
  12142. Client* client = nullptr;
  12143. Spawn* player = lua_interface->GetSpawn(state);
  12144. int32 recipe_book_id = lua_interface->GetInt32Value(state, 2);
  12145. lua_interface->ResetFunctionStack(state);
  12146. if (!player) {
  12147. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not valid");
  12148. lua_interface->SetBooleanValue(state, false);
  12149. return 1;
  12150. }
  12151. if (!player->IsPlayer()) {
  12152. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not a player");
  12153. lua_interface->SetBooleanValue(state, false);
  12154. return 1;
  12155. }
  12156. client = player->GetClient();
  12157. if (!client) {
  12158. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: could not find client");
  12159. lua_interface->SetBooleanValue(state, false);
  12160. return 1;
  12161. }
  12162. bool result = client->AddRecipeBookToPlayer(recipe_book_id);
  12163. lua_interface->SetBooleanValue(state, result);
  12164. return 1;
  12165. }
  12166. int EQ2Emu_lua_RemoveRecipeFromPlayer(lua_State* state) {
  12167. Client* client = nullptr;
  12168. Spawn* player = lua_interface->GetSpawn(state);
  12169. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  12170. lua_interface->ResetFunctionStack(state);
  12171. if (!player) {
  12172. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not valid");
  12173. lua_interface->SetBooleanValue(state, false);
  12174. return 1;
  12175. }
  12176. if (!player->IsPlayer()) {
  12177. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not a player");
  12178. lua_interface->SetBooleanValue(state, false);
  12179. return 1;
  12180. }
  12181. client = player->GetClient();
  12182. if (!client) {
  12183. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: could not find client");
  12184. lua_interface->SetBooleanValue(state, false);
  12185. return 1;
  12186. }
  12187. bool result = client->RemoveRecipeFromPlayer(recipe_id);
  12188. lua_interface->SetBooleanValue(state, result);
  12189. return 1;
  12190. }
  12191. int EQ2Emu_lua_ReplaceWidgetFromClient(lua_State* state) {
  12192. Client* client = nullptr;
  12193. Spawn* player = lua_interface->GetSpawn(state);
  12194. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12195. bool delete_widget = (lua_interface->GetInt8Value(state, 3) == 1);
  12196. // rest are all optional fields
  12197. float x = lua_interface->GetFloatValue(state, 4);
  12198. float y = lua_interface->GetFloatValue(state, 5);
  12199. float z = lua_interface->GetFloatValue(state, 6);
  12200. int32 grid_id = lua_interface->GetInt32Value(state, 7);
  12201. lua_interface->ResetFunctionStack(state);
  12202. if (!player) {
  12203. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not valid");
  12204. lua_interface->SetBooleanValue(state, false);
  12205. return 1;
  12206. }
  12207. if (!player->IsPlayer()) {
  12208. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not a player");
  12209. lua_interface->SetBooleanValue(state, false);
  12210. return 1;
  12211. }
  12212. if(!player->GetZone()) {
  12213. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  12214. lua_interface->SetBooleanValue(state, false);
  12215. return 1;
  12216. }
  12217. client = player->GetClient();
  12218. if (!client) {
  12219. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: could not find client");
  12220. lua_interface->SetBooleanValue(state, false);
  12221. return 1;
  12222. }
  12223. if(!client->IsReadyForUpdates()) {
  12224. lua_interface->LogError("LUA ReplaceWidgetFromClient command failed: client has not signaled sys_client_avatar_ready");
  12225. lua_interface->SetBooleanValue(state, false);
  12226. return 1;
  12227. }
  12228. client->SendReplaceWidget(widget_id, delete_widget, x, y, z, grid_id);
  12229. lua_interface->SetBooleanValue(state, true);
  12230. return 1;
  12231. }
  12232. int EQ2Emu_lua_RemoveWidgetFromSpawnMap(lua_State* state) {
  12233. Client* client = nullptr;
  12234. Spawn* spawn = lua_interface->GetSpawn(state);
  12235. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12236. lua_interface->ResetFunctionStack(state);
  12237. if (!spawn) {
  12238. lua_interface->LogError("LUA RemoveWidgetFromSpawnMap command error: spawn is not valid");
  12239. lua_interface->SetBooleanValue(state, false);
  12240. return 1;
  12241. }
  12242. if(!spawn->GetZone()) {
  12243. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  12244. lua_interface->SetBooleanValue(state, false);
  12245. return 1;
  12246. }
  12247. spawn->AddIgnoredWidget(widget_id);
  12248. lua_interface->SetBooleanValue(state, true);
  12249. return 1;
  12250. }
  12251. int EQ2Emu_lua_RemoveWidgetFromZoneMap(lua_State* state) {
  12252. ZoneServer* zone = lua_interface->GetZone(state);
  12253. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12254. lua_interface->ResetFunctionStack(state);
  12255. if(!zone) {
  12256. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: zone is not valid");
  12257. lua_interface->SetBooleanValue(state, false);
  12258. return 1;
  12259. }
  12260. if(!zone->IsLoading()) {
  12261. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: can only be called during zone loading, in preinit_zone_script ZoneScript function");
  12262. lua_interface->SetBooleanValue(state, false);
  12263. return 1;
  12264. }
  12265. zone->AddIgnoredWidget(widget_id);
  12266. lua_interface->SetBooleanValue(state, true);
  12267. return 1;
  12268. }
  12269. int EQ2Emu_lua_SendHearCast(lua_State* state) {
  12270. if (!lua_interface)
  12271. return 0;
  12272. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  12273. Spawn* spawn = lua_interface->GetSpawn(state);
  12274. int32 spell_visual_id = lua_interface->GetInt32Value(state, 2);
  12275. int16 cast_time = lua_interface->GetInt16Value(state, 3);
  12276. Spawn* caster = lua_interface->GetSpawn(state, 4);
  12277. Spawn* target = lua_interface->GetSpawn(state, 5);
  12278. lua_interface->ResetFunctionStack(state);
  12279. if(spell && spawn && spawn->IsEntity()) {
  12280. ZoneServer* zone = spawn->GetZone();
  12281. if(zone) {
  12282. zone->SendCastSpellPacket(spell, caster && caster->IsEntity() ? (Entity*)caster : (Entity*)spawn, spell_visual_id, cast_time > 0 ? cast_time : 0xFFFF);
  12283. }
  12284. }
  12285. else if (spawn) {
  12286. if (spawn->IsPlayer()) {
  12287. Client* client = ((Player*)spawn)->GetClient();
  12288. if (client) {
  12289. client->SendHearCast(caster ? caster : client->GetPlayer(), target ? target : client->GetPlayer(), spell_visual_id, cast_time);
  12290. }
  12291. }
  12292. }
  12293. return 0;
  12294. }
  12295. int EQ2Emu_lua_GetCharacterFlag(lua_State* state) {
  12296. if (!lua_interface)
  12297. return 0;
  12298. Spawn* player = lua_interface->GetSpawn(state);
  12299. sint32 flag_id = lua_interface->GetSInt32Value(state, 2);
  12300. lua_interface->ResetFunctionStack(state);
  12301. if (!player) {
  12302. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  12303. return 0;
  12304. }
  12305. if (!player->IsPlayer()) {
  12306. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  12307. return 0;
  12308. }
  12309. bool ret = ((Player*)player)->get_character_flag(flag_id);
  12310. lua_interface->SetBooleanValue(state, ret);
  12311. return 1;
  12312. }
  12313. int EQ2Emu_lua_ToggleCharacterFlag(lua_State* state) {
  12314. if (!lua_interface)
  12315. return 0;
  12316. Spawn* player = lua_interface->GetSpawn(state);
  12317. sint32 flag_id = lua_interface->GetSInt32Value(state, 2);
  12318. lua_interface->ResetFunctionStack(state);
  12319. if (!player) {
  12320. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  12321. return 0;
  12322. }
  12323. if (!player->IsPlayer()) {
  12324. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  12325. return 0;
  12326. }
  12327. ((Player*)player)->toggle_character_flag(flag_id);
  12328. return 0;
  12329. }
  12330. int EQ2Emu_lua_GetSpellInitialTarget(lua_State* state) {
  12331. LuaSpell* spell = lua_interface->GetSpell(state);
  12332. if(!spell) {
  12333. spell = lua_interface->GetCurrentSpell(state);
  12334. }
  12335. lua_interface->ResetFunctionStack(state);
  12336. if (spell) {
  12337. if(!spell->caster) {
  12338. lua_interface->LogError("%s: LUA GetSpellTarget command error, caster does not exist.", lua_interface->GetScriptName(state));
  12339. return 0;
  12340. }
  12341. if(!spell->caster->GetZone()) {
  12342. lua_interface->LogError("%s: LUA GetSpellTarget command error, zone does not exist.", lua_interface->GetScriptName(state));
  12343. return 0;
  12344. }
  12345. Spawn* spawn = spell->caster->GetZone()->GetSpawnByID(spell->initial_target);
  12346. if (spawn) {
  12347. lua_interface->SetSpawnValue(state, spawn);
  12348. return 1;
  12349. }
  12350. else {
  12351. lua_interface->LogError("%s: LUA GetSpellTarget command error, could not find initial target %u to map to spawn.", lua_interface->GetScriptName(state), spell->initial_target);
  12352. }
  12353. }
  12354. return 0;
  12355. }
  12356. int EQ2Emu_lua_DespawnByLocationID(lua_State* state) {
  12357. ZoneServer* zone = lua_interface->GetZone(state);
  12358. int32 location_id = lua_interface->GetInt32Value(state, 2);
  12359. int32 delay = lua_interface->GetInt32Value(state, 3);
  12360. lua_interface->ResetFunctionStack(state);
  12361. if (zone) {
  12362. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  12363. if (spawn) {
  12364. vector<Spawn*> groupMembers;
  12365. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  12366. groupMembers = *spawn->GetSpawnGroup();
  12367. for (int32 i = 0; i < groupMembers.size(); i++) {
  12368. Spawn* member = groupMembers.at(i);
  12369. if(member && !member->IsPlayer() && member != spawn) {
  12370. member->GetZone()->Despawn(member, delay);
  12371. }
  12372. }
  12373. }
  12374. zone->Despawn(spawn, delay);
  12375. lua_interface->SetBooleanValue(state, true);
  12376. return 1;
  12377. }
  12378. }
  12379. lua_interface->SetBooleanValue(state, false);
  12380. return 1;
  12381. }