LuaFunctions.cpp 450 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213
  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. if(luaspell && luaspell->resisted) {
  1583. lua_interface->ResetFunctionStack(state);
  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. if (zone && client) {
  1622. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1623. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1624. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1625. {
  1626. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1627. return 0;
  1628. }
  1629. if (x != 0 || y != 0 || z != 0) {
  1630. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1631. player->SetX(x);
  1632. player->SetY(y);
  1633. player->SetZ(z);
  1634. player->SetHeading(heading);
  1635. client->Zone(zone->GetZoneName(), false);
  1636. }
  1637. else
  1638. client->Zone(zone->GetZoneName());
  1639. }
  1640. else
  1641. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1642. lua_interface->ResetFunctionStack(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. if (spawn && spawn2)
  1651. spawn->AddAllowAccessSpawn(spawn2);
  1652. lua_interface->ResetFunctionStack(state);
  1653. return 0;
  1654. }
  1655. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1656. if (!lua_interface)
  1657. return 0;
  1658. Spawn* target = lua_interface->GetSpawn(state);
  1659. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1660. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1661. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1662. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1663. lua_interface->ResetFunctionStack(state);
  1664. if (!target) {
  1665. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1666. return 0;
  1667. }
  1668. if (!target->IsEntity()) {
  1669. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1670. return 0;
  1671. }
  1672. if (spell_id <= 0) {
  1673. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1674. return 0;
  1675. }
  1676. if (caster && !caster->IsEntity()) {
  1677. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1678. return 0;
  1679. }
  1680. if (spell_tier == 0)
  1681. spell_tier = 1;
  1682. if (!caster)
  1683. caster = target;
  1684. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1685. return 0;
  1686. }
  1687. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1688. if (!lua_interface)
  1689. return 0;
  1690. Spawn* target = lua_interface->GetSpawn(state);
  1691. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1692. if(!luaspell || luaspell->resisted) {
  1693. lua_interface->ResetFunctionStack(state);
  1694. lua_interface->SetBooleanValue(state, false);
  1695. return 1;
  1696. }
  1697. Spawn* caster = luaspell->caster;
  1698. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1699. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1700. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1701. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1702. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1703. //lua_interface->ResetFunctionStack(state);
  1704. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1705. vector<int16> faction_req;
  1706. vector<int16> race_req;
  1707. int32 class_req = 0;
  1708. int32 i = 0;
  1709. int8 f = 0;
  1710. int8 r = 0;
  1711. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1712. if (class_id < 100) {
  1713. class_req += pow(2.0, double(class_id - 1));
  1714. }
  1715. else if (class_id > 100 && class_id < 1000) {
  1716. race_req.push_back(class_id);
  1717. r++;
  1718. }
  1719. else {
  1720. faction_req.push_back(class_id);
  1721. f++;
  1722. }
  1723. i++;
  1724. }
  1725. lua_interface->ResetFunctionStack(state);
  1726. if (caster && caster->IsEntity()) {
  1727. bool race_match = false;
  1728. bool success = false;
  1729. luaspell->resisted = false;
  1730. if (luaspell->targets.size() > 0) {
  1731. ZoneServer* zone = luaspell->caster->GetZone();
  1732. Spawn* target = 0;
  1733. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1734. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1735. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1736. if (race_req.size() > 0) {
  1737. for (int8 i = 0; i < race_req.size(); i++) {
  1738. if(race_req[i] == target->GetRace() ||
  1739. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1740. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1741. race_match = true;
  1742. }
  1743. }
  1744. }
  1745. else
  1746. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1747. if (race_match == true) {
  1748. float distance = caster->GetDistance(target, true);
  1749. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1750. }
  1751. }
  1752. }
  1753. success = true;
  1754. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1755. }
  1756. else if (target) {
  1757. //check class and race/faction here
  1758. if (race_req.size() > 0) {
  1759. for (int8 i = 0; i < race_req.size(); i++) {
  1760. if(race_req[i] == target->GetRace() ||
  1761. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1762. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1763. race_match = true;
  1764. }
  1765. }
  1766. }
  1767. else
  1768. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1769. if (race_match == true) {
  1770. float distance = caster->GetDistance(target, true);
  1771. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1772. success = true;
  1773. }
  1774. }
  1775. lua_interface->SetBooleanValue(state, luaspell->has_damaged);
  1776. if (success) {
  1777. Spell* spell = luaspell->spell;
  1778. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1779. ((Player*)caster)->InCombat(true);
  1780. if (caster->GetZone())
  1781. caster->GetZone()->TriggerCharSheetTimer();
  1782. }
  1783. }
  1784. }
  1785. else {
  1786. lua_interface->SetBooleanValue(state, false);
  1787. }
  1788. return 1;
  1789. }
  1790. int EQ2Emu_lua_SpellDamageExt(lua_State* state) {
  1791. if (!lua_interface)
  1792. return 0;
  1793. Spawn* target = lua_interface->GetSpawn(state);
  1794. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1795. if(!luaspell || luaspell->resisted) {
  1796. lua_interface->ResetFunctionStack(state);
  1797. lua_interface->SetBooleanValue(state, false);
  1798. return 1;
  1799. }
  1800. Spawn* caster = luaspell->caster;
  1801. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1802. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1803. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1804. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1805. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1806. int32 override_packet_type = lua_interface->GetInt32Value(state, 7);
  1807. bool take_power = lua_interface->GetInt32Value(state, 8) == 1;
  1808. //lua_interface->ResetFunctionStack(state);
  1809. int32 class_id = lua_interface->GetInt32Value(state, 9);
  1810. vector<int16> faction_req;
  1811. vector<int16> race_req;
  1812. int32 class_req = 0;
  1813. int32 i = 0;
  1814. int8 f = 0;
  1815. int8 r = 0;
  1816. while ((class_id = lua_interface->GetInt32Value(state, 9 + i))) {
  1817. if (class_id < 100) {
  1818. class_req += pow(2.0, double(class_id - 1));
  1819. }
  1820. else if (class_id > 100 && class_id < 1000) {
  1821. race_req.push_back(class_id);
  1822. r++;
  1823. }
  1824. else {
  1825. faction_req.push_back(class_id);
  1826. f++;
  1827. }
  1828. i++;
  1829. }
  1830. lua_interface->ResetFunctionStack(state);
  1831. if (caster && caster->IsEntity()) {
  1832. bool race_match = false;
  1833. bool success = false;
  1834. luaspell->resisted = false;
  1835. if (luaspell->targets.size() > 0) {
  1836. ZoneServer* zone = luaspell->caster->GetZone();
  1837. Spawn* target = 0;
  1838. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1839. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1840. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1841. if (race_req.size() > 0) {
  1842. for (int8 i = 0; i < race_req.size(); i++) {
  1843. if(race_req[i] == target->GetRace() ||
  1844. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1845. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1846. race_match = true;
  1847. }
  1848. }
  1849. }
  1850. else
  1851. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1852. if (race_match == true) {
  1853. float distance = caster->GetDistance(target, true);
  1854. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power);
  1855. }
  1856. }
  1857. }
  1858. success = true;
  1859. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1860. }
  1861. else if (target) {
  1862. //check class and race/faction here
  1863. if (race_req.size() > 0) {
  1864. for (int8 i = 0; i < race_req.size(); i++) {
  1865. if(race_req[i] == target->GetRace() ||
  1866. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1867. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1868. race_match = true;
  1869. }
  1870. }
  1871. }
  1872. else
  1873. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1874. if (race_match == true) {
  1875. float distance = caster->GetDistance(target, true);
  1876. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power))
  1877. success = true;
  1878. }
  1879. }
  1880. lua_interface->SetBooleanValue(state, luaspell->has_damaged);
  1881. if (success) {
  1882. Spell* spell = luaspell->spell;
  1883. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1884. ((Player*)caster)->InCombat(true);
  1885. if (caster->GetZone())
  1886. caster->GetZone()->TriggerCharSheetTimer();
  1887. }
  1888. }
  1889. }
  1890. else {
  1891. lua_interface->SetBooleanValue(state, false);
  1892. }
  1893. return 1;
  1894. }
  1895. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1896. if (!lua_interface)
  1897. return 0;
  1898. Spawn* spawn = lua_interface->GetSpawn(state);
  1899. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1900. lua_interface->ResetFunctionStack(state);
  1901. if (spawn && value != 0) {
  1902. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1903. spawn->SetPower(spawn->GetTotalPower());
  1904. else
  1905. spawn->SetPower(spawn->GetPower() + value);
  1906. }
  1907. return 0;
  1908. }
  1909. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1910. if (!lua_interface)
  1911. return 0;
  1912. Spawn* spawn = lua_interface->GetSpawn(state);
  1913. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1914. lua_interface->ResetFunctionStack(state);
  1915. if (spawn && value != 0) {
  1916. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1917. spawn->SetHP(spawn->GetTotalHP());
  1918. else
  1919. spawn->SetHP(spawn->GetHP() + value);
  1920. }
  1921. return 0;
  1922. }
  1923. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1924. if (!lua_interface)
  1925. return 0;
  1926. Spawn* spawn = lua_interface->GetSpawn(state);
  1927. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1928. lua_interface->ResetFunctionStack(state);
  1929. if (spawn && value != 0) {
  1930. spawn->SetTotalPower(value);
  1931. spawn->SetTotalPowerBaseInstance(value);
  1932. }
  1933. return 0;
  1934. }
  1935. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1936. if (!lua_interface)
  1937. return 0;
  1938. Spawn* spawn = lua_interface->GetSpawn(state);
  1939. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1940. lua_interface->ResetFunctionStack(state);
  1941. if (spawn && value != 0) {
  1942. spawn->SetTotalHP(value);
  1943. spawn->SetTotalHPBaseInstance(value);
  1944. }
  1945. return 0;
  1946. }
  1947. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1948. if (!lua_interface)
  1949. return 0;
  1950. Spawn* spawn = lua_interface->GetSpawn(state);
  1951. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1952. lua_interface->ResetFunctionStack(state);
  1953. if (spawn) {
  1954. spawn->SetHP(value);
  1955. if (value > spawn->GetTotalHPBase())
  1956. spawn->SetTotalHP(value);
  1957. }
  1958. return 0;
  1959. }
  1960. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1961. if (!lua_interface)
  1962. return 0;
  1963. Spawn* spawn = lua_interface->GetSpawn(state);
  1964. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1965. float value = lua_interface->GetFloatValue(state, 2);
  1966. lua_interface->ResetFunctionStack(state);
  1967. if (spawn && spawn->IsEntity() && value > 0)
  1968. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1969. if (spawn && spawn->IsPlayer())
  1970. ((Player*)spawn)->SetCharSheetChanged(true);
  1971. return 0;
  1972. }
  1973. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1974. if (!lua_interface)
  1975. return 0;
  1976. Spawn* spawn = lua_interface->GetSpawn(state);
  1977. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1978. lua_interface->ResetFunctionStack(state);
  1979. if (spawn && spawn->IsEntity() && value > 0)
  1980. ((Entity*)spawn)->SetTotalHPBase(value);
  1981. return 0;
  1982. }
  1983. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1984. if (!lua_interface)
  1985. return 0;
  1986. Spawn* spawn = lua_interface->GetSpawn(state);
  1987. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1988. lua_interface->ResetFunctionStack(state);
  1989. if (spawn && value > 0) {
  1990. spawn->SetPower(value);
  1991. if (value > spawn->GetTotalPowerBase())
  1992. spawn->SetTotalPower(value);
  1993. }
  1994. return 0;
  1995. }
  1996. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1997. if (!lua_interface)
  1998. return 0;
  1999. Spawn* spawn = lua_interface->GetSpawn(state);
  2000. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2001. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2002. lua_interface->ResetFunctionStack(state);
  2003. if (spawn && spawn->IsEntity() && value > 0)
  2004. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  2005. return 0;
  2006. }
  2007. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  2008. if (!lua_interface)
  2009. return 0;
  2010. Spawn* spawn = lua_interface->GetSpawn(state);
  2011. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2012. lua_interface->ResetFunctionStack(state);
  2013. if (spawn && spawn->IsEntity() && value > 0)
  2014. ((Entity*)spawn)->SetTotalPowerBase(value);
  2015. return 0;
  2016. }
  2017. int EQ2Emu_lua_SetPosition(lua_State* state) {
  2018. if (!lua_interface)
  2019. return 0;
  2020. Spawn* spawn = lua_interface->GetSpawn(state);
  2021. float x = lua_interface->GetFloatValue(state, 2);
  2022. float y = lua_interface->GetFloatValue(state, 3);
  2023. float z = lua_interface->GetFloatValue(state, 4);
  2024. float heading = lua_interface->GetFloatValue(state, 5);
  2025. lua_interface->ResetFunctionStack(state);
  2026. if (spawn) {
  2027. spawn->SetX(x);
  2028. spawn->SetY(y);
  2029. spawn->SetZ(z);
  2030. if (heading != 0)
  2031. spawn->SetHeading(heading);
  2032. spawn->SetSpawnOrigX(spawn->GetX());
  2033. spawn->SetSpawnOrigY(spawn->GetY());
  2034. spawn->SetSpawnOrigZ(spawn->GetZ());
  2035. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  2036. if (spawn->IsPlayer()) {
  2037. Client* client = ((Player*)spawn)->GetClient();
  2038. if (client) {
  2039. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  2040. client->QueuePacket(packet);
  2041. }
  2042. }
  2043. }
  2044. return 0;
  2045. }
  2046. int EQ2Emu_lua_SetHeading(lua_State* state) {
  2047. if (!lua_interface)
  2048. return 0;
  2049. Spawn* spawn = lua_interface->GetSpawn(state);
  2050. float value = lua_interface->GetFloatValue(state, 2);
  2051. lua_interface->ResetFunctionStack(state);
  2052. if (spawn) {
  2053. spawn->SetHeading(value);
  2054. if (spawn->IsPlayer()) {
  2055. Client* client = ((Player*)spawn)->GetClient();
  2056. if (client) {
  2057. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  2058. client->QueuePacket(packet);
  2059. }
  2060. }
  2061. }
  2062. return 0;
  2063. }
  2064. int EQ2Emu_lua_SetModelType(lua_State* state) {
  2065. if (!lua_interface)
  2066. return 0;
  2067. Spawn* spawn = lua_interface->GetSpawn(state);
  2068. int16 value = lua_interface->GetInt16Value(state, 2);
  2069. lua_interface->ResetFunctionStack(state);
  2070. if (spawn)
  2071. spawn->SetModelType(value);
  2072. return 0;
  2073. }
  2074. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  2075. if (!lua_interface)
  2076. return 0;
  2077. Spawn* spawn = lua_interface->GetSpawn(state);
  2078. int8 value = lua_interface->GetInt8Value(state, 2);
  2079. lua_interface->ResetFunctionStack(state);
  2080. if (spawn) {
  2081. if (spawn->IsPlayer())
  2082. ((Player*)spawn)->SetPlayerAdventureClass(value);
  2083. else
  2084. spawn->SetAdventureClass(value);
  2085. }
  2086. return 0;
  2087. }
  2088. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  2089. if (!lua_interface)
  2090. return 0;
  2091. Spawn* spawn = lua_interface->GetSpawn(state);
  2092. int8 value = lua_interface->GetInt8Value(state, 2);
  2093. lua_interface->ResetFunctionStack(state);
  2094. if (spawn) {
  2095. spawn->SetTradeskillClass(value);
  2096. if (spawn->IsEntity()) {
  2097. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  2098. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  2099. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  2100. }
  2101. if (spawn->IsPlayer())
  2102. ((Player*)spawn)->SetCharSheetChanged(true);
  2103. }
  2104. return 0;
  2105. }
  2106. int EQ2Emu_lua_SetMount(lua_State* state) {
  2107. if (!lua_interface)
  2108. return 0;
  2109. Spawn* spawn = lua_interface->GetSpawn(state);
  2110. int16 value = lua_interface->GetInt16Value(state, 2);
  2111. if (spawn && spawn->IsEntity()) {
  2112. ((Entity*)spawn)->SetMount(value);
  2113. EQ2_Color color;
  2114. color.red = 255;
  2115. color.green = 255;
  2116. color.blue = 255;
  2117. ((Entity*)spawn)->SetMountColor(&color);
  2118. ((Entity*)spawn)->SetMountSaddleColor(&color);
  2119. }
  2120. return 0;
  2121. }
  2122. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  2123. if (!lua_interface)
  2124. return 0;
  2125. Spawn* spawn = lua_interface->GetSpawn(state);
  2126. EQ2_Color mount_color;
  2127. EQ2_Color saddle_color;
  2128. mount_color.red = lua_interface->GetInt8Value(state, 2);
  2129. mount_color.green = lua_interface->GetInt8Value(state, 3);
  2130. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  2131. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  2132. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  2133. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  2134. if (spawn && spawn->IsEntity()) {
  2135. ((Entity*)spawn)->SetMountColor(&mount_color);
  2136. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  2137. }
  2138. return 0;
  2139. }
  2140. int EQ2Emu_lua_GetMount(lua_State* state) {
  2141. if (!lua_interface)
  2142. return 0;
  2143. Spawn* spawn = lua_interface->GetSpawn(state);
  2144. if (spawn && spawn->IsEntity()) {
  2145. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2146. return 1;
  2147. }
  2148. return 0;
  2149. }
  2150. int EQ2Emu_lua_GetRace(lua_State* state) {
  2151. if (!lua_interface)
  2152. return 0;
  2153. Spawn* spawn = lua_interface->GetSpawn(state);
  2154. if (spawn)
  2155. {
  2156. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2157. lua_interface->SetInt32Value(state, spawn->GetRace());
  2158. return 1;
  2159. }
  2160. return 0;
  2161. }
  2162. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2163. if (!lua_interface)
  2164. return 0;
  2165. Spawn* spawn = lua_interface->GetSpawn(state);
  2166. if (spawn) {
  2167. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2168. return 1;
  2169. }
  2170. return 0;
  2171. }
  2172. int EQ2Emu_lua_GetClass(lua_State* state) {
  2173. Spawn* spawn = lua_interface->GetSpawn(state);
  2174. if (spawn) {
  2175. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2176. return 1;
  2177. }
  2178. return 0;
  2179. }
  2180. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2181. Spawn* spawn = lua_interface->GetSpawn(state);
  2182. if (spawn) {
  2183. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2184. return 1;
  2185. }
  2186. return 0;
  2187. }
  2188. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2189. if (!lua_interface)
  2190. return 0;
  2191. Spawn* spawn = lua_interface->GetSpawn(state);
  2192. float value = lua_interface->GetFloatValue(state, 2);
  2193. lua_interface->ResetFunctionStack(state);
  2194. if (spawn) {
  2195. spawn->SetSpeed(value);
  2196. if(spawn->IsEntity())
  2197. ((Entity*)spawn)->SetSpeed(value);
  2198. if (spawn->IsPlayer()) {
  2199. Client* client = ((Player*)spawn)->GetClient();
  2200. if (client) {
  2201. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2202. if (packet) {
  2203. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2204. packet->setDataByName("speed", value);
  2205. packet->setDataByName("size", 0.51);
  2206. EQ2Packet* app = packet->serialize();
  2207. client->QueuePacket(app);
  2208. safe_delete(packet);
  2209. }
  2210. }
  2211. }
  2212. }
  2213. return 0;
  2214. }
  2215. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2216. if (!lua_interface)
  2217. return 0;
  2218. Spawn* spawn = lua_interface->GetSpawn(state);
  2219. const int16 type = lua_interface->GetInt16Value(state, 2);
  2220. const float value = lua_interface->GetFloatValue(state, 3);
  2221. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2222. if(!luaspell || luaspell->resisted) {
  2223. lua_interface->ResetFunctionStack(state);
  2224. return 0;
  2225. }
  2226. int64 class_req = 0;
  2227. int32 class_id = 0;
  2228. vector<int16> faction_req;
  2229. vector<int16> race_req;
  2230. int32 i = 0;
  2231. int8 f = 0;
  2232. int8 r = 0;
  2233. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2234. if (class_id < 100) {
  2235. class_req += pow(2.0, double(class_id - 1));
  2236. }
  2237. else if (class_id > 100 && class_id < 1000) {
  2238. race_req.push_back(class_id);
  2239. r++;
  2240. }
  2241. else {
  2242. faction_req.push_back(class_id);
  2243. f++;
  2244. }
  2245. i++;
  2246. }
  2247. if (value != 0 && type >= 0) {
  2248. if (luaspell && luaspell->spell && luaspell->caster) {
  2249. ZoneServer* zone = luaspell->caster->GetZone();
  2250. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2251. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2252. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2253. if (target) {
  2254. if (target->IsPlayer()) {
  2255. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2256. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2257. if (((Player*)target)->GetGroupMemberInfo())
  2258. ((Player*)target)->UpdateGroupMemberInfo();
  2259. ((Player*)target)->SetCharSheetChanged(true);
  2260. }
  2261. else if (target->IsNPC())
  2262. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2263. else
  2264. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2265. }
  2266. }
  2267. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2268. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2269. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2270. }
  2271. else if (spawn && spawn->IsEntity()) {
  2272. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2273. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2274. if (spawn->IsPlayer())
  2275. ((Player*)spawn)->SetCharSheetChanged(true);
  2276. }
  2277. else
  2278. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2279. }
  2280. else
  2281. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2282. return 0;
  2283. }
  2284. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2285. if (!lua_interface)
  2286. return 0;
  2287. Spawn* spawn = lua_interface->GetSpawn(state);
  2288. int16 type = lua_interface->GetInt16Value(state, 2);
  2289. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2290. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2291. if (!spawn) {
  2292. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2293. return 0;
  2294. }
  2295. if (!spawn->IsEntity()) {
  2296. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2297. return 0;
  2298. }
  2299. if (value == 0) {
  2300. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2301. return 0;
  2302. }
  2303. if (!luaspell || !luaspell->spell) {
  2304. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2305. return 0;
  2306. }
  2307. if(luaspell->resisted) {
  2308. lua_interface->ResetFunctionStack(state);
  2309. return 0;
  2310. }
  2311. int32 class_req = 0;
  2312. vector<int16> faction_req;
  2313. vector<int16> race_req;
  2314. int32 class_id = 0;
  2315. int32 i = 0;
  2316. int8 f = 0;
  2317. int8 r = 0;
  2318. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2319. if (class_id < 100) {
  2320. class_req += pow(2.0, double(class_id - 1));
  2321. }
  2322. else if (class_id > 100 && class_id < 1000) {
  2323. race_req.push_back(class_id);
  2324. r++;
  2325. }
  2326. else {
  2327. faction_req.push_back(class_id);
  2328. f++;
  2329. }
  2330. i++;
  2331. }
  2332. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2333. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2334. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2335. if (spawn->IsPlayer())
  2336. ((Player*)spawn)->SetCharSheetChanged(true);
  2337. return 0;
  2338. }
  2339. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2340. if (!lua_interface)
  2341. return 0;
  2342. Spawn* spawn = lua_interface->GetSpawn(state);
  2343. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2344. if (!spawn) {
  2345. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2346. return 0;
  2347. }
  2348. if (!spawn->IsEntity()) {
  2349. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2350. return 0;
  2351. }
  2352. if (!luaspell || !luaspell->spell) {
  2353. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2354. return 0;
  2355. }
  2356. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2357. if (spawn->IsPlayer())
  2358. ((Player*)spawn)->SetCharSheetChanged(true);
  2359. return 0;
  2360. }
  2361. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2362. if (!lua_interface)
  2363. return 0;
  2364. Spawn* spawn = lua_interface->GetSpawn(state);
  2365. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2366. if (luaspell && luaspell->spell) {
  2367. ZoneServer* zone = nullptr;
  2368. if (luaspell->caster != nullptr)
  2369. zone = luaspell->caster->GetZone();
  2370. if(!zone && spawn) {
  2371. zone = spawn->GetZone(); // workaround to try to establish a zone to find the targets and remove the spells
  2372. }
  2373. Spawn* target = 0;
  2374. if(zone) {
  2375. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2376. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2377. target = zone->GetSpawnByID(luaspell->targets[i]);
  2378. if (target && target->IsEntity()) {
  2379. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2380. if (target->IsPlayer())
  2381. ((Player*)target)->SetCharSheetChanged(true);
  2382. }
  2383. }
  2384. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2385. }
  2386. else {
  2387. 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());
  2388. }
  2389. }
  2390. else if (spawn && spawn->IsEntity()) {
  2391. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2392. if (spawn->IsPlayer())
  2393. ((Player*)spawn)->SetCharSheetChanged(true);
  2394. }
  2395. return 0;
  2396. }
  2397. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2398. if (!lua_interface)
  2399. return 0;
  2400. Spawn* spawn = lua_interface->GetSpawn(state);
  2401. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2402. float value = lua_interface->GetFloatValue(state, 3);
  2403. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2404. if (value != 0) {
  2405. int32 spell_id = 0;
  2406. if (luaspell && luaspell->spell && luaspell->caster) {
  2407. if(luaspell->resisted) {
  2408. lua_interface->ResetFunctionStack(state);
  2409. return 0;
  2410. }
  2411. spell_id = luaspell->spell->GetSpellID();
  2412. ZoneServer* zone = luaspell->caster->GetZone();
  2413. Spawn* target = 0;
  2414. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2415. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2416. target = zone->GetSpawnByID(luaspell->targets[i]);
  2417. if (target && target->Alive()) {
  2418. if (target->IsPlayer()) {
  2419. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2420. Client* client = ((Player*)target)->GetClient();
  2421. if (client) {
  2422. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2423. if (packet)
  2424. client->QueuePacket(packet);
  2425. }
  2426. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2427. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2428. }
  2429. else if (target->IsNPC()) {
  2430. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2431. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2432. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2433. }
  2434. else
  2435. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2436. }
  2437. }
  2438. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2439. }
  2440. else if (spawn) {
  2441. if (spawn->IsPlayer()) {
  2442. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2443. Client* client = ((Player*)spawn)->GetClient();
  2444. if (client) {
  2445. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2446. if (packet)
  2447. client->QueuePacket(packet);
  2448. }
  2449. }
  2450. else if (spawn->IsNPC())
  2451. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2452. else
  2453. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2454. }
  2455. }
  2456. else
  2457. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2458. return 0;
  2459. }
  2460. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2461. if (!lua_interface)
  2462. return 0;
  2463. Spawn* spawn = lua_interface->GetSpawn(state);
  2464. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2465. if (spawn && spawn->IsPlayer()) {
  2466. int32 spell_id = 0;
  2467. if (luaspell && luaspell->spell && luaspell->caster) {
  2468. if(luaspell->resisted) {
  2469. lua_interface->ResetFunctionStack(state);
  2470. return 0;
  2471. }
  2472. spell_id = luaspell->spell->GetSpellID();
  2473. ZoneServer* zone = luaspell->caster->GetZone();
  2474. Spawn* target = 0;
  2475. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2476. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2477. target = zone->GetSpawnByID(luaspell->targets[i]);
  2478. if (target) {
  2479. if (target->IsPlayer()) {
  2480. ((Player*)target)->RemoveSkillBonus(spell_id);
  2481. Client* client = ((Player*)target)->GetClient();
  2482. if (client) {
  2483. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2484. if (packet)
  2485. client->QueuePacket(packet);
  2486. }
  2487. }
  2488. else if (target->IsNPC())
  2489. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2490. else
  2491. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2492. }
  2493. }
  2494. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2495. }
  2496. else if (spawn) {
  2497. if (spawn->IsPlayer()) {
  2498. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2499. Client* client = ((Player*)spawn)->GetClient();
  2500. if (client) {
  2501. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2502. if (packet)
  2503. client->QueuePacket(packet);
  2504. }
  2505. }
  2506. else if (spawn->IsNPC())
  2507. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2508. else
  2509. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2510. }
  2511. }
  2512. return 0;
  2513. }
  2514. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2515. if (!lua_interface)
  2516. return 0;
  2517. Spawn* spawn = lua_interface->GetSpawn(state);
  2518. int8 type = lua_interface->GetInt32Value(state, 2);
  2519. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2520. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2521. if(luaspell && luaspell->resisted) {
  2522. lua_interface->ResetFunctionStack(state);
  2523. return 0;
  2524. }
  2525. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2526. ZoneServer* zone = luaspell->caster->GetZone();
  2527. Spawn* target = 0;
  2528. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2529. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2530. target = zone->GetSpawnByID(luaspell->targets[i]);
  2531. if (target && target->IsEntity()) {
  2532. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2533. ((Entity*)target)->AddMezSpell(luaspell);
  2534. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2535. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2536. if (target->IsNPC())
  2537. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2538. }
  2539. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2540. ((Entity*)target)->AddStifleSpell(luaspell);
  2541. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2542. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2543. if (target->IsNPC())
  2544. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2545. }
  2546. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2547. ((Entity*)target)->AddDazeSpell(luaspell);
  2548. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2549. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2550. if (target->IsNPC())
  2551. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2552. }
  2553. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2554. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2555. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2556. ((Entity*)target)->AddStunSpell(luaspell);
  2557. if (target->IsNPC())
  2558. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2559. }
  2560. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2561. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2562. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2563. ((Entity*)target)->AddRootSpell(luaspell);
  2564. if (target->IsNPC())
  2565. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2566. }
  2567. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2568. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2569. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2570. ((Entity*)target)->AddFearSpell(luaspell);
  2571. if (target->IsNPC())
  2572. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2573. }
  2574. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2575. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2576. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2577. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2578. }
  2579. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2580. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2581. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2582. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2583. }
  2584. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2585. ((Entity*)target)->AddSnareSpell(luaspell);
  2586. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2587. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2588. if (target->IsNPC())
  2589. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2590. }
  2591. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2592. ((Entity*)target)->AddFlightSpell(luaspell);
  2593. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2594. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2595. }
  2596. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2597. ((Entity*)target)->AddGlideSpell(luaspell);
  2598. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2599. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2600. }
  2601. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2602. ((Entity*)target)->AddSafefallSpell(luaspell);
  2603. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2604. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2605. }
  2606. else
  2607. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2608. }
  2609. else
  2610. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2611. }
  2612. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2613. }
  2614. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2615. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2616. ((Entity*)spawn)->AddMezSpell(luaspell);
  2617. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2618. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2619. }
  2620. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2621. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2622. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2623. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2624. }
  2625. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2626. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2627. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2628. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2629. }
  2630. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2631. ((Entity*)spawn)->AddStunSpell(luaspell);
  2632. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2633. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2634. }
  2635. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2636. ((Entity*)spawn)->AddRootSpell(luaspell);
  2637. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2638. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2639. }
  2640. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2641. ((Entity*)spawn)->AddFearSpell(luaspell);
  2642. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2643. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2644. }
  2645. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2646. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2647. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2648. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2649. }
  2650. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2651. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2652. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2653. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2654. }
  2655. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2656. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2657. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2658. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2659. }
  2660. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2661. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2662. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2663. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2664. }
  2665. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2666. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2667. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2668. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2669. }
  2670. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2671. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2672. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2673. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2674. }
  2675. else
  2676. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2677. }
  2678. else
  2679. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2680. return 0;
  2681. }
  2682. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2683. if (!lua_interface)
  2684. return 0;
  2685. Spawn* spawn = lua_interface->GetSpawn(state);
  2686. int8 type = lua_interface->GetInt8Value(state, 2);
  2687. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2688. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2689. if (spawn && spawn->IsEntity()) {
  2690. if (!only_remove_spawn && luaspell && luaspell->spell && luaspell->caster) {
  2691. ZoneServer* zone = luaspell->caster->GetZone();
  2692. Spawn* target = 0;
  2693. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2694. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2695. target = zone->GetSpawnByID(luaspell->targets[i]);
  2696. if (target) {
  2697. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2698. ((Entity*)target)->RemoveMezSpell(luaspell);
  2699. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2700. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2701. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2702. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2703. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2704. ((Entity*)target)->RemoveStunSpell(luaspell);
  2705. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2706. ((Entity*)target)->RemoveRootSpell(luaspell);
  2707. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2708. ((Entity*)target)->RemoveFearSpell(luaspell);
  2709. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2710. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2711. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2712. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2713. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2714. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2715. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2716. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2717. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2718. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2719. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2720. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2721. else
  2722. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2723. }
  2724. }
  2725. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2726. }
  2727. else if (only_remove_spawn) {
  2728. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2729. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2730. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2731. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2732. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2733. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2734. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2735. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2736. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2737. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2738. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2739. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2740. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2741. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2742. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2743. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2744. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2745. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2746. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2747. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2748. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2749. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2750. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2751. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2752. else
  2753. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2754. }
  2755. }
  2756. return 0;
  2757. }
  2758. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2759. if (!lua_interface)
  2760. return 0;
  2761. Spawn* spawn = lua_interface->GetSpawn(state);
  2762. int8 type = lua_interface->GetInt8Value(state, 2);
  2763. bool hasEffect = false;
  2764. if (!spawn)
  2765. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2766. else if (!spawn->IsEntity())
  2767. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2768. else if (type < CONTROL_MAX_EFFECTS)
  2769. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2770. else
  2771. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2772. lua_interface->SetBooleanValue(state, hasEffect);
  2773. return 1;
  2774. }
  2775. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2776. if (!lua_interface)
  2777. return 0;
  2778. Spawn* spawn = lua_interface->GetSpawn(state);
  2779. float distance = 0.0f;
  2780. if (!spawn)
  2781. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2782. else if (!spawn->IsNPC())
  2783. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2784. else
  2785. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2786. lua_interface->SetFloatValue(state, distance);
  2787. return 1;
  2788. }
  2789. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2790. if (!lua_interface)
  2791. return 0;
  2792. Spawn* spawn = lua_interface->GetSpawn(state);
  2793. float distance = 0.0f;
  2794. if (!spawn)
  2795. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2796. else if (!spawn->IsNPC())
  2797. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2798. else
  2799. distance = ((NPC*)spawn)->GetAggroRadius();
  2800. lua_interface->SetFloatValue(state, distance);
  2801. return 1;
  2802. }
  2803. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2804. if (!lua_interface)
  2805. return 0;
  2806. Spawn* spawn = lua_interface->GetSpawn(state);
  2807. float distance = lua_interface->GetFloatValue(state, 2);
  2808. bool override = lua_interface->GetBooleanValue(state, 3);
  2809. bool result = false;
  2810. lua_interface->ResetFunctionStack(state);
  2811. if (!spawn)
  2812. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2813. else if (!spawn->IsNPC())
  2814. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2815. else
  2816. {
  2817. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2818. result = true;
  2819. }
  2820. lua_interface->SetBooleanValue(state, result);
  2821. return 1;
  2822. }
  2823. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2824. if (!lua_interface)
  2825. return 0;
  2826. Spawn* spawn = lua_interface->GetSpawn(state);
  2827. int16 value = lua_interface->GetInt16Value(state, 2);
  2828. if (spawn && spawn->IsEntity()) {
  2829. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2830. if (spawn->IsPlayer())
  2831. ((Player*)spawn)->SetCharSheetChanged(true);
  2832. }
  2833. return 0;
  2834. }
  2835. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2836. if (!lua_interface)
  2837. return 0;
  2838. Spawn* spawn = lua_interface->GetSpawn(state);
  2839. int16 value = lua_interface->GetInt16Value(state, 2);
  2840. if (spawn && spawn->IsEntity()) {
  2841. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2842. if (spawn->IsPlayer())
  2843. ((Player*)spawn)->SetCharSheetChanged(true);
  2844. }
  2845. return 0;
  2846. }
  2847. int EQ2Emu_lua_SetWisBase(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. if (spawn && spawn->IsEntity()) {
  2853. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2854. if (spawn->IsPlayer())
  2855. ((Player*)spawn)->SetCharSheetChanged(true);
  2856. }
  2857. return 0;
  2858. }
  2859. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2860. if (!lua_interface)
  2861. return 0;
  2862. Spawn* spawn = lua_interface->GetSpawn(state);
  2863. int16 value = lua_interface->GetInt16Value(state, 2);
  2864. if (spawn && spawn->IsEntity()) {
  2865. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2866. if (spawn->IsPlayer())
  2867. ((Player*)spawn)->SetCharSheetChanged(true);
  2868. }
  2869. return 0;
  2870. }
  2871. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2872. if (!lua_interface)
  2873. return 0;
  2874. Spawn* spawn = lua_interface->GetSpawn(state);
  2875. int16 value = lua_interface->GetInt16Value(state, 2);
  2876. if (spawn && spawn->IsEntity()) {
  2877. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2878. if (spawn->IsPlayer())
  2879. ((Player*)spawn)->SetCharSheetChanged(true);
  2880. }
  2881. return 0;
  2882. }
  2883. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2884. if (!lua_interface)
  2885. return 0;
  2886. Spawn* spawn = lua_interface->GetSpawn(state);
  2887. int8 value = lua_interface->GetInt8Value(state, 2);
  2888. if (spawn && spawn->IsEntity()) {
  2889. ((Entity*)spawn)->SetDeity(value);
  2890. if (spawn->IsPlayer())
  2891. ((Player*)spawn)->SetCharSheetChanged(true);
  2892. }
  2893. lua_interface->ResetFunctionStack(state);
  2894. return 0;
  2895. }
  2896. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2897. if (!lua_interface)
  2898. return 0;
  2899. Spawn* spawn = lua_interface->GetSpawn(state);
  2900. if (spawn && spawn->IsEntity()) {
  2901. int8 deity = ((Entity*)spawn)->GetDeity();
  2902. lua_interface->SetInt32Value(state, deity);
  2903. return 1;
  2904. }
  2905. return 0;
  2906. }
  2907. int EQ2Emu_lua_SetInt(lua_State* state) {
  2908. if (!lua_interface)
  2909. return 0;
  2910. Spawn* spawn = lua_interface->GetSpawn(state);
  2911. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2912. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2913. if (spawn && spawn->IsEntity()) {
  2914. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_INT, value);
  2915. if (spawn->IsPlayer())
  2916. ((Player*)spawn)->SetCharSheetChanged(true);
  2917. }
  2918. return 0;
  2919. }
  2920. int EQ2Emu_lua_SetWis(lua_State* state) {
  2921. if (!lua_interface)
  2922. return 0;
  2923. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2924. Spawn* spawn = lua_interface->GetSpawn(state);
  2925. float value = lua_interface->GetFloatValue(state, 2);
  2926. if (spawn && spawn->IsEntity()) {
  2927. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_WIS, value);
  2928. if (spawn->IsPlayer())
  2929. ((Player*)spawn)->SetCharSheetChanged(true);
  2930. }
  2931. return 0;
  2932. }
  2933. int EQ2Emu_lua_SetSta(lua_State* state) {
  2934. if (!lua_interface)
  2935. return 0;
  2936. Spawn* spawn = lua_interface->GetSpawn(state);
  2937. float value = lua_interface->GetFloatValue(state, 2);
  2938. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2939. if (spawn && spawn->IsEntity()) {
  2940. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STA, value);
  2941. if (spawn->IsPlayer())
  2942. ((Player*)spawn)->SetCharSheetChanged(true);
  2943. }
  2944. return 0;
  2945. }
  2946. int EQ2Emu_lua_SetStr(lua_State* state) {
  2947. if (!lua_interface)
  2948. return 0;
  2949. Spawn* spawn = lua_interface->GetSpawn(state);
  2950. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2951. float value = lua_interface->GetFloatValue(state, 2);
  2952. if (spawn && spawn->IsEntity()) {
  2953. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STR, value);
  2954. if (spawn->IsPlayer())
  2955. ((Player*)spawn)->SetCharSheetChanged(true);
  2956. }
  2957. return 0;
  2958. }
  2959. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2960. if (!lua_interface)
  2961. return 0;
  2962. Spawn* spawn = lua_interface->GetSpawn(state);
  2963. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2964. float value = lua_interface->GetFloatValue(state, 2);
  2965. if (spawn && spawn->IsEntity()) {
  2966. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_AGI, value);
  2967. if (spawn->IsPlayer())
  2968. ((Player*)spawn)->SetCharSheetChanged(true);
  2969. }
  2970. return 0;
  2971. }
  2972. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2973. if (!lua_interface)
  2974. return 0;
  2975. Spawn* spawn = lua_interface->GetSpawn(state);
  2976. if (spawn) {
  2977. lua_interface->SetInt32Value(state, spawn->GetHP());
  2978. return 1;
  2979. }
  2980. return 0;
  2981. }
  2982. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2983. if (!lua_interface)
  2984. return 0;
  2985. Spawn* spawn = lua_interface->GetSpawn(state);
  2986. if (spawn) {
  2987. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2988. return 1;
  2989. }
  2990. return 0;
  2991. }
  2992. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2993. if (!lua_interface)
  2994. return 0;
  2995. Spawn* spawn = lua_interface->GetSpawn(state);
  2996. if (spawn) {
  2997. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2998. return 1;
  2999. }
  3000. return 0;
  3001. }
  3002. int EQ2Emu_lua_GetName(lua_State* state) {
  3003. if (!lua_interface)
  3004. return 0;
  3005. Spawn* spawn = lua_interface->GetSpawn(state);
  3006. if (spawn) {
  3007. lua_interface->SetStringValue(state, spawn->GetName());
  3008. return 1;
  3009. }
  3010. return 0;
  3011. }
  3012. int EQ2Emu_lua_GetLevel(lua_State* state) {
  3013. Spawn* spawn = lua_interface->GetSpawn(state);
  3014. if (spawn) {
  3015. lua_interface->SetInt32Value(state, spawn->GetLevel());
  3016. return 1;
  3017. }
  3018. return 0;
  3019. }
  3020. int EQ2Emu_lua_GetDifficulty(lua_State* state) {
  3021. Spawn* spawn = lua_interface->GetSpawn(state);
  3022. if (spawn) {
  3023. lua_interface->SetInt32Value(state, spawn->GetDifficulty());
  3024. return 1;
  3025. }
  3026. return 0;
  3027. }
  3028. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  3029. if (!lua_interface)
  3030. return 0;
  3031. Spawn* spawn = lua_interface->GetSpawn(state);
  3032. if (spawn) {
  3033. lua_interface->SetInt32Value(state, spawn->GetPower());
  3034. return 1;
  3035. }
  3036. return 0;
  3037. }
  3038. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  3039. if (!lua_interface)
  3040. return 0;
  3041. Spawn* spawn = lua_interface->GetSpawn(state);
  3042. if (spawn) {
  3043. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  3044. return 1;
  3045. }
  3046. return 0;
  3047. }
  3048. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  3049. if (!lua_interface)
  3050. return 0;
  3051. Spawn* spawn = lua_interface->GetSpawn(state);
  3052. if (spawn) {
  3053. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  3054. return 1;
  3055. }
  3056. return 0;
  3057. }
  3058. int EQ2Emu_lua_GetDistance(lua_State* state) {
  3059. if (!lua_interface)
  3060. return 0;
  3061. Spawn* spawn = lua_interface->GetSpawn(state);
  3062. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  3063. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  3064. if (spawn && spawn2) {
  3065. float distance = spawn->GetDistance(spawn2, false, include_radius);
  3066. lua_interface->SetFloatValue(state, distance);
  3067. return 1;
  3068. }
  3069. return 0;
  3070. }
  3071. int EQ2Emu_lua_GetX(lua_State* state) {
  3072. if (!lua_interface)
  3073. return 0;
  3074. Spawn* spawn = lua_interface->GetSpawn(state);
  3075. if (spawn) {
  3076. lua_interface->SetFloatValue(state, spawn->GetX());
  3077. return 1;
  3078. }
  3079. return 0;
  3080. }
  3081. int EQ2Emu_lua_GetY(lua_State* state) {
  3082. if (!lua_interface)
  3083. return 0;
  3084. Spawn* spawn = lua_interface->GetSpawn(state);
  3085. if (spawn) {
  3086. lua_interface->SetFloatValue(state, spawn->GetY());
  3087. return 1;
  3088. }
  3089. return 0;
  3090. }
  3091. int EQ2Emu_lua_GetZ(lua_State* state) {
  3092. if (!lua_interface)
  3093. return 0;
  3094. Spawn* spawn = lua_interface->GetSpawn(state);
  3095. if (spawn) {
  3096. lua_interface->SetFloatValue(state, spawn->GetZ());
  3097. return 1;
  3098. }
  3099. return 0;
  3100. }
  3101. int EQ2Emu_lua_GetHeading(lua_State* state) {
  3102. if (!lua_interface)
  3103. return 0;
  3104. Spawn* spawn = lua_interface->GetSpawn(state);
  3105. if (spawn) {
  3106. lua_interface->SetFloatValue(state, spawn->GetHeading());
  3107. return 1;
  3108. }
  3109. return 0;
  3110. }
  3111. int EQ2Emu_lua_GetModelType(lua_State* state) {
  3112. if (!lua_interface)
  3113. return 0;
  3114. Spawn* spawn = lua_interface->GetSpawn(state);
  3115. if (spawn) {
  3116. lua_interface->SetInt32Value(state, spawn->GetModelType());
  3117. return 1;
  3118. }
  3119. return 0;
  3120. }
  3121. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  3122. if (!lua_interface)
  3123. return 0;
  3124. Spawn* spawn = lua_interface->GetSpawn(state);
  3125. if (spawn) {
  3126. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  3127. return 1;
  3128. }
  3129. return 0;
  3130. }
  3131. int EQ2Emu_lua_HasMoved(lua_State* state) {
  3132. if (!lua_interface)
  3133. return 0;
  3134. Spawn* spawn = lua_interface->GetSpawn(state);
  3135. if (spawn && spawn->IsEntity()) {
  3136. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  3137. return 1;
  3138. }
  3139. return 0;
  3140. }
  3141. int EQ2Emu_lua_GetInt(lua_State* state) {
  3142. if (!lua_interface)
  3143. return 0;
  3144. Spawn* spawn = lua_interface->GetSpawn(state);
  3145. if (spawn && spawn->IsEntity()) {
  3146. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  3147. return 1;
  3148. }
  3149. return 0;
  3150. }
  3151. int EQ2Emu_lua_GetWis(lua_State* state) {
  3152. if (!lua_interface)
  3153. return 0;
  3154. Spawn* spawn = lua_interface->GetSpawn(state);
  3155. if (spawn && spawn->IsEntity()) {
  3156. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  3157. return 1;
  3158. }
  3159. return 0;
  3160. }
  3161. int EQ2Emu_lua_GetSta(lua_State* state) {
  3162. if (!lua_interface)
  3163. return 0;
  3164. Spawn* spawn = lua_interface->GetSpawn(state);
  3165. if (spawn && spawn->IsEntity()) {
  3166. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  3167. return 1;
  3168. }
  3169. return 0;
  3170. }
  3171. int EQ2Emu_lua_GetStr(lua_State* state) {
  3172. if (!lua_interface)
  3173. return 0;
  3174. Spawn* spawn = lua_interface->GetSpawn(state);
  3175. if (spawn && spawn->IsEntity()) {
  3176. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3177. return 1;
  3178. }
  3179. return 0;
  3180. }
  3181. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3182. if (!lua_interface)
  3183. return 0;
  3184. Spawn* spawn = lua_interface->GetSpawn(state);
  3185. if (spawn && spawn->IsEntity()) {
  3186. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3187. return 1;
  3188. }
  3189. return 0;
  3190. }
  3191. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3192. if (!lua_interface)
  3193. return 0;
  3194. Spawn* spawn = lua_interface->GetSpawn(state);
  3195. if (spawn && spawn->IsEntity()) {
  3196. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3197. return 1;
  3198. }
  3199. return 0;
  3200. }
  3201. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3202. if (!lua_interface)
  3203. return 0;
  3204. Spawn* spawn = lua_interface->GetSpawn(state);
  3205. if (spawn && spawn->IsEntity()) {
  3206. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3207. return 1;
  3208. }
  3209. return 0;
  3210. }
  3211. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3212. if (!lua_interface)
  3213. return 0;
  3214. Spawn* spawn = lua_interface->GetSpawn(state);
  3215. if (spawn && spawn->IsEntity()) {
  3216. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3217. return 1;
  3218. }
  3219. return 0;
  3220. }
  3221. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3222. if (!lua_interface)
  3223. return 0;
  3224. Spawn* spawn = lua_interface->GetSpawn(state);
  3225. if (spawn && spawn->IsEntity()) {
  3226. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3227. return 1;
  3228. }
  3229. return 0;
  3230. }
  3231. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3232. if (!lua_interface)
  3233. return 0;
  3234. Spawn* spawn = lua_interface->GetSpawn(state);
  3235. if (spawn && spawn->IsEntity()) {
  3236. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3237. return 1;
  3238. }
  3239. return 0;
  3240. }
  3241. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3242. if (!lua_interface)
  3243. return 0;
  3244. Spawn* player = lua_interface->GetSpawn(state);
  3245. if (!player || !player->IsPlayer()) {
  3246. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3247. return 0;
  3248. }
  3249. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3250. if (quest_id <= 0) {
  3251. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3252. return 0;
  3253. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3254. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3255. return 0;
  3256. }
  3257. int32 step = lua_interface->GetInt32Value(state, 3);
  3258. if (step > 0) {
  3259. Client* client = ((Player*)player)->GetClient();
  3260. if (client)
  3261. client->AddPendingQuestUpdate(quest_id, step);
  3262. } else {
  3263. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3264. }
  3265. return 0;
  3266. }
  3267. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3268. Spawn* player = lua_interface->GetSpawn(state);
  3269. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3270. int32 step = lua_interface->GetInt32Value(state, 3);
  3271. int32 progress = lua_interface->GetInt32Value(state, 4);
  3272. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3273. Client* client = ((Player*)player)->GetClient();
  3274. if (client)
  3275. client->AddPendingQuestUpdate(quest_id, step, progress);
  3276. }
  3277. return 0;
  3278. }
  3279. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3280. if (!lua_interface)
  3281. return 0;
  3282. Spawn* player = lua_interface->GetSpawn(state);
  3283. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3284. if (player && player->IsPlayer() && quest_id > 0) {
  3285. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3286. return 1;
  3287. }
  3288. return 0;
  3289. }
  3290. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3291. if (!lua_interface)
  3292. return 0;
  3293. Spawn* player = lua_interface->GetSpawn(state);
  3294. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3295. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3296. if (player && player->IsPlayer() && quest_id > 0) {
  3297. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3298. return 1;
  3299. }
  3300. return 0;
  3301. }
  3302. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3303. if (!lua_interface)
  3304. return 0;
  3305. Spawn* player = lua_interface->GetSpawn(state);
  3306. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3307. if (player && player->IsPlayer() && quest_id > 0) {
  3308. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3309. return 1;
  3310. }
  3311. return 0;
  3312. }
  3313. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3314. if (!lua_interface)
  3315. return 0;
  3316. Quest* quest = lua_interface->GetQuest(state);
  3317. string name = lua_interface->GetStringValue(state, 2);
  3318. string type = lua_interface->GetStringValue(state, 3);
  3319. string zone = lua_interface->GetStringValue(state, 4);
  3320. int16 level = lua_interface->GetInt16Value(state, 5);
  3321. string description = lua_interface->GetStringValue(state, 6);
  3322. bool load = true;
  3323. if (!quest) {
  3324. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3325. load = false;
  3326. }
  3327. if (load && name.length() == 0) {
  3328. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3329. load = false;
  3330. }
  3331. if (load && type.length() == 0) {
  3332. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3333. load = false;
  3334. }
  3335. if (load && zone.length() == 0) {
  3336. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3337. load = false;
  3338. }
  3339. if (load && description.length() == 0) {
  3340. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3341. load = false;
  3342. }
  3343. if (load && level == 0) {
  3344. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3345. load = false;
  3346. }
  3347. if (load)
  3348. quest->RegisterQuest(name, type, zone, level, description);
  3349. return 0;
  3350. }
  3351. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3352. if (!lua_interface)
  3353. return 0;
  3354. Quest* quest = lua_interface->GetQuest(state);
  3355. if (quest) {
  3356. int8 level = lua_interface->GetInt16Value(state, 2);
  3357. quest->SetPrereqLevel(level);
  3358. }
  3359. return 0;
  3360. }
  3361. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3362. if (!lua_interface)
  3363. return 0;
  3364. Quest* quest = lua_interface->GetQuest(state);
  3365. if (quest) {
  3366. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3367. quest->AddPrereqQuest(quest_id);
  3368. }
  3369. return 0;
  3370. }
  3371. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3372. if (!lua_interface)
  3373. return 0;
  3374. Quest* quest = lua_interface->GetQuest(state);
  3375. if (quest) {
  3376. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3377. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3378. if (quantity == 0)
  3379. quantity = 1;
  3380. Item* master_item = master_item_list.GetItem(item_id);
  3381. if (master_item) {
  3382. Item* item = new Item(master_item);
  3383. item->details.count = quantity;
  3384. quest->AddPrereqItem(item);
  3385. }
  3386. }
  3387. return 0;
  3388. }
  3389. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3390. if (!lua_interface)
  3391. return 0;
  3392. Spawn* player = lua_interface->GetSpawn(state);
  3393. if(!player || !player->IsPlayer()) {
  3394. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3395. return 0;
  3396. }
  3397. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3398. if (quest_id > 0) {
  3399. lua_interface->SetBooleanValue(state, (((Player*)player)->HasActiveQuest(quest_id) == TRUE));
  3400. return 1;
  3401. } else {
  3402. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3403. }
  3404. return 0;
  3405. }
  3406. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3407. if (!lua_interface)
  3408. return 0;
  3409. Quest* quest = lua_interface->GetQuest(state);
  3410. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3411. lua_interface->ResetFunctionStack(state);
  3412. if (quest && spawn_id > 0)
  3413. quest->SetQuestReturnNPC(spawn_id);
  3414. return 0;
  3415. }
  3416. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3417. if (!lua_interface)
  3418. return 0;
  3419. Spawn* spawn = lua_interface->GetSpawn(state);
  3420. int32 time = lua_interface->GetInt32Value(state, 2);
  3421. string function = lua_interface->GetStringValue(state, 3);
  3422. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3423. Spawn* player = lua_interface->GetSpawn(state, 5);
  3424. lua_interface->ResetFunctionStack(state);
  3425. if (!spawn) {
  3426. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3427. return 0;
  3428. }
  3429. if (time <= 0) {
  3430. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3431. return 0;
  3432. }
  3433. if (function.length() == 0) {
  3434. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3435. return 0;
  3436. }
  3437. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3438. if ( time < 10)
  3439. time = 10;
  3440. timer->timer = Timer::GetCurrentTime2() + time;
  3441. timer->function = function;
  3442. timer->spawn = spawn->GetID();
  3443. timer->player = player ? player->GetID() : 0;
  3444. if (max_count == 0)
  3445. max_count = 1;
  3446. timer->max_count = max_count;
  3447. timer->current_count = 0;
  3448. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3449. return 0;
  3450. }
  3451. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3452. if (!lua_interface)
  3453. return 0;
  3454. Spawn* spawn = lua_interface->GetSpawn(state);
  3455. string function = lua_interface->GetStringValue(state, 2);
  3456. lua_interface->ResetFunctionStack(state);
  3457. if (!spawn) {
  3458. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3459. return 0;
  3460. }
  3461. if(!spawn->GetZone()) {
  3462. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3463. return 0;
  3464. }
  3465. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3466. return 0;
  3467. }
  3468. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3469. if (!lua_interface)
  3470. return 0;
  3471. Spawn* player = lua_interface->GetSpawn(state);
  3472. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3473. lua_interface->ResetFunctionStack(state);
  3474. if (player && player->IsPlayer() && quest_id > 0) {
  3475. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3476. return 1;
  3477. }
  3478. return 0;
  3479. }
  3480. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3481. if (!lua_interface)
  3482. return 0;
  3483. Spawn* player = lua_interface->GetSpawn(state);
  3484. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3485. lua_interface->ResetFunctionStack(state);
  3486. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3487. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3488. if (quest)
  3489. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3490. return 1;
  3491. }
  3492. return 0;
  3493. }
  3494. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3495. if (!lua_interface)
  3496. return 0;
  3497. Spawn* player = lua_interface->GetSpawn(state);
  3498. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3499. lua_interface->ResetFunctionStack(state);
  3500. if (player && player->IsPlayer() && quest_id > 0) {
  3501. lua_interface->SetBooleanValue(state, (((Player*)player)->HasQuestBeenCompleted(quest_id) != 0));
  3502. return 1;
  3503. }
  3504. return 0;
  3505. }
  3506. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3507. if (!lua_interface)
  3508. return 0;
  3509. Spawn* npc = lua_interface->GetSpawn(state);
  3510. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3511. lua_interface->ResetFunctionStack(state);
  3512. if (npc && !npc->IsPlayer() && quest_id > 0)
  3513. npc->AddProvidedQuest(quest_id);
  3514. return 0;
  3515. }
  3516. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3517. if (!lua_interface)
  3518. return 0;
  3519. Spawn* npc = lua_interface->GetSpawn(state);
  3520. Spawn* player = lua_interface->GetSpawn(state, 2);
  3521. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3522. bool forced = lua_interface->GetBooleanValue(state, 4);
  3523. lua_interface->ResetFunctionStack(state);
  3524. /* NPC is allowed to be null */
  3525. if (player && player->IsPlayer() && quest_id > 0) {
  3526. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3527. if (master_quest) {
  3528. Client* client = ((Player*)player)->GetClient();
  3529. if (!client) {
  3530. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3531. }
  3532. Quest* quest = new Quest(master_quest);
  3533. if (!quest) {
  3534. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3535. }
  3536. if (client && quest) {
  3537. if (npc)
  3538. quest->SetQuestGiver(npc->GetDatabaseID());
  3539. else
  3540. quest->SetQuestGiver(0);
  3541. client->AddPendingQuest(quest, forced);
  3542. }
  3543. }
  3544. else {
  3545. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3546. }
  3547. }
  3548. else {
  3549. 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);
  3550. }
  3551. return 0;
  3552. }
  3553. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3554. if (!lua_interface)
  3555. return 0;
  3556. Quest* quest = lua_interface->GetQuest(state);
  3557. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3558. lua_interface->ResetFunctionStack(state);
  3559. if (quest) {
  3560. quest->AddPrereqClass(class_id);
  3561. }
  3562. return 0;
  3563. }
  3564. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3565. if (!lua_interface)
  3566. return 0;
  3567. Quest* quest = lua_interface->GetQuest(state);
  3568. int8 race = lua_interface->GetInt8Value(state, 2);
  3569. lua_interface->ResetFunctionStack(state);
  3570. if (quest) {
  3571. quest->AddPrereqRace(race);
  3572. }
  3573. return 0;
  3574. }
  3575. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3576. if (!lua_interface)
  3577. return 0;
  3578. Quest* quest = lua_interface->GetQuest(state);
  3579. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3580. lua_interface->ResetFunctionStack(state);
  3581. if (quest) {
  3582. quest->AddPrereqModelType(model_type);
  3583. }
  3584. return 0;
  3585. }
  3586. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3587. if (!lua_interface)
  3588. return 0;
  3589. Quest* quest = lua_interface->GetQuest(state);
  3590. int8 level = lua_interface->GetInt8Value(state, 2);
  3591. lua_interface->ResetFunctionStack(state);
  3592. if (!quest) {
  3593. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3594. return 0;
  3595. }
  3596. quest->SetPrereqTSLevel(level);
  3597. return 0;
  3598. }
  3599. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3600. if (!lua_interface)
  3601. return 0;
  3602. Quest* quest = lua_interface->GetQuest(state);
  3603. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3604. lua_interface->ResetFunctionStack(state);
  3605. if (!quest) {
  3606. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3607. return 0;
  3608. }
  3609. quest->AddPrereqTradeskillClass(class_id);
  3610. return 0;
  3611. }
  3612. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3613. if (!lua_interface)
  3614. return 0;
  3615. Quest* quest = lua_interface->GetQuest(state);
  3616. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3617. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3618. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3619. lua_interface->ResetFunctionStack(state);
  3620. if (quest) {
  3621. quest->AddPrereqFaction(faction_id, min, max);
  3622. }
  3623. return 0;
  3624. }
  3625. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3626. if (!lua_interface)
  3627. return 0;
  3628. Quest* quest = lua_interface->GetQuest(state);
  3629. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3630. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3631. lua_interface->ResetFunctionStack(state);
  3632. if (quest) {
  3633. if (quantity == 0)
  3634. quantity = 1;
  3635. Item* master_item = master_item_list.GetItem(item_id);
  3636. if (master_item) {
  3637. Item* item = new Item(master_item);
  3638. item->details.count = quantity;
  3639. quest->AddSelectableRewardItem(item);
  3640. }
  3641. }
  3642. return 0;
  3643. }
  3644. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3645. if (!lua_interface)
  3646. return 0;
  3647. Quest* quest = lua_interface->GetQuest(state);
  3648. if (quest) {
  3649. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3650. vector<Item*>* items = quest->GetRewardItems();
  3651. if (items) {
  3652. vector<Item*>::iterator itr;
  3653. for (itr = items->begin(); itr != items->end(); itr++) {
  3654. if (*itr && (*itr)->details.item_id == item_id) {
  3655. lua_interface->SetBooleanValue(state, true);
  3656. return 1;
  3657. }
  3658. }
  3659. }
  3660. }
  3661. lua_interface->SetBooleanValue(state, false);
  3662. return 1;
  3663. }
  3664. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3665. if (!lua_interface)
  3666. return 0;
  3667. Quest* quest = lua_interface->GetQuest(state);
  3668. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3669. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3670. lua_interface->ResetFunctionStack(state);
  3671. if (quest) {
  3672. if (quantity == 0)
  3673. quantity = 1;
  3674. Item* master_item = master_item_list.GetItem(item_id);
  3675. if (master_item) {
  3676. Item* item = new Item(master_item);
  3677. item->details.count = quantity;
  3678. quest->AddRewardItem(item);
  3679. }
  3680. }
  3681. return 0;
  3682. }
  3683. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3684. if (!lua_interface)
  3685. return 0;
  3686. Quest* quest = lua_interface->GetQuest(state);
  3687. int32 copper = lua_interface->GetInt32Value(state, 2);
  3688. int32 silver = lua_interface->GetInt32Value(state, 3);
  3689. int32 gold = lua_interface->GetInt32Value(state, 4);
  3690. int32 plat = lua_interface->GetInt32Value(state, 5);
  3691. lua_interface->ResetFunctionStack(state);
  3692. if (quest) {
  3693. quest->AddRewardCoins(copper, silver, gold, plat);
  3694. }
  3695. return 0;
  3696. }
  3697. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3698. if (!lua_interface)
  3699. return 0;
  3700. Quest* quest = lua_interface->GetQuest(state);
  3701. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3702. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3703. lua_interface->ResetFunctionStack(state);
  3704. if (quest && faction_id > 0 && amount != 0)
  3705. quest->AddRewardFaction(faction_id, amount);
  3706. return 0;
  3707. }
  3708. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3709. if (!lua_interface)
  3710. return 0;
  3711. Quest* quest = lua_interface->GetQuest(state);
  3712. int32 status = lua_interface->GetInt32Value(state, 2);
  3713. lua_interface->ResetFunctionStack(state);
  3714. if (quest) {
  3715. quest->SetRewardStatus(status);
  3716. }
  3717. return 0;
  3718. }
  3719. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3720. if (!lua_interface)
  3721. return 0;
  3722. Quest* quest = lua_interface->GetQuest(state);
  3723. int32 status = lua_interface->GetInt32Value(state, 2);
  3724. lua_interface->ResetFunctionStack(state);
  3725. if (quest) {
  3726. quest->SetStatusTmpReward(status);
  3727. }
  3728. return 0;
  3729. }
  3730. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3731. if (!lua_interface)
  3732. return 0;
  3733. Quest* quest = lua_interface->GetQuest(state);
  3734. int64 coins = lua_interface->GetInt64Value(state, 2);
  3735. lua_interface->ResetFunctionStack(state);
  3736. if (quest) {
  3737. quest->SetCoinTmpReward(coins);
  3738. }
  3739. return 0;
  3740. }
  3741. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3742. if (!lua_interface)
  3743. return 0;
  3744. Quest* quest = lua_interface->GetQuest(state);
  3745. string comment = lua_interface->GetStringValue(state, 2);
  3746. lua_interface->ResetFunctionStack(state);
  3747. if (quest) {
  3748. quest->SetRewardComment(comment);
  3749. }
  3750. return 0;
  3751. }
  3752. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3753. if (!lua_interface)
  3754. return 0;
  3755. Quest* quest = lua_interface->GetQuest(state);
  3756. int32 exp = lua_interface->GetInt32Value(state, 2);
  3757. lua_interface->ResetFunctionStack(state);
  3758. if (quest) {
  3759. quest->SetRewardXP(exp);
  3760. }
  3761. return 0;
  3762. }
  3763. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3764. Quest* quest = lua_interface->GetQuest(state);
  3765. int32 step = lua_interface->GetInt32Value(state, 2);
  3766. string description = lua_interface->GetStringValue(state, 3);
  3767. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3768. float percentage = lua_interface->GetFloatValue(state, 5);
  3769. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3770. int16 icon = lua_interface->GetInt16Value(state, 7);
  3771. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3772. if (quest) {
  3773. const char* taskgroup = 0;
  3774. if (str_taskgroup.length() > 0)
  3775. taskgroup = str_taskgroup.c_str();
  3776. int32 id = 0;
  3777. vector<int32>* ids = 0;
  3778. int i = 0;
  3779. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3780. if (ids == 0)
  3781. ids = new vector<int32>;
  3782. ids->push_back(id);
  3783. i++;
  3784. }
  3785. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3786. if (quest_step && icon && quantity > 0)
  3787. quest_step->SetIcon(icon);
  3788. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3789. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3790. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3791. }
  3792. }
  3793. lua_interface->ResetFunctionStack(state);
  3794. return 0;
  3795. }
  3796. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3797. {
  3798. if (!lua_interface)
  3799. return 0;
  3800. Quest* quest = lua_interface->GetQuest(state);
  3801. int32 step = lua_interface->GetInt32Value(state, 2);
  3802. string description = lua_interface->GetStringValue(state, 3);
  3803. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3804. float percentage = lua_interface->GetFloatValue(state, 5);
  3805. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3806. int16 icon = lua_interface->GetInt16Value(state, 7);
  3807. if (quest) {
  3808. const char* taskgroup = 0;
  3809. if (str_taskgroup.length() > 0)
  3810. taskgroup = str_taskgroup.c_str();
  3811. int32 id = 0;
  3812. vector<int32>* ids = 0;
  3813. int i = 0;
  3814. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3815. if (ids == 0)
  3816. ids = new vector<int32>;
  3817. ids->push_back(id);
  3818. i++;
  3819. }
  3820. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3821. if (quest_step && icon > 0 && quantity > 0)
  3822. quest_step->SetIcon(icon);
  3823. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3824. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3825. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3826. }
  3827. safe_delete(ids);
  3828. }
  3829. lua_interface->ResetFunctionStack(state);
  3830. return 0;
  3831. }
  3832. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3833. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3834. }
  3835. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3836. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3837. }
  3838. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3839. if (!lua_interface)
  3840. return 0;
  3841. Quest* quest = lua_interface->GetQuest(state);
  3842. int32 step = lua_interface->GetInt32Value(state, 2);
  3843. string description = lua_interface->GetStringValue(state, 3);
  3844. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3845. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3846. int16 icon = lua_interface->GetInt16Value(state, 6);
  3847. if (quest) {
  3848. const char* taskgroup = 0;
  3849. if (str_taskgroup.length() > 0)
  3850. taskgroup = str_taskgroup.c_str();
  3851. int32 npc_id = 0;
  3852. vector<int32>* ids = 0;
  3853. int i = 0;
  3854. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3855. if (ids == 0)
  3856. ids = new vector<int32>;
  3857. ids->push_back(npc_id);
  3858. i++;
  3859. }
  3860. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3861. if (quest_step && icon > 0)
  3862. quest_step->SetIcon(icon);
  3863. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3864. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3865. if(client)
  3866. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3867. }
  3868. safe_delete(ids);
  3869. }
  3870. lua_interface->ResetFunctionStack(state);
  3871. return 0;
  3872. }
  3873. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3874. if (!lua_interface)
  3875. return 0;
  3876. Quest* quest = lua_interface->GetQuest(state);
  3877. int32 step = lua_interface->GetInt32Value(state, 2);
  3878. string description = lua_interface->GetStringValue(state, 3);
  3879. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3880. float percentage = lua_interface->GetFloatValue(state, 5);
  3881. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3882. int16 icon = lua_interface->GetInt16Value(state, 7);
  3883. if (quest) {
  3884. const char* taskgroup = 0;
  3885. if (str_taskgroup.length() > 0)
  3886. taskgroup = str_taskgroup.c_str();
  3887. int32 item_id = 0;
  3888. vector<int32>* ids = 0;
  3889. int i = 0;
  3890. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3891. if (ids == 0)
  3892. ids = new vector<int32>;
  3893. ids->push_back(item_id);
  3894. i++;
  3895. }
  3896. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3897. if (quest_step && icon > 0 && quantity > 0)
  3898. quest_step->SetIcon(icon);
  3899. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3900. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3901. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3902. }
  3903. safe_delete(ids);
  3904. }
  3905. lua_interface->ResetFunctionStack(state);
  3906. return 0;
  3907. }
  3908. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3909. if (!lua_interface)
  3910. return 0;
  3911. Quest* quest = lua_interface->GetQuest(state);
  3912. int32 step = lua_interface->GetInt32Value(state, 2);
  3913. string description = lua_interface->GetStringValue(state, 3);
  3914. float max_variation = lua_interface->GetFloatValue(state, 4);
  3915. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3916. int16 icon = lua_interface->GetInt16Value(state, 6);
  3917. if (quest) {
  3918. const char* taskgroup = 0;
  3919. if (str_taskgroup.length() > 0)
  3920. taskgroup = str_taskgroup.c_str();
  3921. vector<Location>* locations = 0;
  3922. int8 i = 7;
  3923. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3924. while (true) {
  3925. Location loc;
  3926. loc.x = lua_interface->GetFloatValue(state, i);
  3927. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3928. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3929. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3930. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3931. break;
  3932. if (locations == 0)
  3933. locations = new vector<Location>;
  3934. locations->push_back(loc);
  3935. i += 4;
  3936. }
  3937. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3938. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3939. if (quest_step && icon > 0)
  3940. quest_step->SetIcon(icon);
  3941. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3942. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3943. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3944. }
  3945. }
  3946. lua_interface->ResetFunctionStack(state);
  3947. return 0;
  3948. }
  3949. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3950. if (!lua_interface)
  3951. return 0;
  3952. Quest* quest = lua_interface->GetQuest(state);
  3953. int32 step = lua_interface->GetInt32Value(state, 2);
  3954. string description = lua_interface->GetStringValue(state, 3);
  3955. float max_variation = lua_interface->GetFloatValue(state, 4);
  3956. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3957. int16 icon = lua_interface->GetInt16Value(state, 6);
  3958. if (quest) {
  3959. const char* taskgroup = 0;
  3960. if (str_taskgroup.length() > 0)
  3961. taskgroup = str_taskgroup.c_str();
  3962. vector<Location>* locations = 0;
  3963. int8 i = 7;
  3964. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3965. while (true) {
  3966. Location loc;
  3967. loc.x = lua_interface->GetFloatValue(state, i);
  3968. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3969. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3970. loc.zone_id = 0;
  3971. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3972. break;
  3973. if (locations == 0)
  3974. locations = new vector<Location>;
  3975. locations->push_back(loc);
  3976. i += 3;
  3977. }
  3978. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3979. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3980. if (quest_step && icon > 0)
  3981. quest_step->SetIcon(icon);
  3982. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3983. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3984. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3985. }
  3986. }
  3987. lua_interface->ResetFunctionStack(state);
  3988. return 0;
  3989. }
  3990. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3991. if (!lua_interface)
  3992. return 0;
  3993. Quest* quest = lua_interface->GetQuest(state);
  3994. int32 step = lua_interface->GetInt32Value(state, 2);
  3995. string description = lua_interface->GetStringValue(state, 3);
  3996. float max_variation = lua_interface->GetFloatValue(state, 4);
  3997. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3998. int16 icon = lua_interface->GetInt16Value(state, 6);
  3999. if (quest) {
  4000. const char* taskgroup = 0;
  4001. if (str_taskgroup.length() > 0)
  4002. taskgroup = str_taskgroup.c_str();
  4003. vector<Location>* locations = 0;
  4004. int i = 7;
  4005. while (true) {
  4006. Location loc;
  4007. loc.x = lua_interface->GetFloatValue(state, i);
  4008. loc.y = lua_interface->GetFloatValue(state, i + 1);
  4009. loc.z = lua_interface->GetFloatValue(state, i + 2);
  4010. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  4011. break;
  4012. if (locations == 0)
  4013. locations = new vector<Location>;
  4014. locations->push_back(loc);
  4015. i += 3;
  4016. }
  4017. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  4018. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  4019. if (quest_step && icon > 0)
  4020. quest_step->SetIcon(icon);
  4021. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4022. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4023. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4024. }
  4025. }
  4026. lua_interface->ResetFunctionStack(state);
  4027. return 0;
  4028. }
  4029. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  4030. Quest* quest = lua_interface->GetQuest(state);
  4031. int32 step = lua_interface->GetInt32Value(state, 2);
  4032. string description = lua_interface->GetStringValue(state, 3);
  4033. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4034. float percentage = lua_interface->GetFloatValue(state, 5);
  4035. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4036. int16 icon = lua_interface->GetInt16Value(state, 7);
  4037. if (quest) {
  4038. const char* taskgroup = 0;
  4039. if (str_taskgroup.length() > 0)
  4040. taskgroup = str_taskgroup.c_str();
  4041. int32 spell_id = 0;
  4042. vector<int32>* ids = 0;
  4043. int i = 0;
  4044. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4045. if (ids == 0)
  4046. ids = new vector<int32>;
  4047. ids->push_back(spell_id);
  4048. i++;
  4049. }
  4050. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4051. if (quest_step && icon > 0 && quantity > 0)
  4052. quest_step->SetIcon(icon);
  4053. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4054. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4055. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4056. }
  4057. safe_delete(ids);
  4058. }
  4059. lua_interface->ResetFunctionStack(state);
  4060. return 0;
  4061. }
  4062. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  4063. if (!lua_interface)
  4064. return 0;
  4065. Quest* quest = lua_interface->GetQuest(state);
  4066. int32 step = lua_interface->GetInt32Value(state, 2);
  4067. string description = lua_interface->GetStringValue(state, 3);
  4068. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4069. float percentage = lua_interface->GetFloatValue(state, 5);
  4070. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4071. int16 icon = lua_interface->GetInt16Value(state, 7);
  4072. if (quest) {
  4073. const char* taskgroup = 0;
  4074. if (str_taskgroup.length() > 0)
  4075. taskgroup = str_taskgroup.c_str();
  4076. int32 item_id = 0;
  4077. vector<int32>* ids = 0;
  4078. int i = 0;
  4079. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4080. if (ids == 0)
  4081. ids = new vector<int32>;
  4082. ids->push_back(item_id);
  4083. i++;
  4084. }
  4085. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4086. if (quest_step && icon > 0 && quantity > 0)
  4087. quest_step->SetIcon(icon);
  4088. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4089. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4090. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4091. }
  4092. safe_delete(ids);
  4093. }
  4094. lua_interface->ResetFunctionStack(state);
  4095. return 0;
  4096. }
  4097. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  4098. if (!lua_interface)
  4099. return 0;
  4100. Quest* quest = lua_interface->GetQuest(state);
  4101. int32 step = lua_interface->GetInt32Value(state, 2);
  4102. string description = lua_interface->GetStringValue(state, 3);
  4103. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4104. float percentage = lua_interface->GetFloatValue(state, 5);
  4105. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4106. int16 icon = lua_interface->GetInt16Value(state, 7);
  4107. if (quest) {
  4108. const char* taskgroup = 0;
  4109. if (str_taskgroup.length() > 0)
  4110. taskgroup = str_taskgroup.c_str();
  4111. int32 item_id = 0;
  4112. vector<int32>* ids = 0;
  4113. int i = 0;
  4114. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4115. if (ids == 0)
  4116. ids = new vector<int32>;
  4117. ids->push_back(item_id);
  4118. i++;
  4119. }
  4120. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4121. if (quest_step && icon > 0 && quantity > 0)
  4122. quest_step->SetIcon(icon);
  4123. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4124. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4125. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4126. }
  4127. safe_delete(ids);
  4128. }
  4129. lua_interface->ResetFunctionStack(state);
  4130. return 0;
  4131. }
  4132. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  4133. if (!lua_interface)
  4134. return 0;
  4135. Quest* quest = lua_interface->GetQuest(state);
  4136. string action = lua_interface->GetStringValue(state, 2);
  4137. lua_interface->ResetFunctionStack(state);
  4138. if (quest) {
  4139. if (action.length() > 0)
  4140. quest->SetCompleteAction(action);
  4141. }
  4142. return 0;
  4143. }
  4144. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  4145. if (!lua_interface)
  4146. return 0;
  4147. Quest* quest = lua_interface->GetQuest(state);
  4148. int32 step = lua_interface->GetInt32Value(state, 2);
  4149. string action = lua_interface->GetStringValue(state, 3);
  4150. lua_interface->ResetFunctionStack(state);
  4151. if (quest) {
  4152. if (step > 0 && action.length() > 0)
  4153. quest->AddCompleteAction(step, action);
  4154. }
  4155. return 0;
  4156. }
  4157. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  4158. if (!lua_interface)
  4159. return 0;
  4160. Quest* quest = lua_interface->GetQuest(state);
  4161. int32 step = lua_interface->GetInt32Value(state, 2);
  4162. string action = lua_interface->GetStringValue(state, 3);
  4163. lua_interface->ResetFunctionStack(state);
  4164. if (quest) {
  4165. if (step > 0 && action.length() > 0)
  4166. quest->AddProgressAction(step, action);
  4167. }
  4168. return 0;
  4169. }
  4170. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  4171. if (!lua_interface)
  4172. return 0;
  4173. Quest* quest = lua_interface->GetQuest(state);
  4174. string description = lua_interface->GetStringValue(state, 2);
  4175. lua_interface->ResetFunctionStack(state);
  4176. if (quest && description.length() > 0)
  4177. quest->SetDescription(description);
  4178. return 0;
  4179. }
  4180. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4181. if (!lua_interface)
  4182. return 0;
  4183. Quest* quest = lua_interface->GetQuest(state);
  4184. string description = lua_interface->GetStringValue(state, 2);
  4185. lua_interface->ResetFunctionStack(state);
  4186. if (quest && description.length() > 0)
  4187. quest->SetCompletedDescription(description);
  4188. return 0;
  4189. }
  4190. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4191. if (!lua_interface)
  4192. return 0;
  4193. Quest* quest = lua_interface->GetQuest(state);
  4194. int32 step = lua_interface->GetInt32Value(state, 2);
  4195. string description = lua_interface->GetStringValue(state, 3);
  4196. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4197. lua_interface->ResetFunctionStack(state);
  4198. if (quest && step > 0 && description.length() > 0) {
  4199. quest->SetTaskGroupDescription(step, description, display_bullets);
  4200. }
  4201. return 0;
  4202. }
  4203. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4204. if (!lua_interface)
  4205. return 0;
  4206. Quest* quest = lua_interface->GetQuest(state);
  4207. int32 step = lua_interface->GetInt32Value(state, 2);
  4208. string description = lua_interface->GetStringValue(state, 3);
  4209. lua_interface->ResetFunctionStack(state);
  4210. if (quest && step > 0 && description.length() > 0) {
  4211. quest->SetStepDescription(step, description);
  4212. }
  4213. return 0;
  4214. }
  4215. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4216. Quest* quest = lua_interface->GetQuest(state);
  4217. string zone = lua_interface->GetStringValue(state, 2);
  4218. lua_interface->ResetFunctionStack(state);
  4219. if (quest && zone.length() > 0)
  4220. quest->SetZone(zone);
  4221. return 0;
  4222. }
  4223. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4224. if (!lua_interface)
  4225. return 0;
  4226. Quest* quest = lua_interface->GetQuest(state);
  4227. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4228. lua_interface->ResetFunctionStack(state);
  4229. if (quest && spawn) {
  4230. if (spawn->IsPlayer()) {
  4231. Client* client = ((Player*)spawn)->GetClient();
  4232. if (client) {
  4233. client->AddPendingQuestReward(quest);
  4234. }
  4235. }
  4236. }
  4237. return 0;
  4238. }
  4239. int EQ2Emu_lua_Harvest(lua_State* state) {
  4240. if (!lua_interface)
  4241. return 0;
  4242. Spawn* player = lua_interface->GetSpawn(state);
  4243. Spawn* node = lua_interface->GetSpawn(state, 2);
  4244. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4245. Client* client = ((Player*)player)->GetClient();
  4246. if (client) {
  4247. ((GroundSpawn*)node)->ProcessHarvest(client);
  4248. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4249. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4250. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4251. }
  4252. }
  4253. }
  4254. else if (player && player->IsPlayer()) {
  4255. Client* client = ((Player*)player)->GetClient();
  4256. if (client)
  4257. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4258. }
  4259. lua_interface->ResetFunctionStack(state);
  4260. return 0;
  4261. }
  4262. int EQ2Emu_lua_Bind(lua_State* state) {
  4263. if (!lua_interface)
  4264. return 0;
  4265. Spawn* spawn = lua_interface->GetSpawn(state);
  4266. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4267. float x = lua_interface->GetFloatValue(state, 3);
  4268. float y = lua_interface->GetFloatValue(state, 4);
  4269. float z = lua_interface->GetFloatValue(state, 5);
  4270. float h = lua_interface->GetFloatValue(state, 6);
  4271. lua_interface->ResetFunctionStack(state);
  4272. if (!spawn) {
  4273. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4274. return 0;
  4275. }
  4276. if (!spawn->IsPlayer()) {
  4277. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4278. return 0;
  4279. }
  4280. if (zone_id == 0) {
  4281. Client* client = ((Player*)spawn)->GetClient();
  4282. if (!client) {
  4283. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4284. return 0;
  4285. }
  4286. if (!client->Bind())
  4287. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4288. }
  4289. else {
  4290. Player* player = (Player*)spawn;
  4291. player->GetPlayerInfo()->SetBindZone(zone_id);
  4292. player->GetPlayerInfo()->SetBindX(x);
  4293. player->GetPlayerInfo()->SetBindY(y);
  4294. player->GetPlayerInfo()->SetBindZ(z);
  4295. player->GetPlayerInfo()->SetBindHeading(h);
  4296. }
  4297. return 0;
  4298. }
  4299. int EQ2Emu_lua_Gate(lua_State* state) {
  4300. if (!lua_interface)
  4301. return 0;
  4302. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4303. Spawn* spawn = lua_interface->GetSpawn(state);
  4304. lua_interface->ResetFunctionStack(state);
  4305. if (spawn) {
  4306. if (spawn->IsPlayer()) {
  4307. Client* client = ((Player*)spawn)->GetClient();
  4308. if (client) {
  4309. if (!client->Gate((spell != nullptr) ? true : false))
  4310. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4311. }
  4312. }
  4313. }
  4314. return 0;
  4315. }
  4316. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4317. if (!lua_interface)
  4318. return 0;
  4319. bool ret = false;
  4320. Spawn* spawn = lua_interface->GetSpawn(state);
  4321. lua_interface->ResetFunctionStack(state);
  4322. if (spawn) {
  4323. if (spawn->IsPlayer()) {
  4324. Client* client = ((Player*)spawn)->GetClient();
  4325. if (client)
  4326. ret = client->BindAllowed();
  4327. }
  4328. }
  4329. lua_interface->SetBooleanValue(state, ret);
  4330. return 1;
  4331. }
  4332. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4333. if (!lua_interface)
  4334. return 0;
  4335. bool ret = false;
  4336. Spawn* spawn = lua_interface->GetSpawn(state);
  4337. lua_interface->ResetFunctionStack(state);
  4338. if (spawn) {
  4339. if (spawn->IsPlayer()) {
  4340. Client* client = ((Player*)spawn)->GetClient();
  4341. ZoneServer* zone = lua_interface->GetZone(state);
  4342. if (client && zone){
  4343. ret = zone->GetCanGate();
  4344. }
  4345. }
  4346. }
  4347. lua_interface->SetBooleanValue(state, ret);
  4348. return 1;
  4349. }
  4350. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4351. Spawn* spawn = lua_interface->GetSpawn(state);
  4352. lua_interface->ResetFunctionStack(state);
  4353. if (spawn) {
  4354. lua_interface->SetBooleanValue(state, spawn->Alive());
  4355. return 1;
  4356. }
  4357. return 0;
  4358. }
  4359. int EQ2Emu_lua_IsSpawnGroupAlive(lua_State* state) {
  4360. ZoneServer* zone = lua_interface->GetZone(state);
  4361. int32 group_id = lua_interface->GetInt32Value(state, 2);
  4362. lua_interface->ResetFunctionStack(state);
  4363. if (zone) {
  4364. lua_interface->SetBooleanValue(state, zone->IsSpawnGroupAlive(group_id));
  4365. return 1;
  4366. }
  4367. return 0;
  4368. }
  4369. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4370. if (!lua_interface)
  4371. return 0;
  4372. Spawn* spawn = lua_interface->GetSpawn(state);
  4373. lua_interface->ResetFunctionStack(state);
  4374. if (spawn && spawn->IsEntity()) {
  4375. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4376. return 1;
  4377. }
  4378. return 0;
  4379. }
  4380. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4381. Spawn* spawn = lua_interface->GetSpawn(state);
  4382. string message = lua_interface->GetStringValue(state, 2);
  4383. string color_str = lua_interface->GetStringValue(state, 3);
  4384. lua_interface->ResetFunctionStack(state);
  4385. int8 color = CHANNEL_NARRATIVE;
  4386. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4387. Client* client = ((Player*)spawn)->GetClient();
  4388. if (client) {
  4389. if (color_str.length() > 0) {
  4390. // leave for backwards compat, but all future should just use the number
  4391. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4392. color = CHANNEL_COLOR_RED;
  4393. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4394. color = CHANNEL_COLOR_YELLOW;
  4395. else
  4396. {
  4397. // use a number to specify the channel as per Commands/Commands.h defines
  4398. color = (int8)atoul(color_str.c_str());
  4399. }
  4400. }
  4401. client->SimpleMessage(color, message.c_str());
  4402. }
  4403. }
  4404. return 0;
  4405. }
  4406. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4407. Spawn* spawn = lua_interface->GetSpawn(state);
  4408. string message = lua_interface->GetStringValue(state, 2);
  4409. int8 red = lua_interface->GetInt8Value(state, 3);
  4410. int8 green = lua_interface->GetInt8Value(state, 4);
  4411. int8 blue = lua_interface->GetInt8Value(state, 5);
  4412. lua_interface->ResetFunctionStack(state);
  4413. if (!spawn) {
  4414. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4415. return 0;
  4416. }
  4417. if (!spawn->IsPlayer()) {
  4418. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not a player.", lua_interface->GetScriptName(state));
  4419. return 0;
  4420. }
  4421. int32 words = ::CountWordsInString(message.c_str());
  4422. if (words < 5)
  4423. words = 5;
  4424. Client* client = ((Player*)spawn)->GetClient();
  4425. if (client)
  4426. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4427. return 0;
  4428. }
  4429. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4430. Spawn* spawn = lua_interface->GetSpawn(state);
  4431. int8 param = lua_interface->GetInt8Value(state, 2);
  4432. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4433. int8 value = lua_interface->GetInt8Value(state, 4);
  4434. lua_interface->ResetFunctionStack(state);
  4435. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4436. Client* client = ((Player*)spawn)->GetClient();
  4437. if (client) {
  4438. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4439. switch (param) {
  4440. case 1: {
  4441. packet->setDataByName("parameter1", param_value);
  4442. break;
  4443. }
  4444. case 2: {
  4445. packet->setDataByName("parameter2", param_value);
  4446. break;
  4447. }
  4448. case 3: {
  4449. packet->setDataByName("parameter3", param_value);
  4450. break;
  4451. }
  4452. case 4: {
  4453. packet->setDataByName("parameter4", param_value);
  4454. break;
  4455. }
  4456. case 5: {
  4457. packet->setDataByName("parameter5", param_value);
  4458. break;
  4459. }
  4460. }
  4461. packet->setDataByName("value", value);
  4462. client->QueuePacket(packet->serialize());
  4463. safe_delete(packet);
  4464. }
  4465. }
  4466. return 0;
  4467. }
  4468. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4469. Spawn* spawn = lua_interface->GetSpawn(state);
  4470. lua_interface->ResetFunctionStack(state);
  4471. if (spawn && spawn->IsPlayer()) {
  4472. if (((Player*)spawn)->GetIsTracking())
  4473. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4474. else
  4475. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4476. }
  4477. return 0;
  4478. }
  4479. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4480. Spawn* player = lua_interface->GetSpawn(state);
  4481. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4482. string name = lua_interface->GetStringValue(state, 3);
  4483. float distance = lua_interface->GetFloatValue(state, 4);
  4484. string command = lua_interface->GetStringValue(state, 5);
  4485. string error_text = lua_interface->GetStringValue(state, 6);
  4486. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4487. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4488. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4489. lua_interface->ResetFunctionStack(state);
  4490. if (spawn) {
  4491. if (distance == 0)
  4492. distance = 10.0f;
  4493. if (command.length() == 0)
  4494. command = name;
  4495. if (command.length() < 1 && name.length() < 1)
  4496. {
  4497. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4498. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4499. spawn->RemovePrimaryCommands();
  4500. }
  4501. else
  4502. {
  4503. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4504. }
  4505. }
  4506. return 0;
  4507. }
  4508. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4509. if (!lua_interface)
  4510. return 0;
  4511. Spawn* player = lua_interface->GetSpawn(state);
  4512. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4513. int16 tier = lua_interface->GetInt16Value(state, 3);
  4514. lua_interface->ResetFunctionStack(state);
  4515. if (player && player->IsPlayer()) {
  4516. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4517. return 1;
  4518. }
  4519. return 0;
  4520. }
  4521. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4522. if (!lua_interface)
  4523. return 0;
  4524. Spawn* player = lua_interface->GetSpawn(state);
  4525. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4526. int16 tier = lua_interface->GetInt16Value(state, 3);
  4527. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4528. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4529. bool add_to_hotbar = true;
  4530. if (num_args > 4) {
  4531. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4532. }
  4533. lua_interface->ResetFunctionStack(state);
  4534. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4535. if (player && spell && player->IsPlayer()) {
  4536. Client* client = player->GetClient();
  4537. if (client) {
  4538. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4539. {
  4540. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4541. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4542. client->GetPlayer()->UnlockSpell(spell);
  4543. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4544. }
  4545. else
  4546. {
  4547. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4548. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4549. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4550. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4551. client->GetPlayer()->UnlockSpell(spell);
  4552. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4553. }
  4554. //if (client ) {
  4555. // ((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);
  4556. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4557. if (outapp)
  4558. client->QueuePacket(outapp);
  4559. }
  4560. }
  4561. return 0;
  4562. }
  4563. int EQ2Emu_lua_DeleteSpellBook(lua_State* state) {
  4564. if (!lua_interface)
  4565. return 0;
  4566. Spawn* player = lua_interface->GetSpawn(state);
  4567. int8 type_selection = lua_interface->GetInt8Value(state, 2);
  4568. lua_interface->ResetFunctionStack(state);
  4569. if (player && player->IsPlayer()) {
  4570. Client* client = player->GetClient();
  4571. if (client) {
  4572. ((Player*)player)->DeleteSpellBook(type_selection);
  4573. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4574. if (outapp)
  4575. client->QueuePacket(outapp);
  4576. }
  4577. }
  4578. return 0;
  4579. }
  4580. int EQ2Emu_lua_SendNewAdventureSpells(lua_State* state) {
  4581. if (!lua_interface)
  4582. return 0;
  4583. Spawn* player = lua_interface->GetSpawn(state);
  4584. lua_interface->ResetFunctionStack(state);
  4585. if (player && player->IsPlayer()) {
  4586. Client* client = player->GetClient();
  4587. if (client) {
  4588. client->SendNewAdventureSpells();
  4589. }
  4590. }
  4591. return 0;
  4592. }
  4593. int EQ2Emu_lua_SendNewTradeskillSpells(lua_State* state) {
  4594. if (!lua_interface)
  4595. return 0;
  4596. Spawn* player = lua_interface->GetSpawn(state);
  4597. lua_interface->ResetFunctionStack(state);
  4598. if (player && player->IsPlayer()) {
  4599. Client* client = player->GetClient();
  4600. if (client) {
  4601. client->SendNewTradeskillSpells();
  4602. }
  4603. }
  4604. return 0;
  4605. }
  4606. int EQ2Emu_lua_RemoveSpellBookEntry(lua_State* state) {
  4607. if (!lua_interface)
  4608. return 0;
  4609. Spawn* player = lua_interface->GetSpawn(state);
  4610. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4611. lua_interface->ResetFunctionStack(state);
  4612. if (player && player->IsPlayer()) {
  4613. SpellBookEntry* sbe = ((Player*)player)->GetSpellBookSpell(spellid);
  4614. Client* client = player->GetClient();
  4615. if (sbe && client) {
  4616. ((Player*)player)->RemoveSpellBookEntry(spellid);
  4617. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4618. if (outapp)
  4619. client->QueuePacket(outapp);
  4620. }
  4621. }
  4622. return 0;
  4623. }
  4624. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4625. if (!lua_interface)
  4626. return 0;
  4627. Spawn* player = lua_interface->GetSpawn(state);
  4628. lua_interface->ResetFunctionStack(state);
  4629. if (player && player->IsPlayer()) {
  4630. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4631. return 1;
  4632. }
  4633. return 0;
  4634. }
  4635. int EQ2Emu_lua_Attack(lua_State* state) {
  4636. if (lua_interface) {
  4637. Spawn* npc = lua_interface->GetSpawn(state);
  4638. Spawn* player = lua_interface->GetSpawn(state, 2);
  4639. lua_interface->ResetFunctionStack(state);
  4640. if (npc && player && npc->IsNPC() && player->IsEntity())
  4641. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4642. }
  4643. return 0;
  4644. }
  4645. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4646. if (lua_interface) {
  4647. Spawn* target = lua_interface->GetSpawn(state);
  4648. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4649. lua_interface->ResetFunctionStack(state);
  4650. if (target && target->GetZone())
  4651. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4652. }
  4653. return 0;
  4654. }
  4655. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4656. Spawn* player;
  4657. if (lua_interface) {
  4658. player = lua_interface->GetSpawn(state);
  4659. lua_interface->ResetFunctionStack(state);
  4660. if (player && player->IsPlayer()) {
  4661. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4662. return 1;
  4663. }
  4664. }
  4665. return 0;
  4666. }
  4667. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4668. Spawn* player;
  4669. Client* client;
  4670. if (lua_interface) {
  4671. player = lua_interface->GetSpawn(state);
  4672. lua_interface->ResetFunctionStack(state);
  4673. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4674. if ((client = ((Player*)player)->GetClient()))
  4675. client->HandInCollections();
  4676. }
  4677. return 0;
  4678. }
  4679. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4680. Spawn* widget;
  4681. if (lua_interface) {
  4682. widget = lua_interface->GetSpawn(state);
  4683. lua_interface->ResetFunctionStack(state);
  4684. if (widget && widget->IsWidget())
  4685. ((Widget*)widget)->HandleUse(nullptr, "");
  4686. }
  4687. return 0;
  4688. }
  4689. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4690. Spawn* spawn = 0;
  4691. int32 primary_list = 0;
  4692. int32 secondary_list = 0;
  4693. if (lua_interface) {
  4694. spawn = lua_interface->GetSpawn(state);
  4695. primary_list = lua_interface->GetInt32Value(state, 2);
  4696. secondary_list = lua_interface->GetInt32Value(state, 3);
  4697. lua_interface->ResetFunctionStack(state);
  4698. if (!spawn->IsNPC()) {
  4699. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4700. return 0;
  4701. }
  4702. NPC* npc = (NPC*)spawn;
  4703. npc->SetPrimarySpellList(primary_list);
  4704. npc->SetSecondarySpellList(secondary_list);
  4705. npc->SetSpells(world.GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4706. }
  4707. return 0;
  4708. }
  4709. int EQ2Emu_lua_GetPet(lua_State* state) {
  4710. if (!lua_interface)
  4711. return 0;
  4712. Spawn* spawn = lua_interface->GetSpawn(state);
  4713. lua_interface->ResetFunctionStack(state);
  4714. if (spawn) {
  4715. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4716. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4717. return 1;
  4718. }
  4719. }
  4720. return 0;
  4721. }
  4722. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4723. if (!lua_interface)
  4724. return 0;
  4725. Spawn* spawn = lua_interface->GetSpawn(state);
  4726. lua_interface->ResetFunctionStack(state);
  4727. if (spawn) {
  4728. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4729. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4730. return 1;
  4731. }
  4732. }
  4733. return 0;
  4734. }
  4735. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4736. if (!lua_interface)
  4737. return 0;
  4738. Spawn* spawn = lua_interface->GetSpawn(state);
  4739. lua_interface->ResetFunctionStack(state);
  4740. if (spawn) {
  4741. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4742. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4743. return 1;
  4744. }
  4745. }
  4746. return 0;
  4747. }
  4748. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4749. if (!lua_interface)
  4750. return 0;
  4751. Spawn* spawn = lua_interface->GetSpawn(state);
  4752. lua_interface->ResetFunctionStack(state);
  4753. if (spawn) {
  4754. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4755. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4756. return 1;
  4757. }
  4758. }
  4759. return 0;
  4760. }
  4761. int EQ2Emu_lua_Charm(lua_State* state) {
  4762. if (!lua_interface)
  4763. return 0;
  4764. Spawn* owner = lua_interface->GetSpawn(state);
  4765. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4766. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4767. lua_interface->ResetFunctionStack(state);
  4768. if (!luaspell) {
  4769. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4770. return 0;
  4771. }
  4772. if(luaspell->resisted) {
  4773. return 0;
  4774. }
  4775. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4776. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4777. pet->SetPet(true);
  4778. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4779. ((NPC*)pet)->SetOwner((Entity*)owner);
  4780. // If owner is player and player does not have a summoned pet set the players charsheet
  4781. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4782. Player* player = (Player*)owner;
  4783. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4784. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4785. player->GetInfoStruct()->set_pet_movement(2);
  4786. player->GetInfoStruct()->set_pet_behavior(3);
  4787. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4788. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4789. // Make sure the values get sent to the client
  4790. player->SetCharSheetChanged(true);
  4791. }
  4792. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4793. pet->SetSpawnScript("");
  4794. // Set faction to the same as the owner
  4795. pet->SetFactionID(owner->GetFactionID());
  4796. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4797. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4798. // Clear hate list
  4799. ((NPC*)pet)->Brain()->ClearHate();
  4800. // Set the brain to a pet brain
  4801. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4802. }
  4803. return 0;
  4804. }
  4805. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4806. if (!lua_interface)
  4807. return 0;
  4808. Spawn* spawn = lua_interface->GetSpawn(state);
  4809. lua_interface->ResetFunctionStack(state);
  4810. if (!spawn) {
  4811. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4812. return 0;
  4813. }
  4814. vector<Spawn*> groupMembers;
  4815. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4816. groupMembers = *spawn->GetSpawnGroup();
  4817. }
  4818. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4819. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4820. deque<GroupMemberInfo*>::iterator itr;
  4821. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4822. if (group)
  4823. {
  4824. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4825. deque<GroupMemberInfo*>* members = group->GetMembers();
  4826. GroupMemberInfo* info = 0;
  4827. for (itr = members->begin(); itr != members->end(); itr++) {
  4828. info = *itr;
  4829. if (info->client)
  4830. groupMembers.push_back(info->client->GetPlayer());
  4831. }
  4832. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4833. }
  4834. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4835. }
  4836. else
  4837. return 0;
  4838. lua_createtable(state, groupMembers.size(), 0);
  4839. int newTable = lua_gettop(state);
  4840. for (int32 i = 0; i < groupMembers.size(); i++) {
  4841. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4842. lua_rawseti(state, newTable, i + 1);
  4843. }
  4844. return 1;
  4845. }
  4846. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4847. if (!lua_interface)
  4848. return 0;
  4849. lua_interface->ResetFunctionStack(state);
  4850. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4851. lua_interface->SetOptionWindowValue(state, option_window);
  4852. return 1;
  4853. }
  4854. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4855. if (!lua_interface)
  4856. return 0;
  4857. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4858. if (option_window) {
  4859. OptionWindowOption option_window_option;
  4860. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4861. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4862. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4863. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4864. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4865. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4866. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4867. option_window->push_back(option_window_option);
  4868. }
  4869. lua_interface->ResetFunctionStack(state);
  4870. return 0;
  4871. }
  4872. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4873. if (!lua_interface)
  4874. return 0;
  4875. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4876. Spawn* player = lua_interface->GetSpawn(state, 2);
  4877. string window_title = lua_interface->GetStringValue(state, 3);
  4878. string cancel_command = lua_interface->GetStringValue(state, 4);
  4879. lua_interface->ResetFunctionStack(state);
  4880. if (!player->IsPlayer()) {
  4881. lua_interface->LogError("%s: LUA SendOptionWindow command error: spawn is not a player", lua_interface->GetScriptName(state));
  4882. return 0;
  4883. }
  4884. Client* client = ((Player*)player)->GetClient();
  4885. if (option_window && window_title.length() > 0 && client) {
  4886. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4887. if (!packet)
  4888. return 0;
  4889. packet->setDataByName("title_text", window_title.c_str());
  4890. if (cancel_command.length() > 0)
  4891. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4892. packet->setArrayLengthByName("num_selections", option_window->size());
  4893. vector<OptionWindowOption>::iterator itr;
  4894. int8 i = 0;
  4895. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4896. OptionWindowOption opt = *itr;
  4897. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4898. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4899. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4900. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4901. if (opt.optionCommand.length() > 0)
  4902. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4903. if (opt.optionConfirmTitle.length() > 0)
  4904. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4905. i++;
  4906. }
  4907. client->QueuePacket(packet->serialize());
  4908. lua_interface->SetLuaUserDataStale(option_window);
  4909. safe_delete(option_window);
  4910. safe_delete(packet);
  4911. }
  4912. return 0;
  4913. }
  4914. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4915. if (!lua_interface)
  4916. return 0;
  4917. Spawn* spawn = lua_interface->GetSpawn(state);
  4918. lua_interface->ResetFunctionStack(state);
  4919. if (spawn) {
  4920. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4921. return 1;
  4922. }
  4923. else
  4924. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4925. return 0;
  4926. }
  4927. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4928. if (!lua_interface)
  4929. return 0;
  4930. Spawn* spawn = lua_interface->GetSpawn(state);
  4931. lua_interface->ResetFunctionStack(state);
  4932. if (spawn) {
  4933. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4934. return 1;
  4935. }
  4936. else
  4937. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4938. return 0;
  4939. }
  4940. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4941. if (!lua_interface)
  4942. return 0;
  4943. Spawn* spawn = lua_interface->GetSpawn(state);
  4944. lua_interface->ResetFunctionStack(state);
  4945. if (spawn) {
  4946. int8 class_id = spawn->GetTradeskillClass();
  4947. // Need to add 42 for the offset in the array
  4948. class_id += 44;
  4949. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4950. return 1;
  4951. }
  4952. else
  4953. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4954. return 0;
  4955. }
  4956. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4957. if (!lua_interface)
  4958. return 0;
  4959. Spawn* spawn = lua_interface->GetSpawn(state);
  4960. int16 level = lua_interface->GetInt8Value(state, 2);
  4961. lua_interface->ResetFunctionStack(state);
  4962. if (spawn) {
  4963. if (spawn->IsPlayer() && ((Player*)spawn)->GetClient())
  4964. ((Player*)spawn)->GetClient()->ChangeTSLevel(spawn->GetTSLevel(), level);
  4965. else
  4966. spawn->SetTSLevel(level);
  4967. }
  4968. else
  4969. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4970. return 0;
  4971. }
  4972. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4973. if (!lua_interface)
  4974. return 0;
  4975. Spawn* spawn = lua_interface->GetSpawn(state);
  4976. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4977. lua_interface->ResetFunctionStack(state);
  4978. if (spawn) {
  4979. spawn->SetAttackable(attackable);
  4980. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4981. }
  4982. return 0;
  4983. }
  4984. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4985. // Check to see if we have a valid lua_interface
  4986. if (!lua_interface)
  4987. return 0;
  4988. // Get the spawn that is getting the pet
  4989. Spawn* spawn = lua_interface->GetSpawn(state);
  4990. // Get the DB ID of the pet
  4991. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4992. // The max level the pet can gain
  4993. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4994. // Get the spell that this command was called from
  4995. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4996. lua_interface->ResetFunctionStack(state);
  4997. // Check to make sure the spawn pointer is valid
  4998. if (!spawn) {
  4999. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5000. return 0;
  5001. }
  5002. // Check to make sure the spawn is an entity
  5003. if (!spawn->IsEntity()) {
  5004. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5005. return 0;
  5006. }
  5007. // Check to make sure the spawn doesn't already have a pet of this type
  5008. if (((Entity*)spawn)->GetPet()) {
  5009. if (spawn->IsPlayer()) {
  5010. Client* client = ((Player*)spawn)->GetClient();
  5011. if (client)
  5012. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  5013. }
  5014. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5015. return 0;
  5016. }
  5017. // Check to see if the DB ID for the pet is set
  5018. if (pet_id == 0) {
  5019. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5020. return 0;
  5021. }
  5022. // Check to see if the pointer to the spell is valid
  5023. if (!luaspell) {
  5024. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5025. return 0;
  5026. }
  5027. if(luaspell->resisted) {
  5028. return 0;
  5029. }
  5030. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  5031. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5032. if (!pet) {
  5033. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5034. return 0;
  5035. }
  5036. // Check to make sure the pet is an npc
  5037. if (!pet->IsNPC()) {
  5038. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  5039. return 0;
  5040. }
  5041. // Spawn the pet at the same location as the owner
  5042. pet->SetX(spawn->GetX());
  5043. pet->SetY(spawn->GetY());
  5044. pet->SetZ(spawn->GetZ());
  5045. pet->SetLocation(spawn->GetLocation());
  5046. pet->SetHeading(spawn->GetHeading());
  5047. std::string petName = std::string("");
  5048. if(spawn->IsEntity()) {
  5049. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  5050. }
  5051. if(petName.size() < 1) {
  5052. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5053. petName = spawn->GetZone()->pet_names.at(rand_index);
  5054. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  5055. }
  5056. // If player set various values for the char sheet (pet window)
  5057. if (spawn->IsPlayer()) {
  5058. Player* player = (Player*)spawn;
  5059. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  5060. player->GetInfoStruct()->set_pet_name(petName);
  5061. player->GetInfoStruct()->set_pet_movement(2);
  5062. player->GetInfoStruct()->set_pet_behavior(3);
  5063. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  5064. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  5065. // Make sure the values get sent to the client
  5066. player->SetCharSheetChanged(true);
  5067. }
  5068. // Set the pets name
  5069. pet->SetName(petName.c_str());
  5070. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  5071. if (max_level > 0)
  5072. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  5073. else
  5074. pet->SetLevel(spawn->GetLevel());
  5075. // Set the max level this pet can reach
  5076. ((NPC*)pet)->SetMaxPetLevel(max_level);
  5077. ((NPC*)pet)->UpdateWeapons();
  5078. // Set the faction of the pet to the same faction as the owner
  5079. pet->SetFactionID(spawn->GetFactionID());
  5080. // Set the spawn as a pet
  5081. pet->SetPet(true);
  5082. // Give a pointer of the owner to the pet
  5083. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5084. // Give a pointer of the pet to the owner
  5085. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  5086. // Set the pet type
  5087. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  5088. // Set the spell id used to create this pet
  5089. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5090. // Set the spell tier used to create this pet
  5091. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5092. // Set the pets spawn type to 6
  5093. pet->SetSpawnType(6);
  5094. // Set the pets brain
  5095. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  5096. // Check to see if the pet has a subtitle
  5097. if (strlen(pet->GetSubTitle()) > 0) {
  5098. // Add the players name to the front of the sub title
  5099. string pet_subtitle;
  5100. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5101. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5102. // Set the pets subtitle to the new one
  5103. pet->SetSubTitle(pet_subtitle.c_str());
  5104. }
  5105. // Add the "Pet Options" entity command to the pet
  5106. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5107. const char* spawn_script = world.GetSpawnScript(pet_id);
  5108. bool runScript = false;
  5109. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  5110. runScript = true;
  5111. pet->SetSpawnScript(string(spawn_script));
  5112. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_PRESPAWN);
  5113. }
  5114. spawn->GetZone()->AddSpawn(pet);
  5115. if(runScript){
  5116. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_SPAWN);
  5117. }
  5118. // Set the pet as the return value for this function
  5119. lua_interface->SetSpawnValue(state, pet);
  5120. return 1;
  5121. }
  5122. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  5123. if (!lua_interface)
  5124. return 0;
  5125. Spawn* spawn = lua_interface->GetSpawn(state);
  5126. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5127. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5128. lua_interface->ResetFunctionStack(state);
  5129. if (!spawn) {
  5130. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5131. return 0;
  5132. }
  5133. if (!spawn->IsEntity()) {
  5134. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5135. return 0;
  5136. }
  5137. if (((Entity*)spawn)->GetDeityPet()) {
  5138. if (spawn->IsPlayer()) {
  5139. Client* client = ((Player*)spawn)->GetClient();
  5140. if (client)
  5141. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  5142. }
  5143. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5144. return 0;
  5145. }
  5146. if (pet_id == 0) {
  5147. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5148. return 0;
  5149. }
  5150. if (!luaspell) {
  5151. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5152. return 0;
  5153. }
  5154. if(luaspell->resisted) {
  5155. return 0;
  5156. }
  5157. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5158. if (!pet) {
  5159. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5160. return 0;
  5161. }
  5162. if (!pet->IsNPC()) {
  5163. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5164. return 0;
  5165. }
  5166. pet->SetX(spawn->GetX());
  5167. pet->SetY(spawn->GetY());
  5168. pet->SetZ(spawn->GetZ());
  5169. pet->SetLocation(spawn->GetLocation());
  5170. pet->SetHeading(spawn->GetHeading());
  5171. spawn->GetZone()->AddSpawn(pet);
  5172. string random_pet_name;
  5173. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5174. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5175. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5176. pet->SetName(random_pet_name.c_str());
  5177. pet->SetLevel(spawn->GetLevel());
  5178. pet->SetFactionID(spawn->GetFactionID());
  5179. pet->SetPet(true);
  5180. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  5181. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5182. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  5183. pet->SetSpawnType(6);
  5184. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5185. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5186. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5187. if (strlen(pet->GetSubTitle()) > 0) {
  5188. string pet_subtitle;
  5189. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5190. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5191. pet->SetSubTitle(pet_subtitle.c_str());
  5192. }
  5193. // deity and cosmetic pets are not attackable
  5194. pet->SetAttackable(false);
  5195. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5196. lua_interface->SetSpawnValue(state, pet);
  5197. return 1;
  5198. }
  5199. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  5200. if (!lua_interface)
  5201. return 0;
  5202. Spawn* spawn = lua_interface->GetSpawn(state);
  5203. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5204. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5205. lua_interface->ResetFunctionStack(state);
  5206. if (!spawn) {
  5207. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5208. return 0;
  5209. }
  5210. if (!spawn->IsEntity()) {
  5211. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5212. return 0;
  5213. }
  5214. if (((Entity*)spawn)->GetCosmeticPet()) {
  5215. if (spawn->IsPlayer()) {
  5216. Client* client = ((Player*)spawn)->GetClient();
  5217. if (client)
  5218. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  5219. }
  5220. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5221. return 0;
  5222. }
  5223. if (pet_id == 0) {
  5224. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5225. return 0;
  5226. }
  5227. if (!luaspell) {
  5228. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5229. return 0;
  5230. }
  5231. if(luaspell->resisted) {
  5232. return 0;
  5233. }
  5234. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5235. if (!pet) {
  5236. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5237. return 0;
  5238. }
  5239. if (!pet->IsNPC()) {
  5240. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5241. return 0;
  5242. }
  5243. pet->SetX(spawn->GetX());
  5244. pet->SetY(spawn->GetY());
  5245. pet->SetZ(spawn->GetZ());
  5246. pet->SetLocation(spawn->GetLocation());
  5247. pet->SetHeading(spawn->GetHeading());
  5248. spawn->GetZone()->AddSpawn(pet);
  5249. string random_pet_name;
  5250. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5251. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5252. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5253. pet->SetName(random_pet_name.c_str());
  5254. pet->SetLevel(spawn->GetLevel());
  5255. pet->SetFactionID(spawn->GetFactionID());
  5256. pet->SetPet(true);
  5257. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  5258. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5259. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5260. pet->SetSpawnType(6);
  5261. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5262. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5263. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5264. if (strlen(pet->GetSubTitle()) > 0) {
  5265. string pet_subtitle;
  5266. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5267. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5268. pet->SetSubTitle(pet_subtitle.c_str());
  5269. }
  5270. pet->SetAttackable(false);
  5271. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5272. lua_interface->SetSpawnValue(state, pet);
  5273. return 1;
  5274. }
  5275. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5276. if (!lua_interface)
  5277. return 0;
  5278. Spawn* spawn = lua_interface->GetSpawn(state);
  5279. lua_interface->ResetFunctionStack(state);
  5280. if (!spawn) {
  5281. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5282. return 0;
  5283. }
  5284. if (!spawn->IsPet()) {
  5285. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5286. return 0;
  5287. }
  5288. if (!((NPC*)spawn)->IsDismissing() && ((NPC*)spawn)->GetOwner())
  5289. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5290. return 0;
  5291. }
  5292. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5293. if (!lua_interface)
  5294. return 0;
  5295. Quest* quest = lua_interface->GetQuest(state);
  5296. if (!quest) {
  5297. 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));
  5298. lua_interface->ResetFunctionStack(state);
  5299. return 0;
  5300. }
  5301. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5302. lua_interface->ResetFunctionStack(state);
  5303. if (feather_color > 0)
  5304. quest->SetFeatherColor(feather_color);
  5305. return 0;
  5306. }
  5307. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5308. if (!lua_interface)
  5309. return 0;
  5310. Spawn* spawn = lua_interface->GetSpawn(state);
  5311. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5312. lua_interface->ResetFunctionStack(state);
  5313. if (!spawn) {
  5314. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5315. return 0;
  5316. }
  5317. if (!spawn2) {
  5318. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5319. return 0;
  5320. }
  5321. spawn->RemoveSpawnAccess(spawn2);
  5322. return 0;
  5323. }
  5324. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5325. if (!lua_interface)
  5326. return 0;
  5327. ZoneServer* zone = lua_interface->GetZone(state);
  5328. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5329. lua_interface->ResetFunctionStack(state);
  5330. if (!zone) {
  5331. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5332. return 0;
  5333. }
  5334. if (location_id == 0) {
  5335. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5336. return 0;
  5337. }
  5338. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5339. if (!location) {
  5340. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5341. return 0;
  5342. }
  5343. int32 rand_number = MakeRandomInt(0, location->entities.size() - 1);
  5344. Spawn* spawn = 0;
  5345. if (location->entities[rand_number]) {
  5346. if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5347. spawn = zone->AddNPCSpawn(location, location->entities[rand_number]);
  5348. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5349. spawn = zone->AddGroundSpawn(location, location->entities[rand_number]);
  5350. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5351. spawn = zone->AddObjectSpawn(location, location->entities[rand_number]);
  5352. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5353. spawn = zone->AddWidgetSpawn(location, location->entities[rand_number]);
  5354. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5355. spawn = zone->AddSignSpawn(location, location->entities[rand_number]);
  5356. if(spawn && spawn->IsOmittedByDBFlag())
  5357. {
  5358. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5359. safe_delete(spawn);
  5360. spawn = 0;
  5361. return 0;
  5362. }
  5363. if (spawn) {
  5364. const char* script = 0;
  5365. for (int x = 0; x < 3; x++) {
  5366. switch (x) {
  5367. case 0:
  5368. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5369. break;
  5370. case 1:
  5371. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5372. break;
  5373. case 2:
  5374. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5375. break;
  5376. }
  5377. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5378. spawn->SetSpawnScript(string(script));
  5379. break;
  5380. }
  5381. }
  5382. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5383. lua_interface->SetSpawnValue(state, spawn);
  5384. return 1;
  5385. }
  5386. else {
  5387. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5388. safe_delete(spawn);
  5389. }
  5390. }
  5391. return 0;
  5392. }
  5393. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5394. if (!lua_interface)
  5395. return 0;
  5396. Spawn* caster = lua_interface->GetSpawn(state);
  5397. Spawn* target = lua_interface->GetSpawn(state, 2);
  5398. int32 id = lua_interface->GetInt32Value(state, 3);
  5399. string command = lua_interface->GetStringValue(state, 4);
  5400. lua_interface->ResetFunctionStack(state);
  5401. if (!caster) {
  5402. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5403. return 0;
  5404. }
  5405. if (!target) {
  5406. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5407. return 0;
  5408. }
  5409. if (!caster->IsPlayer()) {
  5410. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5411. return 0;
  5412. }
  5413. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5414. if (!entity_command) {
  5415. 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());
  5416. return 0;
  5417. }
  5418. Client* client = ((Player*)caster)->GetClient();
  5419. if (!client) {
  5420. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5421. return 0;
  5422. }
  5423. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5424. return 0;
  5425. }
  5426. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5427. if (!lua_interface)
  5428. return 0;
  5429. Spawn* spawn = lua_interface->GetSpawn(state);
  5430. lua_interface->ResetFunctionStack(state);
  5431. if (!spawn) {
  5432. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5433. return 0;
  5434. }
  5435. if (!spawn->IsNPC()) {
  5436. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5437. return 0;
  5438. }
  5439. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5440. return 0;
  5441. }
  5442. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5443. if (!lua_interface)
  5444. return 0;
  5445. Spawn* spawn = lua_interface->GetSpawn(state);
  5446. int16 tick = lua_interface->GetInt16Value(state, 2);
  5447. lua_interface->ResetFunctionStack(state);
  5448. if (!spawn) {
  5449. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5450. return 0;
  5451. }
  5452. if (!spawn->IsNPC()) {
  5453. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5454. return 0;
  5455. }
  5456. if (tick < 20) {
  5457. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5458. return 0;
  5459. }
  5460. ((NPC*)spawn)->Brain()->SetTick(tick);
  5461. return 0;
  5462. }
  5463. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5464. if (!lua_interface)
  5465. return 0;
  5466. Spawn* spawn = lua_interface->GetSpawn(state);
  5467. Spawn* target = lua_interface->GetSpawn(state, 2);
  5468. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5469. lua_interface->ResetFunctionStack(state);
  5470. if (!spawn) {
  5471. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5472. return 0;
  5473. }
  5474. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5475. spawn->SetFollowTarget(target, follow_distance);
  5476. return 0;
  5477. }
  5478. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5479. if (!lua_interface)
  5480. return 0;
  5481. Spawn* spawn = lua_interface->GetSpawn(state);
  5482. lua_interface->ResetFunctionStack(state);
  5483. if (!spawn) {
  5484. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5485. return 0;
  5486. }
  5487. Spawn* target = spawn->GetFollowTarget();
  5488. if (target) {
  5489. lua_interface->SetSpawnValue(state, target);
  5490. return 1;
  5491. }
  5492. return 0;
  5493. }
  5494. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5495. if (!lua_interface)
  5496. return 0;
  5497. Spawn* spawn = lua_interface->GetSpawn(state);
  5498. lua_interface->ResetFunctionStack(state);
  5499. if (!spawn) {
  5500. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5501. return 0;
  5502. }
  5503. if (spawn->following)
  5504. spawn->following = false;
  5505. else
  5506. spawn->following = true;
  5507. return 0;
  5508. }
  5509. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5510. if (!lua_interface)
  5511. return 0;
  5512. Spawn* spawn = lua_interface->GetSpawn(state);
  5513. lua_interface->ResetFunctionStack(state);
  5514. if (!spawn) {
  5515. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5516. return 0;
  5517. }
  5518. lua_interface->SetBooleanValue(state, spawn->following);
  5519. return 1;
  5520. }
  5521. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5522. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5523. // I will attempt to explain how this function works for future refrence
  5524. // Fist lets make sure lua_interface is valid, if not return out
  5525. if (!lua_interface)
  5526. return 0;
  5527. // Next we grab the first 2 params same as we usually would
  5528. Spawn* spawn = lua_interface->GetSpawn(state);
  5529. string var = lua_interface->GetStringValue(state, 2);
  5530. // 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
  5531. // 1 = Spawn
  5532. // 2 = Zone
  5533. // 3 = Item
  5534. // 4 = Quest
  5535. // 5 = String
  5536. // 6 = nil (null)
  5537. int8 dataType = 0;
  5538. // Define pointers for each potential type
  5539. Spawn* spawnVal = 0;
  5540. ZoneServer* zone = 0;
  5541. Item* item = 0;
  5542. Quest* quest = 0;
  5543. string val;
  5544. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5545. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5546. // options window are also light user data be we do not handle those.
  5547. // We check with lua_islightuserdata(lua_State*, index)
  5548. if (lua_islightuserdata(state, 3)) {
  5549. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5550. // and convert it to LUAUserData*
  5551. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5552. // Check to make sure the data we got is valid, if not give an error
  5553. if (!data || !data->IsCorrectlyInitialized()) {
  5554. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5555. }
  5556. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5557. else if (data->IsSpawn()) {
  5558. spawnVal = data->spawn;
  5559. dataType = 1;
  5560. }
  5561. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5562. else if (data->IsZone()) {
  5563. zone = data->zone;
  5564. dataType = 2;
  5565. }
  5566. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5567. else if (data->IsItem()) {
  5568. item = data->item;
  5569. dataType = 3;
  5570. }
  5571. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5572. else if (data->IsQuest()) {
  5573. quest = data->quest;
  5574. dataType = 4;
  5575. }
  5576. }
  5577. // Wasn't light user data, check if it is nil(null)
  5578. else if (lua_isnil(state, 3)) {
  5579. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5580. dataType = 6;
  5581. }
  5582. // Wasn't light user data or nil (null), must be a string
  5583. else {
  5584. // Set the string and dataType variable
  5585. val = lua_interface->GetStringValue(state, 3);
  5586. dataType = 5;
  5587. }
  5588. lua_interface->ResetFunctionStack(state);
  5589. // We now have all the params, lets check to make sure they are valid
  5590. if (!spawn) {
  5591. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5592. return 0;
  5593. }
  5594. if (var.length() == 0) {
  5595. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5596. return 0;
  5597. }
  5598. if (dataType == 0) {
  5599. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5600. return 0;
  5601. }
  5602. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5603. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5604. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5605. switch (dataType) {
  5606. case 1:
  5607. // 1 = Spawn
  5608. spawn->AddTempVariable(var, spawnVal);
  5609. break;
  5610. case 2:
  5611. // 2 = Zone
  5612. spawn->AddTempVariable(var, zone);
  5613. break;
  5614. case 3:
  5615. // 3 = Item
  5616. spawn->AddTempVariable(var, item);
  5617. break;
  5618. case 4:
  5619. // 4 = Quest
  5620. spawn->AddTempVariable(var, quest);
  5621. break;
  5622. case 5:
  5623. // 5 = String
  5624. spawn->AddTempVariable(var, val);
  5625. break;
  5626. case 6:
  5627. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5628. spawn->DeleteTempVariable(var);
  5629. break;
  5630. }
  5631. // And we are done so return out
  5632. return 0;
  5633. }
  5634. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5635. if (!lua_interface)
  5636. return 0;
  5637. Spawn* spawn = lua_interface->GetSpawn(state);
  5638. string var = lua_interface->GetStringValue(state, 2);
  5639. lua_interface->ResetFunctionStack(state);
  5640. if (!spawn) {
  5641. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5642. return 0;
  5643. }
  5644. if (var.length() == 0) {
  5645. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5646. return 0;
  5647. }
  5648. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5649. int8 type = spawn->GetTempVariableType(var);
  5650. Spawn* spawn2 = 0;
  5651. ZoneServer* zone = 0;
  5652. Item* item = 0;
  5653. Quest* quest = 0;
  5654. // Set the lua function return value based on the type of data the variable contains
  5655. switch (type) {
  5656. case 1:
  5657. spawn2 = spawn->GetTempVariableSpawn(var);
  5658. if (!spawn2)
  5659. return 0;
  5660. lua_interface->SetSpawnValue(state, spawn2);
  5661. break;
  5662. case 2:
  5663. zone = spawn->GetTempVariableZone(var);
  5664. if (!zone)
  5665. return 0;
  5666. lua_interface->SetZoneValue(state, zone);
  5667. break;
  5668. case 3:
  5669. item = spawn->GetTempVariableItem(var);
  5670. if (!item)
  5671. return 0;
  5672. lua_interface->SetItemValue(state, item);
  5673. break;
  5674. case 4:
  5675. quest = spawn->GetTempVariableQuest(var);
  5676. if (!quest)
  5677. return 0;
  5678. lua_interface->SetQuestValue(state, quest);
  5679. break;
  5680. case 5:
  5681. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5682. break;
  5683. default:
  5684. // Not a valid type then the variable was not set so return out
  5685. return 0;
  5686. }
  5687. // Return value was set so return out
  5688. return 1;
  5689. }
  5690. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5691. {
  5692. if (!lua_interface)
  5693. return 0;
  5694. Quest* quest = lua_interface->GetQuest(state);
  5695. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5696. string description = lua_interface->GetStringValue(state, 3);
  5697. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5698. if (!quest) {
  5699. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5700. lua_interface->ResetFunctionStack(state);
  5701. lua_interface->SetBooleanValue(state, false);
  5702. return 1;
  5703. }
  5704. if (!spawn) {
  5705. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5706. lua_interface->ResetFunctionStack(state);
  5707. lua_interface->SetBooleanValue(state, false);
  5708. return 1;
  5709. }
  5710. if (!spawn->IsPlayer()) {
  5711. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5712. lua_interface->ResetFunctionStack(state);
  5713. lua_interface->SetBooleanValue(state, false);
  5714. return 1;
  5715. }
  5716. if (item_id == 0) {
  5717. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5718. lua_interface->ResetFunctionStack(state);
  5719. lua_interface->SetBooleanValue(state, false);
  5720. return 1;
  5721. }
  5722. Client* client = ((Player*)spawn)->GetClient();
  5723. if (!client) {
  5724. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given player spawn", lua_interface->GetScriptName(state));
  5725. lua_interface->ResetFunctionStack(state);
  5726. lua_interface->SetBooleanValue(state, false);
  5727. return 1;
  5728. }
  5729. Item* item = master_item_list.GetItem(item_id);
  5730. if (!item) {
  5731. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5732. lua_interface->ResetFunctionStack(state);
  5733. lua_interface->SetBooleanValue(state, false);
  5734. return 1;
  5735. }
  5736. Item* firstItem = new Item(item);
  5737. quest->AddTmpRewardItem(firstItem);
  5738. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5739. bool itemsAddedSuccessfully = true;
  5740. if(num_args > 4)
  5741. {
  5742. for(int8 n=5;n<num_args+1;n++)
  5743. {
  5744. int32 new_item = lua_interface->GetInt32Value(state, n);
  5745. Item* tmpItem = master_item_list.GetItem(new_item);
  5746. if(tmpItem)
  5747. {
  5748. Item* newTmpItem = new Item(tmpItem);
  5749. quest->AddTmpRewardItem(newTmpItem);
  5750. }
  5751. else
  5752. itemsAddedSuccessfully = false;
  5753. }
  5754. }
  5755. client->AddPendingQuestReward(quest, true, true, description); // queue for display
  5756. lua_interface->ResetFunctionStack(state);
  5757. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5758. return 1;
  5759. }
  5760. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5761. if (!lua_interface)
  5762. return 0;
  5763. Quest* quest = lua_interface->GetQuest(state);
  5764. lua_interface->ResetFunctionStack(state);
  5765. if (!quest) {
  5766. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5767. return 0;
  5768. }
  5769. quest->SetRepeatable(true);
  5770. return 0;
  5771. }
  5772. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5773. if (!lua_interface)
  5774. return 0;
  5775. Spawn* spawn = lua_interface->GetSpawn(state);
  5776. lua_interface->ResetFunctionStack(state);
  5777. if (!spawn) {
  5778. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5779. return 0;
  5780. }
  5781. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5782. string ret = classes.GetClassNameCase(base_class);
  5783. if (ret.length() > 0) {
  5784. lua_interface->SetStringValue(state, ret.c_str());
  5785. return 1;
  5786. }
  5787. return 0;
  5788. }
  5789. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5790. if (!lua_interface)
  5791. return 0;
  5792. Spawn* player = lua_interface->GetSpawn(state);
  5793. lua_interface->ResetFunctionStack(state);
  5794. if (player && player->IsPlayer()) {
  5795. Client* client = player->GetClient();
  5796. if (client)
  5797. client->SendWaypoints();
  5798. }
  5799. return 0;
  5800. }
  5801. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5802. if (!lua_interface)
  5803. return 0;
  5804. Spawn* player = lua_interface->GetSpawn(state);
  5805. string name = lua_interface->GetStringValue(state, 2);
  5806. int32 type = lua_interface->GetInt32Value(state, 3);
  5807. lua_interface->ResetFunctionStack(state);
  5808. if (type == 0)
  5809. type = 2;
  5810. if (name.length() > 0) {
  5811. if (player && player->IsPlayer()) {
  5812. Client* client = player->GetClient();
  5813. if (client)
  5814. client->AddWaypoint(name, type);
  5815. }
  5816. }
  5817. return 0;
  5818. }
  5819. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5820. if (!lua_interface)
  5821. return 0;
  5822. Spawn* player = lua_interface->GetSpawn(state);
  5823. string name = lua_interface->GetStringValue(state, 2);
  5824. lua_interface->ResetFunctionStack(state);
  5825. if (name.length() > 0) {
  5826. if (player && player->IsPlayer()) {
  5827. Client* client = player->GetClient();
  5828. if (client)
  5829. client->RemoveWaypoint(name);
  5830. }
  5831. }
  5832. return 0;
  5833. }
  5834. int EQ2Emu_lua_AddWard(lua_State* state) {
  5835. if (!lua_interface)
  5836. return 0;
  5837. int32 damage = lua_interface->GetInt32Value(state);
  5838. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5839. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5840. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5841. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5842. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5843. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5844. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5845. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5846. lua_interface->ResetFunctionStack(state);
  5847. if(!spell || spell->resisted) {
  5848. return 0;
  5849. }
  5850. bool ward_was_added = false;
  5851. ZoneServer* zone = spell->caster->GetZone();
  5852. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5853. for (int32 i = 0; i < spell->targets.size(); i++) {
  5854. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5855. if (!target)
  5856. continue;
  5857. if (target->IsEntity()) {
  5858. // If the ward is already active remove it
  5859. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5860. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5861. // Create new ward info
  5862. WardInfo* ward = new WardInfo;
  5863. ward->Spell = spell;
  5864. ward->BaseDamage = damage;
  5865. ward->DamageLeft = damage;
  5866. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5867. ward->keepWard = keepWard;
  5868. ward->WardType = wardType;
  5869. if (damageAbsorptionPercent > 100)
  5870. damageAbsorptionPercent = 100;
  5871. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5872. if (damageAbsorptionMaxHealthPercent > 100)
  5873. damageAbsorptionMaxHealthPercent = 100;
  5874. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5875. ward->RedirectDamagePercent = redirectDamagePercent;
  5876. ward->LastRedirectDamage = 0;
  5877. ward->LastAbsorbedDamage = 0;
  5878. ward->HitCount = 0;
  5879. spell->num_triggers = maxHitCount;
  5880. spell->had_triggers = true;
  5881. spell->cancel_after_all_triggers = false;
  5882. ward->MaxHitCount = maxHitCount;
  5883. ward->RoundTriggered = false;
  5884. if (wardType == WARD_TYPE_MAGICAL)
  5885. ward->DamageType = damageTypes;
  5886. // Add the ward to the entity
  5887. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5888. ward_was_added = true;
  5889. }
  5890. }
  5891. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5892. if (ward_was_added && spell->caster->IsPlayer()) {
  5893. spell->had_dmg_remaining = true;
  5894. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, damage, 1);
  5895. }
  5896. return 0;
  5897. }
  5898. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5899. if (!lua_interface)
  5900. return 0;
  5901. int32 amount = lua_interface->GetInt32Value(state);
  5902. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5903. lua_interface->ResetFunctionStack(state);
  5904. WardInfo* ward = 0;
  5905. if(!spell || spell->resisted) {
  5906. return 0;
  5907. }
  5908. ZoneServer* zone = spell->caster->GetZone();
  5909. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5910. if (spell->targets.size() > 0 && zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5911. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5912. ward = target->GetWard(spell->spell->GetSpellID());
  5913. if (target && ward) {
  5914. ward->DamageLeft += amount;
  5915. if (ward->DamageLeft > ward->BaseDamage)
  5916. ward->DamageLeft = ward->BaseDamage;
  5917. for (int32 i = 0; i < spell->targets.size(); i++) {
  5918. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5919. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5920. }
  5921. }
  5922. }
  5923. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5924. if (ward && spell->caster->IsPlayer())
  5925. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
  5926. return 0;
  5927. }
  5928. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5929. if (!lua_interface)
  5930. return 0;
  5931. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5932. lua_interface->ResetFunctionStack(state);
  5933. if (!spell) {
  5934. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5935. return 0;
  5936. }
  5937. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5938. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5939. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5940. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5941. if (ward) {
  5942. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5943. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5944. return 1;
  5945. }
  5946. }
  5947. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5948. return 0;
  5949. }
  5950. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5951. if (!lua_interface)
  5952. return 0;
  5953. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5954. if (!spell) {
  5955. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5956. lua_interface->ResetFunctionStack(state);
  5957. return 0;
  5958. }
  5959. string type = lua_interface->GetStringValue(state, 2);
  5960. lua_interface->ResetFunctionStack(state);
  5961. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5962. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5963. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5964. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5965. if (ward) {
  5966. if (boost::iequals(type, "damageleft"))
  5967. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5968. else if (boost::iequals(type, "basedamage"))
  5969. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5970. else if (boost::iequals(type, "keepward"))
  5971. lua_interface->SetBooleanValue(state, ward->keepWard);
  5972. else if (boost::iequals(type, "wardtype"))
  5973. lua_interface->SetInt32Value(state, ward->WardType);
  5974. else if (boost::iequals(type, "dmgabsorptionpct"))
  5975. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5976. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5977. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5978. else if (boost::iequals(type, "redirectdamagepercent"))
  5979. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5980. else if (boost::iequals(type, "lastredirectdamage"))
  5981. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5982. else if (boost::iequals(type, "lastabsorbeddamage"))
  5983. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5984. else if (boost::iequals(type, "hitcount"))
  5985. lua_interface->SetInt32Value(state, ward->HitCount);
  5986. else if (boost::iequals(type, "maxhitcount"))
  5987. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5988. else
  5989. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5990. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5991. return 1;
  5992. }
  5993. }
  5994. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5995. return 0;
  5996. }
  5997. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5998. if (!lua_interface)
  5999. return 0;
  6000. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6001. lua_interface->ResetFunctionStack(state);
  6002. if(!spell) {
  6003. return 0;
  6004. }
  6005. ZoneServer* zone = spell->caster->GetZone();
  6006. Spawn* target = 0;
  6007. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6008. for (int32 i = 0; i < spell->targets.size(); i++) {
  6009. target = zone->GetSpawnByID(spell->targets.at(i));
  6010. if (target && target->IsEntity()) {
  6011. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  6012. }
  6013. }
  6014. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6015. return 0;
  6016. }
  6017. int EQ2Emu_lua_Interrupt(lua_State* state)
  6018. {
  6019. if (!lua_interface)
  6020. return 0;
  6021. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  6022. Spawn* target = lua_interface->GetSpawn(state, 2);
  6023. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6024. lua_interface->ResetFunctionStack(state);
  6025. if (!caster)
  6026. {
  6027. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6028. return 0;
  6029. }
  6030. if (!target)
  6031. {
  6032. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6033. return 0;
  6034. }
  6035. if (!spell) {
  6036. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  6037. return 0;
  6038. }
  6039. if (!target->IsEntity() && !spell)
  6040. {
  6041. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  6042. return 0;
  6043. }
  6044. if (!target && spell) {
  6045. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6046. for (int8 i = 0; i < spell->targets.size(); i++) {
  6047. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6048. if (!target || !target->IsEntity())
  6049. continue;
  6050. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  6051. }
  6052. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6053. }
  6054. else
  6055. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  6056. return 0;
  6057. }
  6058. int EQ2Emu_lua_Stealth(lua_State* state) {
  6059. if (!lua_interface)
  6060. return 0;
  6061. int8 type = lua_interface->GetInt8Value(state);
  6062. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6063. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6064. lua_interface->ResetFunctionStack(state);
  6065. if (!spell) {
  6066. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  6067. return 0;
  6068. }
  6069. ZoneServer* zone = spell->caster->GetZone();
  6070. if (spawn) {
  6071. if (spawn->IsEntity()) {
  6072. if (type == 1) {
  6073. ((Entity*)spawn)->AddStealthSpell(spell);
  6074. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  6075. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  6076. }
  6077. else if (type == 2) {
  6078. ((Entity*)spawn)->AddInvisSpell(spell);
  6079. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  6080. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  6081. }
  6082. return 0;
  6083. }
  6084. else {
  6085. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  6086. return 0;
  6087. }
  6088. }
  6089. else {
  6090. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6091. for (int32 i = 0; i < spell->targets.size(); i++) {
  6092. spawn = zone->GetSpawnByID(spell->targets.at(i));
  6093. if (!spawn || !spawn->IsEntity())
  6094. continue;
  6095. if (type == 1) {
  6096. ((Entity*)spawn)->AddStealthSpell(spell);
  6097. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  6098. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  6099. }
  6100. else if (type == 2) {
  6101. ((Entity*)spawn)->AddInvisSpell(spell);
  6102. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  6103. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  6104. }
  6105. else {
  6106. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  6107. break;
  6108. }
  6109. }
  6110. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6111. }
  6112. return 0;
  6113. }
  6114. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  6115. if (!lua_interface)
  6116. return 0;
  6117. Spawn* spawn = lua_interface->GetSpawn(state);
  6118. lua_interface->ResetFunctionStack(state);
  6119. if (!spawn) {
  6120. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6121. return 0;
  6122. }
  6123. if (spawn->IsEntity()) {
  6124. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  6125. return 1;
  6126. }
  6127. else
  6128. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  6129. return 0;
  6130. }
  6131. int EQ2Emu_lua_IsInvis(lua_State* state) {
  6132. if (!lua_interface)
  6133. return 0;
  6134. Spawn* spawn = lua_interface->GetSpawn(state);
  6135. lua_interface->ResetFunctionStack(state);
  6136. if (!spawn) {
  6137. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  6138. return 0;
  6139. }
  6140. if (spawn->IsEntity()) {
  6141. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  6142. return 1;
  6143. }
  6144. else
  6145. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  6146. return 0;
  6147. }
  6148. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  6149. if (!lua_interface)
  6150. return 0;
  6151. Spawn* player = lua_interface->GetSpawn(state);
  6152. int32 item_id = lua_interface->GetInt32Value(state, 2);
  6153. lua_interface->ResetFunctionStack(state);
  6154. if (!player->IsPlayer()) {
  6155. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  6156. return 0;
  6157. }
  6158. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  6159. return 1;
  6160. }
  6161. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  6162. if (!lua_interface)
  6163. return 0;
  6164. Spawn* spawn = lua_interface->GetSpawn(state);
  6165. int8 slot = lua_interface->GetInt8Value(state, 2);
  6166. lua_interface->ResetFunctionStack(state);
  6167. if (!spawn) {
  6168. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6169. return 0;
  6170. }
  6171. if (!spawn->IsEntity()) {
  6172. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6173. return 0;
  6174. }
  6175. Item* item = ((Entity*)spawn)->GetEquipmentList()->GetItem(slot);
  6176. if (!item) {
  6177. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  6178. return 0;
  6179. }
  6180. lua_interface->SetItemValue(state, item);
  6181. return 1;
  6182. }
  6183. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  6184. if (!lua_interface)
  6185. return 0;
  6186. Spawn* player = lua_interface->GetSpawn(state);
  6187. int32 id = lua_interface->GetInt32Value(state, 2);
  6188. lua_interface->ResetFunctionStack(state);
  6189. if (!player) {
  6190. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6191. return 0;
  6192. }
  6193. if (!player->IsPlayer()) {
  6194. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6195. return 0;
  6196. }
  6197. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  6198. if (!item) {
  6199. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  6200. return 0;
  6201. }
  6202. lua_interface->SetItemValue(state, item);
  6203. return 1;
  6204. }
  6205. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  6206. if (!lua_interface)
  6207. return 0;
  6208. Spawn* spawn = lua_interface->GetSpawn(state);
  6209. int8 slot = lua_interface->GetInt8Value(state, 2);
  6210. int32 item_id = lua_interface->GetInt32Value(state, 3);
  6211. lua_interface->ResetFunctionStack(state);
  6212. if (!spawn) {
  6213. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6214. return 0;
  6215. }
  6216. if (!spawn->IsEntity()) {
  6217. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6218. return 0;
  6219. }
  6220. Item* item = master_item_list.GetItem(item_id);
  6221. if (!item) {
  6222. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  6223. return 0;
  6224. }
  6225. Item* copy = new Item(item);
  6226. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  6227. if(result)
  6228. {
  6229. ((Entity*)spawn)->SetEquipment(copy, slot);
  6230. spawn->vis_changed = true;
  6231. if(spawn->IsPlayer())
  6232. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6233. }
  6234. else
  6235. {
  6236. safe_delete(copy);
  6237. }
  6238. lua_interface->SetBooleanValue(state, result);
  6239. return 1;
  6240. }
  6241. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  6242. if (!lua_interface)
  6243. return 0;
  6244. Spawn* spawn = lua_interface->GetSpawn(state);
  6245. int8 slot = lua_interface->GetInt8Value(state, 2);
  6246. Item* item = lua_interface->GetItem(state, 3);
  6247. lua_interface->ResetFunctionStack(state);
  6248. if (!spawn) {
  6249. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  6250. return 0;
  6251. }
  6252. if (!spawn->IsEntity()) {
  6253. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6254. return 0;
  6255. }
  6256. if (!item) {
  6257. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  6258. return 0;
  6259. }
  6260. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  6261. if(result)
  6262. {
  6263. ((Entity*)spawn)->SetEquipment(item, slot);
  6264. spawn->vis_changed = true;
  6265. if(spawn->IsPlayer())
  6266. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6267. }
  6268. lua_interface->SetBooleanValue(state, result);
  6269. return 1;
  6270. }
  6271. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  6272. if (!lua_interface)
  6273. return 0;
  6274. Spawn* spawn = lua_interface->GetSpawn(state);
  6275. int8 slot = lua_interface->GetInt8Value(state, 2);
  6276. 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
  6277. lua_interface->ResetFunctionStack(state);
  6278. if (!spawn) {
  6279. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6280. return 0;
  6281. }
  6282. if (!spawn->IsEntity()) {
  6283. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6284. return 0;
  6285. }
  6286. if(slot >= NUM_SLOTS) {
  6287. lua_interface->LogError("%s: LUA UnequipSlot command error: wrong slot id given %u, max %u", lua_interface->GetScriptName(state), slot, NUM_SLOTS);
  6288. return 0;
  6289. }
  6290. if(spawn->IsPlayer() && ((Player*)spawn)->GetClient()) {
  6291. Item* item = ((Player*)spawn)->GetEquipmentList()->GetItem(slot);
  6292. if(item) {
  6293. item->save_needed = true;
  6294. if(no_delete_item) {
  6295. database.DeleteItem(((Player*)spawn)->GetClient()->GetCharacterID(), item, 0);
  6296. ((Player*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6297. }
  6298. else{
  6299. Client* client = ((Player*)spawn)->GetClient();
  6300. client->UnequipItem(item->details.index);
  6301. }
  6302. }
  6303. }
  6304. else
  6305. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6306. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  6307. spawn->vis_changed = true;
  6308. if(spawn->IsPlayer())
  6309. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6310. lua_interface->SetBooleanValue(state, true);
  6311. return 1;
  6312. }
  6313. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  6314. if (!lua_interface)
  6315. return 0;
  6316. Spawn* spawn = lua_interface->GetSpawn(state);
  6317. int8 slot = lua_interface->GetInt8Value(state, 2);
  6318. int16 type = lua_interface->GetInt16Value(state, 3);
  6319. int8 r = lua_interface->GetInt8Value(state, 4);
  6320. int8 g = lua_interface->GetInt8Value(state, 5);
  6321. int8 b = lua_interface->GetInt8Value(state, 6);
  6322. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6323. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6324. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6325. lua_interface->ResetFunctionStack(state);
  6326. if (!spawn) {
  6327. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6328. return 0;
  6329. }
  6330. if (!spawn->IsEntity()) {
  6331. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6332. return 0;
  6333. }
  6334. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6335. spawn->vis_changed = true;
  6336. lua_interface->SetBooleanValue(state, true);
  6337. return 1;
  6338. }
  6339. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6340. if (!lua_interface)
  6341. return 0;
  6342. Spawn* player = lua_interface->GetSpawn(state);
  6343. int32 id = lua_interface->GetInt32Value(state, 2);
  6344. int8 count = lua_interface->GetInt8Value(state, 3);
  6345. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6346. lua_interface->ResetFunctionStack(state);
  6347. if (!player) {
  6348. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6349. return 0;
  6350. }
  6351. if (!player->IsPlayer()) {
  6352. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6353. return 0;
  6354. }
  6355. if (!count)
  6356. count = 1;
  6357. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6358. if (!item) {
  6359. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6360. return 0;
  6361. }
  6362. lua_interface->SetItemValue(state, item);
  6363. return 1;
  6364. }
  6365. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6366. if (!lua_interface)
  6367. return 0;
  6368. Spawn* spawn = lua_interface->GetSpawn(state);
  6369. int32 anim = lua_interface->GetInt32Value(state, 2);
  6370. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6371. int8 type = lua_interface->GetInt8Value(state, 4);
  6372. lua_interface->ResetFunctionStack(state);
  6373. if (!spawn) {
  6374. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6375. return 0;
  6376. }
  6377. if (spawn2) {
  6378. if (spawn2->IsPlayer()) {
  6379. if (type != 1 && type != 2)
  6380. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6381. else
  6382. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6383. return 0;
  6384. }
  6385. else {
  6386. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6387. return 0;
  6388. }
  6389. }
  6390. else
  6391. spawn->GetZone()->PlayAnimation(spawn, anim);
  6392. return 0;
  6393. }
  6394. int EQ2Emu_lua_IsPet(lua_State* state) {
  6395. if (!lua_interface)
  6396. return 0;
  6397. Spawn* spawn = lua_interface->GetSpawn(state);
  6398. lua_interface->ResetFunctionStack(state);
  6399. if (!spawn) {
  6400. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6401. return 0;
  6402. }
  6403. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6404. return 1;
  6405. }
  6406. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6407. if (!lua_interface)
  6408. return 0;
  6409. Spawn* spawn = lua_interface->GetSpawn(state);
  6410. lua_interface->ResetFunctionStack(state);
  6411. if (!spawn) {
  6412. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6413. return 0;
  6414. }
  6415. if (!spawn->IsNPC()) {
  6416. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6417. return 0;
  6418. }
  6419. if (((NPC*)spawn)->GetOwner()) {
  6420. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6421. return 1;
  6422. }
  6423. return 0;
  6424. }
  6425. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6426. if (!lua_interface)
  6427. return 0;
  6428. Spawn* spawn = lua_interface->GetSpawn(state);
  6429. Spawn* target = lua_interface->GetSpawn(state, 2);
  6430. lua_interface->ResetFunctionStack(state);
  6431. if (!spawn) {
  6432. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6433. return 0;
  6434. }
  6435. if (!spawn) {
  6436. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6437. return 0;
  6438. }
  6439. spawn->SetTarget(target);
  6440. return 0;
  6441. }
  6442. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6443. if (!lua_interface)
  6444. return 0;
  6445. Spawn* spawn = lua_interface->GetSpawn(state);
  6446. bool val = lua_interface->GetBooleanValue(state, 2);
  6447. lua_interface->ResetFunctionStack(state);
  6448. if (!spawn) {
  6449. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6450. return 0;
  6451. }
  6452. if (!spawn->IsEntity()) {
  6453. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6454. return 0;
  6455. }
  6456. ((Entity*)spawn)->InCombat(val);
  6457. if (val) {
  6458. spawn->ClearRunningLocations();
  6459. spawn->CalculateRunningLocation(true);
  6460. }
  6461. return 0;
  6462. }
  6463. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6464. if (!lua_interface)
  6465. return 0;
  6466. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6467. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6468. lua_interface->ResetFunctionStack(state);
  6469. if (!spawn1) {
  6470. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6471. return 0;
  6472. }
  6473. if (!spawn2) {
  6474. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6475. return 0;
  6476. }
  6477. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6478. return 1;
  6479. }
  6480. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6481. if (!lua_interface)
  6482. return 0;
  6483. Spawn* spawn = lua_interface->GetSpawn(state);
  6484. lua_interface->ResetFunctionStack(state);
  6485. if (!spawn) {
  6486. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6487. return 0;
  6488. }
  6489. if (!spawn->IsNPC()) {
  6490. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6491. return 0;
  6492. }
  6493. ((NPC*)spawn)->ClearRunback();
  6494. return 0;
  6495. }
  6496. int EQ2Emu_lua_Runback(lua_State* state) {
  6497. if (!lua_interface)
  6498. return 0;
  6499. Spawn* spawn = lua_interface->GetSpawn(state);
  6500. lua_interface->ResetFunctionStack(state);
  6501. if (!spawn) {
  6502. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6503. return 0;
  6504. }
  6505. if (!spawn->IsNPC()) {
  6506. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6507. return 0;
  6508. }
  6509. ((NPC*)spawn)->Runback();
  6510. return 0;
  6511. }
  6512. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6513. if (!lua_interface)
  6514. return 0;
  6515. Spawn* spawn = lua_interface->GetSpawn(state);
  6516. lua_interface->ResetFunctionStack(state);
  6517. if (!spawn) {
  6518. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6519. return 0;
  6520. }
  6521. if (!spawn->IsNPC()) {
  6522. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6523. return 0;
  6524. }
  6525. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6526. return 1;
  6527. }
  6528. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6529. if (!lua_interface)
  6530. return 0;
  6531. Spawn* spawn = lua_interface->GetSpawn(state);
  6532. lua_interface->ResetFunctionStack(state);
  6533. if (!spawn) {
  6534. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6535. return 0;
  6536. }
  6537. if (!spawn->IsEntity()) {
  6538. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6539. return 0;
  6540. }
  6541. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6542. return 1;
  6543. }
  6544. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6545. if (!lua_interface)
  6546. return 0;
  6547. Spawn* spawn = lua_interface->GetSpawn(state);
  6548. lua_interface->ResetFunctionStack(state);
  6549. if (!spawn) {
  6550. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6551. return 0;
  6552. }
  6553. if (!spawn->IsEntity()) {
  6554. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6555. return 0;
  6556. }
  6557. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6558. return 1;
  6559. }
  6560. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6561. if (!lua_interface)
  6562. return 0;
  6563. Spawn* spawn = lua_interface->GetSpawn(state);
  6564. lua_interface->ResetFunctionStack(state);
  6565. if (!spawn) {
  6566. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6567. return 0;
  6568. }
  6569. if (!spawn->IsEntity()) {
  6570. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6571. return 0;
  6572. }
  6573. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6574. return 1;
  6575. }
  6576. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6577. if (!lua_interface)
  6578. return 0;
  6579. Spawn* spawn = lua_interface->GetSpawn(state);
  6580. lua_interface->ResetFunctionStack(state);
  6581. if (!spawn) {
  6582. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6583. return 0;
  6584. }
  6585. if (!spawn->IsEntity()) {
  6586. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6587. return 0;
  6588. }
  6589. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6590. return 1;
  6591. }
  6592. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6593. if (!lua_interface)
  6594. return 0;
  6595. Spawn* spawn = lua_interface->GetSpawn(state);
  6596. Spawn* target = lua_interface->GetSpawn(state, 2);
  6597. float distance = lua_interface->GetFloatValue(state, 3);
  6598. lua_interface->ResetFunctionStack(state);
  6599. if (!spawn) {
  6600. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6601. return 0;
  6602. }
  6603. if (!target) {
  6604. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6605. return 0;
  6606. }
  6607. if (!spawn->IsNPC()) {
  6608. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6609. return 0;
  6610. }
  6611. if (!target->IsEntity()) {
  6612. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6613. return 0;
  6614. }
  6615. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6616. return 1;
  6617. }
  6618. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6619. if (!lua_interface)
  6620. return 0;
  6621. Spawn* spawn = lua_interface->GetSpawn(state);
  6622. Spawn* target = lua_interface->GetSpawn(state, 2);
  6623. float distance = lua_interface->GetFloatValue(state, 3);
  6624. lua_interface->ResetFunctionStack(state);
  6625. if (!spawn) {
  6626. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6627. return 0;
  6628. }
  6629. if (!target) {
  6630. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6631. return 0;
  6632. }
  6633. if (!spawn->IsNPC()) {
  6634. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6635. return 0;
  6636. }
  6637. if (!target->IsEntity()) {
  6638. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6639. return 0;
  6640. }
  6641. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6642. return 0;
  6643. }
  6644. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6645. if (!lua_interface)
  6646. return 0;
  6647. Spawn* spawn = lua_interface->GetSpawn(state);
  6648. lua_interface->ResetFunctionStack(state);
  6649. if (!spawn) {
  6650. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6651. return 0;
  6652. }
  6653. if (!spawn->IsNPC()) {
  6654. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6655. return 0;
  6656. }
  6657. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6658. return 1;
  6659. }
  6660. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6661. if (!lua_interface)
  6662. return 0;
  6663. Spawn* spawn = lua_interface->GetSpawn(state);
  6664. lua_interface->ResetFunctionStack(state);
  6665. if (!spawn) {
  6666. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6667. return 0;
  6668. }
  6669. if (!spawn->IsNPC()) {
  6670. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6671. return 0;
  6672. }
  6673. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6674. return 1;
  6675. }
  6676. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6677. if (!lua_interface)
  6678. return 0;
  6679. Spawn* spawn = lua_interface->GetSpawn(state);
  6680. lua_interface->ResetFunctionStack(state);
  6681. if (!spawn) {
  6682. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6683. return 0;
  6684. }
  6685. if (!spawn->IsNPC()) {
  6686. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6687. return 0;
  6688. }
  6689. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6690. if (hated) {
  6691. lua_interface->SetSpawnValue(state, hated);
  6692. return 1;
  6693. }
  6694. return 0;
  6695. }
  6696. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6697. if (!lua_interface)
  6698. return 0;
  6699. Spawn* spawn = lua_interface->GetSpawn(state);
  6700. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6701. lua_interface->ResetFunctionStack(state);
  6702. if (!spawn) {
  6703. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6704. return 0;
  6705. }
  6706. if (!spawn->IsNPC()) {
  6707. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6708. return 0;
  6709. }
  6710. if (!hated) {
  6711. ((NPC*)spawn)->Brain()->ClearHate();
  6712. return 0;
  6713. }
  6714. else
  6715. {
  6716. if (!hated->IsEntity()) {
  6717. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6718. return 0;
  6719. }
  6720. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6721. return 0;
  6722. }
  6723. return 0;
  6724. }
  6725. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6726. if (!lua_interface)
  6727. return 0;
  6728. Spawn* spawn = lua_interface->GetSpawn(state);
  6729. lua_interface->ResetFunctionStack(state);
  6730. if (!spawn) {
  6731. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6732. return 0;
  6733. }
  6734. if (!spawn->IsNPC()) {
  6735. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6736. return 0;
  6737. }
  6738. ((NPC*)spawn)->Brain()->ClearEncounter();
  6739. return 0;
  6740. }
  6741. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6742. if (!lua_interface)
  6743. return 0;
  6744. Spawn* spawn = lua_interface->GetSpawn(state);
  6745. lua_interface->ResetFunctionStack(state);
  6746. if (!spawn) {
  6747. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6748. return 0;
  6749. }
  6750. if (!spawn->IsNPC()) {
  6751. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6752. return 0;
  6753. }
  6754. // Temp list to store hate list
  6755. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6756. if (encounterList->size() == 0) {
  6757. safe_delete(encounterList);
  6758. return 0;
  6759. }
  6760. lua_createtable(state, encounterList->size(), 0);
  6761. int newTable = lua_gettop(state);
  6762. for (int32 i = 0; i < encounterList->size(); i++) {
  6763. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6764. if (temp)
  6765. lua_interface->SetSpawnValue(state, temp);
  6766. lua_rawseti(state, newTable, i + 1);
  6767. }
  6768. safe_delete(encounterList);
  6769. return 1;
  6770. }
  6771. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6772. if (!lua_interface)
  6773. return 0;
  6774. Spawn* spawn = lua_interface->GetSpawn(state);
  6775. lua_interface->ResetFunctionStack(state);
  6776. if (!spawn) {
  6777. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6778. return 0;
  6779. }
  6780. if (!spawn->IsNPC()) {
  6781. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6782. return 0;
  6783. }
  6784. // Temp list to store hate list
  6785. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6786. if (hateList->size() == 0) {
  6787. safe_delete(hateList);
  6788. return 0;
  6789. }
  6790. lua_createtable(state, hateList->size(), 0);
  6791. int newTable = lua_gettop(state);
  6792. for (int32 i = 0; i < hateList->size(); i++) {
  6793. lua_interface->SetSpawnValue(state, hateList->at(i));
  6794. lua_rawseti(state, newTable, i + 1);
  6795. }
  6796. safe_delete(hateList);
  6797. return 1;
  6798. }
  6799. int EQ2Emu_lua_HasGroup(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 HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6806. return 0;
  6807. }
  6808. if (spawn->IsPlayer()) {
  6809. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6810. lua_interface->SetBooleanValue(state, true);
  6811. else
  6812. lua_interface->SetBooleanValue(state, false);
  6813. return 1;
  6814. }
  6815. else {
  6816. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6817. return 1;
  6818. }
  6819. }
  6820. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6821. if (!lua_interface)
  6822. return 0;
  6823. Quest* quest = lua_interface->GetQuest(state);
  6824. lua_interface->ResetFunctionStack(state);
  6825. if (!quest) {
  6826. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6827. return 0;
  6828. }
  6829. quest->SetCompletedFlag(true);
  6830. return 0;
  6831. }
  6832. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6833. if (!lua_interface)
  6834. return 0;
  6835. Spawn* spawn = lua_interface->GetSpawn(state);
  6836. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6837. int8 tier = lua_interface->GetInt8Value(state, 3);
  6838. lua_interface->ResetFunctionStack(state);
  6839. if (!spawn) {
  6840. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6841. return 0;
  6842. }
  6843. if (!spawn->IsEntity()) {
  6844. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6845. return 0;
  6846. }
  6847. if (spellID == 0) {
  6848. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6849. return 0;
  6850. }
  6851. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6852. if (effect) {
  6853. if (tier > 0) {
  6854. // If a tier was passed chec to see if it is the same as the effect
  6855. if (tier == effect->tier)
  6856. lua_interface->SetBooleanValue(state, true);
  6857. else
  6858. lua_interface->SetBooleanValue(state, false);
  6859. return 1;
  6860. }
  6861. else {
  6862. // Have an effect but no tier was passed so return true
  6863. lua_interface->SetBooleanValue(state, true);
  6864. }
  6865. return 1;
  6866. }
  6867. // no effect so return false
  6868. lua_interface->SetBooleanValue(state, false);
  6869. return 1;
  6870. }
  6871. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6872. if (!lua_interface)
  6873. return 0;
  6874. Spawn* spawn = lua_interface->GetSpawn(state);
  6875. int32 id = lua_interface->GetInt32Value(state, 2);
  6876. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6877. lua_interface->ResetFunctionStack(state);
  6878. Spawn* spawn2 = 0;
  6879. vector<Spawn*> list;
  6880. if (!spawn) {
  6881. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6882. return 0;
  6883. }
  6884. //If zone not provided, use spawn's zone
  6885. if (!zone)
  6886. zone = spawn->GetZone();
  6887. list = zone->GetSpawnsByID(id);
  6888. if (list.size() == 0) {
  6889. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6890. return 0;
  6891. }
  6892. vector<Spawn*>::iterator itr = list.begin();
  6893. for (int8 i = 0; i < list.size(); i++) {
  6894. spawn2 = itr[i];
  6895. if (spawn2)
  6896. spawn2->AddAllowAccessSpawn(spawn);
  6897. }
  6898. return 0;
  6899. }
  6900. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6901. if (!lua_interface)
  6902. return 0;
  6903. Spawn* spawn = lua_interface->GetSpawn(state);
  6904. int32 id = lua_interface->GetInt32Value(state, 2);
  6905. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6906. lua_interface->ResetFunctionStack(state);
  6907. Spawn* spawn2 = 0;
  6908. if (!spawn) {
  6909. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6910. return 0;
  6911. }
  6912. //If zone not provided, use spawn's zone
  6913. if (!zone)
  6914. zone = spawn->GetZone();
  6915. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6916. vector<Spawn*>::iterator itr = list.begin();
  6917. if (list.size() == 0) {
  6918. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6919. return 0;
  6920. }
  6921. for (int8 i = 0; i < list.size(); i++) {
  6922. spawn2 = itr[i];
  6923. if (spawn2)
  6924. spawn2->RemoveSpawnAccess(spawn);
  6925. }
  6926. return 0;
  6927. }
  6928. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6929. if (!lua_interface)
  6930. return 0;
  6931. Quest* quest = lua_interface->GetQuest(state);
  6932. lua_interface->ResetFunctionStack(state);
  6933. if (!quest) {
  6934. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6935. return 0;
  6936. }
  6937. quest->SetYellowName(true);
  6938. return 0;
  6939. }
  6940. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6941. if (!lua_interface)
  6942. return 0;
  6943. Spawn* spawn = lua_interface->GetSpawn(state);
  6944. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6945. lua_interface->ResetFunctionStack(state);
  6946. if (!spawn) {
  6947. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6948. return 0;
  6949. }
  6950. if (!spawn->IsPlayer()) {
  6951. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6952. return 0;
  6953. }
  6954. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6955. return 1;
  6956. }
  6957. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6958. if (!lua_interface)
  6959. return 0;
  6960. Spawn* spawn = lua_interface->GetSpawn(state);
  6961. lua_interface->ResetFunctionStack(state);
  6962. if (!spawn) {
  6963. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6964. return 0;
  6965. }
  6966. if (!spawn->IsPlayer()) {
  6967. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6968. return 0;
  6969. }
  6970. ZoneServer* zone = spawn->GetZone();
  6971. if (!zone) {
  6972. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6973. return 0;
  6974. }
  6975. Instance_Type iType = zone->GetInstanceType();
  6976. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6977. iType == GROUP_LOCKOUT_INSTANCE ||
  6978. iType == RAID_LOCKOUT_INSTANCE ||
  6979. iType == SOLO_PERSIST_INSTANCE ||
  6980. iType == GROUP_PERSIST_INSTANCE ||
  6981. iType == RAID_PERSIST_INSTANCE) {
  6982. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6983. if (data) {
  6984. // Check to see if the timer has already been set, if it has return out.
  6985. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6986. return 0;
  6987. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6988. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6989. if(spawn->IsPlayer()) {
  6990. Client* client = ((Player*)spawn)->GetClient();
  6991. if (client) {
  6992. string time_msg = "";
  6993. int32 time = data->success_lockout_time;
  6994. int16 hour;
  6995. int8 min;
  6996. int8 sec;
  6997. hour = time / 3600;
  6998. time = time % 3600;
  6999. min = time / 60;
  7000. time = time % 60;
  7001. sec = time;
  7002. if (hour > 0) {
  7003. char temp[10];
  7004. sprintf(temp, " %i", hour);
  7005. time_msg.append(temp);
  7006. time_msg.append(" hour");
  7007. time_msg.append((hour > 1) ? "s" : "");
  7008. }
  7009. if (min > 0) {
  7010. char temp[5];
  7011. sprintf(temp, " %i", min);
  7012. time_msg.append(temp);
  7013. time_msg.append(" minute");
  7014. time_msg.append((min > 1) ? "s" : "");
  7015. }
  7016. // Only add seconds if minutes and hours are 0
  7017. if (hour == 0 && min == 0 && sec > 0) {
  7018. char temp[5];
  7019. sprintf(temp, " %i", sec);
  7020. time_msg.append(temp);
  7021. time_msg.append(" second");
  7022. time_msg.append((sec > 1) ? "s" : "");
  7023. }
  7024. 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());
  7025. }
  7026. else {
  7027. lua_interface->LogError("LUA SetSuccessTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7028. }
  7029. }
  7030. }
  7031. else
  7032. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7033. }
  7034. else
  7035. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  7036. return 0;
  7037. }
  7038. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  7039. if (!lua_interface)
  7040. return 0;
  7041. Spawn* spawn = lua_interface->GetSpawn(state);
  7042. lua_interface->ResetFunctionStack(state);
  7043. if (!spawn) {
  7044. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7045. return 0;
  7046. }
  7047. if (!spawn->IsPlayer()) {
  7048. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  7049. return 0;
  7050. }
  7051. ZoneServer* zone = spawn->GetZone();
  7052. if (!zone) {
  7053. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  7054. return 0;
  7055. }
  7056. Instance_Type iType = zone->GetInstanceType();
  7057. if (iType == SOLO_LOCKOUT_INSTANCE ||
  7058. iType == GROUP_LOCKOUT_INSTANCE ||
  7059. iType == RAID_LOCKOUT_INSTANCE ||
  7060. iType == SOLO_PERSIST_INSTANCE ||
  7061. iType == GROUP_PERSIST_INSTANCE ||
  7062. iType == RAID_PERSIST_INSTANCE) {
  7063. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  7064. if (data) {
  7065. // Check to see if the timer has already been set, if it has return out.
  7066. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  7067. return 0;
  7068. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  7069. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  7070. if(spawn->IsPlayer()) {
  7071. Client* client = ((Player*)spawn)->GetClient();
  7072. if (client) {
  7073. string time_msg = "";
  7074. int32 time = data->failure_lockout_time;
  7075. int16 hour;
  7076. int8 min;
  7077. int8 sec;
  7078. hour = time / 3600;
  7079. time = time % 3600;
  7080. min = time / 60;
  7081. time = time % 60;
  7082. sec = time;
  7083. if (hour > 0) {
  7084. char temp[10];
  7085. sprintf(temp, " %i", hour);
  7086. time_msg.append(temp);
  7087. time_msg.append(" hour");
  7088. time_msg.append((hour > 1) ? "s" : "");
  7089. }
  7090. if (min > 0) {
  7091. char temp[5];
  7092. sprintf(temp, " %i", min);
  7093. time_msg.append(temp);
  7094. time_msg.append(" minute");
  7095. time_msg.append((min > 1) ? "s" : "");
  7096. }
  7097. // Only add seconds if minutes and hours are 0
  7098. if (hour == 0 && min == 0 && sec > 0) {
  7099. char temp[5];
  7100. sprintf(temp, " %i", sec);
  7101. time_msg.append(temp);
  7102. time_msg.append(" second");
  7103. time_msg.append((sec > 1) ? "s" : "");
  7104. }
  7105. 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());
  7106. }
  7107. }
  7108. else {
  7109. lua_interface->LogError("LUA SetFailureTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7110. }
  7111. }
  7112. else
  7113. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7114. }
  7115. else
  7116. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  7117. return 0;
  7118. }
  7119. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  7120. if (!lua_interface)
  7121. return 0;
  7122. Spawn* spawn = lua_interface->GetSpawn(state);
  7123. lua_interface->ResetFunctionStack(state);
  7124. if (!spawn) {
  7125. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  7126. return 0;
  7127. }
  7128. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  7129. return 1;
  7130. }
  7131. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  7132. if (!lua_interface)
  7133. return 0;
  7134. Spawn* player = lua_interface->GetSpawn(state);
  7135. Spawn* ground = lua_interface->GetSpawn(state, 2);
  7136. if (!player) {
  7137. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7138. lua_interface->ResetFunctionStack(state);
  7139. return 0;
  7140. }
  7141. if (!player->IsPlayer()) {
  7142. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  7143. lua_interface->ResetFunctionStack(state);
  7144. return 0;
  7145. }
  7146. if (!ground) {
  7147. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7148. lua_interface->ResetFunctionStack(state);
  7149. return 0;
  7150. }
  7151. if (!ground->IsGroundSpawn()) {
  7152. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  7153. lua_interface->ResetFunctionStack(state);
  7154. return 0;
  7155. }
  7156. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7157. if (!groundspawn_entries) {
  7158. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7159. lua_interface->ResetFunctionStack(state);
  7160. return 0;
  7161. }
  7162. Skill* skill = 0;
  7163. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  7164. if (collection_skill == "Collecting")
  7165. skill = ((Player*)player)->GetSkillByName("Gathering");
  7166. else
  7167. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  7168. if (!skill) {
  7169. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  7170. lua_interface->ResetFunctionStack(state);
  7171. return 0;
  7172. }
  7173. vector<GroundSpawnEntry*>::iterator itr;
  7174. GroundSpawnEntry* entry = 0;
  7175. bool can_harvest = false;
  7176. sint32 min_skill = -1;
  7177. int16 totalSkill = skill->current_val;
  7178. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  7179. if(skillID != 0xFFFFFFFF)
  7180. {
  7181. ((Entity*)player)->MStats.lock();
  7182. totalSkill += ((Entity*)player)->stats[skillID];
  7183. ((Entity*)player)->MStats.unlock();
  7184. }
  7185. // first, iterate through groundspawn_entries, discard tables player cannot use
  7186. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  7187. {
  7188. entry = *itr;
  7189. if (min_skill == -1 || entry->min_skill_level < min_skill)
  7190. min_skill = entry->min_skill_level;
  7191. // if player lacks skill, skip table
  7192. if (entry->min_skill_level > totalSkill)
  7193. continue;
  7194. // if bonus, but player lacks level, skip table
  7195. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  7196. continue;
  7197. can_harvest = true;
  7198. break;
  7199. }
  7200. lua_interface->SetBooleanValue(state, can_harvest);
  7201. // If false, send the message to the client
  7202. if (!can_harvest) {
  7203. Client* client = ((Player*)player)->GetClient();
  7204. if (client) {
  7205. string msg = "You do not have enough skill to ";
  7206. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  7207. msg.append("gather");
  7208. else if (collection_skill == "Mining")
  7209. msg.append("mine");
  7210. else if (collection_skill == "Trapping")
  7211. msg.append("trap");
  7212. else if (collection_skill == "Foresting")
  7213. msg.append("forest");
  7214. else if (collection_skill == "Fishing")
  7215. msg.append("catch");
  7216. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  7217. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  7218. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  7219. }
  7220. }
  7221. lua_interface->ResetFunctionStack(state);
  7222. return 1;
  7223. }
  7224. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  7225. if (!lua_interface)
  7226. return 0;
  7227. Spawn* player = lua_interface->GetSpawn(state);
  7228. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  7229. lua_interface->ResetFunctionStack(state);
  7230. if (!player) {
  7231. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  7232. return 0;
  7233. }
  7234. if (!player->IsPlayer()) {
  7235. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  7236. return 0;
  7237. }
  7238. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  7239. lua_interface->SetBooleanValue(state, ret);
  7240. return 1;
  7241. }
  7242. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  7243. // Check to see if we have a valid lua_interface
  7244. if (!lua_interface)
  7245. return 0;
  7246. // Get the spawn that is getting the pet
  7247. Spawn* spawn = lua_interface->GetSpawn(state);
  7248. Spawn* target = lua_interface->GetSpawn(state, 2);
  7249. // Get the DB ID of the pet
  7250. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  7251. float x = lua_interface->GetFloatValue(state, 4);
  7252. float y = lua_interface->GetFloatValue(state, 5);
  7253. float z = lua_interface->GetFloatValue(state, 6);
  7254. // Get the spell that this command was called from
  7255. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7256. lua_interface->ResetFunctionStack(state);
  7257. // Check to make sure the spawn pointer is valid
  7258. if (!spawn) {
  7259. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  7260. return 0;
  7261. }
  7262. // Check to make sure the spawn is an entity
  7263. if (!spawn->IsEntity()) {
  7264. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  7265. return 0;
  7266. }
  7267. if (!target) {
  7268. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  7269. return 0;
  7270. }
  7271. if (!target->IsEntity()) {
  7272. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  7273. return 0;
  7274. }
  7275. // Check to see if the DB ID for the pet is set
  7276. if (pet_id == 0) {
  7277. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  7278. return 0;
  7279. }
  7280. // Check to see if the pointer to the spell is valid
  7281. if (!luaspell) {
  7282. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  7283. return 0;
  7284. }
  7285. if(luaspell->resisted) {
  7286. return 0;
  7287. }
  7288. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  7289. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  7290. if (!pet) {
  7291. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  7292. return 0;
  7293. }
  7294. // Check to make sure the pet is an npc
  7295. if (!pet->IsNPC()) {
  7296. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  7297. return 0;
  7298. }
  7299. if (x == 0)
  7300. x = spawn->GetX();
  7301. if (y == 0)
  7302. y = spawn->GetY();
  7303. if (z == 0)
  7304. z = spawn->GetZ();
  7305. // Spawn the pet at the same location as the owner
  7306. pet->SetX(x);
  7307. pet->SetY(y);
  7308. pet->SetZ(z);
  7309. pet->SetLocation(spawn->GetLocation());
  7310. pet->SetHeading(spawn->GetHeading());
  7311. spawn->GetZone()->AddSpawn(pet);
  7312. const char* spawn_script = world.GetSpawnScript(pet_id);
  7313. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  7314. spawn->SetSpawnScript(string(spawn_script));
  7315. spawn->GetZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7316. }
  7317. std::string petName = std::string("");
  7318. if(spawn->IsEntity()) {
  7319. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  7320. }
  7321. if(petName.size() < 1) {
  7322. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  7323. petName = spawn->GetZone()->pet_names.at(rand_index);
  7324. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  7325. }
  7326. // Set the pets name
  7327. pet->SetName(petName.c_str());
  7328. // Set the level of the pet to the owners level
  7329. pet->SetLevel(spawn->GetLevel());
  7330. // Set the faction of the pet to the same faction as the owner
  7331. pet->SetFactionID(spawn->GetFactionID());
  7332. // Set the spawn as a pet
  7333. pet->SetPet(true);
  7334. // Give a pointer of the owner to the pet
  7335. ((NPC*)pet)->SetOwner((Entity*)spawn);
  7336. // Set the pet type
  7337. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  7338. // Set the spell id used to create this pet
  7339. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  7340. // Set the spell tier used to create this pet
  7341. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  7342. // Set the pets spawn type to 6
  7343. pet->SetSpawnType(6);
  7344. // Set the pets brain
  7345. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  7346. // Check to see if the pet has a subtitle
  7347. if (strlen(pet->GetSubTitle()) > 0) {
  7348. // Add the players name to the front of the sub title
  7349. string pet_subtitle;
  7350. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  7351. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  7352. // Set the pets subtitle to the new one
  7353. pet->SetSubTitle(pet_subtitle.c_str());
  7354. }
  7355. // Set the pet as the return value for this function
  7356. lua_interface->SetSpawnValue(state, pet);
  7357. return 1;
  7358. }
  7359. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  7360. if (!lua_interface)
  7361. return 0;
  7362. Spawn* spawn = lua_interface->GetSpawn(state);
  7363. Spawn* player = lua_interface->GetSpawn(state, 2);
  7364. float max_distance = lua_interface->GetFloatValue(state, 3);
  7365. string type = lua_interface->GetStringValue(state, 4);
  7366. lua_interface->ResetFunctionStack(state);
  7367. if (!spawn || (spawn && spawn->IsPlayer())) {
  7368. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  7369. return 0;
  7370. }
  7371. if (!player || !player->IsPlayer()) {
  7372. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  7373. return 0;
  7374. }
  7375. Client* client = ((Player*)player)->GetClient();
  7376. if (!client) {
  7377. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7378. return 0;
  7379. }
  7380. //Set max_distance to default if not set or not proper value
  7381. if (max_distance <= 0)
  7382. max_distance = 500;
  7383. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7384. if (packet) {
  7385. float unknown2_3 = 0;
  7386. int8 placement_mode = 0;
  7387. if (type == "wall") {
  7388. placement_mode = 2;
  7389. unknown2_3 = 150;
  7390. }
  7391. else if (type == "ceiling")
  7392. placement_mode = 1;
  7393. packet->setDataByName("placement_mode", placement_mode);
  7394. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7395. packet->setDataByName("model_type", spawn->GetModelType());
  7396. packet->setDataByName("unknown", 1); //size
  7397. packet->setDataByName("unknown2", 1); //size 2
  7398. packet->setDataByName("unknown2", .5, 1); //size 3
  7399. packet->setDataByName("unknown2", 3, 2);
  7400. packet->setDataByName("unknown2", unknown2_3, 3);
  7401. packet->setDataByName("max_distance", max_distance);
  7402. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7403. client->QueuePacket(packet->serialize());
  7404. safe_delete(packet);
  7405. }
  7406. return 0;
  7407. }
  7408. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7409. if (!lua_interface)
  7410. return 0;
  7411. Item* item = lua_interface->GetItem(state);
  7412. lua_interface->ResetFunctionStack(state);
  7413. if (!item) {
  7414. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7415. return 0;
  7416. }
  7417. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7418. return 1;
  7419. }
  7420. int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
  7421. if (!lua_interface)
  7422. return 0;
  7423. Item* item = lua_interface->GetItem(state);
  7424. lua_interface->ResetFunctionStack(state);
  7425. if (!item) {
  7426. lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7427. return 0;
  7428. }
  7429. lua_interface->SetInt32Value(state, item->effect_type);
  7430. return 1;
  7431. }
  7432. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7433. if (!lua_interface)
  7434. return 0;
  7435. Spawn* spawn = lua_interface->GetSpawn(state);
  7436. lua_interface->ResetFunctionStack(state);
  7437. if (!spawn) {
  7438. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7439. return 0;
  7440. }
  7441. if (spawn->GetZone())
  7442. spawn->GetZone()->AddTransportSpawn(spawn);
  7443. return 0;
  7444. }
  7445. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7446. if (!lua_interface)
  7447. return 0;
  7448. Spawn* spawn = lua_interface->GetSpawn(state);
  7449. lua_interface->ResetFunctionStack(state);
  7450. if (!spawn) {
  7451. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7452. return 0;
  7453. }
  7454. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7455. return 1;
  7456. }
  7457. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7458. if (!lua_interface)
  7459. return 0;
  7460. Skill* skill = lua_interface->GetSkill(state);
  7461. lua_interface->ResetFunctionStack(state);
  7462. if (!skill) {
  7463. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7464. return 0;
  7465. }
  7466. lua_interface->SetInt32Value(state, skill->current_val);
  7467. return 1;
  7468. }
  7469. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7470. if (!lua_interface)
  7471. return 0;
  7472. Skill* skill = lua_interface->GetSkill(state);
  7473. lua_interface->ResetFunctionStack(state);
  7474. if (!skill) {
  7475. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7476. return 0;
  7477. }
  7478. lua_interface->SetInt32Value(state, skill->max_val);
  7479. return 1;
  7480. }
  7481. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7482. if (!lua_interface)
  7483. return 0;
  7484. Skill* skill = lua_interface->GetSkill(state);
  7485. lua_interface->ResetFunctionStack(state);
  7486. if (!skill) {
  7487. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7488. return 0;
  7489. }
  7490. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7491. return 1;
  7492. }
  7493. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7494. if (!lua_interface)
  7495. return 0;
  7496. Skill* skill = lua_interface->GetSkill(state);
  7497. int16 value = lua_interface->GetInt16Value(state, 2);
  7498. lua_interface->ResetFunctionStack(state);
  7499. if (!skill) {
  7500. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7501. return 0;
  7502. }
  7503. skill->max_val = value;
  7504. if (skill->max_val < skill->current_val)
  7505. skill->current_val = skill->max_val;
  7506. return 0;
  7507. }
  7508. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7509. if (!lua_interface)
  7510. return 0;
  7511. Skill* skill = lua_interface->GetSkill(state);
  7512. int16 value = lua_interface->GetInt16Value(state, 2);
  7513. lua_interface->ResetFunctionStack(state);
  7514. if (!skill) {
  7515. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7516. return 0;
  7517. }
  7518. if (value > skill->max_val)
  7519. skill->current_val = skill->max_val;
  7520. else
  7521. skill->current_val = value;
  7522. return 0;
  7523. }
  7524. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7525. if (!lua_interface)
  7526. return 0;
  7527. Spawn* player = lua_interface->GetSpawn(state);
  7528. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7529. lua_interface->ResetFunctionStack(state);
  7530. if (skill_id > 0 && player && player->IsPlayer()) {
  7531. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7532. return 1;
  7533. }
  7534. return 0;
  7535. }
  7536. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7537. if (!lua_interface)
  7538. return 0;
  7539. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7540. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7541. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7542. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7543. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7544. lua_interface->ResetFunctionStack(state);
  7545. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7546. if (player_spawn && player_spawn->IsPlayer()) {
  7547. Player* player = (Player*)player_spawn;
  7548. bool added = false;
  7549. if (!player->skill_list.HasSkill(skill_id)) {
  7550. player->AddSkill(skill_id, current_val, max_val, true);
  7551. added = true;
  7552. }
  7553. 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
  7554. Client* client = player->GetClient();
  7555. if (client) {
  7556. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7557. if (packet)
  7558. client->QueuePacket(packet);
  7559. }
  7560. }
  7561. if (added) {
  7562. lua_interface->SetBooleanValue(state, true);
  7563. return 1;
  7564. }
  7565. }
  7566. else {
  7567. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7568. }
  7569. }
  7570. else {
  7571. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7572. }
  7573. lua_interface->SetBooleanValue(state, false);
  7574. return 1;
  7575. }
  7576. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7577. if (!lua_interface)
  7578. return 0;
  7579. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7580. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7581. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7582. lua_interface->ResetFunctionStack(state);
  7583. if (skill_id > 0) {
  7584. if (player_spawn && player_spawn->IsPlayer()) {
  7585. Player* player = (Player*)player_spawn;
  7586. if (player->skill_list.HasSkill(skill_id)) {
  7587. player->RemovePlayerSkill(skill_id, true);
  7588. if (!more_to_remove) {
  7589. Client* client = player->GetClient();
  7590. if (client) {
  7591. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7592. if (packet)
  7593. client->QueuePacket(packet);
  7594. }
  7595. }
  7596. }
  7597. }
  7598. else {
  7599. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7600. }
  7601. }
  7602. else {
  7603. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7604. }
  7605. return 0;
  7606. }
  7607. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7608. if (!lua_interface)
  7609. return 0;
  7610. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7611. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7612. int16 amount = lua_interface->GetInt8Value(state, 3);
  7613. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7614. lua_interface->ResetFunctionStack(state);
  7615. if (amount > 0 && skill_type < 100) {
  7616. if (player_spawn && player_spawn->IsPlayer()) {
  7617. Player* player = (Player*)player_spawn;
  7618. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7619. if (!more_to_increase) {
  7620. Client* client = player->GetClient();
  7621. if (client) {
  7622. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7623. if (packet)
  7624. client->QueuePacket(packet);
  7625. }
  7626. }
  7627. }
  7628. else {
  7629. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7630. }
  7631. }
  7632. else {
  7633. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7634. }
  7635. return 0;
  7636. }
  7637. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7638. if (!lua_interface)
  7639. return 0;
  7640. Spawn* spawn = lua_interface->GetSpawn(state);
  7641. string name = lua_interface->GetStringValue(state, 2);
  7642. lua_interface->ResetFunctionStack(state);
  7643. if (!spawn) {
  7644. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7645. return 0;
  7646. }
  7647. if (!spawn->IsEntity()) {
  7648. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7649. return 0;
  7650. }
  7651. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7652. if (skill) {
  7653. lua_interface->SetSkillValue(state, skill);
  7654. return 1;
  7655. }
  7656. return 0;
  7657. }
  7658. int EQ2Emu_lua_AddProc(lua_State* state) {
  7659. if (!lua_interface)
  7660. return 0;
  7661. Spawn* spawn = lua_interface->GetSpawn(state);
  7662. int8 type = lua_interface->GetInt8Value(state, 2);
  7663. float chance = lua_interface->GetFloatValue(state, 3);
  7664. Item* item = lua_interface->GetItem(state, 4);
  7665. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7666. LuaSpell* spell = 0;
  7667. if (!item)
  7668. spell = lua_interface->GetCurrentSpell(state);
  7669. if (!spawn && (!spell || !use_all_spelltargets)) {
  7670. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7671. return 0;
  7672. }
  7673. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7674. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7675. return 0;
  7676. }
  7677. if (!item && !spell) {
  7678. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7679. return 0;
  7680. }
  7681. if(spell && spell->resisted) {
  7682. return 0;
  7683. }
  7684. if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
  7685. Spawn* target;
  7686. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7687. for (int8 i = 0; i < spell->targets.size(); i++) {
  7688. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7689. if (!target || !target->IsEntity())
  7690. continue;
  7691. ((Entity*)target)->AddProc(type, chance, item, spell);
  7692. }
  7693. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7694. }
  7695. else
  7696. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7697. return 0;
  7698. }
  7699. int EQ2Emu_lua_AddProcExt(lua_State* state) {
  7700. if (!lua_interface)
  7701. return 0;
  7702. Spawn* spawn = lua_interface->GetSpawn(state);
  7703. int8 type = lua_interface->GetInt8Value(state, 2);
  7704. int8 damage_type = lua_interface->GetInt8Value(state, 3);
  7705. float chance = lua_interface->GetFloatValue(state, 4);
  7706. int8 hp_ratio = lua_interface->GetInt8Value(state, 5);
  7707. bool below_health = lua_interface->GetBooleanValue(state, 6);
  7708. bool target_health = lua_interface->GetBooleanValue(state, 7);
  7709. Item* item = lua_interface->GetItem(state, 8);
  7710. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 9) == 1);
  7711. bool extended_version = true;
  7712. LuaSpell* spell = 0;
  7713. if (!item)
  7714. spell = lua_interface->GetCurrentSpell(state);
  7715. if (!spawn && (!spell || !use_all_spelltargets)) {
  7716. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7717. return 0;
  7718. }
  7719. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7720. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7721. return 0;
  7722. }
  7723. if (!item && !spell) {
  7724. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7725. return 0;
  7726. }
  7727. if(spell && spell->resisted) {
  7728. return 0;
  7729. }
  7730. if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
  7731. Spawn* target;
  7732. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7733. for (int8 i = 0; i < spell->targets.size(); i++) {
  7734. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7735. if (!target || !target->IsEntity())
  7736. continue;
  7737. ((Entity*)target)->AddProc(type, chance, item, spell, damage_type, hp_ratio, below_health, target_health, extended_version);
  7738. }
  7739. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7740. }
  7741. else
  7742. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7743. return 0;
  7744. }
  7745. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7746. if (!lua_interface)
  7747. return 0;
  7748. Spawn* spawn = lua_interface->GetSpawn(state);
  7749. Item* item = lua_interface->GetItem(state, 2);
  7750. LuaSpell* spell = 0;
  7751. if (!spawn) {
  7752. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7753. lua_interface->ResetFunctionStack(state);
  7754. return 0;
  7755. }
  7756. if (!spawn->IsEntity()) {
  7757. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7758. lua_interface->ResetFunctionStack(state);
  7759. return 0;
  7760. }
  7761. if (!item)
  7762. spell = lua_interface->GetCurrentSpell(state);
  7763. lua_interface->ResetFunctionStack(state);
  7764. if (!item && !spell) {
  7765. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7766. return 0;
  7767. }
  7768. if (spell && spell->caster && spell->caster->GetZone()) {
  7769. Spawn* target;
  7770. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7771. for (int8 i = 0; i < spell->targets.size(); i++) {
  7772. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7773. if (!target || !target->IsEntity())
  7774. continue;
  7775. ((Entity*)target)->RemoveProc(item, spell);
  7776. }
  7777. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7778. spell->caster->RemoveProc(item, spell);
  7779. }
  7780. else
  7781. ((Entity*)spawn)->RemoveProc(item, spell);
  7782. return 0;
  7783. }
  7784. int EQ2Emu_lua_Knockback(lua_State* state) {
  7785. if (!lua_interface)
  7786. return 0;
  7787. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7788. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7789. int32 duration = lua_interface->GetInt32Value(state, 3);
  7790. float vertical = lua_interface->GetFloatValue(state, 4);
  7791. float horizontal = lua_interface->GetFloatValue(state, 5);
  7792. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7793. lua_interface->ResetFunctionStack(state);
  7794. if (!target_spawn) {
  7795. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7796. return 0;
  7797. }
  7798. if (!spawn) {
  7799. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7800. return 0;
  7801. }
  7802. if ((vertical != 0 || horizontal != 0)) {
  7803. if(spawn->IsPlayer()) {
  7804. Client* client = ((Player*)spawn)->GetClient();
  7805. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7806. if (packet) {
  7807. packet->setDataByName("target_x", target_spawn->GetX());
  7808. packet->setDataByName("target_y", target_spawn->GetY());
  7809. packet->setDataByName("target_z", target_spawn->GetZ());
  7810. packet->setDataByName("vertical_movement", vertical);
  7811. packet->setDataByName("horizontal_movement", horizontal);
  7812. if (use_heading)
  7813. packet->setDataByName("use_player_heading", 1);
  7814. client->QueuePacket(packet->serialize());
  7815. }
  7816. safe_delete(packet);
  7817. }
  7818. else {
  7819. spawn->SetKnockback(target_spawn, duration, vertical, horizontal);
  7820. }
  7821. }
  7822. return 0;
  7823. }
  7824. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7825. if (!lua_interface)
  7826. return 0;
  7827. Spawn* spawn = lua_interface->GetSpawn(state);
  7828. lua_interface->ResetFunctionStack(state);
  7829. if (!spawn) {
  7830. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7831. return 0;
  7832. }
  7833. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7834. return 1;
  7835. }
  7836. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7837. if (!lua_interface)
  7838. return 0;
  7839. Spawn* caster = lua_interface->GetSpawn(state);
  7840. Spawn* target = lua_interface->GetSpawn(state, 2);
  7841. string name = lua_interface->GetStringValue(state, 3);
  7842. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7843. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7844. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7845. string success_msg = lua_interface->GetStringValue(state, 7);
  7846. string effect_msg = lua_interface->GetStringValue(state, 8);
  7847. lua_interface->ResetFunctionStack(state);
  7848. if (!caster) {
  7849. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7850. return 0;
  7851. }
  7852. if (!caster->IsEntity()) {
  7853. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7854. return 0;
  7855. }
  7856. if (!target) {
  7857. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7858. return 0;
  7859. }
  7860. if (!target->IsEntity()) {
  7861. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7862. return 0;
  7863. }
  7864. if (name.length() == 0) {
  7865. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7866. return 0;
  7867. }
  7868. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7869. return 0;
  7870. }
  7871. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7872. if (!lua_interface)
  7873. return 0;
  7874. string name = lua_interface->GetStringValue(state);
  7875. lua_interface->ResetFunctionStack(state);
  7876. if (name.length() == 0) {
  7877. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7878. return 0;
  7879. }
  7880. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7881. if (!skill) {
  7882. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7883. return 0;
  7884. }
  7885. lua_interface->SetInt32Value(state, skill->skill_id);
  7886. return 1;
  7887. }
  7888. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7889. if (!lua_interface)
  7890. return 0;
  7891. Spawn* spawn = lua_interface->GetSpawn(state);
  7892. lua_interface->ResetFunctionStack(state);
  7893. if (!spawn) {
  7894. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7895. return 0;
  7896. }
  7897. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7898. return 1;
  7899. }
  7900. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7901. if (!lua_interface)
  7902. return 0;
  7903. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7904. lua_interface->ResetFunctionStack(state);
  7905. if (!luaspell) {
  7906. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7907. return 0;
  7908. }
  7909. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7910. return 1;
  7911. }
  7912. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7913. if (!lua_interface)
  7914. return 0;
  7915. Spawn* spawn = lua_interface->GetSpawn(state);
  7916. Spawn* target = lua_interface->GetSpawn(state, 2);
  7917. lua_interface->ResetFunctionStack(state);
  7918. if (!spawn) {
  7919. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7920. return 0;
  7921. }
  7922. if (!spawn->IsEntity()) {
  7923. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7924. return 0;
  7925. }
  7926. if (!target) {
  7927. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7928. return 0;
  7929. }
  7930. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7931. return 1;
  7932. }
  7933. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7934. if (!lua_interface)
  7935. return 0;
  7936. Spawn* spawn = lua_interface->GetSpawn(state);
  7937. Spawn* target = lua_interface->GetSpawn(state, 2);
  7938. lua_interface->ResetFunctionStack(state);
  7939. if (!spawn) {
  7940. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7941. return 0;
  7942. }
  7943. if (!spawn->IsEntity()) {
  7944. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7945. return 0;
  7946. }
  7947. if (!target) {
  7948. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7949. return 0;
  7950. }
  7951. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7952. return 1;
  7953. }
  7954. int EQ2Emu_lua_InFront(lua_State* state) {
  7955. if (!lua_interface)
  7956. return 0;
  7957. Spawn* spawn = lua_interface->GetSpawn(state);
  7958. Spawn* target = lua_interface->GetSpawn(state, 2);
  7959. lua_interface->ResetFunctionStack(state);
  7960. if (!spawn) {
  7961. lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7962. return 0;
  7963. }
  7964. if (!spawn->IsEntity()) {
  7965. lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7966. return 0;
  7967. }
  7968. if (!target) {
  7969. lua_interface->LogError("%s: LUA InFrontSpawn command error: target is not valid", lua_interface->GetScriptName(state));
  7970. return 0;
  7971. }
  7972. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->InFrontSpawn(target, spawn->GetX(), spawn->GetZ()));
  7973. return 1;
  7974. }
  7975. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7976. if (!lua_interface)
  7977. return 0;
  7978. Item* item = lua_interface->GetItem(state);
  7979. lua_interface->ResetFunctionStack(state);
  7980. if (!item) {
  7981. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7982. return 0;
  7983. }
  7984. lua_interface->SetInt32Value(state, item->details.count);
  7985. return 1;
  7986. }
  7987. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7988. if (!lua_interface)
  7989. return 0;
  7990. Item* item = lua_interface->GetItem(state);
  7991. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7992. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7993. lua_interface->ResetFunctionStack(state);
  7994. if (!item) {
  7995. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7996. return 0;
  7997. }
  7998. if (!owner) {
  7999. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  8000. return 0;
  8001. }
  8002. if (!owner->IsPlayer()) {
  8003. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8004. return 0;
  8005. }
  8006. if (item->stack_count < new_count) {
  8007. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  8008. return 0;
  8009. }
  8010. if (new_count > 0) {
  8011. item->details.count = new_count;
  8012. item->save_needed = true;
  8013. }
  8014. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  8015. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  8016. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  8017. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  8018. else
  8019. {
  8020. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  8021. return 0;
  8022. }
  8023. Client* client = ((Player*)owner)->GetClient();
  8024. if (!client)
  8025. return 0;
  8026. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  8027. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  8028. if (app)
  8029. client->QueuePacket(app);
  8030. return 0;
  8031. }
  8032. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  8033. if (!lua_interface)
  8034. return 0;
  8035. int32 time = lua_interface->GetInt32Value(state);
  8036. string function = lua_interface->GetStringValue(state, 2);
  8037. Spawn* caster = lua_interface->GetSpawn(state, 3);
  8038. Spawn* target = lua_interface->GetSpawn(state, 4);
  8039. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8040. lua_interface->ResetFunctionStack(state);
  8041. if (time == 0) {
  8042. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  8043. return 0;
  8044. }
  8045. if (function.length() == 0) {
  8046. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  8047. return 0;
  8048. }
  8049. if (!spell || (!spell->caster || !spell->caster->GetZone())) {
  8050. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  8051. return 0;
  8052. }
  8053. SpellScriptTimer* timer = new SpellScriptTimer;
  8054. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  8055. #ifdef WIN32
  8056. ZeroMemory(timer, sizeof(SpellScriptTimer));
  8057. #else
  8058. bzero(timer, sizeof(SpellScriptTimer));
  8059. #endif*/
  8060. timer->caster = 0;
  8061. timer->deleteWhenDone = false;
  8062. timer->target = 0;
  8063. timer->time = Timer::GetCurrentTime2() + time;
  8064. timer->customFunction = function;
  8065. timer->spell = spell;
  8066. if (caster)
  8067. timer->caster = caster->GetID();
  8068. if (target)
  8069. timer->target = target->GetID();
  8070. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  8071. return 0;
  8072. }
  8073. int EQ2Emu_lua_Resurrect(lua_State* state) {
  8074. if (!lua_interface)
  8075. return 0;
  8076. float hp_perc = lua_interface->GetFloatValue(state);
  8077. float power_perc = lua_interface->GetFloatValue(state, 2);
  8078. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  8079. Spawn* target = lua_interface->GetSpawn(state, 4);
  8080. string heal_name = lua_interface->GetStringValue(state, 5);
  8081. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  8082. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  8083. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8084. lua_interface->ResetFunctionStack(state);
  8085. if (!spell) {
  8086. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  8087. return 0;
  8088. }
  8089. Entity* caster = spell->caster;
  8090. if (!caster) {
  8091. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  8092. return 0;
  8093. }
  8094. Client* client = 0;
  8095. PendingResurrection* rez = 0;
  8096. ZoneServer* zone = spell->caster->GetZone();
  8097. if (!target) {
  8098. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8099. if (spell->targets.size() > 0) {
  8100. vector<int32> spell_targets = spell->targets;
  8101. for (int8 i = 0; i < spell_targets.size(); i++) {
  8102. target = zone->GetSpawnByID(spell_targets.at(i));
  8103. if (!target)
  8104. continue;
  8105. if (!target->IsPlayer())
  8106. continue;
  8107. client = ((Player*)target)->GetClient();
  8108. if (!client)
  8109. continue;
  8110. rez = client->GetCurrentRez();
  8111. if (rez->active)
  8112. continue;
  8113. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  8114. rez->active = true;
  8115. rez->caster = caster;
  8116. rez->expire_timer = new Timer;
  8117. int32 duration = spell->spell->GetSpellDuration();
  8118. rez->expire_timer->Start(duration * 100);
  8119. rez->hp_perc = hp_perc;
  8120. rez->mp_perc = power_perc;
  8121. rez->range = spell->spell->GetSpellData()->range;
  8122. rez->spell_name = spell->spell->GetName();
  8123. if (heal_name.length() > 0)
  8124. rez->heal_name = heal_name;
  8125. else
  8126. rez->heal_name = rez->spell_name;
  8127. rez->no_calcs = no_calcs;
  8128. rez->crit_mod = crit_mod;
  8129. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  8130. if (send_window)
  8131. client->SendResurrectionWindow();
  8132. else {
  8133. target->GetZone()->ResurrectSpawn(target, client);
  8134. rez->should_delete = true;
  8135. }
  8136. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  8137. }
  8138. }
  8139. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8140. }
  8141. else {
  8142. if(!target->IsPlayer())
  8143. return 0;
  8144. client = ((Player*)target)->GetClient();
  8145. if (!client)
  8146. return 0;
  8147. rez = client->GetCurrentRez();
  8148. if (rez->active)
  8149. return 0;
  8150. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  8151. rez->active = true;
  8152. rez->caster = caster;
  8153. rez->expire_timer = new Timer;
  8154. int32 duration = spell->spell->GetSpellDuration();
  8155. rez->expire_timer->Start(duration * 100);
  8156. rez->hp_perc = hp_perc;
  8157. rez->mp_perc = power_perc;
  8158. rez->range = spell->spell->GetSpellData()->range;
  8159. rez->spell_name = spell->spell->GetName();
  8160. if (heal_name.length() > 0)
  8161. rez->heal_name = heal_name;
  8162. else
  8163. rez->heal_name = rez->spell_name;
  8164. rez->no_calcs = no_calcs;
  8165. rez->crit_mod = crit_mod;
  8166. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  8167. if (send_window)
  8168. client->SendResurrectionWindow();
  8169. else {
  8170. target->GetZone()->ResurrectSpawn(target, client);
  8171. rez->should_delete = true;
  8172. }
  8173. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  8174. }
  8175. return 0;
  8176. }
  8177. int EQ2Emu_lua_SetVision(lua_State* state) {
  8178. if (!lua_interface)
  8179. return 0;
  8180. Spawn* spawn = lua_interface->GetSpawn(state);
  8181. int32 vision = lua_interface->GetInt32Value(state, 2);
  8182. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8183. lua_interface->ResetFunctionStack(state);
  8184. if (!spawn) {
  8185. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8186. return 0;
  8187. }
  8188. if (!spawn->IsEntity()) {
  8189. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8190. return 0;
  8191. }
  8192. if (spell && spell->targets.size() > 0) {
  8193. ZoneServer* zone = spell->caster->GetZone();
  8194. for (int8 i = 0; i < spell->targets.size(); i++) {
  8195. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8196. if (target && target->IsEntity()) {
  8197. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  8198. if (target->IsPlayer())
  8199. ((Player*)target)->SetCharSheetChanged(true);
  8200. }
  8201. }
  8202. }
  8203. else {
  8204. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  8205. if (spawn->IsPlayer())
  8206. ((Player*)spawn)->SetCharSheetChanged(true);
  8207. }
  8208. return 0;
  8209. }
  8210. int EQ2Emu_lua_BlurVision(lua_State* state) {
  8211. if (!lua_interface)
  8212. return 0;
  8213. Spawn* spawn = lua_interface->GetSpawn(state);
  8214. float intensity = lua_interface->GetFloatValue(state, 2);
  8215. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8216. lua_interface->ResetFunctionStack(state);
  8217. if (!spawn) {
  8218. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8219. return 0;
  8220. }
  8221. if (!spawn->IsEntity()) {
  8222. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8223. return 0;
  8224. }
  8225. if (spell && spell->targets.size() > 0) {
  8226. ZoneServer* zone = spell->caster->GetZone();
  8227. for (int8 i = 0; i < spell->targets.size(); i++) {
  8228. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8229. if (target && target->IsEntity()) {
  8230. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  8231. if (target->IsPlayer())
  8232. ((Player*)target)->SetCharSheetChanged(true);
  8233. }
  8234. }
  8235. }
  8236. else {
  8237. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  8238. if (spawn->IsPlayer())
  8239. ((Player*)spawn)->SetCharSheetChanged(true);
  8240. }
  8241. return 0;
  8242. }
  8243. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  8244. if (!lua_interface)
  8245. return 0;
  8246. Spawn* spawn = lua_interface->GetSpawn(state);
  8247. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  8248. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8249. lua_interface->ResetFunctionStack(state);
  8250. if (!spawn) {
  8251. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  8252. return 0;
  8253. }
  8254. if (!spawn->IsEntity()) {
  8255. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  8256. return 0;
  8257. }
  8258. if (spell && spell->targets.size() > 0) {
  8259. ZoneServer* zone = spell->caster->GetZone();
  8260. for (int8 i = 0; i < spell->targets.size(); i++) {
  8261. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8262. if (target && target->IsEntity()) {
  8263. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8264. if (target->IsPlayer())
  8265. ((Player*)target)->SetCharSheetChanged(true);
  8266. }
  8267. }
  8268. }
  8269. else {
  8270. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8271. if (spawn->IsPlayer())
  8272. ((Player*)spawn)->SetCharSheetChanged(true);
  8273. }
  8274. return 0;
  8275. }
  8276. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  8277. if (!lua_interface)
  8278. return 0;
  8279. Item* item = lua_interface->GetItem(state);
  8280. int8 type = lua_interface->GetInt32Value(state, 2);
  8281. lua_interface->ResetFunctionStack(state);
  8282. if (!item) {
  8283. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  8284. return 0;
  8285. }
  8286. if (type == 1)
  8287. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  8288. else if (type == 2)
  8289. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  8290. return 1;
  8291. }
  8292. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  8293. if (!lua_interface)
  8294. return 0;
  8295. Spawn* target = lua_interface->GetSpawn(state);
  8296. float val = lua_interface->GetFloatValue(state, 2);
  8297. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8298. lua_interface->ResetFunctionStack(state);
  8299. // Added from Gangrenous post
  8300. if (spell && spell->resisted)
  8301. return 0;
  8302. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  8303. if (val > 1.0f)
  8304. val = 1.0f - (val / 100.0f);
  8305. if (spell && spell->spell && spell->targets.size() > 0) {
  8306. ZoneServer* zone = spell->caster->GetZone();
  8307. for (int32 i = 0; i != spell->targets.size(); i++) {
  8308. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  8309. if (spawn && spawn->IsEntity()) {
  8310. ((Entity*)spawn)->SetSpeedMultiplier(val);
  8311. if (spawn->IsPlayer())
  8312. ((Player*)spawn)->SetCharSheetChanged(true);
  8313. }
  8314. }
  8315. }
  8316. else {
  8317. if (target && target->IsEntity()) {
  8318. ((Entity*)target)->SetSpeedMultiplier(val);
  8319. if (target->IsPlayer())
  8320. ((Player*)target)->SetCharSheetChanged(true);
  8321. }
  8322. }
  8323. return 0;
  8324. }
  8325. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  8326. if (!lua_interface)
  8327. return 0;
  8328. Spawn* spawn = lua_interface->GetSpawn(state);
  8329. int16 model = lua_interface->GetInt16Value(state, 2);
  8330. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8331. lua_interface->ResetFunctionStack(state);
  8332. if (spell && spell->spell && spell->targets.size() > 0) {
  8333. ZoneServer* zone = spell->caster->GetZone();
  8334. for (int32 i = 0; i < spell->targets.size(); i++) {
  8335. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8336. if (target)
  8337. target->SetIllusionModel(model);
  8338. }
  8339. }
  8340. else {
  8341. if (!spawn) {
  8342. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8343. return 0;
  8344. }
  8345. spawn->SetIllusionModel(model);
  8346. }
  8347. return 0;
  8348. }
  8349. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  8350. if (!lua_interface)
  8351. return 0;
  8352. Spawn* spawn = lua_interface->GetSpawn(state);
  8353. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8354. lua_interface->ResetFunctionStack(state);
  8355. if (spell && spell->spell && spell->targets.size() > 0) {
  8356. ZoneServer* zone = spell->caster->GetZone();
  8357. for (int32 i = 0; i < spell->targets.size(); i++) {
  8358. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8359. if (target)
  8360. target->SetIllusionModel(0);
  8361. }
  8362. }
  8363. else {
  8364. if (!spawn) {
  8365. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8366. return 0;
  8367. }
  8368. spawn->SetIllusionModel(0);
  8369. }
  8370. return 0;
  8371. }
  8372. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  8373. if (!lua_interface)
  8374. return 0;
  8375. Spawn* caster = lua_interface->GetSpawn(state);
  8376. Spawn* target = lua_interface->GetSpawn(state, 2);
  8377. float chance = lua_interface->GetFloatValue(state, 3);
  8378. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8379. lua_interface->ResetFunctionStack(state);
  8380. if (!caster) {
  8381. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8382. return 0;
  8383. }
  8384. if (!caster->IsEntity()) {
  8385. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  8386. return 0;
  8387. }
  8388. if (!target) {
  8389. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8390. return 0;
  8391. }
  8392. if (!target->IsEntity()) {
  8393. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  8394. return 0;
  8395. }
  8396. if (chance <= 0) {
  8397. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  8398. return 0;
  8399. }
  8400. if (!spell) {
  8401. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8402. return 0;
  8403. }
  8404. if(spell->resisted) {
  8405. return 0;
  8406. }
  8407. if (((Entity*)caster)->GetThreatTransfer()) {
  8408. return 0;
  8409. }
  8410. ThreatTransfer* transfer = new ThreatTransfer;
  8411. transfer->Target = target->GetID();
  8412. transfer->Amount = chance;
  8413. transfer->Spell = spell;
  8414. ((Entity*)caster)->SetThreatTransfer(transfer);
  8415. return 0;
  8416. }
  8417. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  8418. if (!lua_interface)
  8419. return 0;
  8420. Spawn* spawn = lua_interface->GetSpawn(state);
  8421. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8422. lua_interface->ResetFunctionStack(state);
  8423. if (!spawn) {
  8424. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  8425. return 0;
  8426. }
  8427. if (!spell) {
  8428. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8429. return 0;
  8430. }
  8431. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  8432. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  8433. if(transfer && transfer->Spell != spell) {
  8434. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  8435. return 0;
  8436. }
  8437. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  8438. }
  8439. return 0;
  8440. }
  8441. int EQ2Emu_lua_CureByType(lua_State* state) {
  8442. if (!lua_interface)
  8443. return 0;
  8444. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8445. int8 cure_count = lua_interface->GetInt8Value(state);
  8446. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8447. string cure_name = lua_interface->GetStringValue(state, 3);
  8448. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8449. Spawn* target = lua_interface->GetSpawn(state, 5);
  8450. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  8451. lua_interface->ResetFunctionStack(state);
  8452. if(spell && spell->resisted) {
  8453. return 0;
  8454. }
  8455. if (target) {
  8456. if (!target->IsEntity()) {
  8457. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8458. return 0;
  8459. }
  8460. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8461. std::string alternate_name = "item";
  8462. if(spell)
  8463. alternate_name = std::string(spell->spell->GetName());
  8464. if(!caster && spell)
  8465. caster = (Spawn*)spell->caster;
  8466. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  8467. }
  8468. }
  8469. else {
  8470. ZoneServer* zone = spell->caster->GetZone();
  8471. vector<int32> targets = spell->targets;
  8472. vector<Entity*> targets_to_cure;
  8473. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8474. for (int8 i = 0; i < targets.size(); i++) {
  8475. target = zone->GetSpawnByID(targets.at(i));
  8476. if (!target || !target->IsEntity())
  8477. continue;
  8478. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8479. targets_to_cure.push_back((Entity*)target);
  8480. }
  8481. }
  8482. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8483. vector<Entity*>::iterator itr;
  8484. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  8485. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8486. }
  8487. }
  8488. return 0;
  8489. }
  8490. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  8491. if (!lua_interface)
  8492. return 0;
  8493. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8494. if (!spell) {
  8495. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8496. lua_interface->ResetFunctionStack(state);
  8497. return 0;
  8498. }
  8499. if(spell->resisted) {
  8500. lua_interface->ResetFunctionStack(state);
  8501. return 0;
  8502. }
  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. lua_interface->ResetFunctionStack(state);
  8509. if (target) {
  8510. if (!target->IsEntity()) {
  8511. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8512. return 0;
  8513. }
  8514. if (((Entity*)target)->GetDetCount() > 0)
  8515. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8516. }
  8517. else {
  8518. ZoneServer* zone = spell->caster->GetZone();
  8519. vector<int32> targets = spell->targets;
  8520. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8521. for (int8 i = 0; i < targets.size(); i++) {
  8522. target = zone->GetSpawnByID(targets.at(i));
  8523. if (!target || !target->IsEntity())
  8524. continue;
  8525. if (((Entity*)target)->GetDetCount() > 0)
  8526. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8527. }
  8528. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8529. }
  8530. return 0;
  8531. }
  8532. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8533. if (!lua_interface)
  8534. return 0;
  8535. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8536. lua_interface->ResetFunctionStack(state);
  8537. if (!spell) {
  8538. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8539. return 0;
  8540. }
  8541. if (!spell->caster) {
  8542. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8543. return 0;
  8544. }
  8545. if (!spell->caster->GetZone()) {
  8546. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8547. return 0;
  8548. }
  8549. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8550. return 0;
  8551. }
  8552. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8553. if (!lua_interface)
  8554. return 0;
  8555. Spawn* spawn = lua_interface->GetSpawn(state);
  8556. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8557. lua_interface->ResetFunctionStack(state);
  8558. if (!spell) {
  8559. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8560. return 0;
  8561. }
  8562. if (spawn && spawn->IsEntity())
  8563. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8564. else {
  8565. ZoneServer* zone = spell->caster->GetZone();
  8566. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8567. for (int32 i = 0; i < spell->targets.size(); i++) {
  8568. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8569. if (!spawn || !spawn->IsEntity())
  8570. continue;
  8571. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8572. }
  8573. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8574. }
  8575. return 0;
  8576. }
  8577. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8578. if (!lua_interface)
  8579. return 0;
  8580. Spawn* spawn = lua_interface->GetSpawn(state);
  8581. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8582. lua_interface->ResetFunctionStack(state);
  8583. if (!spell) {
  8584. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8585. return 0;
  8586. }
  8587. if (spawn && spawn->IsEntity())
  8588. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8589. else {
  8590. ZoneServer* zone = spell->caster->GetZone();
  8591. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8592. for (int32 i = 0; i < spell->targets.size(); i++) {
  8593. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8594. if (!spawn || !spawn->IsEntity())
  8595. continue;
  8596. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8597. }
  8598. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8599. }
  8600. return 0;
  8601. }
  8602. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8603. if (!lua_interface)
  8604. return 0;
  8605. Spawn* caster = lua_interface->GetSpawn(state);
  8606. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8607. lua_interface->ResetFunctionStack(state);
  8608. if (!caster) {
  8609. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8610. return 0;
  8611. }
  8612. if (!caster->IsPlayer()) {
  8613. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8614. return 0;
  8615. }
  8616. Spawn* target = caster->GetTarget();
  8617. if (!target) {
  8618. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8619. return 0;
  8620. }
  8621. Client* client = ((Player*)caster)->GetClient();
  8622. if (!client) {
  8623. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8624. return 0;
  8625. }
  8626. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8627. if (ho) {
  8628. ho->SetTarget(target->GetID());
  8629. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8630. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8631. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8632. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8633. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8634. deque<GroupMemberInfo*>::iterator itr;
  8635. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8636. if (group)
  8637. {
  8638. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8639. deque<GroupMemberInfo*>* members = group->GetMembers();
  8640. for (itr = members->begin(); itr != members->end(); itr++) {
  8641. if ((*itr)->client)
  8642. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8643. }
  8644. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8645. }
  8646. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8647. }
  8648. else
  8649. safe_delete(ho);
  8650. }
  8651. else {
  8652. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8653. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8654. }
  8655. else
  8656. safe_delete(ho);
  8657. }
  8658. }
  8659. return 0;
  8660. }
  8661. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8662. if (!lua_interface)
  8663. return 0;
  8664. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8665. if (!spell) {
  8666. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8667. return 0;
  8668. }
  8669. int16 triggerCount = lua_interface->GetInt16Value(state);
  8670. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8671. if (!triggerCount) {
  8672. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8673. return 0;
  8674. }
  8675. spell->num_triggers = triggerCount;
  8676. spell->had_triggers = true;
  8677. spell->cancel_after_all_triggers = cancel_after_triggers;
  8678. return 0;
  8679. }
  8680. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8681. if (!lua_interface)
  8682. return 0;
  8683. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8684. lua_interface->ResetFunctionStack(state);
  8685. if (!spell) {
  8686. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8687. return 0;
  8688. }
  8689. lua_interface->SetInt32Value(state, spell->num_triggers);
  8690. return 1;
  8691. }
  8692. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8693. if (!lua_interface)
  8694. return 0;
  8695. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8696. if (!spell) {
  8697. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8698. lua_interface->ResetFunctionStack(state);
  8699. return 0;
  8700. }
  8701. if (!spell->caster || !spell->caster->GetZone()) {
  8702. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: caster / caster zone must be set!", lua_interface->GetScriptName(state));
  8703. lua_interface->ResetFunctionStack(state);
  8704. return 0;
  8705. }
  8706. int16 remove_count = lua_interface->GetInt16Value(state);
  8707. lua_interface->ResetFunctionStack(state);
  8708. if (!remove_count)
  8709. remove_count = 1;
  8710. if (remove_count >= spell->num_triggers) {
  8711. spell->num_triggers = 0;
  8712. if (spell->cancel_after_all_triggers)
  8713. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8714. }
  8715. else {
  8716. spell->num_triggers -= remove_count;
  8717. Client* client = spell->caster->IsPlayer() ? ((Player*)spell->caster)->GetClient() : nullptr;
  8718. ClientPacketFunctions::SendMaintainedExamineUpdate(client, spell->slot_pos, spell->num_triggers, 0);
  8719. }
  8720. return 0;
  8721. }
  8722. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8723. if (!lua_interface)
  8724. return 0;
  8725. Spawn* spawn = lua_interface->GetSpawn(state);
  8726. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8727. lua_interface->ResetFunctionStack(state);
  8728. if (!spawn) {
  8729. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8730. return 0;
  8731. }
  8732. if (!copy_spawn) {
  8733. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8734. return 0;
  8735. }
  8736. spawn->CopySpawnAppearance(copy_spawn);
  8737. return 0;
  8738. }
  8739. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8740. Spawn* spawn = lua_interface->GetSpawn(state);
  8741. int8 type = lua_interface->GetInt8Value(state, 2);
  8742. lua_interface->ResetFunctionStack(state);
  8743. if (!spawn) {
  8744. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8745. return 0;
  8746. }
  8747. else if (!spawn->IsEntity()) {
  8748. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8749. return 0;
  8750. }
  8751. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8752. return 1;
  8753. }
  8754. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8755. if (!lua_interface)
  8756. return 0;
  8757. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8758. int8 type = lua_interface->GetInt8Value(state);
  8759. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8760. lua_interface->ResetFunctionStack(state);
  8761. if (!spell) {
  8762. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8763. return 0;
  8764. }
  8765. if(spell->resisted) {
  8766. return 0;
  8767. }
  8768. if (spawn) {
  8769. if (!spawn->IsEntity()) {
  8770. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8771. return 0;
  8772. }
  8773. Entity* entity = ((Entity*)spawn);
  8774. entity->AddImmunity(spell, type);
  8775. }
  8776. else if(spell->caster && spell->caster->GetZone()) {
  8777. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8778. for (int8 i = 0; i < spell->targets.size(); i++) {
  8779. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8780. if (!spawn || !spawn->IsEntity())
  8781. continue;
  8782. Entity* entity = ((Entity*)spawn);
  8783. entity->AddImmunity(spell, type);
  8784. }
  8785. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8786. }
  8787. return 0;
  8788. }
  8789. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8790. if (!lua_interface)
  8791. return 0;
  8792. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8793. int8 type = lua_interface->GetInt8Value(state);
  8794. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8795. lua_interface->ResetFunctionStack(state);
  8796. if (!spell) {
  8797. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8798. return 0;
  8799. }
  8800. if (spawn) {
  8801. if (!spawn->IsEntity()) {
  8802. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8803. return 0;
  8804. }
  8805. Entity* entity = ((Entity*)spawn);
  8806. entity->RemoveImmunity(spell, type);
  8807. }
  8808. else if(spell->caster && spell->caster->GetZone()) {
  8809. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8810. for (int8 i = 0; i < spell->targets.size(); i++) {
  8811. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8812. if (!spawn || !spawn->IsEntity())
  8813. continue;
  8814. Entity* entity = ((Entity*)spawn);
  8815. entity->RemoveImmunity(spell, type);
  8816. }
  8817. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8818. }
  8819. return 0;
  8820. }
  8821. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8822. if (!lua_interface)
  8823. return 0;
  8824. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8825. if (!spell) {
  8826. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8827. lua_interface->ResetFunctionStack(state);
  8828. return 0;
  8829. }
  8830. if(spell->resisted) {
  8831. lua_interface->ResetFunctionStack(state);
  8832. return 0;
  8833. }
  8834. float snare = lua_interface->GetFloatValue(state);
  8835. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8836. lua_interface->ResetFunctionStack(state);
  8837. // convert the val to the speed multipler value (100 - val)
  8838. float val = 100.0 - snare;
  8839. val /= 100.0;
  8840. if (spawn) {
  8841. if (!spawn->IsEntity()) {
  8842. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8843. return 0;
  8844. }
  8845. ((Entity*)spawn)->SetSnareValue(spell, val);
  8846. }
  8847. else if(spell->caster && spell->caster->GetZone()) {
  8848. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8849. for (int8 i = 0; i < spell->targets.size(); i++) {
  8850. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8851. if (!spawn || !spawn->IsEntity())
  8852. continue;
  8853. ((Entity*)spawn)->SetSnareValue(spell, val);
  8854. }
  8855. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8856. }
  8857. return 0;
  8858. }
  8859. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8860. if (!lua_interface)
  8861. return 0;
  8862. Spawn* spawn = lua_interface->GetSpawn(state);
  8863. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8864. lua_interface->ResetFunctionStack(state);
  8865. if (!spawn) {
  8866. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8867. return 0;
  8868. }
  8869. if (race_id == 0) {
  8870. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8871. return 0;
  8872. }
  8873. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8874. return 1;
  8875. }
  8876. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8877. if (!lua_interface)
  8878. return 0;
  8879. Spawn* spawn = lua_interface->GetSpawn(state);
  8880. lua_interface->ResetFunctionStack(state);
  8881. if (!spawn) {
  8882. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8883. return 0;
  8884. }
  8885. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8886. return 1;
  8887. }
  8888. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8889. if (!lua_interface)
  8890. return 0;
  8891. Spawn* spawn = lua_interface->GetSpawn(state);
  8892. lua_interface->ResetFunctionStack(state);
  8893. if (!spawn) {
  8894. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8895. return 0;
  8896. }
  8897. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8898. return 1;
  8899. }
  8900. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8901. if (!lua_interface)
  8902. return 0;
  8903. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8904. lua_interface->ResetFunctionStack(state);
  8905. if (!spell) {
  8906. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8907. return 0;
  8908. }
  8909. lua_interface->SetStringValue(state, spell->spell->GetName());
  8910. return 1;
  8911. }
  8912. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8913. if (!lua_interface)
  8914. return 0;
  8915. Quest* quest = lua_interface->GetQuest(state);
  8916. lua_interface->ResetFunctionStack(state);
  8917. if (!quest) {
  8918. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8919. return 0;
  8920. }
  8921. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8922. return 1;
  8923. }
  8924. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8925. if (!lua_interface)
  8926. return 0;
  8927. Quest* quest = lua_interface->GetQuest(state);
  8928. int32 flags = lua_interface->GetInt32Value(state, 2);
  8929. lua_interface->ResetFunctionStack(state);
  8930. if (!quest) {
  8931. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8932. return 0;
  8933. }
  8934. quest->SetQuestFlags(flags);
  8935. return 0;
  8936. }
  8937. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8938. if (!lua_interface)
  8939. return 0;
  8940. Quest* quest = lua_interface->GetQuest(state);
  8941. Spawn* player = lua_interface->GetSpawn(state, 2);
  8942. int32 step = lua_interface->GetInt32Value(state, 3);
  8943. int32 duration = lua_interface->GetInt32Value(state, 4);
  8944. string action = lua_interface->GetStringValue(state, 5);
  8945. lua_interface->ResetFunctionStack(state);
  8946. if (!quest) {
  8947. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8948. return 0;
  8949. }
  8950. if (!player) {
  8951. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8952. return 0;
  8953. }
  8954. if (!player->IsPlayer()) {
  8955. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8956. return 0;
  8957. }
  8958. if (step == 0) {
  8959. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8960. return 0;
  8961. }
  8962. if (duration == 0) {
  8963. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8964. return 0;
  8965. }
  8966. if (action.length() == 0) {
  8967. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8968. return 0;
  8969. }
  8970. Client* client = ((Player*)player)->GetClient();
  8971. if (!client) {
  8972. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8973. return 0;
  8974. }
  8975. quest->SetTimerStep(step);
  8976. quest->AddFailedAction(step, action);
  8977. quest->SetStepTimer(duration);
  8978. client->AddQuestTimer(quest->GetQuestID());
  8979. return 0;
  8980. }
  8981. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8982. if (!lua_interface)
  8983. return 0;
  8984. Quest* quest = lua_interface->GetQuest(state);
  8985. Spawn* player = lua_interface->GetSpawn(state, 2);
  8986. lua_interface->ResetFunctionStack(state);
  8987. if (!quest) {
  8988. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8989. return 0;
  8990. }
  8991. if (!player) {
  8992. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8993. return 0;
  8994. }
  8995. if (!player->IsPlayer()) {
  8996. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8997. return 0;
  8998. }
  8999. Client* client = ((Player*)player)->GetClient();
  9000. if (!client) {
  9001. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  9002. return 0;
  9003. }
  9004. quest->SetTimerStep(0);
  9005. quest->SetStepTimer(0);
  9006. client->RemoveQuestTimer(quest->GetQuestID());
  9007. return 0;
  9008. }
  9009. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  9010. if (!lua_interface)
  9011. return 0;
  9012. Spawn* player = lua_interface->GetSpawn(state);
  9013. Quest* quest = lua_interface->GetQuest(state, 2);
  9014. int32 step = lua_interface->GetInt32Value(state, 3);
  9015. lua_interface->ResetFunctionStack(state);
  9016. if (!player) {
  9017. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  9018. return 0;
  9019. }
  9020. if (!player->IsPlayer()) {
  9021. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9022. return 0;
  9023. }
  9024. if (!quest) {
  9025. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  9026. return 0;
  9027. }
  9028. if (step == 0) {
  9029. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  9030. return 0;
  9031. }
  9032. Client* client = ((Player*)player)->GetClient();
  9033. if (!client) {
  9034. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  9035. return 0;
  9036. }
  9037. if (quest->RemoveQuestStep(step, client)) {
  9038. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  9039. client->GetCurrentZone()->SendQuestUpdates(client);
  9040. }
  9041. else
  9042. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  9043. return 0;
  9044. }
  9045. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  9046. if (!lua_interface)
  9047. return 0;
  9048. Quest* quest = lua_interface->GetQuest(state, 1);
  9049. int32 step = lua_interface->GetInt32Value(state, 2);
  9050. string desc = lua_interface->GetStringValue(state, 3);
  9051. string task_group = lua_interface->GetStringValue(state, 4);
  9052. lua_interface->ResetFunctionStack(state);
  9053. if (!quest) {
  9054. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  9055. return 0;
  9056. }
  9057. if (step == 0) {
  9058. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  9059. return 0;
  9060. }
  9061. QuestStep* quest_step = quest->GetQuestStep(step);
  9062. if (!quest_step) {
  9063. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  9064. return 0;
  9065. }
  9066. quest_step->SetStepProgress(0);
  9067. quest_step->SetTaskGroup(task_group);
  9068. quest_step->SetDescription(desc);
  9069. return 0;
  9070. }
  9071. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  9072. if (!lua_interface)
  9073. return 0;
  9074. Quest* quest = lua_interface->GetQuest(state);
  9075. int32 step = lua_interface->GetInt32Value(state, 2);
  9076. string action = lua_interface->GetStringValue(state, 3);
  9077. lua_interface->ResetFunctionStack(state);
  9078. if (!quest) {
  9079. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  9080. return 0;
  9081. }
  9082. if (step == 0) {
  9083. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  9084. return 0;
  9085. }
  9086. if (action.length() == 0) {
  9087. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  9088. return 0;
  9089. }
  9090. quest->AddFailedAction(step, action);
  9091. return 0;
  9092. }
  9093. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  9094. if (!lua_interface)
  9095. return 0;
  9096. Spawn* player = lua_interface->GetSpawn(state);
  9097. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9098. int32 step = lua_interface->GetInt32Value(state, 3);
  9099. lua_interface->ResetFunctionStack(state);
  9100. if (!player) {
  9101. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  9102. return 0;
  9103. }
  9104. if (!player->IsPlayer()) {
  9105. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9106. return 0;
  9107. }
  9108. if (quest_id == 0) {
  9109. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  9110. return 0;
  9111. }
  9112. if (step == 0) {
  9113. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  9114. return 0;
  9115. }
  9116. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  9117. if (!quest) {
  9118. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  9119. return 0;
  9120. }
  9121. quest->StepFailed(step);
  9122. return 0;
  9123. }
  9124. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  9125. if (!lua_interface)
  9126. return 0;
  9127. Spawn* player = lua_interface->GetSpawn(state);
  9128. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9129. lua_interface->ResetFunctionStack(state);
  9130. if (!player) {
  9131. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  9132. return 0;
  9133. }
  9134. if (!player->IsPlayer()) {
  9135. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  9136. return 0;
  9137. }
  9138. if (quest_id == 0) {
  9139. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  9140. return 0;
  9141. }
  9142. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestCompletedCount(quest_id));
  9143. return 1;
  9144. }
  9145. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  9146. if (!lua_interface)
  9147. return 0;
  9148. string name = lua_interface->GetStringValue(state);
  9149. string value = lua_interface->GetStringValue(state, 2);
  9150. string comment = lua_interface->GetStringValue(state, 3);
  9151. lua_interface->ResetFunctionStack(state);
  9152. if (name.length() == 0) {
  9153. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  9154. return 0;
  9155. }
  9156. if (value.length() == 0) {
  9157. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  9158. return 0;
  9159. }
  9160. string varname = string("lua_").append(name);
  9161. Variable* var = variables.FindVariable(varname);
  9162. if (var)
  9163. var->SetValue(value.c_str());
  9164. else {
  9165. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  9166. variables.AddVariable(var);
  9167. }
  9168. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  9169. return 0;
  9170. }
  9171. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  9172. if (!lua_interface)
  9173. return 0;
  9174. string name = lua_interface->GetStringValue(state);
  9175. lua_interface->ResetFunctionStack(state);
  9176. if (name.length() == 0) {
  9177. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  9178. return 0;
  9179. }
  9180. string varname = string("lua_").append(name);
  9181. Variable* var = variables.FindVariable(varname);
  9182. if (var)
  9183. lua_interface->SetStringValue(state, var->GetValue());
  9184. else
  9185. lua_interface->SetStringValue(state, "NULL");
  9186. return 1;
  9187. }
  9188. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  9189. if (!lua_interface)
  9190. return 0;
  9191. Spawn* player = lua_interface->GetSpawn(state);
  9192. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9193. lua_interface->ResetFunctionStack(state);
  9194. if (!player) {
  9195. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9196. return 0;
  9197. }
  9198. if (!player->IsPlayer()) {
  9199. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9200. return 0;
  9201. }
  9202. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  9203. return 1;
  9204. }
  9205. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  9206. if (!lua_interface)
  9207. return 0;
  9208. Spawn* player = lua_interface->GetSpawn(state);
  9209. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9210. lua_interface->ResetFunctionStack(state);
  9211. if (!player) {
  9212. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9213. return 0;
  9214. }
  9215. if (!player->IsPlayer()) {
  9216. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9217. return 0;
  9218. }
  9219. Language* language = master_languages_list.GetLanguage(language_id);
  9220. if (language)
  9221. {
  9222. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  9223. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID(), 0);
  9224. }
  9225. return 0;
  9226. }
  9227. int EQ2Emu_lua_IsNight(lua_State* state) {
  9228. if (!lua_interface)
  9229. return 0;
  9230. ZoneServer* zone = lua_interface->GetZone(state);
  9231. lua_interface->ResetFunctionStack(state);
  9232. if (!zone) {
  9233. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  9234. return 0;
  9235. }
  9236. lua_interface->SetBooleanValue(state, zone->IsDusk());
  9237. return 1;
  9238. }
  9239. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  9240. if (!lua_interface)
  9241. return 0;
  9242. Spawn* spawn = lua_interface->GetSpawn(state);
  9243. lua_interface->ResetFunctionStack(state);
  9244. if (!spawn) {
  9245. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  9246. return 0;
  9247. }
  9248. if (!spawn->IsWidget()) {
  9249. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  9250. return 0;
  9251. }
  9252. ((Widget*)spawn)->SetMultiFloorLift(true);
  9253. if (spawn->GetZone())
  9254. spawn->GetZone()->AddTransportSpawn(spawn);
  9255. return 0;
  9256. }
  9257. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  9258. if (!lua_interface)
  9259. return 0;
  9260. Spawn* player = lua_interface->GetSpawn(state);
  9261. int32 path = lua_interface->GetInt32Value(state, 2);
  9262. lua_interface->ResetFunctionStack(state);
  9263. if (!player) {
  9264. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9265. return 0;
  9266. }
  9267. if (!player->IsPlayer()) {
  9268. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9269. return 0;
  9270. }
  9271. if (path == 0) {
  9272. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  9273. return 0;
  9274. }
  9275. Client* client = ((Player*)player)->GetClient();
  9276. if (!client) {
  9277. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9278. return 0;
  9279. }
  9280. client->SendFlightAutoMount(path);
  9281. return 0;
  9282. }
  9283. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  9284. if (!lua_interface)
  9285. return 0;
  9286. Spawn* player = lua_interface->GetSpawn(state);
  9287. if (!player) {
  9288. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9289. return 0;
  9290. }
  9291. if (!player->IsPlayer()) {
  9292. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9293. return 0;
  9294. }
  9295. Client* client = ((Player*)player)->GetClient();
  9296. if (!client) {
  9297. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9298. return 0;
  9299. }
  9300. client->EndAutoMount();
  9301. return 0;
  9302. }
  9303. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  9304. if (!lua_interface)
  9305. return 0;
  9306. Spawn* player = lua_interface->GetSpawn(state);
  9307. lua_interface->ResetFunctionStack(state);
  9308. if (!player) {
  9309. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  9310. return 0;
  9311. }
  9312. if (!player->IsPlayer()) {
  9313. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9314. return 0;
  9315. }
  9316. Client* client = ((Player*)player)->GetClient();
  9317. if (!client) {
  9318. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9319. return 0;
  9320. }
  9321. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  9322. return 1;
  9323. }
  9324. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  9325. if (!lua_interface)
  9326. return 0;
  9327. Spawn* player = lua_interface->GetSpawn(state);
  9328. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9329. int32 value = lua_interface->GetInt32Value(state, 3);
  9330. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9331. lua_interface->ResetFunctionStack(state);
  9332. if (!player) {
  9333. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9334. return 0;
  9335. }
  9336. if (!player->IsPlayer()) {
  9337. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9338. return 0;
  9339. }
  9340. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  9341. return 0;
  9342. }
  9343. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  9344. if (!lua_interface)
  9345. return 0;
  9346. Spawn* player = lua_interface->GetSpawn(state);
  9347. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9348. lua_interface->ResetFunctionStack(state);
  9349. if (!player) {
  9350. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9351. return 0;
  9352. }
  9353. if (!player->IsPlayer()) {
  9354. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9355. return 0;
  9356. }
  9357. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  9358. if (!hd)
  9359. return 0;
  9360. lua_interface->SetInt32Value(state, hd->Value);
  9361. lua_interface->SetInt32Value(state, hd->Value2);
  9362. return 2;
  9363. }
  9364. int EQ2Emu_lua_SetGridID(lua_State* state) {
  9365. if (!lua_interface)
  9366. return 0;
  9367. Spawn* spawn = lua_interface->GetSpawn(state);
  9368. int32 grid = lua_interface->GetInt32Value(state, 2);
  9369. lua_interface->ResetFunctionStack(state);
  9370. if (!spawn) {
  9371. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9372. return 0;
  9373. }
  9374. if (grid == 0) {
  9375. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  9376. return 0;
  9377. }
  9378. spawn->SetLocation(grid);
  9379. return 0;
  9380. }
  9381. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  9382. if (!lua_interface)
  9383. return 0;
  9384. Spawn* spawn = lua_interface->GetSpawn(state);
  9385. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9386. int32 value1 = lua_interface->GetInt32Value(state, 3);
  9387. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9388. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  9389. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  9390. lua_interface->ResetFunctionStack(state);
  9391. if (!spawn) {
  9392. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9393. return 0;
  9394. }
  9395. //Add this quest to the list of required quests for this spawn
  9396. spawn->SetRequiredHistory(event_id, value1, value2);
  9397. //If private spawn value set
  9398. if (private_spawn) {
  9399. //Set the spawn to be private when not granted access via history
  9400. spawn->AddAllowAccessSpawn(spawn);
  9401. spawn->SetPrivateQuestSpawn(true);
  9402. }
  9403. //This value will override vis_flags in the vis packet
  9404. if (flag_override > 0)
  9405. spawn->SetQuestsRequiredOverride(flag_override);
  9406. return 0;
  9407. }
  9408. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  9409. if (!lua_interface)
  9410. return 0;
  9411. Spawn* player = lua_interface->GetSpawn(state);
  9412. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9413. int32 step_id = lua_interface->GetInt32Value(state, 3);
  9414. lua_interface->ResetFunctionStack(state);
  9415. if (!player) {
  9416. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  9417. return 0;
  9418. }
  9419. if (!player->IsPlayer()) {
  9420. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  9421. return 0;
  9422. }
  9423. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  9424. return 1;
  9425. }
  9426. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  9427. if (!lua_interface)
  9428. return 0;
  9429. Spawn* player = lua_interface->GetSpawn(state);
  9430. int8 level = lua_interface->GetInt8Value(state, 2);
  9431. lua_interface->ResetFunctionStack(state);
  9432. if (!player) {
  9433. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  9434. return 0;
  9435. }
  9436. if (!player->IsPlayer()) {
  9437. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  9438. return 0;
  9439. }
  9440. if (level == 0) {
  9441. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  9442. return 0;
  9443. }
  9444. Client* client = ((Player*)player)->GetClient();
  9445. if (!client) {
  9446. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  9447. return 0;
  9448. }
  9449. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  9450. return 0;
  9451. }
  9452. int EQ2Emu_lua_AddCoin(lua_State* state) {
  9453. if (!lua_interface)
  9454. return 0;
  9455. Spawn* player = lua_interface->GetSpawn(state);
  9456. int32 amount = lua_interface->GetInt32Value(state, 2);
  9457. lua_interface->ResetFunctionStack(state);
  9458. if (!player) {
  9459. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9460. return 0;
  9461. }
  9462. if (!player->IsPlayer()) {
  9463. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9464. return 0;
  9465. }
  9466. if (amount == 0) {
  9467. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9468. return 0;
  9469. }
  9470. ((Player*)player)->AddCoins(amount);
  9471. return 0;
  9472. }
  9473. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  9474. if (!lua_interface)
  9475. return 0;
  9476. Spawn* player = lua_interface->GetSpawn(state);
  9477. int32 amount = lua_interface->GetInt32Value(state, 2);
  9478. lua_interface->ResetFunctionStack(state);
  9479. if (!player) {
  9480. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9481. return 0;
  9482. }
  9483. if (!player->IsPlayer()) {
  9484. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9485. return 0;
  9486. }
  9487. if (amount == 0) {
  9488. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9489. return 0;
  9490. }
  9491. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  9492. return 1;
  9493. }
  9494. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  9495. if (!lua_interface)
  9496. return 0;
  9497. ZoneServer* zone = lua_interface->GetZone(state);
  9498. lua_interface->ResetFunctionStack(state);
  9499. if (!zone) {
  9500. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9501. return 0;
  9502. }
  9503. vector<Entity*> players = zone->GetPlayers();
  9504. if (players.size() == 0)
  9505. return 0;
  9506. lua_createtable(state, players.size(), 0);
  9507. int newTable = lua_gettop(state);
  9508. for (int32 i = 0; i < players.size(); i++) {
  9509. lua_interface->SetSpawnValue(state, players.at(i));
  9510. lua_rawseti(state, newTable, i + 1);
  9511. }
  9512. return 1;
  9513. }
  9514. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  9515. if (!lua_interface)
  9516. return 0;
  9517. ZoneServer* zone = lua_interface->GetZone(state, 1);
  9518. if (!zone) {
  9519. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9520. return 0;
  9521. }
  9522. int32 group_id = lua_interface->GetInt32Value(state, 2);
  9523. int16 custom_level = lua_interface->GetInt32Value(state, 3);
  9524. lua_interface->ResetFunctionStack(state);
  9525. //Map of <placement_id, location_id>
  9526. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  9527. map<int32, int32>::iterator itr;
  9528. vector<Spawn*> group;
  9529. Spawn* leader = 0;
  9530. if(locs == nullptr)
  9531. return 0;
  9532. for (itr = locs->begin(); itr != locs->end(); itr++) {
  9533. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  9534. if (!location) {
  9535. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  9536. return 0;
  9537. }
  9538. int32 rand_number = MakeRandomInt(0, location->entities.size() - 1);
  9539. Spawn* spawn = 0;
  9540. if (location->entities[rand_number]) {
  9541. if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  9542. spawn = zone->AddNPCSpawn(location, location->entities[rand_number]);
  9543. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  9544. spawn = zone->AddGroundSpawn(location, location->entities[rand_number]);
  9545. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  9546. spawn = zone->AddObjectSpawn(location, location->entities[rand_number]);
  9547. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  9548. spawn = zone->AddWidgetSpawn(location, location->entities[rand_number]);
  9549. else if (location->entities[rand_number]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9550. spawn = zone->AddSignSpawn(location, location->entities[rand_number]);
  9551. if(spawn && spawn->IsOmittedByDBFlag())
  9552. {
  9553. 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);
  9554. safe_delete(spawn);
  9555. continue;
  9556. }
  9557. if (spawn) {
  9558. if(!leader)
  9559. leader = spawn;
  9560. if(leader)
  9561. leader->AddSpawnToGroup(spawn);
  9562. spawn->SetSpawnGroupID(group_id);
  9563. if(custom_level > 0 && custom_level != 0xFFFF) {
  9564. spawn->SetLevel(custom_level);
  9565. }
  9566. const char* script = 0;
  9567. for (int x = 0; x < 3; x++) {
  9568. switch (x) {
  9569. case 0:
  9570. script = world.GetSpawnEntryScript(location->entities[rand_number]->spawn_entry_id);
  9571. break;
  9572. case 1:
  9573. script = world.GetSpawnLocationScript(location->entities[rand_number]->spawn_location_id);
  9574. break;
  9575. case 2:
  9576. script = world.GetSpawnScript(location->entities[rand_number]->spawn_id);
  9577. break;
  9578. }
  9579. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9580. spawn->SetSpawnScript(string(script));
  9581. break;
  9582. }
  9583. }
  9584. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9585. lua_interface->SetSpawnValue(state, spawn);
  9586. group.push_back(spawn);
  9587. }
  9588. else {
  9589. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  9590. safe_delete(spawn);
  9591. }
  9592. }
  9593. }
  9594. if (!group.empty()) {
  9595. lua_createtable(state, group.size(), 0);
  9596. int newTable = lua_gettop(state);
  9597. for (int32 i = 0; i < group.size(); i++) {
  9598. lua_interface->SetSpawnValue(state, group[i]);
  9599. lua_rawseti(state, newTable, i + 1);
  9600. }
  9601. }
  9602. else
  9603. lua_pushnil(state);
  9604. return 1;
  9605. }
  9606. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9607. if (!lua_interface)
  9608. return 0;
  9609. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9610. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9611. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9612. lua_interface->ResetFunctionStack(state);
  9613. if (!spawn) {
  9614. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9615. return 0;
  9616. }
  9617. if (anim_id == 0) {
  9618. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9619. return 0;
  9620. }
  9621. if (leeway == 0)
  9622. leeway = 5000;
  9623. spawn->SetSpawnAnim(anim_id);
  9624. spawn->SetSpawnAnimLeeway(leeway);
  9625. return 0;
  9626. }
  9627. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9628. if (!lua_interface)
  9629. return 0;
  9630. Spawn* player = lua_interface->GetSpawn(state);
  9631. lua_interface->ResetFunctionStack(state);
  9632. if (!player || !player->IsPlayer()) {
  9633. return 0;
  9634. }
  9635. Client* client = ((Player*)player)->GetClient();
  9636. if (!client) {
  9637. return 0;
  9638. }
  9639. lua_interface->SetInt32Value(state, client->GetVersion());
  9640. return 1;
  9641. }
  9642. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9643. if (!lua_interface)
  9644. return 0;
  9645. Item* item = lua_interface->GetItem(state);
  9646. lua_interface->ResetFunctionStack(state);
  9647. if (!item) {
  9648. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9649. return 0;
  9650. }
  9651. lua_interface->SetInt32Value(state, item->details.item_id);
  9652. return 1;
  9653. }
  9654. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9655. if (!lua_interface)
  9656. return 0;
  9657. Spawn* spawn = lua_interface->GetSpawn(state);
  9658. lua_interface->ResetFunctionStack(state);
  9659. if (!spawn) {
  9660. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9661. return 0;
  9662. }
  9663. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9664. return 1;
  9665. }
  9666. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9667. if (!lua_interface)
  9668. return 0;
  9669. Spawn* spawn = lua_interface->GetSpawn(state);
  9670. lua_interface->ResetFunctionStack(state);
  9671. if (!spawn) {
  9672. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9673. return 0;
  9674. }
  9675. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9676. return 1;
  9677. }
  9678. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9679. if (!lua_interface)
  9680. return 0;
  9681. Spawn* spawn = lua_interface->GetSpawn(state);
  9682. lua_interface->ResetFunctionStack(state);
  9683. if (!spawn) {
  9684. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9685. return 0;
  9686. }
  9687. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9688. return 1;
  9689. }
  9690. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9691. if (!lua_interface)
  9692. return 0;
  9693. Spawn* spawn = lua_interface->GetSpawn(state);
  9694. lua_interface->ResetFunctionStack(state);
  9695. if (!spawn) {
  9696. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9697. return 0;
  9698. }
  9699. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9700. return 1;
  9701. }
  9702. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9703. if (!lua_interface)
  9704. return 0;
  9705. Spawn* spawn = lua_interface->GetSpawn(state);
  9706. float pct = lua_interface->GetFloatValue(state, 2);
  9707. lua_interface->ResetFunctionStack(state);
  9708. if (!spawn) {
  9709. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9710. return 0;
  9711. }
  9712. if (pct == 0) {
  9713. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9714. return 0;
  9715. }
  9716. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9717. lua_interface->SetInt32Value(state, amount);
  9718. return 1;
  9719. }
  9720. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9721. if (!lua_interface)
  9722. return 0;
  9723. Spawn* spawn = lua_interface->GetSpawn(state);
  9724. float pct = lua_interface->GetFloatValue(state, 2);
  9725. lua_interface->ResetFunctionStack(state);
  9726. if (!spawn) {
  9727. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9728. return 0;
  9729. }
  9730. if (pct == 0) {
  9731. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9732. return 0;
  9733. }
  9734. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9735. lua_interface->SetInt32Value(state, amount);
  9736. return 1;
  9737. }
  9738. int EQ2Emu_lua_GetBoundZoneID(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 GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9745. return 0;
  9746. }
  9747. if (!spawn->IsPlayer()) {
  9748. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9749. return 0;
  9750. }
  9751. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9752. return 1;
  9753. }
  9754. int EQ2Emu_lua_Evac(lua_State* state) {
  9755. if (!lua_interface)
  9756. return 0;
  9757. Spawn* target = lua_interface->GetSpawn(state);
  9758. if (target) {
  9759. float x = target->GetZone()->GetSafeX();
  9760. float y = target->GetZone()->GetSafeY();
  9761. float z = target->GetZone()->GetSafeZ();
  9762. float h = target->GetZone()->GetSafeHeading();
  9763. target->SetX(x);
  9764. target->SetY(y);
  9765. target->SetZ(z);
  9766. target->SetHeading(h);
  9767. target->SetSpawnOrigX(x);
  9768. target->SetSpawnOrigY(y);
  9769. target->SetSpawnOrigZ(z);
  9770. target->SetSpawnOrigHeading(h);
  9771. if (target->IsPlayer()) {
  9772. Client* client = ((Player*)target)->GetClient();
  9773. if (client) {
  9774. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9775. int numargs = lua_interface->GetNumberOfArgs(state);
  9776. if(numargs == 4) {
  9777. x = lua_interface->GetFloatValue(state,1);
  9778. y = lua_interface->GetFloatValue(state,2);
  9779. z = lua_interface->GetFloatValue(state,3);
  9780. h = lua_interface->GetFloatValue(state,4);
  9781. }
  9782. client->SetReloadingZone(true);
  9783. target->SetX(x);
  9784. target->SetY(y);
  9785. target->SetZ(z);
  9786. target->SetHeading(h);
  9787. target->SetSpawnOrigX(x);
  9788. target->SetSpawnOrigY(y);
  9789. target->SetSpawnOrigZ(z);
  9790. target->SetSpawnOrigHeading(h);
  9791. target->SetAppearancePosition(x,y,z);
  9792. client->SetZoningCoords(x,y,z,h);
  9793. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9794. if (packet)
  9795. {
  9796. packet->setDataByName("x", x);
  9797. packet->setDataByName("y", y);
  9798. packet->setDataByName("z", z);
  9799. client->QueuePacket(packet->serialize());
  9800. safe_delete(packet);
  9801. }
  9802. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9803. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9804. }
  9805. }
  9806. lua_interface->ResetFunctionStack(state);
  9807. }
  9808. else {
  9809. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9810. if(!spell || !spell->caster || !spell->caster->GetZone()) {
  9811. lua_interface->ResetFunctionStack(state);
  9812. return 0;
  9813. }
  9814. ZoneServer* zone = spell->caster->GetZone();
  9815. float x = spell->caster->GetZone()->GetSafeX();
  9816. float y = spell->caster->GetZone()->GetSafeY();
  9817. float z = spell->caster->GetZone()->GetSafeZ();
  9818. float h = spell->caster->GetZone()->GetSafeHeading();
  9819. int numargs = lua_interface->GetNumberOfArgs(state);
  9820. if(numargs == 4) {
  9821. x = lua_interface->GetFloatValue(state,1);
  9822. y = lua_interface->GetFloatValue(state,2);
  9823. z = lua_interface->GetFloatValue(state,3);
  9824. h = lua_interface->GetFloatValue(state,4);
  9825. }
  9826. lua_interface->ResetFunctionStack(state);
  9827. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9828. for (int32 i = 0; i < spell->targets.size(); i++) {
  9829. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9830. if (!target2)
  9831. continue;
  9832. if (target2->IsPlayer()) {
  9833. Client* client = ((Player*)target2)->GetClient();
  9834. if (client) {
  9835. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9836. client->SetReloadingZone(true);
  9837. target2->SetX(x);
  9838. target2->SetY(y);
  9839. target2->SetZ(z);
  9840. target2->SetHeading(h);
  9841. target2->SetSpawnOrigX(x);
  9842. target2->SetSpawnOrigY(y);
  9843. target2->SetSpawnOrigZ(z);
  9844. target2->SetSpawnOrigHeading(h);
  9845. target2->SetAppearancePosition(x,y,z);
  9846. client->SetZoningCoords(x,y,z,h);
  9847. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9848. if (packet)
  9849. {
  9850. packet->setDataByName("x", x);
  9851. packet->setDataByName("y", y);
  9852. packet->setDataByName("z", z);
  9853. client->QueuePacket(packet->serialize());
  9854. safe_delete(packet);
  9855. }
  9856. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9857. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9858. }
  9859. }
  9860. }
  9861. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9862. }
  9863. return 0;
  9864. }
  9865. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9866. if (!lua_interface)
  9867. return 0;
  9868. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9869. lua_interface->ResetFunctionStack(state);
  9870. if (!luaspell || !luaspell->spell) {
  9871. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9872. return 0;
  9873. }
  9874. int8 tier = luaspell->spell->GetSpellTier();
  9875. lua_interface->SetInt32Value(state, tier);
  9876. return 1;
  9877. }
  9878. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9879. if (!lua_interface)
  9880. return 0;
  9881. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9882. lua_interface->ResetFunctionStack(state);
  9883. if (!luaspell || !luaspell->spell) {
  9884. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9885. return 0;
  9886. }
  9887. int32 spell_id = luaspell->spell->GetSpellID();
  9888. lua_interface->SetInt32Value(state, spell_id);
  9889. return 1;
  9890. }
  9891. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9892. if (!lua_interface)
  9893. return 0;
  9894. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9895. lua_interface->ResetFunctionStack(state);
  9896. if (!spawn) {
  9897. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9898. return 0;
  9899. }
  9900. if (!spawn->IsPlayer()) {
  9901. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9902. return 0;
  9903. }
  9904. ZoneServer* zone = spawn->GetZone();
  9905. if (!zone) {
  9906. return 0;
  9907. }
  9908. Client* client = ((Player*)spawn)->GetClient();
  9909. if (!client) {
  9910. return 0;
  9911. }
  9912. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9913. return 0;
  9914. }
  9915. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9916. if (!lua_interface)
  9917. return 0;
  9918. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9919. lua_interface->ResetFunctionStack(state);
  9920. if (!spawn) {
  9921. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9922. return 0;
  9923. }
  9924. if (!spawn->IsPlayer()) {
  9925. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9926. return 0;
  9927. }
  9928. ZoneServer* zone = spawn->GetZone();
  9929. if (!zone) {
  9930. return 0;
  9931. }
  9932. Client* client = ((Player*)spawn)->GetClient();
  9933. if (!client) {
  9934. return 0;
  9935. }
  9936. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9937. return 0;
  9938. }
  9939. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9940. if (!lua_interface)
  9941. return 0;
  9942. Spawn* caster = lua_interface->GetSpawn(state);
  9943. Spawn* target = lua_interface->GetSpawn(state, 2);
  9944. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9945. string spell_name = lua_interface->GetStringValue(state, 4);
  9946. lua_interface->ResetFunctionStack(state);
  9947. if (!caster) {
  9948. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9949. return 0;
  9950. }
  9951. if (!caster->IsEntity()) {
  9952. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9953. return 0;
  9954. }
  9955. if (!target) {
  9956. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9957. return 0;
  9958. }
  9959. if (!target->IsEntity()) {
  9960. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9961. return 0;
  9962. }
  9963. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9964. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9965. return 0;
  9966. }
  9967. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9968. if (!lua_interface)
  9969. return 0;
  9970. Spawn* player = lua_interface->GetSpawn(state);
  9971. int32 amount = lua_interface->GetInt32Value(state, 2);
  9972. lua_interface->ResetFunctionStack(state);
  9973. if (player && player->IsPlayer() && amount > 0) {
  9974. ((Player*)player)->AddXP(amount);
  9975. }
  9976. return 0;
  9977. }
  9978. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9979. if (!lua_interface)
  9980. return 0;
  9981. Spawn* player = lua_interface->GetSpawn(state);
  9982. int8 type = lua_interface->GetInt8Value(state, 2);
  9983. string text = lua_interface->GetStringValue(state, 3);
  9984. lua_interface->ResetFunctionStack(state);
  9985. Client* client = 0;
  9986. if (player && player->IsPlayer())
  9987. client = ((Player*)player)->GetClient();
  9988. if (!client || text.length() == 0) {
  9989. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9990. return 0;
  9991. }
  9992. client->SimpleMessage(type, text.c_str());
  9993. return 0;
  9994. }
  9995. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9996. if (!lua_interface)
  9997. return 0;
  9998. Spawn* player = lua_interface->GetSpawn(state);
  9999. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10000. lua_interface->ResetFunctionStack(state);
  10001. Client* client = 0;
  10002. if (player && player->IsPlayer())
  10003. client = ((Player*)player)->GetClient();
  10004. if (!client || !spawn) {
  10005. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  10006. return 0;
  10007. }
  10008. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  10009. if (!items) {
  10010. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  10011. return 0;
  10012. }
  10013. client->SendLootResponsePacket(spawn->GetLootCoins(), items, spawn, true);
  10014. return 0;
  10015. }
  10016. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  10017. if (!lua_interface)
  10018. return 0;
  10019. Spawn* spawnref = lua_interface->GetSpawn(state);
  10020. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  10021. lua_interface->ResetFunctionStack(state);
  10022. if (spawn_id > 0 && spawnref) {
  10023. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  10024. if (spawns.size() == 0) {
  10025. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  10026. return 0;
  10027. }
  10028. Spawn* spawn = 0;
  10029. int16 index = MakeRandomInt(0, spawns.size());
  10030. if (index >= spawns.size() || index < 0)
  10031. index = 0;
  10032. spawn = spawns[index];
  10033. lua_interface->SetSpawnValue(state, spawn);
  10034. return 1;
  10035. }
  10036. else {
  10037. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  10038. }
  10039. return 0;
  10040. }
  10041. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  10042. Spawn* player = lua_interface->GetSpawn(state);
  10043. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  10044. string name = lua_interface->GetStringValue(state, 3);
  10045. float distance = lua_interface->GetFloatValue(state, 4);
  10046. string command = lua_interface->GetStringValue(state, 5);
  10047. string error_text = lua_interface->GetStringValue(state, 6);
  10048. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  10049. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  10050. lua_interface->ResetFunctionStack(state);
  10051. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  10052. if (distance == 0)
  10053. distance = 10.0f;
  10054. if (command.length() == 0)
  10055. command = name;
  10056. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  10057. if (spawns.size() == 0) {
  10058. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  10059. return 0;
  10060. }
  10061. Spawn* spawn = 0;
  10062. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  10063. spawn = *itr;
  10064. if (spawn) {
  10065. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  10066. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  10067. }
  10068. }
  10069. }
  10070. return 0;
  10071. }
  10072. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  10073. if (!lua_interface)
  10074. return 0;
  10075. Client* client = 0;
  10076. Spawn* player = lua_interface->GetSpawn(state);
  10077. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  10078. lua_interface->ResetFunctionStack(state);
  10079. if (player && player->IsPlayer() && player->GetZone())
  10080. client = ((Player*)player)->GetClient();
  10081. else{
  10082. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  10083. return 0;
  10084. }
  10085. if (client) {
  10086. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  10087. if (packet) {
  10088. packet->setDataByName("goal_num", goal_num);
  10089. client->QueuePacket(packet->serialize());
  10090. safe_delete(packet);
  10091. }
  10092. }
  10093. return 0;
  10094. }
  10095. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  10096. if (!lua_interface)
  10097. return 0;
  10098. Client* client = 0;
  10099. Spawn* player = lua_interface->GetSpawn(state);
  10100. lua_interface->ResetFunctionStack(state);
  10101. if (player && player->IsPlayer() && player->GetZone())
  10102. client = ((Player*)player)->GetClient();
  10103. else {
  10104. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  10105. return 0;
  10106. }
  10107. if (client && client->GetVersion() >= 374) {
  10108. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  10109. }
  10110. return 0;
  10111. }
  10112. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  10113. if (!lua_interface)
  10114. return 0;
  10115. Client* client = 0;
  10116. Spawn* player = lua_interface->GetSpawn(state);
  10117. float duration = lua_interface->GetFloatValue(state, 2);
  10118. string text = lua_interface->GetStringValue(state, 3);
  10119. string voice = lua_interface->GetStringValue(state, 4);
  10120. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  10121. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  10122. string signal = lua_interface->GetStringValue(state, 7);
  10123. string goal1 = lua_interface->GetStringValue(state, 8);
  10124. string task1 = lua_interface->GetStringValue(state, 9);
  10125. string goal2 = lua_interface->GetStringValue(state, 10);
  10126. string task2 = lua_interface->GetStringValue(state, 11);
  10127. string goal3 = lua_interface->GetStringValue(state, 12);
  10128. string task3 = lua_interface->GetStringValue(state, 13);
  10129. string goal4 = lua_interface->GetStringValue(state, 14);
  10130. string task4 = lua_interface->GetStringValue(state, 15);
  10131. lua_interface->ResetFunctionStack(state);
  10132. if (!player) {
  10133. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  10134. return 0;
  10135. }
  10136. if (!player->IsPlayer()) {
  10137. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  10138. return 0;
  10139. }
  10140. else
  10141. client = ((Player*)player)->GetClient();
  10142. if (!client) {
  10143. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  10144. return 0;
  10145. }
  10146. if (text.length() == 0) {
  10147. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  10148. return 0;
  10149. }
  10150. if (duration >= 0 && duration < 2)
  10151. duration = 2;
  10152. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  10153. if (packet) {
  10154. packet->setDataByName("open_seconds_max", duration);
  10155. packet->setDataByName("text", text.c_str());
  10156. packet->setDataByName("voice", voice.c_str());
  10157. int8 num_goals = 1;
  10158. if (task2.length() > 0)
  10159. num_goals++;
  10160. if (task3.length() > 0)
  10161. num_goals++;
  10162. if (task4.length() > 0)
  10163. num_goals++;
  10164. packet->setArrayLengthByName("num_goals", num_goals);
  10165. for (int8 i = 0; i < num_goals; i++) {
  10166. packet->setSubArrayLengthByName("num_tasks", 1, i);
  10167. }
  10168. if (goal1.length() > 0)
  10169. packet->setArrayDataByName("goal_text", goal1.c_str());
  10170. if (goal2.length() > 0)
  10171. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  10172. if (goal3.length() > 0)
  10173. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  10174. if (goal4.length() > 0)
  10175. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  10176. packet->setSubArrayDataByName("task_text", task1.c_str());
  10177. if (task2.length() > 0)
  10178. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  10179. if (task3.length() > 0)
  10180. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  10181. if (task4.length() > 0)
  10182. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  10183. packet->setDataByName("complete_sound", "click");
  10184. packet->setDataByName("signal", signal.c_str());
  10185. packet->setDataByName("voice_key1", voice_key1);
  10186. packet->setDataByName("voice_key2", voice_key2);
  10187. client->QueuePacket(packet->serialize());
  10188. safe_delete(packet);
  10189. }
  10190. return 0;
  10191. }
  10192. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  10193. if (!lua_interface)
  10194. return 0;
  10195. Client* client = 0;
  10196. Spawn* player = lua_interface->GetSpawn(state);
  10197. string window = lua_interface->GetStringValue(state, 2);
  10198. int8 show = lua_interface->GetInt8Value(state, 3);
  10199. lua_interface->ResetFunctionStack(state);
  10200. if (!player) {
  10201. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  10202. return 0;
  10203. }
  10204. if (!player->IsPlayer()) {
  10205. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  10206. return 0;
  10207. }
  10208. else
  10209. client = ((Player*)player)->GetClient();
  10210. if (!client) {
  10211. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  10212. return 0;
  10213. }
  10214. if (window.length() == 0) {
  10215. lua_interface->LogError("LUA ShowWindow required parameters not given");
  10216. return 0;
  10217. }
  10218. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  10219. if (packet) {
  10220. packet->setDataByName("window", window.c_str());
  10221. packet->setDataByName("show", show);
  10222. client->QueuePacket(packet->serialize());
  10223. safe_delete(packet);
  10224. }
  10225. return 0;
  10226. }
  10227. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  10228. //See GameEvents.txt for options that can be used for this function
  10229. if (!lua_interface)
  10230. return 0;
  10231. Client* client = 0;
  10232. Spawn* player = lua_interface->GetSpawn(state);
  10233. string event_name = lua_interface->GetStringValue(state, 2);
  10234. int8 enabled = lua_interface->GetInt8Value(state, 3);
  10235. lua_interface->ResetFunctionStack(state);
  10236. if (!player || !player->IsPlayer()) {
  10237. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  10238. return 0;
  10239. }
  10240. client = ((Player*)player)->GetClient();
  10241. if (!client) {
  10242. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  10243. return 0;
  10244. }
  10245. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  10246. if (packet) {
  10247. packet->setDataByName("event_name", event_name.c_str());
  10248. packet->setDataByName("enabled", enabled);
  10249. client->QueuePacket(packet->serialize());
  10250. safe_delete(packet);
  10251. }
  10252. return 0;
  10253. }
  10254. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  10255. if (!lua_interface)
  10256. return 0;
  10257. Spawn* player = lua_interface->GetSpawn(state);
  10258. lua_interface->ResetFunctionStack(state);
  10259. if (player && player->IsPlayer()) {
  10260. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  10261. return 1;
  10262. }
  10263. return 0;
  10264. }
  10265. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  10266. if (!lua_interface)
  10267. return 0;
  10268. Spawn* player = lua_interface->GetSpawn(state);
  10269. int8 step = lua_interface->GetInt8Value(state, 2);
  10270. lua_interface->ResetFunctionStack(state);
  10271. if (player && player->IsPlayer() && step > 0) {
  10272. ((Player*)player)->SetTutorialStep(step);
  10273. }
  10274. return 0;
  10275. }
  10276. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  10277. if (!lua_interface)
  10278. return 0;
  10279. Client* client = 0;
  10280. Spawn* player = lua_interface->GetSpawn(state);
  10281. string window = lua_interface->GetStringValue(state, 2);
  10282. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  10283. lua_interface->ResetFunctionStack(state);
  10284. if (!player) {
  10285. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  10286. return 0;
  10287. }
  10288. if (!player->IsPlayer()) {
  10289. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  10290. return 0;
  10291. }
  10292. else
  10293. client = ((Player*)player)->GetClient();
  10294. if (!client) {
  10295. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  10296. return 0;
  10297. }
  10298. if (window.length() == 0) {
  10299. lua_interface->LogError("LUA FlashWindow required parameters not given");
  10300. return 0;
  10301. }
  10302. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  10303. if (packet) {
  10304. packet->setDataByName("window", window.c_str());
  10305. packet->setDataByName("flash_seconds", flash_seconds);
  10306. client->QueuePacket(packet->serialize());
  10307. safe_delete(packet);
  10308. }
  10309. return 0;
  10310. }
  10311. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  10312. if (!lua_interface)
  10313. return 0;
  10314. Spawn* spawn = lua_interface->GetSpawn(state);
  10315. Spawn* target = lua_interface->GetSpawn(state, 2);
  10316. lua_interface->ResetFunctionStack(state);
  10317. if (spawn && target)
  10318. return spawn->CheckLoS(target);
  10319. return 0;
  10320. }
  10321. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  10322. if (!lua_interface)
  10323. return 0;
  10324. Spawn* spawn = lua_interface->GetSpawn(state);
  10325. float x = lua_interface->GetFloatValue(state, 2);
  10326. float y = lua_interface->GetFloatValue(state, 3);
  10327. float z = lua_interface->GetFloatValue(state, 4);
  10328. lua_interface->ResetFunctionStack(state);
  10329. if (spawn)
  10330. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  10331. return 0;
  10332. }
  10333. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  10334. if (!lua_interface)
  10335. return 0;
  10336. ZoneServer* zone = lua_interface->GetZone(state);
  10337. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  10338. lua_interface->ResetFunctionStack(state);
  10339. if (zone)
  10340. zone->SetExpansionFlag(xpackFlag);
  10341. return 0;
  10342. }
  10343. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  10344. if (!lua_interface)
  10345. return 0;
  10346. ZoneServer* zone = lua_interface->GetZone(state);
  10347. lua_interface->ResetFunctionStack(state);
  10348. if (zone) {
  10349. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  10350. return 1;
  10351. }
  10352. return 0;
  10353. }
  10354. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  10355. if (!lua_interface)
  10356. return 0;
  10357. ZoneServer* zone = lua_interface->GetZone(state);
  10358. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  10359. lua_interface->ResetFunctionStack(state);
  10360. if (zone)
  10361. zone->SetHolidayFlag(holidayFlag);
  10362. return 0;
  10363. }
  10364. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  10365. if (!lua_interface)
  10366. return 0;
  10367. ZoneServer* zone = lua_interface->GetZone(state);
  10368. lua_interface->ResetFunctionStack(state);
  10369. if (zone) {
  10370. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  10371. return 1;
  10372. }
  10373. return 0;
  10374. }
  10375. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  10376. if (!lua_interface)
  10377. return 0;
  10378. Spawn* spawn = lua_interface->GetSpawn(state);
  10379. bool canbind = lua_interface->GetInt32Value(state, 2);
  10380. lua_interface->ResetFunctionStack(state);
  10381. if(!spawn) {
  10382. lua_interface->LogError("%s: LUA SetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10383. return 0;
  10384. }
  10385. ZoneServer* zone = spawn->GetZone();
  10386. if (zone)
  10387. zone->SetCanBind(canbind);
  10388. return 0;
  10389. }
  10390. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  10391. if (!lua_interface)
  10392. return 0;
  10393. Spawn* spawn = lua_interface->GetSpawn(state);
  10394. lua_interface->ResetFunctionStack(state);
  10395. if(!spawn) {
  10396. lua_interface->LogError("%s: LUA GetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10397. return 0;
  10398. }
  10399. ZoneServer* zone = spawn->GetZone();
  10400. if (zone) {
  10401. lua_interface->SetInt32Value(state, zone->GetCanBind());
  10402. return 1;
  10403. }
  10404. return 0;
  10405. }
  10406. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  10407. if (!lua_interface)
  10408. return 0;
  10409. Spawn* spawn = lua_interface->GetSpawn(state);
  10410. bool cangate = lua_interface->GetInt32Value(state, 2);
  10411. lua_interface->ResetFunctionStack(state);
  10412. if(!spawn) {
  10413. lua_interface->LogError("%s: LUA SetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10414. return 0;
  10415. }
  10416. ZoneServer* zone = spawn->GetZone();
  10417. if (zone)
  10418. zone->SetCanGate(cangate);
  10419. return 0;
  10420. }
  10421. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  10422. if (!lua_interface)
  10423. return 0;
  10424. Spawn* spawn = lua_interface->GetSpawn(state);
  10425. lua_interface->ResetFunctionStack(state);
  10426. if(!spawn) {
  10427. lua_interface->LogError("%s: LUA GetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10428. return 0;
  10429. }
  10430. ZoneServer* zone = spawn->GetZone();
  10431. if (zone) {
  10432. lua_interface->SetInt32Value(state, zone->GetCanGate());
  10433. return 1;
  10434. }
  10435. return 0;
  10436. }
  10437. int EQ2Emu_lua_SetCanEvac(lua_State* state) {
  10438. if (!lua_interface)
  10439. return 0;
  10440. Spawn* spawn = lua_interface->GetSpawn(state);
  10441. bool canevac = lua_interface->GetInt32Value(state, 2);
  10442. lua_interface->ResetFunctionStack(state);
  10443. if(!spawn) {
  10444. lua_interface->LogError("%s: LUA SetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10445. return 0;
  10446. }
  10447. ZoneServer* zone = spawn->GetZone();
  10448. if (zone)
  10449. zone->SetCanEvac(canevac);
  10450. return 0;
  10451. }
  10452. int EQ2Emu_lua_GetCanEvac(lua_State* state) {
  10453. if (!lua_interface)
  10454. return 0;
  10455. Spawn* spawn = lua_interface->GetSpawn(state);
  10456. lua_interface->ResetFunctionStack(state);
  10457. if(!spawn) {
  10458. lua_interface->LogError("%s: LUA GetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10459. return 0;
  10460. }
  10461. ZoneServer* zone = spawn->GetZone();
  10462. if (zone) {
  10463. lua_interface->SetInt32Value(state, zone->GetCanEvac());
  10464. return 1;
  10465. }
  10466. return 0;
  10467. }
  10468. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  10469. if (!lua_interface)
  10470. return 0;
  10471. Spawn* spawn = lua_interface->GetSpawn(state);
  10472. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  10473. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  10474. float distance = lua_interface->GetFloatValue(state, 4);
  10475. string in_range_function = lua_interface->GetStringValue(state, 5);
  10476. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  10477. lua_interface->ResetFunctionStack(state);
  10478. if (spawn && distance > 0 && in_range_function.length() > 0)
  10479. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  10480. return 0;
  10481. }
  10482. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  10483. if (!lua_interface)
  10484. return 0;
  10485. Spawn* spawn = lua_interface->GetSpawn(state);
  10486. Spawn* target = lua_interface->GetSpawn(state, 2);
  10487. lua_interface->ResetFunctionStack(state);
  10488. if (spawn && target)
  10489. {
  10490. if (spawn->IsPlayer() && target->IsEntity())
  10491. {
  10492. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  10493. return 1;
  10494. }
  10495. else if (spawn->IsEntity() && target->IsEntity())
  10496. {
  10497. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  10498. return 1;
  10499. }
  10500. }
  10501. return 0;
  10502. }
  10503. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  10504. if (!lua_interface)
  10505. return 0;
  10506. Spawn* spawn = lua_interface->GetSpawn(state);
  10507. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10508. lua_interface->ResetFunctionStack(state);
  10509. if (spawn && spawn->IsEntity())
  10510. {
  10511. ((Entity*)spawn)->SetSeeInvisSpell(val);
  10512. if (spawn->IsPlayer())
  10513. {
  10514. Client* client = ((Player*)spawn)->GetClient();
  10515. if (client)
  10516. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  10517. }
  10518. }
  10519. return 0;
  10520. }
  10521. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  10522. if (!lua_interface)
  10523. return 0;
  10524. Spawn* spawn = lua_interface->GetSpawn(state);
  10525. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10526. lua_interface->ResetFunctionStack(state);
  10527. if (spawn && spawn->IsEntity())
  10528. {
  10529. ((Entity*)spawn)->SetSeeHideSpell(val);
  10530. if (spawn->IsPlayer())
  10531. {
  10532. Client* client = ((Player*)spawn)->GetClient();
  10533. if (client)
  10534. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  10535. }
  10536. }
  10537. return 0;
  10538. }
  10539. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  10540. {
  10541. if (!lua_interface)
  10542. return 0;
  10543. Spawn* player = lua_interface->GetSpawn(state);
  10544. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10545. string command = lua_interface->GetStringValue(state, 3);
  10546. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10547. lua_interface->ResetFunctionStack(state);
  10548. if (spawn && player && player->IsPlayer())
  10549. {
  10550. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10551. bool res = false;
  10552. if (cmd)
  10553. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  10554. lua_interface->SetBooleanValue(state, res);
  10555. return 1;
  10556. }
  10557. return 0;
  10558. }
  10559. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  10560. {
  10561. if (!lua_interface)
  10562. return 0;
  10563. Spawn* spawn = lua_interface->GetSpawn(state);
  10564. int32 charID = lua_interface->GetInt32Value(state, 2);
  10565. string command = lua_interface->GetStringValue(state, 3);
  10566. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10567. lua_interface->ResetFunctionStack(state);
  10568. if (spawn && charID)
  10569. {
  10570. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10571. bool res = false;
  10572. if (cmd)
  10573. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  10574. lua_interface->SetBooleanValue(state, res);
  10575. return 1;
  10576. }
  10577. return 0;
  10578. }
  10579. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  10580. {
  10581. if (!lua_interface)
  10582. return 0;
  10583. Spawn* spawn = lua_interface->GetSpawn(state);
  10584. string command = lua_interface->GetStringValue(state, 2);
  10585. lua_interface->ResetFunctionStack(state);
  10586. if (spawn && command.length() > 0)
  10587. spawn->RemovePrimaryEntityCommand(command.c_str());
  10588. return 0;
  10589. }
  10590. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  10591. if (!lua_interface)
  10592. return 0;
  10593. Spawn* spawn = lua_interface->GetSpawn(state);
  10594. float distance = lua_interface->GetFloatValue(state, 2);
  10595. string command = lua_interface->GetStringValue(state, 3);
  10596. Spawn* player = lua_interface->GetSpawn(state, 4);
  10597. lua_interface->ResetFunctionStack(state);
  10598. if (spawn) {
  10599. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  10600. }
  10601. return 0;
  10602. }
  10603. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  10604. if (!lua_interface)
  10605. return 0;
  10606. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10607. Spawn* spawn = lua_interface->GetSpawn(state);
  10608. Spawn* player = lua_interface->GetSpawn(state, 2);
  10609. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  10610. lua_interface->ResetFunctionStack(state);
  10611. if (spawn && player && transport_id && player->IsPlayer()) {
  10612. Client* client = 0;
  10613. if (player && player->IsPlayer())
  10614. client = ((Player*)player)->GetClient();
  10615. if (!client)
  10616. return 0;
  10617. vector<TransportDestination*> destinations;
  10618. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  10619. if (destinations.size())
  10620. {
  10621. client->SetTemporaryTransportID(transport_id);
  10622. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  10623. }
  10624. else
  10625. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  10626. }
  10627. return 0;
  10628. }
  10629. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  10630. if (!lua_interface)
  10631. return 0;
  10632. Spawn* player = lua_interface->GetSpawn(state);
  10633. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  10634. lua_interface->ResetFunctionStack(state);
  10635. if (player && player->IsPlayer()) {
  10636. Client* client = 0;
  10637. if (player && player->IsPlayer())
  10638. client = ((Player*)player)->GetClient();
  10639. if (!client)
  10640. return 0;
  10641. client->SetTemporaryTransportID(transport_id);
  10642. }
  10643. return 0;
  10644. }
  10645. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10646. if (!lua_interface)
  10647. return 0;
  10648. Spawn* player = lua_interface->GetSpawn(state);
  10649. lua_interface->ResetFunctionStack(state);
  10650. if (player && player->IsPlayer()) {
  10651. Client* client = 0;
  10652. if (player && player->IsPlayer())
  10653. client = ((Player*)player)->GetClient();
  10654. if (!client)
  10655. return 0;
  10656. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10657. return 1;
  10658. }
  10659. return 0;
  10660. }
  10661. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10662. if (!lua_interface)
  10663. return 0;
  10664. Spawn* spawn = lua_interface->GetSpawn(state);
  10665. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10666. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10667. if (!spawn) {
  10668. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10669. return 0;
  10670. }
  10671. if (!spawn->IsEntity()) {
  10672. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10673. return 0;
  10674. }
  10675. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10676. {
  10677. 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);
  10678. return 0;
  10679. }
  10680. lua_interface->ResetFunctionStack(state);
  10681. if (spell && spell->targets.size() > 0) {
  10682. ZoneServer* zone = spell->caster->GetZone();
  10683. for (int8 i = 0; i < spell->targets.size(); i++) {
  10684. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10685. if (target && target->IsEntity()) {
  10686. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10687. if (target->IsPlayer())
  10688. ((Player*)target)->SetCharSheetChanged(true);
  10689. }
  10690. }
  10691. }
  10692. else {
  10693. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10694. if (spawn->IsPlayer())
  10695. ((Player*)spawn)->SetCharSheetChanged(true);
  10696. }
  10697. return 0;
  10698. }
  10699. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10700. if (!lua_interface)
  10701. return 0;
  10702. Spawn* spawn = lua_interface->GetSpawn(state);
  10703. lua_interface->ResetFunctionStack(state);
  10704. if (!spawn) {
  10705. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10706. return 0;
  10707. }
  10708. if (!spawn->IsEntity()) {
  10709. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10710. return 0;
  10711. }
  10712. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10713. return 1;
  10714. }
  10715. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10716. if (!lua_interface)
  10717. return 0;
  10718. int32 spell_id = lua_interface->GetInt32Value(state);
  10719. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10720. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10721. if (spell_id > 0) {
  10722. if (spell_tier == 0)
  10723. spell_tier = 1;
  10724. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10725. if(!spell) {
  10726. lua_interface->LogError("%s: GetSpell: Failed, spell id %u spell tier %u does not exist.", lua_interface->GetScriptName(state), spell_id, spell_tier);
  10727. lua_interface->ResetFunctionStack(state);
  10728. return 0;
  10729. }
  10730. LuaSpell* lua_spell = 0;
  10731. if(custom_lua_script.size() > 0)
  10732. {
  10733. // attempt to load the custom script since it isn't already loaded
  10734. // we will re-obtain the lua_spell further below
  10735. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10736. {
  10737. 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());
  10738. }
  10739. }
  10740. else
  10741. custom_lua_script = spell->GetSpellData()->lua_script;
  10742. if (!lua_spell && lua_interface)
  10743. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10744. lua_interface->ResetFunctionStack(state);
  10745. if (!lua_spell)
  10746. {
  10747. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10748. return 0;
  10749. }
  10750. lua_spell->spell = new Spell(spell);
  10751. lua_interface->AddCustomSpell(lua_spell);
  10752. lua_interface->SetSpellValue(state, lua_spell);
  10753. return 1;
  10754. }
  10755. return 0;
  10756. }
  10757. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10758. if (!lua_interface)
  10759. return 0;
  10760. LuaSpell* spell = lua_interface->GetSpell(state);
  10761. string field = lua_interface->GetStringValue(state, 2);
  10762. lua_interface->ResetFunctionStack(state);
  10763. if (!spell) {
  10764. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10765. return 0;
  10766. }
  10767. if (!spell->spell || !spell->spell->GetSpellData()) {
  10768. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10769. return 0;
  10770. }
  10771. boost::to_lower(field);
  10772. return spell->spell->GetSpellData(state, field);
  10773. }
  10774. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10775. if (!lua_interface)
  10776. return 0;
  10777. LuaSpell* spell = lua_interface->GetSpell(state);
  10778. string field = lua_interface->GetStringValue(state, 2);
  10779. int8 fieldArg = 3; // field value after the initial set
  10780. if (!spell) {
  10781. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10782. lua_interface->ResetFunctionStack(state);
  10783. return 0;
  10784. }
  10785. if (!spell->spell || !spell->spell->GetSpellData()) {
  10786. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10787. lua_interface->ResetFunctionStack(state);
  10788. return 0;
  10789. }
  10790. boost::to_lower(field);
  10791. bool valSet = false;
  10792. spell->spell->SetSpellData(state, field, fieldArg);
  10793. lua_interface->ResetFunctionStack(state);
  10794. return valSet;
  10795. }
  10796. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10797. if (!lua_interface)
  10798. return 0;
  10799. LuaSpell* spell = lua_interface->GetSpell(state);
  10800. int8 idx = lua_interface->GetInt32Value(state, 2);
  10801. if (!spell) {
  10802. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10803. lua_interface->ResetFunctionStack(state);
  10804. return 0;
  10805. }
  10806. if (!spell->spell || !spell->spell->GetSpellData()) {
  10807. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10808. lua_interface->ResetFunctionStack(state);
  10809. return 0;
  10810. }
  10811. if (spell->spell->lua_data.size() <= idx)
  10812. {
  10813. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10814. lua_interface->ResetFunctionStack(state);
  10815. return 0;
  10816. }
  10817. bool setVal = true;
  10818. LUAData* data = spell->spell->lua_data[idx];
  10819. switch (data->type)
  10820. {
  10821. case 0:
  10822. {
  10823. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10824. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10825. data->int_value = value;
  10826. data->int_value2 = value2;
  10827. break;
  10828. }
  10829. case 1:
  10830. {
  10831. float value = lua_interface->GetFloatValue(state, 3);
  10832. float value2 = lua_interface->GetFloatValue(state, 4);
  10833. data->float_value = value;
  10834. data->float_value2 = value2;
  10835. break;
  10836. }
  10837. case 2:
  10838. {
  10839. bool value = lua_interface->GetBooleanValue(state, 3);
  10840. data->bool_value = value;
  10841. break;
  10842. }
  10843. case 3:
  10844. {
  10845. string value = lua_interface->GetStringValue(state, 3);
  10846. string value2 = lua_interface->GetStringValue(state, 4);
  10847. data->string_value = value;
  10848. data->string_value2 = value2;
  10849. break;
  10850. }
  10851. default:
  10852. setVal = false;
  10853. }
  10854. lua_interface->ResetFunctionStack(state);
  10855. return setVal;
  10856. }
  10857. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10858. if (!lua_interface)
  10859. return 0;
  10860. LuaSpell* spell = lua_interface->GetSpell(state);
  10861. int8 idx = lua_interface->GetInt32Value(state, 2);
  10862. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10863. lua_interface->ResetFunctionStack(state);
  10864. if (!spell) {
  10865. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10866. return 0;
  10867. }
  10868. if (!spell->spell || !spell->spell->GetSpellData()) {
  10869. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10870. return 0;
  10871. }
  10872. if (spell->spell->lua_data.size() <= idx)
  10873. {
  10874. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10875. return 0;
  10876. }
  10877. bool setVal = true;
  10878. LUAData* data = spell->spell->lua_data[idx];
  10879. switch (data->type)
  10880. {
  10881. case 0:
  10882. {
  10883. if(!secondfield)
  10884. lua_interface->SetSInt32Value(state, data->int_value);
  10885. else
  10886. lua_interface->SetSInt32Value(state, data->int_value2);
  10887. break;
  10888. }
  10889. case 1:
  10890. {
  10891. if (!secondfield)
  10892. lua_interface->SetFloatValue(state, data->float_value);
  10893. else
  10894. lua_interface->SetFloatValue(state, data->float_value2);
  10895. break;
  10896. }
  10897. case 2:
  10898. {
  10899. lua_interface->SetBooleanValue(state, data->bool_value);
  10900. break;
  10901. }
  10902. case 3:
  10903. {
  10904. if (!secondfield)
  10905. lua_interface->SetStringValue(state, data->string_value.c_str());
  10906. else
  10907. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10908. break;
  10909. }
  10910. default:
  10911. setVal = false;
  10912. }
  10913. return setVal;
  10914. }
  10915. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10916. if (!lua_interface)
  10917. return 0;
  10918. LuaSpell* spell = lua_interface->GetSpell(state);
  10919. int8 idx = lua_interface->GetInt32Value(state, 2);
  10920. string field = lua_interface->GetStringValue(state, 3);
  10921. boost::to_lower(field);
  10922. if (!spell) {
  10923. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10924. lua_interface->ResetFunctionStack(state);
  10925. return 0;
  10926. }
  10927. if (!spell->spell || !spell->spell->GetSpellData()) {
  10928. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10929. lua_interface->ResetFunctionStack(state);
  10930. return 0;
  10931. }
  10932. if (spell->spell->effects.size() <= idx)
  10933. {
  10934. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10935. lua_interface->ResetFunctionStack(state);
  10936. return 0;
  10937. }
  10938. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10939. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10940. if (field == "description")
  10941. effect->description = string(lua_interface->GetStringValue(state, 4));
  10942. else if (field == "bullet")
  10943. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10944. else if (field == "percentage")
  10945. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10946. else { // no match
  10947. lua_interface->ResetFunctionStack(state);
  10948. return 0;
  10949. }
  10950. lua_interface->ResetFunctionStack(state);
  10951. return 1;
  10952. }
  10953. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10954. if (!lua_interface)
  10955. return 0;
  10956. LuaSpell* spell = lua_interface->GetSpell(state);
  10957. int8 idx = lua_interface->GetInt32Value(state, 2);
  10958. string field = lua_interface->GetStringValue(state, 3);
  10959. lua_interface->ResetFunctionStack(state);
  10960. boost::to_lower(field);
  10961. if (!spell) {
  10962. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10963. return 0;
  10964. }
  10965. if (!spell->spell || !spell->spell->GetSpellData()) {
  10966. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10967. return 0;
  10968. }
  10969. if (spell->spell->effects.size() <= idx)
  10970. {
  10971. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10972. return 0;
  10973. }
  10974. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10975. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10976. if (field == "description")
  10977. lua_interface->SetStringValue(state, effect->description.c_str());
  10978. else if (field == "bullet")
  10979. lua_interface->SetInt32Value(state, effect->subbullet);
  10980. else if (field == "percentage")
  10981. lua_interface->SetInt32Value(state, effect->percentage);
  10982. else // no match
  10983. return 0;
  10984. return 1;
  10985. }
  10986. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10987. if (!lua_interface)
  10988. return 0;
  10989. LuaSpell* spell = lua_interface->GetSpell(state);
  10990. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10991. Spawn* target = lua_interface->GetSpawn(state, 3);
  10992. lua_interface->ResetFunctionStack(state);
  10993. if (!target) {
  10994. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10995. return 0;
  10996. }
  10997. if (!target->IsEntity()) {
  10998. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10999. return 0;
  11000. }
  11001. if (!spell) {
  11002. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  11003. return 0;
  11004. }
  11005. if (caster && !caster->IsEntity()) {
  11006. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  11007. return 0;
  11008. }
  11009. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  11010. return 0;
  11011. }
  11012. int EQ2Emu_lua_InWater(lua_State* state) {
  11013. if (!lua_interface)
  11014. return 0;
  11015. Spawn* spawn = lua_interface->GetSpawn(state);
  11016. lua_interface->ResetFunctionStack(state);
  11017. if (spawn) {
  11018. lua_interface->SetBooleanValue(state, spawn->InWater());
  11019. return 1;
  11020. }
  11021. return 0;
  11022. }
  11023. int EQ2Emu_lua_InLava(lua_State* state) {
  11024. if (!lua_interface)
  11025. return 0;
  11026. Spawn* spawn = lua_interface->GetSpawn(state);
  11027. lua_interface->ResetFunctionStack(state);
  11028. if (spawn) {
  11029. lua_interface->SetBooleanValue(state, spawn->InLava());
  11030. return 1;
  11031. }
  11032. return 0;
  11033. }
  11034. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  11035. if (!lua_interface)
  11036. return 0;
  11037. Spawn* attacker = lua_interface->GetSpawn(state);
  11038. Spawn* victim = lua_interface->GetSpawn(state, 2);
  11039. int8 type = lua_interface->GetInt8Value(state, 3);
  11040. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  11041. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  11042. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  11043. string spell_name = lua_interface->GetStringValue(state, 7);
  11044. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  11045. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  11046. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  11047. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  11048. bool take_power = (lua_interface->GetInt8Value(state, 12) == 1);
  11049. lua_interface->ResetFunctionStack(state);
  11050. if (!attacker) {
  11051. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  11052. lua_interface->SetBooleanValue(state, false);
  11053. return 1;
  11054. }
  11055. if (!attacker->IsEntity()) {
  11056. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  11057. lua_interface->SetBooleanValue(state, false);
  11058. return 1;
  11059. }
  11060. if (!victim) {
  11061. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  11062. lua_interface->SetBooleanValue(state, false);
  11063. return 1;
  11064. }
  11065. if (!victim->IsEntity()) {
  11066. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  11067. lua_interface->SetBooleanValue(state, false);
  11068. return 1;
  11069. }
  11070. 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);
  11071. lua_interface->SetBooleanValue(state, has_damaged);
  11072. return 1;
  11073. }
  11074. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  11075. if (!lua_interface)
  11076. return 0;
  11077. Spawn* spawn = lua_interface->GetSpawn(state);
  11078. lua_interface->ResetFunctionStack(state);
  11079. if (spawn) {
  11080. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  11081. return 1;
  11082. }
  11083. return 0;
  11084. }
  11085. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  11086. if (!lua_interface)
  11087. return 0;
  11088. Spawn* spawn = lua_interface->GetSpawn(state);
  11089. bool invul = lua_interface->GetBooleanValue(state, 2);
  11090. lua_interface->ResetFunctionStack(state);
  11091. if (spawn) {
  11092. spawn->SetInvulnerable(invul);
  11093. }
  11094. return 0;
  11095. }
  11096. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  11097. if (!lua_interface)
  11098. return 0;
  11099. string category = lua_interface->GetStringValue(state);
  11100. string name = lua_interface->GetStringValue(state, 2);
  11101. lua_interface->ResetFunctionStack(state);
  11102. Rule *ret = 0;
  11103. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11104. lua_interface->SetBooleanValue(state, ret->GetBool());
  11105. return 1;
  11106. }
  11107. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11108. return 0;
  11109. }
  11110. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  11111. if (!lua_interface)
  11112. return 0;
  11113. string category = lua_interface->GetStringValue(state);
  11114. string name = lua_interface->GetStringValue(state, 2);
  11115. lua_interface->ResetFunctionStack(state);
  11116. Rule *ret = 0;
  11117. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11118. lua_interface->SetInt32Value(state, ret->GetInt32());
  11119. return 1;
  11120. }
  11121. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11122. return 0;
  11123. }
  11124. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  11125. if (!lua_interface)
  11126. return 0;
  11127. string category = lua_interface->GetStringValue(state);
  11128. string name = lua_interface->GetStringValue(state, 2);
  11129. lua_interface->ResetFunctionStack(state);
  11130. Rule *ret = 0;
  11131. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11132. lua_interface->SetFloatValue(state, ret->GetFloat());
  11133. return 1;
  11134. }
  11135. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11136. return 0;
  11137. }
  11138. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  11139. if (!lua_interface)
  11140. return 0;
  11141. Spawn* spawn = lua_interface->GetSpawn(state);
  11142. string type = lua_interface->GetStringValue(state, 2);
  11143. lua_interface->ResetFunctionStack(state);
  11144. if (spawn) {
  11145. int res = 1;
  11146. boost::to_lower(type);
  11147. if(type == "assigned_aa")
  11148. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  11149. else if ( type == "unassigned_aa")
  11150. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  11151. else if ( type == "assigned_tradeskill_aa")
  11152. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  11153. else if ( type == "unassigned_tradeskill_aa")
  11154. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  11155. else if ( type == "assigned_prestige_aa")
  11156. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  11157. else if ( type == "unassigned_prestige_aa")
  11158. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  11159. else if ( type == "assigned_tradeskill_prestige_aa")
  11160. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  11161. else if ( type == "unassigned_tradeskill_prestige_aa")
  11162. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  11163. else
  11164. res = 0;
  11165. return res;
  11166. }
  11167. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  11168. return 0;
  11169. }
  11170. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  11171. if (!lua_interface)
  11172. return 0;
  11173. Spawn* spawn = lua_interface->GetSpawn(state);
  11174. string type = lua_interface->GetStringValue(state, 2);
  11175. sint32 value = lua_interface->GetSInt32Value(state, 3);
  11176. lua_interface->ResetFunctionStack(state);
  11177. if (spawn) {
  11178. boost::to_lower(type);
  11179. if(type == "assigned_aa")
  11180. spawn->SetAssignedAA((sint16)value);
  11181. else if ( type == "unassigned_aa")
  11182. spawn->SetUnassignedAA((sint16)value);
  11183. else if ( type == "assigned_tradeskill_aa")
  11184. spawn->SetTradeskillAA((sint16)value);
  11185. else if ( type == "unassigned_tradeskill_aa")
  11186. spawn->SetUnassignedTradeskillAA((sint16)value);
  11187. else if ( type == "assigned_prestige_aa")
  11188. spawn->SetPrestigeAA((sint16)value);
  11189. else if ( type == "unassigned_prestige_aa")
  11190. spawn->SetUnassignedPrestigeAA((sint16)value);
  11191. else if ( type == "assigned_tradeskill_prestige_aa")
  11192. spawn->SetTradeskillPrestigeAA((sint16)value);
  11193. else if ( type == "unassigned_tradeskill_prestige_aa")
  11194. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  11195. if(spawn->IsPlayer())
  11196. ((Player*)spawn)->SetCharSheetChanged(true);
  11197. }
  11198. return 0;
  11199. }
  11200. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  11201. if (!lua_interface)
  11202. return 0;
  11203. string titleName = lua_interface->GetStringValue(state);
  11204. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  11205. lua_interface->ResetFunctionStack(state);
  11206. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  11207. lua_interface->SetSInt32Value(state, index);
  11208. return 1;
  11209. }
  11210. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  11211. if (!lua_interface)
  11212. return 0;
  11213. Spawn* spawn = lua_interface->GetSpawn(state);
  11214. string titleName = lua_interface->GetStringValue(state, 2);
  11215. lua_interface->ResetFunctionStack(state);
  11216. if(!spawn->IsPlayer())
  11217. {
  11218. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  11219. lua_interface->SetSInt32Value(state, -1);
  11220. return 1;
  11221. }
  11222. Player* player = (Player*)spawn;
  11223. // check if player already has the title, don't need to add twice
  11224. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11225. if ( playerHasTitle)
  11226. {
  11227. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  11228. return 1;
  11229. }
  11230. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  11231. if(!title)
  11232. {
  11233. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11234. lua_interface->SetSInt32Value(state, -1);
  11235. return 1;
  11236. }
  11237. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  11238. if(returnIdx < 0)
  11239. {
  11240. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11241. }
  11242. lua_interface->SetSInt32Value(state, returnIdx);
  11243. player->GetClient()->SendTitleUpdate();
  11244. return 1;
  11245. }
  11246. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  11247. if (!lua_interface)
  11248. return 0;
  11249. Spawn* spawn = lua_interface->GetSpawn(state);
  11250. string titleName = lua_interface->GetStringValue(state, 2);
  11251. lua_interface->ResetFunctionStack(state);
  11252. if(!spawn->IsPlayer())
  11253. {
  11254. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11255. return 0;
  11256. }
  11257. Player* player = (Player*)spawn;
  11258. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11259. if(!title)
  11260. {
  11261. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11262. return 0;
  11263. }
  11264. if(title->GetPrefix())
  11265. {
  11266. 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());
  11267. return 0;
  11268. }
  11269. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  11270. player->GetClient()->SendTitleUpdate();
  11271. return 1;
  11272. }
  11273. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  11274. if (!lua_interface)
  11275. return 0;
  11276. Spawn* spawn = lua_interface->GetSpawn(state);
  11277. string titleName = lua_interface->GetStringValue(state, 2);
  11278. lua_interface->ResetFunctionStack(state);
  11279. if(!spawn->IsPlayer())
  11280. {
  11281. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11282. return 0;
  11283. }
  11284. Player* player = (Player*)spawn;
  11285. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11286. if(!title)
  11287. {
  11288. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11289. return 0;
  11290. }
  11291. if(!title->GetPrefix())
  11292. {
  11293. 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());
  11294. return 0;
  11295. }
  11296. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  11297. player->GetClient()->SendTitleUpdate();
  11298. return 1;
  11299. }
  11300. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  11301. if (!lua_interface)
  11302. return 0;
  11303. Spawn* spawn = lua_interface->GetSpawn(state);
  11304. lua_interface->ResetFunctionStack(state);
  11305. if(!spawn->IsPlayer())
  11306. {
  11307. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11308. return 0;
  11309. }
  11310. Player* player = (Player*)spawn;
  11311. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  11312. player->GetClient()->SendTitleUpdate();
  11313. return 1;
  11314. }
  11315. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  11316. if (!lua_interface)
  11317. return 0;
  11318. Spawn* spawn = lua_interface->GetSpawn(state);
  11319. lua_interface->ResetFunctionStack(state);
  11320. if(!spawn->IsPlayer())
  11321. {
  11322. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11323. return 0;
  11324. }
  11325. Player* player = (Player*)spawn;
  11326. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  11327. player->GetClient()->SendTitleUpdate();
  11328. return 1;
  11329. }
  11330. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  11331. if (!lua_interface)
  11332. return 0;
  11333. Spawn* spawn = lua_interface->GetSpawn(state);
  11334. string field = lua_interface->GetStringValue(state, 2);
  11335. lua_interface->ResetFunctionStack(state);
  11336. if(!spawn || !spawn->IsEntity())
  11337. {
  11338. 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));
  11339. return 0;
  11340. }
  11341. Entity* ent = (Entity*)spawn;
  11342. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  11343. return 1;
  11344. }
  11345. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  11346. if (!lua_interface)
  11347. return 0;
  11348. Spawn* spawn = lua_interface->GetSpawn(state);
  11349. string field = lua_interface->GetStringValue(state, 2);
  11350. lua_interface->ResetFunctionStack(state);
  11351. if(!spawn || !spawn->IsEntity())
  11352. {
  11353. 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));
  11354. return 0;
  11355. }
  11356. Entity* ent = (Entity*)spawn;
  11357. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  11358. return 1;
  11359. }
  11360. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  11361. if (!lua_interface)
  11362. return 0;
  11363. Spawn* spawn = lua_interface->GetSpawn(state);
  11364. string field = lua_interface->GetStringValue(state, 2);
  11365. lua_interface->ResetFunctionStack(state);
  11366. if(!spawn || !spawn->IsEntity())
  11367. {
  11368. 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));
  11369. return 0;
  11370. }
  11371. Entity* ent = (Entity*)spawn;
  11372. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  11373. return 1;
  11374. }
  11375. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  11376. if (!lua_interface)
  11377. return 0;
  11378. Spawn* spawn = lua_interface->GetSpawn(state);
  11379. string field = lua_interface->GetStringValue(state, 2);
  11380. lua_interface->ResetFunctionStack(state);
  11381. if(!spawn || !spawn->IsEntity())
  11382. {
  11383. 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));
  11384. return 0;
  11385. }
  11386. Entity* ent = (Entity*)spawn;
  11387. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  11388. return 1;
  11389. }
  11390. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  11391. if (!lua_interface)
  11392. return 0;
  11393. Spawn* spawn = lua_interface->GetSpawn(state);
  11394. string field = lua_interface->GetStringValue(state, 2);
  11395. string value = lua_interface->GetStringValue(state, 3);
  11396. lua_interface->ResetFunctionStack(state);
  11397. if(!spawn || !spawn->IsEntity())
  11398. {
  11399. 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));
  11400. return 0;
  11401. }
  11402. Entity* ent = (Entity*)spawn;
  11403. bool set_ = ent->SetInfoStructString(field, value);
  11404. lua_interface->SetBooleanValue(state, set_);
  11405. return 1;
  11406. }
  11407. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  11408. if (!lua_interface)
  11409. return 0;
  11410. Spawn* spawn = lua_interface->GetSpawn(state);
  11411. string field = lua_interface->GetStringValue(state, 2);
  11412. int64 value = lua_interface->GetInt64Value(state, 3);
  11413. lua_interface->ResetFunctionStack(state);
  11414. if(!spawn || !spawn->IsEntity())
  11415. {
  11416. 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));
  11417. return 0;
  11418. }
  11419. Entity* ent = (Entity*)spawn;
  11420. bool set_ = ent->SetInfoStructUInt(field, value);
  11421. lua_interface->SetBooleanValue(state, set_);
  11422. return 1;
  11423. }
  11424. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  11425. if (!lua_interface)
  11426. return 0;
  11427. Spawn* spawn = lua_interface->GetSpawn(state);
  11428. string field = lua_interface->GetStringValue(state, 2);
  11429. sint64 value = lua_interface->GetSInt64Value(state, 3);
  11430. lua_interface->ResetFunctionStack(state);
  11431. if(!spawn || !spawn->IsEntity())
  11432. {
  11433. 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));
  11434. return 0;
  11435. }
  11436. Entity* ent = (Entity*)spawn;
  11437. bool set_ = ent->SetInfoStructSInt(field, value);
  11438. lua_interface->SetBooleanValue(state, set_);
  11439. return 1;
  11440. }
  11441. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  11442. if (!lua_interface)
  11443. return 0;
  11444. Spawn* spawn = lua_interface->GetSpawn(state);
  11445. string field = lua_interface->GetStringValue(state, 2);
  11446. float value = lua_interface->GetFloatValue(state, 3);
  11447. lua_interface->ResetFunctionStack(state);
  11448. if(!spawn || !spawn->IsEntity())
  11449. {
  11450. 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));
  11451. return 0;
  11452. }
  11453. Entity* ent = (Entity*)spawn;
  11454. bool set_ = ent->SetInfoStructFloat(field, value);
  11455. lua_interface->SetBooleanValue(state, set_);
  11456. return 1;
  11457. }
  11458. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  11459. if (!lua_interface)
  11460. return 0;
  11461. Spawn* spawn = lua_interface->GetSpawn(state);
  11462. bool value = lua_interface->GetBooleanValue(state, 2);
  11463. lua_interface->ResetFunctionStack(state);
  11464. if(!spawn || !spawn->IsPlayer())
  11465. {
  11466. 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));
  11467. return 0;
  11468. }
  11469. ((Player*)spawn)->SetCharSheetChanged(value);
  11470. return 0;
  11471. }
  11472. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  11473. if (!lua_interface)
  11474. return 0;
  11475. Spawn* spawn = lua_interface->GetSpawn(state);
  11476. std::string fromName = lua_interface->GetStringValue(state, 2);
  11477. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11478. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11479. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11480. int32 copper = lua_interface->GetInt32Value(state, 6);
  11481. int32 silver = lua_interface->GetInt32Value(state, 7);
  11482. int32 gold = lua_interface->GetInt32Value(state, 8);
  11483. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11484. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11485. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11486. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11487. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11488. lua_interface->ResetFunctionStack(state);
  11489. if(!spawn || !spawn->IsPlayer())
  11490. {
  11491. 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));
  11492. lua_interface->SetBooleanValue(state, false);
  11493. return 1;
  11494. }
  11495. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11496. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11497. lua_interface->SetBooleanValue(state, true);
  11498. return 1;
  11499. }
  11500. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  11501. if (!lua_interface)
  11502. return 0;
  11503. int32 char_id = lua_interface->GetInt32Value(state);
  11504. std::string fromName = lua_interface->GetStringValue(state, 2);
  11505. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11506. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11507. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11508. int32 copper = lua_interface->GetInt32Value(state, 6);
  11509. int32 silver = lua_interface->GetInt32Value(state, 7);
  11510. int32 gold = lua_interface->GetInt32Value(state, 8);
  11511. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11512. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11513. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11514. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11515. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11516. lua_interface->ResetFunctionStack(state);
  11517. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11518. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11519. lua_interface->SetBooleanValue(state, true);
  11520. return 1;
  11521. }
  11522. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  11523. Spawn* widget;
  11524. if (lua_interface) {
  11525. widget = lua_interface->GetSpawn(state);
  11526. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  11527. lua_interface->ResetFunctionStack(state);
  11528. if (widget && widget->IsWidget())
  11529. {
  11530. ((Widget*)widget)->OpenDoor();
  11531. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  11532. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11533. }
  11534. else
  11535. 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));
  11536. }
  11537. return 0;
  11538. }
  11539. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  11540. Spawn* widget;
  11541. if (lua_interface) {
  11542. widget = lua_interface->GetSpawn(state);
  11543. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  11544. lua_interface->ResetFunctionStack(state);
  11545. if (widget && widget->IsWidget())
  11546. {
  11547. ((Widget*)widget)->CloseDoor();
  11548. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  11549. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11550. }
  11551. else
  11552. 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));
  11553. }
  11554. return 0;
  11555. }
  11556. int EQ2Emu_lua_IsOpen(lua_State* state) {
  11557. if (!lua_interface)
  11558. return 0;
  11559. Spawn* widget = lua_interface->GetSpawn(state);
  11560. lua_interface->ResetFunctionStack(state);
  11561. if (widget && widget->IsWidget())
  11562. {
  11563. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  11564. return 1;
  11565. }
  11566. return 0;
  11567. }
  11568. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  11569. if (!lua_interface)
  11570. return 0;
  11571. sint32 min = lua_interface->GetSInt32Value(state);
  11572. sint32 max = lua_interface->GetSInt32Value(state, 2);
  11573. lua_interface->ResetFunctionStack(state);
  11574. sint32 result = MakeRandomInt(min, max);
  11575. lua_interface->SetSInt32Value(state, result);
  11576. return 1;
  11577. }
  11578. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  11579. if (!lua_interface)
  11580. return 0;
  11581. float min = lua_interface->GetFloatValue(state);
  11582. float max = lua_interface->GetFloatValue(state, 2);
  11583. lua_interface->ResetFunctionStack(state);
  11584. float result = MakeRandomFloat(min, max);
  11585. lua_interface->SetFloatValue(state, result);
  11586. return 1;
  11587. }
  11588. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  11589. if (!lua_interface)
  11590. return 0;
  11591. Spawn* spawn = lua_interface->GetSpawn(state);
  11592. int32 value = lua_interface->GetInt32Value(state, 2);
  11593. lua_interface->ResetFunctionStack(state);
  11594. if(!spawn)
  11595. {
  11596. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11597. lua_interface->SetBooleanValue(state, false);
  11598. return 1;
  11599. }
  11600. spawn->AddIconValue(value);
  11601. lua_interface->SetBooleanValue(state, true);
  11602. return 1;
  11603. }
  11604. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  11605. if (!lua_interface)
  11606. return 0;
  11607. Spawn* spawn = lua_interface->GetSpawn(state);
  11608. int32 value = lua_interface->GetInt32Value(state, 2);
  11609. lua_interface->ResetFunctionStack(state);
  11610. if(!spawn)
  11611. {
  11612. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11613. lua_interface->SetBooleanValue(state, false);
  11614. return 1;
  11615. }
  11616. spawn->RemoveIconValue(value);
  11617. lua_interface->SetBooleanValue(state, true);
  11618. return 1;
  11619. }
  11620. int EQ2Emu_lua_GetShardID(lua_State* state) {
  11621. Spawn* npc = lua_interface->GetSpawn(state);
  11622. lua_interface->ResetFunctionStack(state);
  11623. if (npc && npc->IsNPC()) {
  11624. NPC* shard = (NPC*)npc;
  11625. int32 shardid = shard->GetShardID();
  11626. lua_interface->SetInt32Value(state, shardid);
  11627. return 1;
  11628. }
  11629. lua_interface->SetInt32Value(state, 0);
  11630. return 1;
  11631. }
  11632. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  11633. Spawn* npc = lua_interface->GetSpawn(state);
  11634. lua_interface->ResetFunctionStack(state);
  11635. if (npc && npc->IsNPC()) {
  11636. NPC* shard = (NPC*)npc;
  11637. int32 charid = shard->GetShardCharID();
  11638. lua_interface->SetInt32Value(state, charid);
  11639. return 1;
  11640. }
  11641. lua_interface->SetInt32Value(state, 0);
  11642. return 1;
  11643. }
  11644. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  11645. Spawn* npc = lua_interface->GetSpawn(state);
  11646. lua_interface->ResetFunctionStack(state);
  11647. if (npc && npc->IsNPC()) {
  11648. NPC* shard = (NPC*)npc;
  11649. int64 timestamp = shard->GetShardCreatedTimestamp();
  11650. lua_interface->SetSInt64Value(state, timestamp);
  11651. return 1;
  11652. }
  11653. lua_interface->SetSInt64Value(state, 0);
  11654. return 1;
  11655. }
  11656. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  11657. if (!lua_interface)
  11658. return 0;
  11659. int32 shardid = lua_interface->GetInt32Value(state);
  11660. lua_interface->ResetFunctionStack(state);
  11661. if(shardid < 1)
  11662. lua_interface->SetBooleanValue(state, false);
  11663. else
  11664. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  11665. return 1;
  11666. }
  11667. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  11668. if (!lua_interface)
  11669. return 0;
  11670. Spawn* spawn = lua_interface->GetSpawn(state);
  11671. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11672. if (spawn) {
  11673. spawn->PauseMovement(delay_in_ms);
  11674. }
  11675. lua_interface->ResetFunctionStack(state);
  11676. return 0;
  11677. }
  11678. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11679. if (!lua_interface)
  11680. return 0;
  11681. Spawn* spawn = lua_interface->GetSpawn(state);
  11682. if (spawn) {
  11683. spawn->ResetMovement();
  11684. }
  11685. lua_interface->ResetFunctionStack(state);
  11686. return 0;
  11687. }
  11688. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11689. Player* player = (Player*)lua_interface->GetSpawn(state);
  11690. int8 level = lua_interface->GetInt8Value(state, 2);
  11691. lua_interface->ResetFunctionStack(state);
  11692. if (player && player->IsPlayer() && level > 0) {
  11693. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11694. return 1;
  11695. }
  11696. return 0;
  11697. }
  11698. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11699. Player* player = (Player*)lua_interface->GetSpawn(state);
  11700. int8 level = lua_interface->GetInt8Value(state, 2);
  11701. lua_interface->ResetFunctionStack(state);
  11702. if (player && player->IsPlayer() && level > 0) {
  11703. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11704. return 1;
  11705. }
  11706. return 0;
  11707. }
  11708. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11709. ZoneServer* zone = lua_interface->GetZone(state);
  11710. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11711. lua_interface->ResetFunctionStack(state);
  11712. if (zone) {
  11713. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11714. if (spawn) {
  11715. lua_interface->SetSpawnValue(state, spawn);
  11716. return 1;
  11717. }
  11718. }
  11719. return 0;
  11720. }
  11721. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11722. if (!lua_interface)
  11723. return 0;
  11724. Spawn* spawn = lua_interface->GetSpawn(state);
  11725. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11726. lua_interface->ResetFunctionStack(state);
  11727. bool res = false;
  11728. if(spawn && spawn->IsTransportSpawn())
  11729. {
  11730. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11731. spawn->SetRailID(rail_id);
  11732. res = true;
  11733. }
  11734. else if (!spawn) {
  11735. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11736. }
  11737. else if(!spawn->IsTransportSpawn()) {
  11738. 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());
  11739. }
  11740. lua_interface->SetBooleanValue(state, res);
  11741. return 1;
  11742. }
  11743. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11744. if (!lua_interface)
  11745. return 0;
  11746. ZoneServer* zone = lua_interface->GetZone(state);
  11747. lua_interface->ResetFunctionStack(state);
  11748. if (zone) {
  11749. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11750. return 1;
  11751. }
  11752. return 0;
  11753. }
  11754. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11755. if (!lua_interface)
  11756. return 0;
  11757. Spawn* spawn = lua_interface->GetSpawn(state);
  11758. lua_interface->ResetFunctionStack(state);
  11759. if (spawn) {
  11760. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11761. return 1;
  11762. }
  11763. return 0;
  11764. }
  11765. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11766. if (!lua_interface)
  11767. return 0;
  11768. Spawn* player = lua_interface->GetSpawn(state);
  11769. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11770. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11771. lua_interface->ResetFunctionStack(state);
  11772. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11773. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11774. }
  11775. else if(!zoneID) {
  11776. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11777. }
  11778. else
  11779. {
  11780. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11781. return 1;
  11782. }
  11783. return 0;
  11784. }
  11785. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11786. if (!lua_interface)
  11787. return 0;
  11788. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11789. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11790. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11791. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11792. lua_interface->ResetFunctionStack(state);
  11793. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11794. world.GetWorldTimeStruct()->year = newYear;
  11795. world.GetWorldTimeStruct()->month = newMonth;
  11796. world.GetWorldTimeStruct()->hour = newHour;
  11797. world.GetWorldTimeStruct()->minute = newMinute;
  11798. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11799. return 0;
  11800. }
  11801. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11802. if (!lua_interface)
  11803. return 0;
  11804. lua_interface->ResetFunctionStack(state);
  11805. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11806. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11807. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11808. return 1;
  11809. }
  11810. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11811. if (!lua_interface)
  11812. return 0;
  11813. lua_interface->ResetFunctionStack(state);
  11814. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11815. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11816. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11817. return 1;
  11818. }
  11819. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11820. if (!lua_interface)
  11821. return 0;
  11822. lua_interface->ResetFunctionStack(state);
  11823. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11824. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11825. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11826. return 1;
  11827. }
  11828. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11829. if (!lua_interface)
  11830. return 0;
  11831. lua_interface->ResetFunctionStack(state);
  11832. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11833. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11834. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11835. return 1;
  11836. }
  11837. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11838. if (!lua_interface)
  11839. return 0;
  11840. lua_interface->ResetFunctionStack(state);
  11841. world.SendTimeUpdate();
  11842. return 0;
  11843. }
  11844. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11845. bool update_result = false;
  11846. Faction* faction = 0;
  11847. Spawn* spawn = lua_interface->GetSpawn(state);
  11848. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11849. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11850. lua_interface->ResetFunctionStack(state);
  11851. if(!spawn || !spawn->IsPlayer()) {
  11852. lua_interface->LogError("LUA ChangeFaction command error: player is not valid");
  11853. return 0;
  11854. }
  11855. Player* player = (Player*)spawn;
  11856. Client* client = player->GetClient();
  11857. if (faction_id > 0) {
  11858. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11859. if(hasfaction == 0) {
  11860. //they do not have the faction. Lets get the default value and feed it in.
  11861. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11862. //add the default faction for the player.
  11863. player->SetFactionValue(faction_id, defaultfaction);
  11864. }
  11865. if(increase >= 0) {
  11866. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11867. faction = master_faction_list.GetFaction(faction_id);
  11868. if(faction && update_result)
  11869. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11870. else if(faction)
  11871. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11872. lua_interface->SetBooleanValue(state, true);
  11873. return 1;
  11874. }
  11875. if(increase < 0){
  11876. //change the negative to a positive, since thats how decreasefaction() likes it.
  11877. increase *= -1;
  11878. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11879. faction = master_faction_list.GetFaction(faction_id);
  11880. if(faction && update_result)
  11881. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11882. else if(faction)
  11883. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11884. lua_interface->SetBooleanValue(state, true);
  11885. return 1;
  11886. }
  11887. }
  11888. lua_interface->SetBooleanValue(state, false);
  11889. return 1;
  11890. }
  11891. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11892. bool hascoin = 0;
  11893. Player* player = (Player*)lua_interface->GetSpawn(state);
  11894. int32 coins = lua_interface->GetInt32Value(state, 2);
  11895. lua_interface->ResetFunctionStack(state);
  11896. if (player && player->IsPlayer()) {
  11897. hascoin = player->HasCoins(coins);
  11898. if(hascoin == 0) {
  11899. lua_interface->SetBooleanValue(state, false);
  11900. return 1;
  11901. }
  11902. if(hascoin == 1) {
  11903. lua_interface->SetBooleanValue(state, true);
  11904. return 1;
  11905. }
  11906. }
  11907. return 0;
  11908. }
  11909. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11910. int32 loot_tier = 0;
  11911. Spawn* spawn = lua_interface->GetSpawn(state);
  11912. lua_interface->ResetFunctionStack(state);
  11913. if (spawn) {
  11914. loot_tier = spawn->GetLootTier();
  11915. lua_interface->SetInt32Value(state, loot_tier);
  11916. return 1;
  11917. }
  11918. return 0;
  11919. }
  11920. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11921. if (!lua_interface)
  11922. return 0;
  11923. Spawn* spawn = lua_interface->GetSpawn(state);
  11924. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11925. lua_interface->ResetFunctionStack(state);
  11926. if (spawn) {
  11927. spawn->SetLootTier(loot_tier);
  11928. lua_interface->SetBooleanValue(state, true);
  11929. return 1;
  11930. }
  11931. lua_interface->SetBooleanValue(state, false);
  11932. return 1;
  11933. }
  11934. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11935. int32 loot_drop_type = 0;
  11936. Spawn* spawn = lua_interface->GetSpawn(state);
  11937. lua_interface->ResetFunctionStack(state);
  11938. if (spawn) {
  11939. loot_drop_type = spawn->GetLootDropType();
  11940. lua_interface->SetInt32Value(state, loot_drop_type);
  11941. return 1;
  11942. }
  11943. return 0;
  11944. }
  11945. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11946. if (!lua_interface)
  11947. return 0;
  11948. Spawn* spawn = lua_interface->GetSpawn(state);
  11949. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11950. lua_interface->ResetFunctionStack(state);
  11951. if (spawn) {
  11952. spawn->SetLootDropType(loot_drop_type);
  11953. lua_interface->SetBooleanValue(state, true);
  11954. return 1;
  11955. }
  11956. lua_interface->SetBooleanValue(state, false);
  11957. return 1;
  11958. }
  11959. int EQ2Emu_lua_DamageEquippedItems(lua_State* state) {
  11960. if (!lua_interface)
  11961. return 0;
  11962. Spawn* spawn = lua_interface->GetSpawn(state);
  11963. int8 damage_amount = lua_interface->GetInt32Value(state, 2);
  11964. if(damage_amount > 100) {
  11965. damage_amount = 100;
  11966. }
  11967. if (!spawn) {
  11968. lua_interface->LogError("%s: LUA DamageEquippedItems command error: spawn is not valid", lua_interface->GetScriptName(state));
  11969. lua_interface->ResetFunctionStack(state);
  11970. return 0;
  11971. }
  11972. lua_interface->ResetFunctionStack(state);
  11973. if (spawn->IsPlayer()) {
  11974. if (((Player*)spawn)->GetClient() && ((Player*)spawn)->DamageEquippedItems(damage_amount, ((Player*)spawn)->GetClient()))
  11975. lua_interface->SetBooleanValue(state, true);
  11976. else
  11977. lua_interface->SetBooleanValue(state, false);
  11978. }
  11979. else {
  11980. lua_interface->SetBooleanValue(state, false);
  11981. }
  11982. return 1;
  11983. }
  11984. int EQ2Emu_lua_CreateWidgetRegion(lua_State* state) {
  11985. ZoneServer* zone = lua_interface->GetZone(state);
  11986. int32 version = lua_interface->GetInt32Value(state, 2);
  11987. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11988. if(region_map == nullptr) {
  11989. lua_interface->LogError("%s: LUA CreateWidgetRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11990. lua_interface->ResetFunctionStack(state);
  11991. return 0;
  11992. }
  11993. string region_name = lua_interface->GetStringValue(state, 3);
  11994. string env_name = lua_interface->GetStringValue(state, 4);
  11995. int32 grid_id = lua_interface->GetInt32Value(state, 5);
  11996. int32 widget_id = lua_interface->GetInt32Value(state, 6);
  11997. float dist = lua_interface->GetFloatValue(state, 7);
  11998. region_map->InsertRegionNode(zone, version, region_name, env_name, grid_id, widget_id, dist);
  11999. lua_interface->ResetFunctionStack(state);
  12000. lua_interface->SetBooleanValue(state, true);
  12001. return 1;
  12002. }
  12003. int EQ2Emu_lua_RemoveRegion(lua_State* state) {
  12004. ZoneServer* zone = lua_interface->GetZone(state);
  12005. int32 version = lua_interface->GetInt32Value(state, 2);
  12006. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  12007. if(region_map == nullptr) {
  12008. lua_interface->LogError("%s: LUA RemoveRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  12009. lua_interface->ResetFunctionStack(state);
  12010. return 0;
  12011. }
  12012. string region_name = lua_interface->GetStringValue(state, 3);
  12013. region_map->RemoveRegionNode(region_name);
  12014. lua_interface->ResetFunctionStack(state);
  12015. lua_interface->SetBooleanValue(state, true);
  12016. return 1;
  12017. }
  12018. int EQ2Emu_lua_SetPlayerPOVGhost(lua_State* state) {
  12019. Client* client = nullptr;
  12020. Spawn* player = lua_interface->GetSpawn(state);
  12021. if (!player) {
  12022. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not valid");
  12023. lua_interface->SetBooleanValue(state, false);
  12024. lua_interface->ResetFunctionStack(state);
  12025. return 1;
  12026. }
  12027. if (!player->IsPlayer()) {
  12028. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
  12029. lua_interface->SetBooleanValue(state, false);
  12030. lua_interface->ResetFunctionStack(state);
  12031. return 1;
  12032. }
  12033. client = player->GetClient();
  12034. if (!client) {
  12035. lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
  12036. lua_interface->SetBooleanValue(state, false);
  12037. lua_interface->ResetFunctionStack(state);
  12038. return 1;
  12039. }
  12040. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  12041. bool success_sight = client->SetPlayerPOVGhost(spawn);
  12042. lua_interface->ResetFunctionStack(state);
  12043. lua_interface->SetBooleanValue(state, success_sight);
  12044. return 1;
  12045. }
  12046. int EQ2Emu_lua_SetCastOnAggroComplete(lua_State* state) {
  12047. if (!lua_interface)
  12048. return 0;
  12049. bool result = false;
  12050. Spawn* spawn = lua_interface->GetSpawn(state);
  12051. bool cast_completed = (lua_interface->GetInt8Value(state, 2) == 1);
  12052. lua_interface->ResetFunctionStack(state);
  12053. if (!spawn)
  12054. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  12055. else if (!spawn->IsNPC())
  12056. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  12057. else
  12058. {
  12059. ((NPC*)spawn)->cast_on_aggro_completed = cast_completed;
  12060. result = true;
  12061. }
  12062. lua_interface->SetBooleanValue(state, result);
  12063. return 1;
  12064. }
  12065. int EQ2Emu_lua_IsCastOnAggroComplete(lua_State* state) {
  12066. if (!lua_interface)
  12067. return 0;
  12068. bool result = false;
  12069. Spawn* spawn = lua_interface->GetSpawn(state);
  12070. lua_interface->ResetFunctionStack(state);
  12071. if (!spawn)
  12072. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  12073. else if (!spawn->IsNPC())
  12074. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  12075. else
  12076. {
  12077. if(((NPC*)spawn)->cast_on_aggro_completed)
  12078. result = true;
  12079. }
  12080. lua_interface->SetBooleanValue(state, result);
  12081. return 1;
  12082. }
  12083. int EQ2Emu_lua_AddRecipeBookToPlayer(lua_State* state) {
  12084. Client* client = nullptr;
  12085. Spawn* player = lua_interface->GetSpawn(state);
  12086. int32 recipe_book_id = lua_interface->GetInt32Value(state, 2);
  12087. lua_interface->ResetFunctionStack(state);
  12088. if (!player) {
  12089. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not valid");
  12090. lua_interface->SetBooleanValue(state, false);
  12091. return 1;
  12092. }
  12093. if (!player->IsPlayer()) {
  12094. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not a player");
  12095. lua_interface->SetBooleanValue(state, false);
  12096. return 1;
  12097. }
  12098. client = player->GetClient();
  12099. if (!client) {
  12100. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: could not find client");
  12101. lua_interface->SetBooleanValue(state, false);
  12102. return 1;
  12103. }
  12104. bool result = client->AddRecipeBookToPlayer(recipe_book_id);
  12105. lua_interface->SetBooleanValue(state, result);
  12106. return 1;
  12107. }
  12108. int EQ2Emu_lua_RemoveRecipeFromPlayer(lua_State* state) {
  12109. Client* client = nullptr;
  12110. Spawn* player = lua_interface->GetSpawn(state);
  12111. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  12112. lua_interface->ResetFunctionStack(state);
  12113. if (!player) {
  12114. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not valid");
  12115. lua_interface->SetBooleanValue(state, false);
  12116. return 1;
  12117. }
  12118. if (!player->IsPlayer()) {
  12119. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not a player");
  12120. lua_interface->SetBooleanValue(state, false);
  12121. return 1;
  12122. }
  12123. client = player->GetClient();
  12124. if (!client) {
  12125. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: could not find client");
  12126. lua_interface->SetBooleanValue(state, false);
  12127. return 1;
  12128. }
  12129. bool result = client->RemoveRecipeFromPlayer(recipe_id);
  12130. lua_interface->SetBooleanValue(state, result);
  12131. return 1;
  12132. }
  12133. int EQ2Emu_lua_ReplaceWidgetFromClient(lua_State* state) {
  12134. Client* client = nullptr;
  12135. Spawn* player = lua_interface->GetSpawn(state);
  12136. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12137. bool delete_widget = (lua_interface->GetInt8Value(state, 3) == 1);
  12138. // rest are all optional fields
  12139. float x = lua_interface->GetFloatValue(state, 4);
  12140. float y = lua_interface->GetFloatValue(state, 5);
  12141. float z = lua_interface->GetFloatValue(state, 6);
  12142. int32 grid_id = lua_interface->GetInt32Value(state, 7);
  12143. lua_interface->ResetFunctionStack(state);
  12144. if (!player) {
  12145. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not valid");
  12146. lua_interface->SetBooleanValue(state, false);
  12147. return 1;
  12148. }
  12149. if (!player->IsPlayer()) {
  12150. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not a player");
  12151. lua_interface->SetBooleanValue(state, false);
  12152. return 1;
  12153. }
  12154. if(!player->GetZone()) {
  12155. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  12156. lua_interface->SetBooleanValue(state, false);
  12157. return 1;
  12158. }
  12159. client = player->GetClient();
  12160. if (!client) {
  12161. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: could not find client");
  12162. lua_interface->SetBooleanValue(state, false);
  12163. return 1;
  12164. }
  12165. if(!client->IsReadyForUpdates()) {
  12166. lua_interface->LogError("LUA ReplaceWidgetFromClient command failed: client has not signaled sys_client_avatar_ready");
  12167. lua_interface->SetBooleanValue(state, false);
  12168. return 1;
  12169. }
  12170. client->SendReplaceWidget(widget_id, delete_widget, x, y, z, grid_id);
  12171. lua_interface->SetBooleanValue(state, true);
  12172. return 1;
  12173. }
  12174. int EQ2Emu_lua_RemoveWidgetFromSpawnMap(lua_State* state) {
  12175. Client* client = nullptr;
  12176. Spawn* spawn = lua_interface->GetSpawn(state);
  12177. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12178. lua_interface->ResetFunctionStack(state);
  12179. if (!spawn) {
  12180. lua_interface->LogError("LUA RemoveWidgetFromSpawnMap command error: spawn is not valid");
  12181. lua_interface->SetBooleanValue(state, false);
  12182. return 1;
  12183. }
  12184. if(!spawn->GetZone()) {
  12185. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  12186. lua_interface->SetBooleanValue(state, false);
  12187. return 1;
  12188. }
  12189. spawn->AddIgnoredWidget(widget_id);
  12190. lua_interface->SetBooleanValue(state, true);
  12191. return 1;
  12192. }
  12193. int EQ2Emu_lua_RemoveWidgetFromZoneMap(lua_State* state) {
  12194. ZoneServer* zone = lua_interface->GetZone(state);
  12195. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12196. lua_interface->ResetFunctionStack(state);
  12197. if(!zone) {
  12198. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: zone is not valid");
  12199. lua_interface->SetBooleanValue(state, false);
  12200. return 1;
  12201. }
  12202. if(!zone->IsLoading()) {
  12203. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: can only be called during zone loading, in preinit_zone_script ZoneScript function");
  12204. lua_interface->SetBooleanValue(state, false);
  12205. return 1;
  12206. }
  12207. zone->AddIgnoredWidget(widget_id);
  12208. lua_interface->SetBooleanValue(state, true);
  12209. return 1;
  12210. }
  12211. int EQ2Emu_lua_SendHearCast(lua_State* state) {
  12212. if (!lua_interface)
  12213. return 0;
  12214. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  12215. Spawn* spawn = lua_interface->GetSpawn(state);
  12216. int32 spell_visual_id = lua_interface->GetInt32Value(state, 2);
  12217. int16 cast_time = lua_interface->GetInt16Value(state, 3);
  12218. Spawn* caster = lua_interface->GetSpawn(state, 4);
  12219. Spawn* target = lua_interface->GetSpawn(state, 5);
  12220. lua_interface->ResetFunctionStack(state);
  12221. if(spell && spawn && spawn->IsEntity()) {
  12222. ZoneServer* zone = spawn->GetZone();
  12223. if(zone) {
  12224. zone->SendCastSpellPacket(spell, caster && caster->IsEntity() ? (Entity*)caster : (Entity*)spawn, spell_visual_id, cast_time > 0 ? cast_time : 0xFFFF);
  12225. }
  12226. }
  12227. else if (spawn) {
  12228. if (spawn->IsPlayer()) {
  12229. Client* client = ((Player*)spawn)->GetClient();
  12230. if (client) {
  12231. client->SendHearCast(caster ? caster : client->GetPlayer(), target ? target : client->GetPlayer(), spell_visual_id, cast_time);
  12232. }
  12233. }
  12234. }
  12235. return 0;
  12236. }
  12237. int EQ2Emu_lua_GetCharacterFlag(lua_State* state) {
  12238. if (!lua_interface)
  12239. return 0;
  12240. Spawn* player = lua_interface->GetSpawn(state);
  12241. sint32 flag_id = lua_interface->GetSInt32Value(state, 2);
  12242. lua_interface->ResetFunctionStack(state);
  12243. if (!player) {
  12244. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  12245. return 0;
  12246. }
  12247. if (!player->IsPlayer()) {
  12248. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  12249. return 0;
  12250. }
  12251. bool ret = ((Player*)player)->get_character_flag(flag_id);
  12252. lua_interface->SetBooleanValue(state, ret);
  12253. return 1;
  12254. }
  12255. int EQ2Emu_lua_ToggleCharacterFlag(lua_State* state) {
  12256. if (!lua_interface)
  12257. return 0;
  12258. Spawn* player = lua_interface->GetSpawn(state);
  12259. sint32 flag_id = lua_interface->GetSInt32Value(state, 2);
  12260. lua_interface->ResetFunctionStack(state);
  12261. if (!player) {
  12262. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  12263. return 0;
  12264. }
  12265. if (!player->IsPlayer()) {
  12266. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  12267. return 0;
  12268. }
  12269. ((Player*)player)->toggle_character_flag(flag_id);
  12270. return 0;
  12271. }
  12272. int EQ2Emu_lua_GetSpellInitialTarget(lua_State* state) {
  12273. LuaSpell* spell = lua_interface->GetSpell(state);
  12274. if(!spell) {
  12275. spell = lua_interface->GetCurrentSpell(state);
  12276. }
  12277. lua_interface->ResetFunctionStack(state);
  12278. if (spell) {
  12279. if(!spell->caster) {
  12280. lua_interface->LogError("%s: LUA GetSpellTarget command error, caster does not exist.", lua_interface->GetScriptName(state));
  12281. return 0;
  12282. }
  12283. if(!spell->caster->GetZone()) {
  12284. lua_interface->LogError("%s: LUA GetSpellTarget command error, zone does not exist.", lua_interface->GetScriptName(state));
  12285. return 0;
  12286. }
  12287. Spawn* spawn = spell->caster->GetZone()->GetSpawnByID(spell->initial_target);
  12288. if (spawn) {
  12289. lua_interface->SetSpawnValue(state, spawn);
  12290. return 1;
  12291. }
  12292. else {
  12293. 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);
  12294. }
  12295. }
  12296. return 0;
  12297. }
  12298. int EQ2Emu_lua_DespawnByLocationID(lua_State* state) {
  12299. ZoneServer* zone = lua_interface->GetZone(state);
  12300. int32 location_id = lua_interface->GetInt32Value(state, 2);
  12301. int32 delay = lua_interface->GetInt32Value(state, 3);
  12302. lua_interface->ResetFunctionStack(state);
  12303. if (zone) {
  12304. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  12305. if (spawn) {
  12306. vector<Spawn*> groupMembers;
  12307. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  12308. groupMembers = *spawn->GetSpawnGroup();
  12309. for (int32 i = 0; i < groupMembers.size(); i++) {
  12310. Spawn* member = groupMembers.at(i);
  12311. if(member && !member->IsPlayer() && member != spawn) {
  12312. member->GetZone()->Despawn(member, delay);
  12313. }
  12314. }
  12315. }
  12316. zone->Despawn(spawn, delay);
  12317. lua_interface->SetBooleanValue(state, true);
  12318. return 1;
  12319. }
  12320. }
  12321. lua_interface->SetBooleanValue(state, false);
  12322. return 1;
  12323. }