LuaFunctions.cpp 430 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "Rules/Rules.h"
  29. #include "../common/Log.h"
  30. #include <math.h>
  31. #include "HeroicOp/HeroicOp.h"
  32. #include "RaceTypes/RaceTypes.h"
  33. #include "ClientPacketFunctions.h"
  34. #include "Transmute.h"
  35. #include "Titles.h"
  36. #include <boost/algorithm/string/predicate.hpp>
  37. #include <sstream>
  38. #include <boost/algorithm/string.hpp>
  39. extern MasterFactionList master_faction_list;
  40. extern WorldDatabase database;
  41. extern LuaInterface* lua_interface;
  42. extern ConfigReader configReader;
  43. extern MasterQuestList master_quest_list;
  44. extern MasterItemList master_item_list;
  45. extern MasterSpellList master_spell_list;
  46. extern World world;
  47. extern Commands commands;
  48. extern ZoneList zone_list;
  49. extern Races races;
  50. extern Classes classes;
  51. extern Variables variables;
  52. extern MasterSkillList master_skill_list;
  53. extern MasterHeroicOPList master_ho_list;
  54. extern MasterRaceTypeList race_types_list;
  55. extern MasterLanguagesList master_languages_list;
  56. extern MasterTitlesList master_titles_list;
  57. extern RuleManager rule_manager;
  58. vector<string> ParseString(string strVal, char delim) {
  59. stringstream ss(strVal);
  60. vector<string> ret;
  61. while (ss.good())
  62. {
  63. string substr;
  64. getline(ss, substr, delim);
  65. ret.push_back(substr);
  66. }
  67. return ret;
  68. }
  69. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  70. stringstream ss(strVal);
  71. vector<unsigned int> ret;
  72. while (ss.good())
  73. {
  74. string substr;
  75. getline(ss, substr, delim);
  76. stringstream valss(substr);
  77. unsigned int val = 0;
  78. valss >> val;
  79. ret.push_back(val);
  80. }
  81. return ret;
  82. }
  83. map<string, signed int> ParseStringMap(string strVal, char delim) {
  84. vector<string> pairs = ParseString(strVal, delim);
  85. vector<string>::iterator itr;
  86. map<string, signed int> ret;
  87. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  88. vector<string> keyvaluepair = ParseString(*itr, ':');
  89. if (keyvaluepair.size() == 2) {
  90. stringstream valss(keyvaluepair[1]);
  91. int32 val = 0;
  92. valss >> val;
  93. ret[keyvaluepair[0]] = val;
  94. }
  95. }
  96. return ret;
  97. }
  98. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  99. vector<string> pairs = ParseString(strVal, delim);
  100. vector<string>::iterator itr;
  101. map<unsigned int, unsigned short> ret;
  102. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  103. vector<string> keyvaluepair = ParseString(*itr, ':');
  104. int32 key = 0;
  105. if (keyvaluepair.size() > 0) {
  106. stringstream keyss(keyvaluepair[0]);
  107. keyss >> key;
  108. }
  109. if (keyvaluepair.size() == 1) {
  110. ret[key] = 1;
  111. }
  112. else if (keyvaluepair.size() == 2) {
  113. stringstream valss(keyvaluepair[1]);
  114. unsigned short val = 0;
  115. valss >> val;
  116. ret[key] = val;
  117. }
  118. }
  119. return ret;
  120. }
  121. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  122. vector<string> pairs = ParseString(strVal, delim);
  123. vector<string>::iterator itr;
  124. map<unsigned int, signed int> ret;
  125. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  126. vector<string> keyvaluepair = ParseString(*itr, ':');
  127. int32 key = 0;
  128. if (keyvaluepair.size() > 0) {
  129. stringstream keyss(keyvaluepair[0]);
  130. keyss >> key;
  131. }
  132. if (keyvaluepair.size() == 1) {
  133. ret[key] = 1;
  134. }
  135. else if (keyvaluepair.size() == 2) {
  136. stringstream valss(keyvaluepair[1]);
  137. signed int val = 0;
  138. valss >> val;
  139. ret[key] = val;
  140. }
  141. }
  142. return ret;
  143. }
  144. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  145. if (!lua_interface)
  146. return 0;
  147. Spawn* spawn = lua_interface->GetSpawn(state);
  148. string mp3_string = lua_interface->GetStringValue(state, 2);
  149. string text_string = lua_interface->GetStringValue(state, 3);
  150. string emote_string = lua_interface->GetStringValue(state, 4);
  151. int32 key1 = lua_interface->GetInt32Value(state, 5);
  152. int32 key2 = lua_interface->GetInt32Value(state, 6);
  153. Spawn* player = lua_interface->GetSpawn(state, 7);
  154. int8 language = lua_interface->GetInt8Value(state, 8);
  155. lua_interface->ResetFunctionStack(state);
  156. if (spawn) {
  157. const char* mp3 = 0;
  158. const char* text = 0;
  159. const char* emote = 0;
  160. if (mp3_string.length() > 0)
  161. mp3 = mp3_string.c_str();
  162. if (text_string.length() > 0)
  163. text = text_string.c_str();
  164. if (emote_string.length() > 0)
  165. emote = emote_string.c_str();
  166. Client* client = 0;
  167. if (player && player->IsPlayer())
  168. client = ((Player*)player)->GetClient();
  169. if (client) {
  170. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  171. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  172. }
  173. else
  174. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  175. }
  176. return 0;
  177. }
  178. int EQ2Emu_lua_PlayFlavorID(lua_State* state) {
  179. if (!lua_interface)
  180. return 0;
  181. Spawn* spawn = lua_interface->GetSpawn(state);
  182. int8 type = lua_interface->GetInt8Value(state, 2);
  183. int32 id = lua_interface->GetInt32Value(state, 3);
  184. int16 index = lua_interface->GetInt16Value(state, 4);
  185. Spawn* player = lua_interface->GetSpawn(state, 5);
  186. int8 language = lua_interface->GetInt8Value(state, 6);
  187. lua_interface->ResetFunctionStack(state);
  188. if (spawn) {
  189. Client* client = 0;
  190. if (player && player->IsPlayer())
  191. client = ((Player*)player)->GetClient();
  192. if (client) {
  193. VoiceOverStruct non_garble, garble;
  194. bool garble_success = false;
  195. bool success = world.FindVoiceOver(type, id, index, &non_garble, &garble_success, &garble);
  196. client->SendPlayFlavor(spawn, language, &non_garble, &garble, success, garble_success);
  197. }
  198. else
  199. spawn->GetZone()->PlayFlavorID(spawn, type, id, index, language);
  200. }
  201. return 0;
  202. }
  203. int EQ2Emu_lua_PlaySound(lua_State* state) {
  204. if (!lua_interface)
  205. return 0;
  206. Spawn* spawn = lua_interface->GetSpawn(state);
  207. string sound_string = lua_interface->GetStringValue(state, 2);
  208. float x = lua_interface->GetFloatValue(state, 3);
  209. float y = lua_interface->GetFloatValue(state, 4);
  210. float z = lua_interface->GetFloatValue(state, 5);
  211. Spawn* player = lua_interface->GetSpawn(state, 6);
  212. lua_interface->ResetFunctionStack(state);
  213. if (spawn && sound_string.length() > 0) {
  214. Client* client = 0;
  215. if (player && player->IsPlayer())
  216. client = ((Player*)player)->GetClient();
  217. if (client)
  218. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  219. else
  220. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  221. }
  222. return 0;
  223. }
  224. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  225. if (!lua_interface)
  226. return 0;
  227. Spawn* spawn = lua_interface->GetSpawn(state);
  228. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  229. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  230. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  231. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  232. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  233. lua_interface->ResetFunctionStack(state);
  234. if (!spawn) {
  235. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  236. return 0;
  237. }
  238. if (quest_id > 0) {
  239. //Add this quest to the list of required quests for this spawn
  240. spawn->SetQuestsRequired(quest_id, quest_step);
  241. //If private spawn value set
  242. if (private_spawn) {
  243. //Set the spawn to be private when not granted access through this quest
  244. spawn->AddAllowAccessSpawn(spawn);
  245. spawn->SetPrivateQuestSpawn(true);
  246. }
  247. //This value allows access after a quest step, or the whole quest has been completed
  248. if (continued_access)
  249. spawn->SetQuestsRequiredContinuedAccess(true);
  250. //This value will override vis_flags in the vis packet
  251. if (flag_override > 0)
  252. spawn->SetQuestsRequiredOverride(flag_override);
  253. }
  254. return 0;
  255. }
  256. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  257. if (!lua_interface)
  258. return 0;
  259. Spawn* spawn = lua_interface->GetSpawn(state);
  260. float max_distance = lua_interface->GetFloatValue(state, 2);
  261. string variable = lua_interface->GetStringValue(state, 3);
  262. string value = lua_interface->GetStringValue(state, 4);
  263. lua_interface->ResetFunctionStack(state);
  264. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  265. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  266. return 0;
  267. }
  268. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  269. if (!lua_interface)
  270. return 0;
  271. Client* client = 0;
  272. Spawn* player = lua_interface->GetSpawn(state);
  273. float intensity = lua_interface->GetFloatValue(state, 2);
  274. int8 direction = lua_interface->GetInt8Value(state, 3);
  275. lua_interface->ResetFunctionStack(state);
  276. if (!player) {
  277. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  278. return 0;
  279. }
  280. if (!player->IsPlayer()) {
  281. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  282. return 0;
  283. }
  284. if (player->GetZone())
  285. client = ((Player*)player)->GetClient();
  286. if (!client) {
  287. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  288. return 0;
  289. }
  290. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  291. if (packet) {
  292. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  293. v1 = *(float *)(a1 + 4);
  294. if ( v1 > 0.0 )
  295. v2 = fminf(v1, 1.0);
  296. else
  297. v2 = 0.1;
  298. */
  299. packet->setDataByName("intensity", intensity);
  300. if ( client->GetVersion() > 546 )
  301. packet->setDataByName("direction", direction);
  302. client->QueuePacket(packet->serialize());
  303. safe_delete(packet);
  304. }
  305. return 0;
  306. }
  307. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* dead = lua_interface->GetSpawn(state);
  311. Spawn* killer = lua_interface->GetSpawn(state, 2);
  312. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  313. lua_interface->ResetFunctionStack(state);
  314. if (dead && dead->Alive() && dead->GetZone())
  315. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  316. return 0;
  317. }
  318. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  319. if (!lua_interface)
  320. return 0;
  321. Spawn* spawn = lua_interface->GetSpawn(state);
  322. float max_distance = lua_interface->GetFloatValue(state, 2);
  323. bool include_players = lua_interface->GetInt8Value(state, 3);
  324. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  325. lua_interface->ResetFunctionStack(state);
  326. if (max_distance > 0 && spawn && spawn->GetZone())
  327. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  328. return 0;
  329. }
  330. int EQ2Emu_lua_Despawn(lua_State* state) {
  331. if (!lua_interface)
  332. return 0;
  333. Spawn* spawn = lua_interface->GetSpawn(state);
  334. int32 delay = lua_interface->GetInt32Value(state, 2);
  335. lua_interface->ResetFunctionStack(state);
  336. if (spawn && spawn->GetZone())
  337. spawn->GetZone()->Despawn(spawn, delay);
  338. return 0;
  339. }
  340. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  341. if (!lua_interface)
  342. return 0;
  343. Spawn* spawn = lua_interface->GetSpawn(state);
  344. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  345. lua_interface->ResetFunctionStack(state);
  346. if (spawn) {
  347. spawn->info_changed = true;
  348. spawn->SetShowHandIcon(displayHandIcon);
  349. }
  350. return 0;
  351. }
  352. //this function is used to force an update packet to be sent.
  353. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  354. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  355. if (!lua_interface)
  356. return 0;
  357. Spawn* spawn = lua_interface->GetSpawn(state);
  358. lua_interface->ResetFunctionStack(state);
  359. if (spawn) {
  360. spawn->vis_changed = true;
  361. spawn->GetZone()->AddChangedSpawn(spawn);
  362. }
  363. return 0;
  364. }
  365. //this function is used to force an update packet to be sent.
  366. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  367. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  368. if (!lua_interface)
  369. return 0;
  370. Spawn* spawn = lua_interface->GetSpawn(state);
  371. lua_interface->ResetFunctionStack(state);
  372. if (spawn) {
  373. spawn->info_changed = true;
  374. spawn->GetZone()->AddChangedSpawn(spawn);
  375. }
  376. return 0;
  377. }
  378. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  379. if (!lua_interface)
  380. return 0;
  381. Spawn* spawn = lua_interface->GetSpawn(state);
  382. int32 new_state = lua_interface->GetInt32Value(state, 2);
  383. Spawn* player = lua_interface->GetSpawn(state, 3);
  384. lua_interface->ResetFunctionStack(state);
  385. if (spawn) {
  386. if(player)
  387. {
  388. if(player->IsPlayer())
  389. {
  390. Client* client = ((Player*)player)->GetClient();
  391. if(client)
  392. {
  393. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  394. lua_interface->SetBooleanValue(state, true);
  395. return 1;
  396. }
  397. else
  398. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument does not have active client.", spawn->GetName());
  399. }
  400. else
  401. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument is NOT a player.", spawn->GetName());
  402. }
  403. else
  404. {
  405. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  406. lua_interface->SetBooleanValue(state, true);
  407. return 1;
  408. }
  409. }
  410. lua_interface->SetBooleanValue(state, false);
  411. return 1;
  412. }
  413. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  414. if (!lua_interface)
  415. return 0;
  416. Spawn* spawn = lua_interface->GetSpawn(state);
  417. string variable = lua_interface->GetStringValue(state, 2);
  418. string value = lua_interface->GetStringValue(state, 3);
  419. bool no_update = lua_interface->GetBooleanValue(state, 4); // send update is true by default in SetSpawnCommand, so allow user to specify 'true' to disable send update.
  420. bool temporary_flag = true;
  421. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  422. int8 index = 0;
  423. if(num_args >= 5)
  424. {
  425. temporary_flag = lua_interface->GetBooleanValue(state, 5); // this used to be false, but no one bothered to set it temporary, we don't need to update the DB
  426. index = lua_interface->GetInt8Value(state, 6);
  427. }
  428. lua_interface->ResetFunctionStack(state);
  429. int32 type = commands.GetSpawnSetType(variable);
  430. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  431. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  432. return 0;
  433. }
  434. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  435. if (!lua_interface)
  436. return 0;
  437. Spawn* spawn = lua_interface->GetSpawn(state);
  438. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  439. lua_interface->ResetFunctionStack(state);
  440. if (spawn && spawn_id > 0) {
  441. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  442. if (closest_spawn) {
  443. lua_interface->SetSpawnValue(state, closest_spawn);
  444. return 1;
  445. }
  446. }
  447. return 0;
  448. }
  449. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  450. if (!lua_interface)
  451. return 0;
  452. vector<Spawn*> spawns;
  453. int32 position = 0;
  454. if(lua_istable(state, 1)) {
  455. size_t len = lua_rawlen(state, 1);
  456. for(int i=1;i <= len; i++)
  457. {
  458. // get the entry to stack
  459. lua_rawgeti(state, 1, i);
  460. int Top = lua_gettop(state);
  461. if(lua_islightuserdata(state,Top)) {
  462. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  463. if(data->IsSpawn()) {
  464. spawns.push_back(data->spawn);
  465. }
  466. }
  467. // remove entry from stack
  468. lua_pop(state,1);
  469. }
  470. }
  471. position = lua_interface->GetInt32Value(state, 2);
  472. lua_interface->ResetFunctionStack(state);
  473. Spawn* spawn = 0;
  474. if(position < spawns.size()) {
  475. spawn = spawns.at(position);
  476. }
  477. if(spawn) {
  478. lua_interface->SetSpawnValue(state, spawn);
  479. return 1;
  480. }
  481. return 0;
  482. }
  483. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  484. if (!lua_interface)
  485. return 0;
  486. vector<Spawn*> spawns;
  487. if(lua_istable(state, 1)) {
  488. size_t len = lua_rawlen(state, 1);
  489. for(int i=1;i <= len; i++)
  490. {
  491. // get the entry to stack
  492. lua_rawgeti(state, 1, i);
  493. int Top = lua_gettop(state);
  494. if(lua_islightuserdata(state,Top)) {
  495. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  496. if(data->IsSpawn()) {
  497. spawns.push_back(data->spawn);
  498. }
  499. }
  500. // remove entry from stack
  501. lua_pop(state,1);
  502. }
  503. }
  504. lua_interface->ResetFunctionStack(state);
  505. lua_interface->SetInt32Value(state, spawns.size());
  506. return 1;
  507. }
  508. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  509. if (!lua_interface)
  510. return 0;
  511. Spawn* spawn = lua_interface->GetSpawn(state);
  512. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  513. lua_interface->ResetFunctionStack(state);
  514. if (spawn) {
  515. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  516. if (spawns.size() > 0) {
  517. lua_createtable(state, spawns.size(), 0);
  518. int newTable = lua_gettop(state);
  519. for (int32 i = 0; i < spawns.size(); i++) {
  520. lua_interface->SetSpawnValue(state, spawns.at(i));
  521. lua_rawseti(state, newTable, i + 1);
  522. }
  523. return 1;
  524. }
  525. }
  526. return 0;
  527. }
  528. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  529. if (!lua_interface)
  530. return 0;
  531. Spawn* spawn = lua_interface->GetSpawn(state);
  532. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  533. lua_interface->ResetFunctionStack(state);
  534. if (spawn) {
  535. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  536. if (spawns.size() > 0) {
  537. lua_createtable(state, spawns.size(), 0);
  538. int newTable = lua_gettop(state);
  539. for (int32 i = 0; i < spawns.size(); i++) {
  540. lua_interface->SetSpawnValue(state, spawns.at(i));
  541. lua_rawseti(state, newTable, i + 1);
  542. }
  543. return 1;
  544. }
  545. }
  546. return 0;
  547. }
  548. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  549. if (!lua_interface)
  550. return 0;
  551. Spawn* spawn = lua_interface->GetSpawn(state);
  552. lua_interface->ResetFunctionStack(state);
  553. if (spawn) {
  554. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  555. if (spawns.size() > 0) {
  556. lua_createtable(state, spawns.size(), 0);
  557. int newTable = lua_gettop(state);
  558. for (int32 i = 0; i < spawns.size(); i++) {
  559. lua_interface->SetSpawnValue(state, spawns.at(i));
  560. lua_rawseti(state, newTable, i + 1);
  561. }
  562. return 1;
  563. }
  564. }
  565. return 0;
  566. }
  567. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  568. if (!lua_interface)
  569. return 0;
  570. string variable_name = lua_interface->GetStringValue(state);
  571. lua_interface->ResetFunctionStack(state);
  572. Variable* var = variables.FindVariable(variable_name);
  573. if (var) {
  574. lua_interface->SetStringValue(state, var->GetValue());
  575. return 1;
  576. }
  577. return 0;
  578. }
  579. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  580. if (!lua_interface)
  581. return 0;
  582. int32 total_coins = lua_interface->GetInt32Value(state);
  583. lua_interface->ResetFunctionStack(state);
  584. if (total_coins == 0) {
  585. lua_interface->SetStringValue(state, "0 copper");
  586. return 1;
  587. }
  588. char tmp[64] = { 0 };
  589. string message = "";
  590. int32 val = 0;
  591. if (total_coins >= 1000000) {
  592. val = total_coins / 1000000;
  593. total_coins -= 1000000 * val;
  594. sprintf(tmp, " %u Platinum", val);
  595. message.append(tmp);
  596. memset(tmp, 0, 64);
  597. }
  598. if (total_coins >= 10000) {
  599. val = total_coins / 10000;
  600. total_coins -= 10000 * val;
  601. sprintf(tmp, " %u Gold", val);
  602. message.append(tmp);
  603. memset(tmp, 0, 64);
  604. }
  605. if (total_coins >= 100) {
  606. val = total_coins / 100;
  607. total_coins -= 100 * val;
  608. sprintf(tmp, " %u Silver", val);
  609. message.append(tmp);
  610. memset(tmp, 0, 64);
  611. }
  612. if (total_coins > 0) {
  613. sprintf(tmp, " %u Copper", (int32)total_coins);
  614. message.append(tmp);
  615. }
  616. lua_interface->SetStringValue(state, message.c_str());
  617. return 1;
  618. }
  619. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  620. ZoneServer* zone = lua_interface->GetZone(state);
  621. int32 group_id = lua_interface->GetInt32Value(state, 2);
  622. lua_interface->ResetFunctionStack(state);
  623. if (zone) {
  624. Spawn* spawn = zone->GetSpawnGroup(group_id);
  625. if (spawn) {
  626. lua_interface->SetSpawnValue(state, spawn);
  627. return 1;
  628. }
  629. }
  630. return 0;
  631. }
  632. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  633. ZoneServer* zone = lua_interface->GetZone(state);
  634. int32 location_id = lua_interface->GetInt32Value(state, 2);
  635. lua_interface->ResetFunctionStack(state);
  636. if (zone) {
  637. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  638. if (spawn) {
  639. lua_interface->SetSpawnValue(state, spawn);
  640. return 1;
  641. }
  642. }
  643. return 0;
  644. }
  645. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  646. Spawn* spawn = lua_interface->GetSpawn(state);
  647. lua_interface->ResetFunctionStack(state);
  648. if (spawn) {
  649. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  650. return 1;
  651. }
  652. return 0;
  653. }
  654. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  655. Spawn* spawn = lua_interface->GetSpawn(state);
  656. lua_interface->ResetFunctionStack(state);
  657. if (spawn) {
  658. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  659. return 1;
  660. }
  661. return 0;
  662. }
  663. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  664. if (!lua_interface)
  665. return 0;
  666. Spawn* spawn = lua_interface->GetSpawn(state);
  667. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  668. lua_interface->ResetFunctionStack(state);
  669. if (spawn) {
  670. spawn->SetSpawnGroupID(new_group_id);
  671. lua_interface->SetBooleanValue(state, true);
  672. return 1;
  673. }
  674. lua_interface->SetBooleanValue(state, false);
  675. return 1;
  676. }
  677. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  678. if (!lua_interface)
  679. return 0;
  680. Spawn* spawn = lua_interface->GetSpawn(state);
  681. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  682. lua_interface->ResetFunctionStack(state);
  683. if (spawn) {
  684. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  685. lua_interface->SetBooleanValue(state, true);
  686. return 1;
  687. }
  688. lua_interface->SetBooleanValue(state, false);
  689. return 1;
  690. }
  691. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  692. Spawn* spawn = lua_interface->GetSpawn(state);
  693. lua_interface->ResetFunctionStack(state);
  694. if (spawn) {
  695. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  696. return 1;
  697. }
  698. return 0;
  699. }
  700. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  701. Spawn* spawn = lua_interface->GetSpawn(state);
  702. lua_interface->ResetFunctionStack(state);
  703. if (spawn) {
  704. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  705. return 1;
  706. }
  707. return 0;
  708. }
  709. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  710. Player* player = (Player*)lua_interface->GetSpawn(state);
  711. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  712. lua_interface->ResetFunctionStack(state);
  713. if (player && player->IsPlayer() && faction_id > 0) {
  714. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  715. return 1;
  716. }
  717. return 0;
  718. }
  719. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  720. if (!lua_interface)
  721. return 0;
  722. Spawn* spawn = lua_interface->GetSpawn(state);
  723. int32 value = lua_interface->GetInt32Value(state, 2);
  724. lua_interface->ResetFunctionStack(state);
  725. if (spawn) {
  726. spawn->SetFactionID(value);
  727. }
  728. return 0;
  729. }
  730. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  731. Spawn* spawn = lua_interface->GetSpawn(state);
  732. lua_interface->ResetFunctionStack(state);
  733. if (spawn) {
  734. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  735. return 1;
  736. }
  737. return 0;
  738. }
  739. int EQ2Emu_lua_GetGender(lua_State* state) {
  740. Spawn* spawn = lua_interface->GetSpawn(state);
  741. lua_interface->ResetFunctionStack(state);
  742. if (spawn) {
  743. lua_interface->SetInt32Value(state, spawn->GetGender());
  744. return 1;
  745. }
  746. return 0;
  747. }
  748. int EQ2Emu_lua_GetTarget(lua_State* state) {
  749. Spawn* spawn = lua_interface->GetSpawn(state);
  750. lua_interface->ResetFunctionStack(state);
  751. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  752. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  753. return 1;
  754. }
  755. return 0;
  756. }
  757. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  758. if (!lua_interface)
  759. return 0;
  760. Spawn* spawn = lua_interface->GetSpawn(state);
  761. string mp3_string = lua_interface->GetStringValue(state, 2);
  762. int32 key1 = lua_interface->GetInt32Value(state, 3);
  763. int32 key2 = lua_interface->GetInt32Value(state, 4);
  764. Spawn* player = lua_interface->GetSpawn(state, 5);
  765. lua_interface->ResetFunctionStack(state);
  766. if (spawn && mp3_string.length() > 0) {
  767. Client* client = 0;
  768. if (player && player->IsPlayer())
  769. client = ((Player*)player)->GetClient();
  770. if (client) {
  771. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  772. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  773. }
  774. else
  775. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  776. }
  777. return 0;
  778. }
  779. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  780. if (!lua_interface)
  781. return 0;
  782. Spawn* spawn = lua_interface->GetSpawn(state);
  783. lua_interface->ResetFunctionStack(state);
  784. if (spawn) {
  785. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  786. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  787. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  788. return 3;
  789. }
  790. return 0;
  791. }
  792. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  793. if (!lua_interface)
  794. return 0;
  795. Spawn* spawn = lua_interface->GetSpawn(state);
  796. if (spawn) {
  797. int32 item_id = lua_interface->GetInt32Value(state, 2);
  798. lua_interface->ResetFunctionStack(state);
  799. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  800. return 1;
  801. }
  802. lua_interface->ResetFunctionStack(state);
  803. return 0;
  804. }
  805. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  806. if (!lua_interface)
  807. return 0;
  808. Spawn* spawn = lua_interface->GetSpawn(state);
  809. if (spawn && spawn->IsEntity()) {
  810. int32 item_id = lua_interface->GetInt32Value(state, 2);
  811. int16 charges = lua_interface->GetInt16Value(state, 3);
  812. if (charges == 0)
  813. charges = 1;
  814. ((Entity*)spawn)->AddLootItem(item_id, charges);
  815. }
  816. lua_interface->ResetFunctionStack(state);
  817. return 0;
  818. }
  819. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  820. if (!lua_interface)
  821. return 0;
  822. Spawn* spawn = lua_interface->GetSpawn(state);
  823. if (spawn && spawn->IsEntity()) {
  824. int32 item_id = lua_interface->GetInt32Value(state, 2);
  825. Item* item = spawn->LootItem(item_id);
  826. lua_interface->SetLuaUserDataStale(item);
  827. safe_delete(item);
  828. }
  829. lua_interface->ResetFunctionStack(state);
  830. return 0;
  831. }
  832. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  833. if (!lua_interface)
  834. return 0;
  835. Spawn* spawn = lua_interface->GetSpawn(state);
  836. if (spawn) {
  837. int32 val = lua_interface->GetInt32Value(state, 2);
  838. spawn->AddLootCoins(val);
  839. }
  840. lua_interface->ResetFunctionStack(state);
  841. return 0;
  842. }
  843. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  844. if (!lua_interface)
  845. return 0;
  846. Spawn* entity = lua_interface->GetSpawn(state);
  847. Spawn* player = lua_interface->GetSpawn(state, 2);
  848. if (entity && player && player->IsPlayer()) {
  849. int32 coins = lua_interface->GetInt32Value(state, 3);
  850. vector<Item*>* items = 0;
  851. int i = 0;
  852. int32 item_id = 0;
  853. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  854. if (items == 0)
  855. items = new vector<Item*>;
  856. if (master_item_list.GetItem(item_id))
  857. items->push_back(master_item_list.GetItem(item_id));
  858. i++;
  859. }
  860. Client* client = 0;
  861. client = ((Player*)player)->GetClient();
  862. if (client)
  863. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  864. if(coins > 0)
  865. entity->AddLootCoins(coins);
  866. safe_delete(items);
  867. }
  868. lua_interface->ResetFunctionStack(state);
  869. return 0;
  870. }
  871. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  872. if (!lua_interface)
  873. return 0;
  874. Spawn* entity = lua_interface->GetSpawn(state);
  875. Spawn* player = lua_interface->GetSpawn(state, 2);
  876. int32 item_id = lua_interface->GetInt32Value(state, 3);
  877. lua_interface->ResetFunctionStack(state);
  878. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  879. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  880. return 1;
  881. }
  882. return 0;
  883. }
  884. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  885. if (!lua_interface)
  886. return 0;
  887. Spawn* entity = lua_interface->GetSpawn(state);
  888. Spawn* player = lua_interface->GetSpawn(state, 2);
  889. lua_interface->ResetFunctionStack(state);
  890. if (entity && player && player->IsPlayer()) {
  891. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  892. return 1;
  893. }
  894. return 0;
  895. }
  896. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  897. if (!lua_interface)
  898. return 0;
  899. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  900. lua_interface->SetLuaUserDataStale(conversation);
  901. safe_delete(conversation);
  902. lua_interface->ResetFunctionStack(state);
  903. conversation = new vector<ConversationOption>();
  904. lua_interface->SetConversationValue(state, conversation);
  905. return 1;
  906. }
  907. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  908. if (!lua_interface)
  909. return 0;
  910. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  911. if (conversation) {
  912. ConversationOption conv_option;
  913. conv_option.option = lua_interface->GetStringValue(state, 2);
  914. conv_option.function = lua_interface->GetStringValue(state, 3);
  915. if (conv_option.option.length() > 0)
  916. conversation->push_back(conv_option);
  917. }
  918. lua_interface->ResetFunctionStack(state);
  919. return 0;
  920. }
  921. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  922. if (!lua_interface)
  923. return 0;
  924. Spawn* npc = lua_interface->GetSpawn(state);
  925. Spawn* player = lua_interface->GetSpawn(state, 2);
  926. lua_interface->ResetFunctionStack(state);
  927. if (npc && player && player->IsPlayer() && player->GetZone()) {
  928. Client* client = ((Player*)player)->GetClient();
  929. if (client) {
  930. int32 conversation_id = client->GetConversationID(npc, 0);
  931. client->CloseDialog(conversation_id);
  932. }
  933. }
  934. return 0;
  935. }
  936. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  937. if (!lua_interface)
  938. return 0;
  939. Item* item = lua_interface->GetItem(state);
  940. Spawn* player = lua_interface->GetSpawn(state, 2);
  941. lua_interface->ResetFunctionStack(state);
  942. if (item && player && player->IsPlayer() && player->GetZone()) {
  943. Client* client = ((Player*)player)->GetClient();
  944. if (client) {
  945. int32 conversation_id = client->GetConversationID(0, item);
  946. client->CloseDialog(conversation_id);
  947. }
  948. }
  949. return 0;
  950. }
  951. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  952. if (!lua_interface)
  953. return 0;
  954. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  955. Spawn* spawn = 0;
  956. Item* item = 0;
  957. int8 type = lua_interface->GetInt8Value(state, 2);
  958. if (type == 1 || type == 3)
  959. spawn = lua_interface->GetSpawn(state, 3);
  960. else if (type == 2 || type == 4)
  961. item = lua_interface->GetItem(state, 3);
  962. Spawn* player = lua_interface->GetSpawn(state, 4);
  963. string text = lua_interface->GetStringValue(state, 5);
  964. string mp3 = lua_interface->GetStringValue(state, 6);
  965. int32 key1 = lua_interface->GetInt32Value(state, 7);
  966. int32 key2 = lua_interface->GetInt32Value(state, 8);
  967. int8 language = lua_interface->GetInt8Value(state, 9);
  968. int numargs = lua_interface->GetNumberOfArgs(state);
  969. int8 can_close = 1;
  970. if(numargs > 9)
  971. can_close = lua_interface->GetInt32Value(state, 10);
  972. lua_interface->ResetFunctionStack(state);
  973. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  974. Client* client = ((Player*)player)->GetClient();
  975. if (client) {
  976. if (spawn) {
  977. // Need to do this so the function works the same as it did before
  978. if (type == 1)
  979. type++;
  980. if (mp3.length() > 0)
  981. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2, language, can_close);
  982. else
  983. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), nullptr, 0, 0, language, can_close);
  984. }
  985. else {
  986. if (mp3.length() > 0)
  987. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2, language, can_close);
  988. else
  989. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, nullptr, 0, 0, language, can_close);
  990. }
  991. }
  992. }
  993. lua_interface->SetLuaUserDataStale(conversation);
  994. safe_delete(conversation);
  995. return 0;
  996. }
  997. int EQ2Emu_lua_StartConversation(lua_State* state) {
  998. if (!lua_interface)
  999. return 0;
  1000. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  1001. Spawn* source = lua_interface->GetSpawn(state, 2);
  1002. Spawn* player = lua_interface->GetSpawn(state, 3);
  1003. string text = lua_interface->GetStringValue(state, 4);
  1004. string mp3 = lua_interface->GetStringValue(state, 5);
  1005. int32 key1 = lua_interface->GetInt32Value(state, 6);
  1006. int32 key2 = lua_interface->GetInt32Value(state, 7);
  1007. int8 language = lua_interface->GetInt32Value(state, 8);
  1008. int numargs = lua_interface->GetNumberOfArgs(state);
  1009. int8 can_close = 1;
  1010. if(numargs > 8)
  1011. can_close = lua_interface->GetInt32Value(state, 9);
  1012. lua_interface->ResetFunctionStack(state);
  1013. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1014. Client* client = ((Player*)player)->GetClient();
  1015. if (mp3.length() > 0)
  1016. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2, language, can_close);
  1017. else
  1018. client->DisplayConversation(source, 1, conversation, text.c_str(), nullptr, 0, 0, language, can_close);
  1019. lua_interface->SetLuaUserDataStale(conversation);
  1020. safe_delete(conversation);
  1021. }
  1022. else
  1023. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in StartConversation, potentially AddConversationOption not yet called or the StartConversation arguments are incorrect, text: %s, conversationSize: %i.", source ? source->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  1024. return 0;
  1025. }
  1026. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1027. if (!lua_interface)
  1028. return 0;
  1029. Spawn* spawn = lua_interface->GetSpawn(state);
  1030. float distance = lua_interface->GetFloatValue(state, 2);
  1031. string in_range_function = lua_interface->GetStringValue(state, 3);
  1032. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1033. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1034. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1035. return 0;
  1036. }
  1037. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1038. ZoneServer* zone = lua_interface->GetZone(state);
  1039. float x = lua_interface->GetFloatValue(state, 2);
  1040. float y = lua_interface->GetFloatValue(state, 3);
  1041. float z = lua_interface->GetFloatValue(state, 4);
  1042. float max_variation = lua_interface->GetFloatValue(state, 5);
  1043. string in_range_function = lua_interface->GetStringValue(state, 6);
  1044. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1045. lua_interface->ResetFunctionStack(state);
  1046. if (zone && in_range_function.length() > 0)
  1047. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1048. return 0;
  1049. }
  1050. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1051. if (!lua_interface)
  1052. return 0;
  1053. Spawn* spawn = lua_interface->GetSpawn(state);
  1054. if (spawn && spawn->IsEntity()) {
  1055. int32 val = lua_interface->GetInt32Value(state, 2);
  1056. ((Entity*)spawn)->SetLootCoins(val);
  1057. }
  1058. lua_interface->ResetFunctionStack(state);
  1059. return 0;
  1060. }
  1061. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1062. if (!lua_interface)
  1063. return 0;
  1064. Spawn* spawn = lua_interface->GetSpawn(state);
  1065. lua_interface->ResetFunctionStack(state);
  1066. if (spawn && spawn->IsEntity()) {
  1067. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1068. return 1;
  1069. }
  1070. return 0;
  1071. }
  1072. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1073. if (!lua_interface)
  1074. return 0;
  1075. Spawn* spawn = lua_interface->GetSpawn(state);
  1076. float x = lua_interface->GetFloatValue(state, 2);
  1077. float y = lua_interface->GetFloatValue(state, 3);
  1078. float z = lua_interface->GetFloatValue(state, 4);
  1079. float speed = lua_interface->GetFloatValue(state, 5);
  1080. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1081. string function = lua_interface->GetStringValue(state, 7);
  1082. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1083. float heading = lua_interface->GetFloatValue(state, 8);
  1084. if (spawn) {
  1085. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1086. spawn->GetZone()->AddMovementNPC(spawn);
  1087. }
  1088. lua_interface->ResetFunctionStack(state);
  1089. return 0;
  1090. }
  1091. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1092. if (!lua_interface)
  1093. return 0;
  1094. Spawn* spawn = lua_interface->GetSpawn(state);
  1095. lua_interface->ResetFunctionStack(state);
  1096. if (spawn) {
  1097. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1098. return 1;
  1099. }
  1100. return 0;
  1101. }
  1102. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1103. if (!lua_interface)
  1104. return 0;
  1105. Spawn* spawn = lua_interface->GetSpawn(state);
  1106. lua_interface->ResetFunctionStack(state);
  1107. if (spawn && spawn->IsPlayer()) {
  1108. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1109. return 1;
  1110. }
  1111. lua_interface->SetInt32Value(state, 0);
  1112. return 1;
  1113. }
  1114. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1115. if (!lua_interface)
  1116. return 0;
  1117. Spawn* spawn = lua_interface->GetSpawn(state);
  1118. Spawn* target = lua_interface->GetSpawn(state, 2);
  1119. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1120. bool reset_action_state = true;
  1121. if(num_args > 2)
  1122. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1123. if (spawn && target) {
  1124. if (spawn->IsEntity())
  1125. // ((Entity*)spawn)->FaceTarget(target);
  1126. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1127. }
  1128. lua_interface->ResetFunctionStack(state);
  1129. return 0;
  1130. }
  1131. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1132. if (!lua_interface)
  1133. return 0;
  1134. Spawn* spawn = lua_interface->GetSpawn(state);
  1135. float x = lua_interface->GetFloatValue(state, 2);
  1136. float y = lua_interface->GetFloatValue(state, 3);
  1137. float z = lua_interface->GetFloatValue(state, 4);
  1138. float speed = lua_interface->GetFloatValue(state, 5);
  1139. string lua_function = lua_interface->GetStringValue(state, 6);
  1140. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1141. if (spawn) {
  1142. if (speed == 0)
  1143. speed = spawn->GetSpeed();
  1144. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1145. }
  1146. lua_interface->ResetFunctionStack(state);
  1147. return 0;
  1148. }
  1149. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1150. if (!lua_interface)
  1151. return 0;
  1152. Spawn* spawn = lua_interface->GetSpawn(state);
  1153. lua_interface->ResetFunctionStack(state);
  1154. if (spawn) {
  1155. spawn->ClearRunningLocations();
  1156. }
  1157. return 0;
  1158. }
  1159. int EQ2Emu_lua_Say(lua_State* state) {
  1160. if (!lua_interface)
  1161. return 0;
  1162. Spawn* spawn = lua_interface->GetSpawn(state);
  1163. string message = lua_interface->GetStringValue(state, 2);
  1164. Spawn* player = lua_interface->GetSpawn(state, 3);
  1165. float dist = lua_interface->GetFloatValue(state, 4);
  1166. int32 language = lua_interface->GetInt32Value(state, 5);
  1167. if (spawn && message.length() > 0) {
  1168. Client* client = 0;
  1169. if (player && player->IsPlayer())
  1170. client = ((Player*)player)->GetClient();
  1171. if (client)
  1172. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1173. else
  1174. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1175. }
  1176. lua_interface->ResetFunctionStack(state);
  1177. return 0;
  1178. }
  1179. int EQ2Emu_lua_Shout(lua_State* state) {
  1180. if (!lua_interface)
  1181. return 0;
  1182. Spawn* spawn = lua_interface->GetSpawn(state);
  1183. string message = lua_interface->GetStringValue(state, 2);
  1184. Spawn* player = lua_interface->GetSpawn(state, 3);
  1185. float dist = lua_interface->GetFloatValue(state, 4);
  1186. int32 language = lua_interface->GetInt32Value(state, 5);
  1187. if (spawn && message.length() > 0) {
  1188. Client* client = 0;
  1189. if (player && player->IsPlayer())
  1190. client = ((Player*)player)->GetClient();
  1191. if (client)
  1192. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1193. else
  1194. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1195. }
  1196. lua_interface->ResetFunctionStack(state);
  1197. return 0;
  1198. }
  1199. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1200. if (!lua_interface)
  1201. return 0;
  1202. Spawn* spawn = lua_interface->GetSpawn(state);
  1203. string message = lua_interface->GetStringValue(state, 2);
  1204. Spawn* player = lua_interface->GetSpawn(state, 3);
  1205. float dist = lua_interface->GetFloatValue(state, 4);
  1206. int32 language = lua_interface->GetInt32Value(state, 5);
  1207. if (spawn && message.length() > 0) {
  1208. Client* client = 0;
  1209. if (player && player->IsPlayer())
  1210. client = ((Player*)player)->GetClient();
  1211. if (client)
  1212. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1213. else
  1214. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1215. }
  1216. lua_interface->ResetFunctionStack(state);
  1217. return 0;
  1218. }
  1219. int EQ2Emu_lua_Emote(lua_State* state) {
  1220. if (!lua_interface)
  1221. return 0;
  1222. Spawn* spawn = lua_interface->GetSpawn(state);
  1223. string message = lua_interface->GetStringValue(state, 2);
  1224. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1225. Spawn* player = lua_interface->GetSpawn(state, 4);
  1226. char* to = 0;
  1227. if (spawn2)
  1228. to = spawn2->GetName();
  1229. if (spawn && message.length() > 0) {
  1230. Client* client = 0;
  1231. if (player && player->IsPlayer())
  1232. client = ((Player*)player)->GetClient();
  1233. if (client)
  1234. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1235. else
  1236. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1237. }
  1238. lua_interface->ResetFunctionStack(state);
  1239. return 0;
  1240. }
  1241. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1242. if (!lua_interface)
  1243. return 0;
  1244. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1245. if(!luaspell || luaspell->resisted) {
  1246. lua_interface->ResetFunctionStack(state);
  1247. return 0;
  1248. }
  1249. Spawn* caster = luaspell->caster;
  1250. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1251. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1252. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1253. Spawn* target = lua_interface->GetSpawn(state, 4);
  1254. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1255. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1256. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1257. lua_interface->ResetFunctionStack(state);
  1258. boost::to_lower(heal_type);
  1259. if (caster && caster->IsEntity()) {
  1260. bool success = false;
  1261. luaspell->resisted = false;
  1262. if (target) {
  1263. float distance = caster->GetDistance(target, true);
  1264. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1265. success = true;
  1266. }
  1267. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1268. Spawn* target = 0;
  1269. ZoneServer* zone = luaspell->caster->GetZone();
  1270. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1271. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1272. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1273. float distance = caster->GetDistance(target, true);
  1274. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1275. }
  1276. }
  1277. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1278. success = true;
  1279. }
  1280. if (success) {
  1281. if (caster->GetZone())
  1282. caster->GetZone()->TriggerCharSheetTimer();
  1283. }
  1284. }
  1285. return 0;
  1286. }
  1287. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1288. if (!lua_interface)
  1289. return 0;
  1290. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1291. if(!luaspell || luaspell->resisted) {
  1292. lua_interface->ResetFunctionStack(state);
  1293. return 0;
  1294. }
  1295. Spawn* caster = luaspell->caster;
  1296. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1297. float percentage = lua_interface->GetFloatValue(state, 2);
  1298. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1299. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1300. Spawn* target = lua_interface->GetSpawn(state, 5);
  1301. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1302. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1303. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1304. lua_interface->ResetFunctionStack(state);
  1305. boost::to_lower(heal_type);
  1306. int32 min_heal = 0, max_heal = 0;
  1307. if (caster && caster->IsEntity() && target) {
  1308. if(percentage <= 0.0f)
  1309. {
  1310. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1311. return 0;
  1312. }
  1313. if(heal_type == "power")
  1314. {
  1315. if(current_value)
  1316. {
  1317. if(caster_value)
  1318. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1319. else
  1320. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1321. }
  1322. else
  1323. {
  1324. if(caster_value)
  1325. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1326. else
  1327. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1328. }
  1329. }
  1330. else
  1331. {
  1332. if(current_value)
  1333. {
  1334. if(caster_value)
  1335. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1336. else
  1337. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1338. }
  1339. else
  1340. {
  1341. if(caster_value)
  1342. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1343. else
  1344. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1345. }
  1346. }
  1347. bool success = false;
  1348. luaspell->resisted = false;
  1349. if (target) {
  1350. float distance = caster->GetDistance(target, true);
  1351. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1352. success = true;
  1353. }
  1354. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1355. Spawn* target = 0;
  1356. ZoneServer* zone = luaspell->caster->GetZone();
  1357. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1358. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1359. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1360. float distance = caster->GetDistance(target, true);
  1361. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1362. }
  1363. }
  1364. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1365. success = true;
  1366. }
  1367. if (success) {
  1368. if (caster->GetZone())
  1369. caster->GetZone()->TriggerCharSheetTimer();
  1370. }
  1371. }
  1372. return 0;
  1373. }
  1374. int EQ2Emu_lua_AddItem(lua_State* state) {
  1375. if (!lua_interface)
  1376. return 0;
  1377. Spawn* spawn = lua_interface->GetSpawn(state);
  1378. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1379. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1380. lua_interface->ResetFunctionStack(state);
  1381. // default of 1 quantity to add
  1382. if (quantity == 0)
  1383. quantity = 1;
  1384. if (spawn && spawn->IsPlayer()) {
  1385. Client* client = ((Player*)spawn)->GetClient();
  1386. if (client && item_id > 0) {
  1387. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1388. return 1;
  1389. }
  1390. }
  1391. lua_interface->SetBooleanValue(state, false);
  1392. return 1;
  1393. }
  1394. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1395. if (!lua_interface)
  1396. return 0;
  1397. Spawn* spawn = lua_interface->GetSpawn(state);
  1398. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1399. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1400. string location = lua_interface->GetStringValue(state, 4);
  1401. int16 item_count = lua_interface->GetInt16Value(state,5);
  1402. //devn00b: if we dont have a count, assume 1 item.
  1403. if(!item_count) {
  1404. item_count = 1;
  1405. }
  1406. lua_interface->ResetFunctionStack(state);
  1407. if (spawn && spawn->IsPlayer()) {
  1408. Client* client = ((Player*)spawn)->GetClient();
  1409. if (client && item_id > 0) {
  1410. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1411. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1412. else
  1413. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1414. if (send_messages) {
  1415. Item* item = master_item_list.GetItem(item_id);
  1416. if (item) {
  1417. if(item_count > 1) {
  1418. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1419. string popup_text1 = "You receive "+ item_count;
  1420. string popup_text2 = " " + item->name;
  1421. string popup_text = popup_text1 + popup_text2;
  1422. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1423. // return 1;
  1424. } else {
  1425. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1426. string popup_text = "You receive " + item->name;
  1427. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1428. }
  1429. }
  1430. }
  1431. return 1;
  1432. }
  1433. }
  1434. lua_interface->SetBooleanValue(state, false);
  1435. return 1;
  1436. }
  1437. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1438. Spawn* spawn = lua_interface->GetSpawn(state);
  1439. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1440. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1441. lua_interface->ResetFunctionStack(state);
  1442. // default of 1 to remove
  1443. if (quantity == 0)
  1444. quantity = 1;
  1445. Client* client;
  1446. Item* item;
  1447. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1448. if ((client = ((Player*)spawn)->GetClient())) {
  1449. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1450. if (client->RemoveItem(item, quantity)) {
  1451. lua_interface->SetBooleanValue(state, true);
  1452. return 1;
  1453. }
  1454. }
  1455. }
  1456. }
  1457. lua_interface->SetBooleanValue(state, false);
  1458. return 1;
  1459. }
  1460. int EQ2Emu_lua_HasItem(lua_State* state) {
  1461. Spawn* player = lua_interface->GetSpawn(state);
  1462. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1463. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1464. lua_interface->ResetFunctionStack(state);
  1465. if (player && player->IsPlayer()) {
  1466. bool hasItem = false;
  1467. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1468. if (!hasItem)
  1469. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1470. lua_interface->SetBooleanValue(state, hasItem);
  1471. return 1;
  1472. }
  1473. lua_interface->SetBooleanValue(state, false);
  1474. return 1;
  1475. }
  1476. int EQ2Emu_lua_Spawn(lua_State* state) {
  1477. if (!lua_interface)
  1478. return 0;
  1479. ZoneServer* zone = lua_interface->GetZone(state);
  1480. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1481. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1482. float x = lua_interface->GetFloatValue(state, 4);
  1483. float y = lua_interface->GetFloatValue(state, 5);
  1484. float z = lua_interface->GetFloatValue(state, 6);
  1485. float heading = lua_interface->GetFloatValue(state, 7);
  1486. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1487. Spawn* spawn = zone->GetSpawn(spawn_id);
  1488. if (!spawn)
  1489. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1490. else {
  1491. spawn->SetX(x);
  1492. spawn->SetZ(z);
  1493. spawn->SetY(y,true,true);
  1494. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1495. spawn->SetHeading(heading);
  1496. if (restricted_npc)
  1497. spawn->AddAllowAccessSpawn(spawn);
  1498. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1499. bool scriptActive = false;
  1500. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1501. scriptActive = true;
  1502. spawn->SetSpawnScript(string(spawn_script));
  1503. }
  1504. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1505. zone->AddSpawn(spawn);
  1506. if (scriptActive) {
  1507. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1508. }
  1509. lua_interface->ResetFunctionStack(state);
  1510. lua_interface->SetSpawnValue(state, spawn);
  1511. return 1;
  1512. }
  1513. }
  1514. else {
  1515. string output = "Invalid paramaters to LUA Spawn command: \n";
  1516. if (!zone)
  1517. output = output.append("\t").append("Missing zone reference. \n");
  1518. if (spawn_id == 0)
  1519. output = output.append("\t").append("Missing spawn_id.");
  1520. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1521. }
  1522. lua_interface->ResetFunctionStack(state);
  1523. return 0;
  1524. }
  1525. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1526. if (!lua_interface)
  1527. return 0;
  1528. ZoneServer* zone = lua_interface->GetZone(state);
  1529. lua_interface->ResetFunctionStack(state);
  1530. if (zone) {
  1531. lua_interface->SetStringValue(state, zone->GetZoneName());
  1532. return 1;
  1533. }
  1534. return 0;
  1535. }
  1536. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1537. if (!lua_interface)
  1538. return 0;
  1539. ZoneServer* zone = lua_interface->GetZone(state);
  1540. lua_interface->ResetFunctionStack(state);
  1541. if (zone) {
  1542. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1543. return 1;
  1544. }
  1545. return 0;
  1546. }
  1547. int EQ2Emu_lua_GetZone(lua_State* state) {
  1548. if (!lua_interface)
  1549. return 0;
  1550. int32 zone_id = lua_interface->GetInt32Value(state);
  1551. ZoneServer* zone = 0;
  1552. if (zone_id > 0)
  1553. zone = zone_list.Get(zone_id, true, false, false);
  1554. else {
  1555. string zone_name = lua_interface->GetStringValue(state);
  1556. if (zone_name.length() > 0) {
  1557. zone = zone_list.Get(zone_name.c_str(), true, false, false);
  1558. }
  1559. else {
  1560. Spawn* spawn = lua_interface->GetSpawn(state);
  1561. if (spawn)
  1562. zone = spawn->GetZone();
  1563. }
  1564. }
  1565. lua_interface->ResetFunctionStack(state);
  1566. if (zone) {
  1567. lua_interface->SetZoneValue(state, zone);
  1568. return 1;
  1569. }
  1570. return 0;
  1571. }
  1572. int EQ2Emu_lua_AddHate(lua_State* state) {
  1573. Spawn* entity = lua_interface->GetSpawn(state);
  1574. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1575. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1576. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1577. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1578. if(luaspell && luaspell->resisted) {
  1579. lua_interface->ResetFunctionStack(state);
  1580. return 0;
  1581. }
  1582. if (entity && entity->IsEntity() && amount != 0) {
  1583. if (luaspell && luaspell->caster) {
  1584. ZoneServer* zone = luaspell->caster->GetZone();
  1585. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1586. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1587. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1588. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1589. entity->CheckEncounterState((Entity*)spawn);
  1590. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1591. if (send_packet)
  1592. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1593. }
  1594. }
  1595. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1596. }
  1597. else if (npc && npc->IsNPC() && npc->GetZone()) {
  1598. entity->CheckEncounterState((Entity*)npc);
  1599. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1600. }
  1601. }
  1602. lua_interface->ResetFunctionStack(state);
  1603. return 0;
  1604. }
  1605. int EQ2Emu_lua_Zone(lua_State* state) {
  1606. if (!lua_interface)
  1607. return 0;
  1608. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1609. ZoneServer* zone = lua_interface->GetZone(state);
  1610. Spawn* player = lua_interface->GetSpawn(state, 2);
  1611. Client* client = 0;
  1612. if (player && player->IsPlayer())
  1613. client = ((Player*)player)->GetClient();
  1614. float x = lua_interface->GetFloatValue(state, 3);
  1615. float y = lua_interface->GetFloatValue(state, 4);
  1616. float z = lua_interface->GetFloatValue(state, 5);
  1617. float heading = lua_interface->GetFloatValue(state, 6);
  1618. if (zone && client) {
  1619. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1620. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1621. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1622. {
  1623. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1624. return 0;
  1625. }
  1626. if (x != 0 || y != 0 || z != 0) {
  1627. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1628. player->SetX(x);
  1629. player->SetY(y);
  1630. player->SetZ(z);
  1631. player->SetHeading(heading);
  1632. client->Zone(zone->GetZoneName(), false);
  1633. }
  1634. else
  1635. client->Zone(zone->GetZoneName());
  1636. }
  1637. else
  1638. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1639. lua_interface->ResetFunctionStack(state);
  1640. return 0;
  1641. }
  1642. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1643. if (!lua_interface)
  1644. return 0;
  1645. Spawn* spawn = lua_interface->GetSpawn(state);
  1646. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1647. if (spawn && spawn2)
  1648. spawn->AddAllowAccessSpawn(spawn2);
  1649. lua_interface->ResetFunctionStack(state);
  1650. return 0;
  1651. }
  1652. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1653. if (!lua_interface)
  1654. return 0;
  1655. Spawn* target = lua_interface->GetSpawn(state);
  1656. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1657. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1658. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1659. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1660. lua_interface->ResetFunctionStack(state);
  1661. if (!target) {
  1662. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1663. return 0;
  1664. }
  1665. if (!target->IsEntity()) {
  1666. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1667. return 0;
  1668. }
  1669. if (spell_id <= 0) {
  1670. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1671. return 0;
  1672. }
  1673. if (caster && !caster->IsEntity()) {
  1674. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1675. return 0;
  1676. }
  1677. if (spell_tier == 0)
  1678. spell_tier = 1;
  1679. if (!caster)
  1680. caster = target;
  1681. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1682. return 0;
  1683. }
  1684. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1685. if (!lua_interface)
  1686. return 0;
  1687. Spawn* target = lua_interface->GetSpawn(state);
  1688. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1689. if(!luaspell || luaspell->resisted) {
  1690. lua_interface->ResetFunctionStack(state);
  1691. lua_interface->SetBooleanValue(state, false);
  1692. return 1;
  1693. }
  1694. Spawn* caster = luaspell->caster;
  1695. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1696. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1697. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1698. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1699. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1700. //lua_interface->ResetFunctionStack(state);
  1701. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1702. vector<int16> faction_req;
  1703. vector<int16> race_req;
  1704. int32 class_req = 0;
  1705. int32 i = 0;
  1706. int8 f = 0;
  1707. int8 r = 0;
  1708. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1709. if (class_id < 100) {
  1710. class_req += pow(2.0, double(class_id - 1));
  1711. }
  1712. else if (class_id > 100 && class_id < 1000) {
  1713. race_req.push_back(class_id);
  1714. r++;
  1715. }
  1716. else {
  1717. faction_req.push_back(class_id);
  1718. f++;
  1719. }
  1720. i++;
  1721. }
  1722. lua_interface->ResetFunctionStack(state);
  1723. if (caster && caster->IsEntity()) {
  1724. bool race_match = false;
  1725. bool success = false;
  1726. luaspell->resisted = false;
  1727. if (luaspell->targets.size() > 0) {
  1728. ZoneServer* zone = luaspell->caster->GetZone();
  1729. Spawn* target = 0;
  1730. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1731. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1732. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1733. if (race_req.size() > 0) {
  1734. for (int8 i = 0; i < race_req.size(); i++) {
  1735. if(race_req[i] == target->GetRace() ||
  1736. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1737. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1738. race_match = true;
  1739. }
  1740. }
  1741. }
  1742. else
  1743. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1744. if (race_match == true) {
  1745. float distance = caster->GetDistance(target, true);
  1746. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1747. }
  1748. }
  1749. }
  1750. success = true;
  1751. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1752. }
  1753. else if (target) {
  1754. //check class and race/faction here
  1755. if (race_req.size() > 0) {
  1756. for (int8 i = 0; i < race_req.size(); i++) {
  1757. if(race_req[i] == target->GetRace() ||
  1758. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1759. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1760. race_match = true;
  1761. }
  1762. }
  1763. }
  1764. else
  1765. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1766. if (race_match == true) {
  1767. float distance = caster->GetDistance(target, true);
  1768. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1769. success = true;
  1770. }
  1771. }
  1772. lua_interface->SetBooleanValue(state, luaspell->has_damaged);
  1773. if (success) {
  1774. Spell* spell = luaspell->spell;
  1775. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1776. ((Player*)caster)->InCombat(true);
  1777. if (caster->GetZone())
  1778. caster->GetZone()->TriggerCharSheetTimer();
  1779. }
  1780. }
  1781. }
  1782. else {
  1783. lua_interface->SetBooleanValue(state, false);
  1784. }
  1785. return 1;
  1786. }
  1787. int EQ2Emu_lua_SpellDamageExt(lua_State* state) {
  1788. if (!lua_interface)
  1789. return 0;
  1790. Spawn* target = lua_interface->GetSpawn(state);
  1791. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1792. if(!luaspell || luaspell->resisted) {
  1793. lua_interface->ResetFunctionStack(state);
  1794. lua_interface->SetBooleanValue(state, false);
  1795. return 1;
  1796. }
  1797. Spawn* caster = luaspell->caster;
  1798. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1799. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1800. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1801. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1802. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1803. int32 override_packet_type = lua_interface->GetInt32Value(state, 7);
  1804. bool take_power = lua_interface->GetInt32Value(state, 8) == 1;
  1805. //lua_interface->ResetFunctionStack(state);
  1806. int32 class_id = lua_interface->GetInt32Value(state, 9);
  1807. vector<int16> faction_req;
  1808. vector<int16> race_req;
  1809. int32 class_req = 0;
  1810. int32 i = 0;
  1811. int8 f = 0;
  1812. int8 r = 0;
  1813. while ((class_id = lua_interface->GetInt32Value(state, 9 + i))) {
  1814. if (class_id < 100) {
  1815. class_req += pow(2.0, double(class_id - 1));
  1816. }
  1817. else if (class_id > 100 && class_id < 1000) {
  1818. race_req.push_back(class_id);
  1819. r++;
  1820. }
  1821. else {
  1822. faction_req.push_back(class_id);
  1823. f++;
  1824. }
  1825. i++;
  1826. }
  1827. lua_interface->ResetFunctionStack(state);
  1828. if (caster && caster->IsEntity()) {
  1829. bool race_match = false;
  1830. bool success = false;
  1831. luaspell->resisted = false;
  1832. if (luaspell->targets.size() > 0) {
  1833. ZoneServer* zone = luaspell->caster->GetZone();
  1834. Spawn* target = 0;
  1835. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1836. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1837. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1838. if (race_req.size() > 0) {
  1839. for (int8 i = 0; i < race_req.size(); i++) {
  1840. if(race_req[i] == target->GetRace() ||
  1841. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1842. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1843. race_match = true;
  1844. }
  1845. }
  1846. }
  1847. else
  1848. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1849. if (race_match == true) {
  1850. float distance = caster->GetDistance(target, true);
  1851. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power);
  1852. }
  1853. }
  1854. }
  1855. success = true;
  1856. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1857. }
  1858. else if (target) {
  1859. //check class and race/faction here
  1860. if (race_req.size() > 0) {
  1861. for (int8 i = 0; i < race_req.size(); i++) {
  1862. if(race_req[i] == target->GetRace() ||
  1863. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1864. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1865. race_match = true;
  1866. }
  1867. }
  1868. }
  1869. else
  1870. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1871. if (race_match == true) {
  1872. float distance = caster->GetDistance(target, true);
  1873. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power))
  1874. success = true;
  1875. }
  1876. }
  1877. lua_interface->SetBooleanValue(state, luaspell->has_damaged);
  1878. if (success) {
  1879. Spell* spell = luaspell->spell;
  1880. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1881. ((Player*)caster)->InCombat(true);
  1882. if (caster->GetZone())
  1883. caster->GetZone()->TriggerCharSheetTimer();
  1884. }
  1885. }
  1886. }
  1887. else {
  1888. lua_interface->SetBooleanValue(state, false);
  1889. }
  1890. return 1;
  1891. }
  1892. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1893. if (!lua_interface)
  1894. return 0;
  1895. Spawn* spawn = lua_interface->GetSpawn(state);
  1896. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1897. lua_interface->ResetFunctionStack(state);
  1898. if (spawn && value != 0) {
  1899. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1900. spawn->SetPower(spawn->GetTotalPower());
  1901. else
  1902. spawn->SetPower(spawn->GetPower() + value);
  1903. }
  1904. return 0;
  1905. }
  1906. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1907. if (!lua_interface)
  1908. return 0;
  1909. Spawn* spawn = lua_interface->GetSpawn(state);
  1910. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1911. lua_interface->ResetFunctionStack(state);
  1912. if (spawn && value != 0) {
  1913. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1914. spawn->SetHP(spawn->GetTotalHP());
  1915. else
  1916. spawn->SetHP(spawn->GetHP() + value);
  1917. }
  1918. return 0;
  1919. }
  1920. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1921. if (!lua_interface)
  1922. return 0;
  1923. Spawn* spawn = lua_interface->GetSpawn(state);
  1924. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1925. lua_interface->ResetFunctionStack(state);
  1926. if (spawn && value != 0) {
  1927. spawn->SetPower(spawn->GetPower() + value);
  1928. if (value > spawn->GetTotalHPBase())
  1929. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1930. }
  1931. return 0;
  1932. }
  1933. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1934. if (!lua_interface)
  1935. return 0;
  1936. Spawn* spawn = lua_interface->GetSpawn(state);
  1937. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1938. lua_interface->ResetFunctionStack(state);
  1939. if (spawn && value != 0) {
  1940. spawn->SetHP(spawn->GetHP() + value);
  1941. if (value > spawn->GetTotalHPBase())
  1942. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1943. }
  1944. return 0;
  1945. }
  1946. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1947. if (!lua_interface)
  1948. return 0;
  1949. Spawn* spawn = lua_interface->GetSpawn(state);
  1950. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1951. lua_interface->ResetFunctionStack(state);
  1952. if (spawn) {
  1953. spawn->SetHP(value);
  1954. if (value > spawn->GetTotalHPBase())
  1955. spawn->SetTotalHP(value);
  1956. }
  1957. return 0;
  1958. }
  1959. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1960. if (!lua_interface)
  1961. return 0;
  1962. Spawn* spawn = lua_interface->GetSpawn(state);
  1963. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1964. float value = lua_interface->GetFloatValue(state, 2);
  1965. lua_interface->ResetFunctionStack(state);
  1966. if (spawn && spawn->IsEntity() && value > 0)
  1967. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1968. if (spawn && spawn->IsPlayer())
  1969. ((Player*)spawn)->SetCharSheetChanged(true);
  1970. return 0;
  1971. }
  1972. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1973. if (!lua_interface)
  1974. return 0;
  1975. Spawn* spawn = lua_interface->GetSpawn(state);
  1976. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1977. lua_interface->ResetFunctionStack(state);
  1978. if (spawn && spawn->IsEntity() && value > 0)
  1979. ((Entity*)spawn)->SetTotalHPBase(value);
  1980. return 0;
  1981. }
  1982. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1983. if (!lua_interface)
  1984. return 0;
  1985. Spawn* spawn = lua_interface->GetSpawn(state);
  1986. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1987. lua_interface->ResetFunctionStack(state);
  1988. if (spawn && value > 0) {
  1989. spawn->SetPower(value);
  1990. if (value > spawn->GetTotalPowerBase())
  1991. spawn->SetTotalPower(value);
  1992. }
  1993. return 0;
  1994. }
  1995. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1996. if (!lua_interface)
  1997. return 0;
  1998. Spawn* spawn = lua_interface->GetSpawn(state);
  1999. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2000. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2001. lua_interface->ResetFunctionStack(state);
  2002. if (spawn && spawn->IsEntity() && value > 0)
  2003. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  2004. return 0;
  2005. }
  2006. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  2007. if (!lua_interface)
  2008. return 0;
  2009. Spawn* spawn = lua_interface->GetSpawn(state);
  2010. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2011. lua_interface->ResetFunctionStack(state);
  2012. if (spawn && spawn->IsEntity() && value > 0)
  2013. ((Entity*)spawn)->SetTotalPowerBase(value);
  2014. return 0;
  2015. }
  2016. int EQ2Emu_lua_SetPosition(lua_State* state) {
  2017. if (!lua_interface)
  2018. return 0;
  2019. Spawn* spawn = lua_interface->GetSpawn(state);
  2020. float x = lua_interface->GetFloatValue(state, 2);
  2021. float y = lua_interface->GetFloatValue(state, 3);
  2022. float z = lua_interface->GetFloatValue(state, 4);
  2023. float heading = lua_interface->GetFloatValue(state, 5);
  2024. lua_interface->ResetFunctionStack(state);
  2025. if (spawn) {
  2026. spawn->SetX(x);
  2027. spawn->SetY(y);
  2028. spawn->SetZ(z);
  2029. if (heading != 0)
  2030. spawn->SetHeading(heading);
  2031. spawn->SetSpawnOrigX(spawn->GetX());
  2032. spawn->SetSpawnOrigY(spawn->GetY());
  2033. spawn->SetSpawnOrigZ(spawn->GetZ());
  2034. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  2035. if (spawn->IsPlayer()) {
  2036. Client* client = ((Player*)spawn)->GetClient();
  2037. if (client) {
  2038. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  2039. client->QueuePacket(packet);
  2040. }
  2041. }
  2042. }
  2043. return 0;
  2044. }
  2045. int EQ2Emu_lua_SetHeading(lua_State* state) {
  2046. if (!lua_interface)
  2047. return 0;
  2048. Spawn* spawn = lua_interface->GetSpawn(state);
  2049. float value = lua_interface->GetFloatValue(state, 2);
  2050. lua_interface->ResetFunctionStack(state);
  2051. if (spawn) {
  2052. spawn->SetHeading(value);
  2053. if (spawn->IsPlayer()) {
  2054. Client* client = ((Player*)spawn)->GetClient();
  2055. if (client) {
  2056. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  2057. client->QueuePacket(packet);
  2058. }
  2059. }
  2060. }
  2061. return 0;
  2062. }
  2063. int EQ2Emu_lua_SetModelType(lua_State* state) {
  2064. if (!lua_interface)
  2065. return 0;
  2066. Spawn* spawn = lua_interface->GetSpawn(state);
  2067. int16 value = lua_interface->GetInt16Value(state, 2);
  2068. lua_interface->ResetFunctionStack(state);
  2069. if (spawn)
  2070. spawn->SetModelType(value);
  2071. return 0;
  2072. }
  2073. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  2074. if (!lua_interface)
  2075. return 0;
  2076. Spawn* spawn = lua_interface->GetSpawn(state);
  2077. int8 value = lua_interface->GetInt8Value(state, 2);
  2078. lua_interface->ResetFunctionStack(state);
  2079. if (spawn) {
  2080. if (spawn->IsPlayer())
  2081. ((Player*)spawn)->SetPlayerAdventureClass(value);
  2082. else
  2083. spawn->SetAdventureClass(value);
  2084. }
  2085. return 0;
  2086. }
  2087. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  2088. if (!lua_interface)
  2089. return 0;
  2090. Spawn* spawn = lua_interface->GetSpawn(state);
  2091. int8 value = lua_interface->GetInt8Value(state, 2);
  2092. lua_interface->ResetFunctionStack(state);
  2093. if (spawn) {
  2094. spawn->SetTradeskillClass(value);
  2095. if (spawn->IsEntity()) {
  2096. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  2097. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  2098. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  2099. }
  2100. if (spawn->IsPlayer())
  2101. ((Player*)spawn)->SetCharSheetChanged(true);
  2102. }
  2103. return 0;
  2104. }
  2105. int EQ2Emu_lua_SetMount(lua_State* state) {
  2106. if (!lua_interface)
  2107. return 0;
  2108. Spawn* spawn = lua_interface->GetSpawn(state);
  2109. int16 value = lua_interface->GetInt16Value(state, 2);
  2110. if (spawn && spawn->IsEntity()) {
  2111. ((Entity*)spawn)->SetMount(value);
  2112. EQ2_Color color;
  2113. color.red = 255;
  2114. color.green = 255;
  2115. color.blue = 255;
  2116. ((Entity*)spawn)->SetMountColor(&color);
  2117. ((Entity*)spawn)->SetMountSaddleColor(&color);
  2118. }
  2119. return 0;
  2120. }
  2121. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  2122. if (!lua_interface)
  2123. return 0;
  2124. Spawn* spawn = lua_interface->GetSpawn(state);
  2125. EQ2_Color mount_color;
  2126. EQ2_Color saddle_color;
  2127. mount_color.red = lua_interface->GetInt8Value(state, 2);
  2128. mount_color.green = lua_interface->GetInt8Value(state, 3);
  2129. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  2130. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  2131. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  2132. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  2133. if (spawn && spawn->IsEntity()) {
  2134. ((Entity*)spawn)->SetMountColor(&mount_color);
  2135. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  2136. }
  2137. return 0;
  2138. }
  2139. int EQ2Emu_lua_GetMount(lua_State* state) {
  2140. if (!lua_interface)
  2141. return 0;
  2142. Spawn* spawn = lua_interface->GetSpawn(state);
  2143. if (spawn && spawn->IsEntity()) {
  2144. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2145. return 1;
  2146. }
  2147. return 0;
  2148. }
  2149. int EQ2Emu_lua_GetRace(lua_State* state) {
  2150. if (!lua_interface)
  2151. return 0;
  2152. Spawn* spawn = lua_interface->GetSpawn(state);
  2153. if (spawn)
  2154. {
  2155. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2156. lua_interface->SetInt32Value(state, spawn->GetRace());
  2157. return 1;
  2158. }
  2159. return 0;
  2160. }
  2161. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2162. if (!lua_interface)
  2163. return 0;
  2164. Spawn* spawn = lua_interface->GetSpawn(state);
  2165. if (spawn) {
  2166. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2167. return 1;
  2168. }
  2169. return 0;
  2170. }
  2171. int EQ2Emu_lua_GetClass(lua_State* state) {
  2172. Spawn* spawn = lua_interface->GetSpawn(state);
  2173. if (spawn) {
  2174. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2175. return 1;
  2176. }
  2177. return 0;
  2178. }
  2179. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2180. Spawn* spawn = lua_interface->GetSpawn(state);
  2181. if (spawn) {
  2182. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2183. return 1;
  2184. }
  2185. return 0;
  2186. }
  2187. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2188. if (!lua_interface)
  2189. return 0;
  2190. Spawn* spawn = lua_interface->GetSpawn(state);
  2191. float value = lua_interface->GetFloatValue(state, 2);
  2192. lua_interface->ResetFunctionStack(state);
  2193. if (spawn) {
  2194. spawn->SetSpeed(value);
  2195. if(spawn->IsEntity())
  2196. ((Entity*)spawn)->SetSpeed(value);
  2197. if (spawn->IsPlayer()) {
  2198. Client* client = ((Player*)spawn)->GetClient();
  2199. if (client) {
  2200. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2201. if (packet) {
  2202. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2203. packet->setDataByName("speed", value);
  2204. packet->setDataByName("size", 0.51);
  2205. EQ2Packet* app = packet->serialize();
  2206. client->QueuePacket(app);
  2207. safe_delete(packet);
  2208. }
  2209. }
  2210. }
  2211. }
  2212. return 0;
  2213. }
  2214. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2215. if (!lua_interface)
  2216. return 0;
  2217. Spawn* spawn = lua_interface->GetSpawn(state);
  2218. const int16 type = lua_interface->GetInt16Value(state, 2);
  2219. const float value = lua_interface->GetFloatValue(state, 3);
  2220. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2221. if(!luaspell || luaspell->resisted) {
  2222. lua_interface->ResetFunctionStack(state);
  2223. return 0;
  2224. }
  2225. int64 class_req = 0;
  2226. int32 class_id = 0;
  2227. vector<int16> faction_req;
  2228. vector<int16> race_req;
  2229. int32 i = 0;
  2230. int8 f = 0;
  2231. int8 r = 0;
  2232. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2233. if (class_id < 100) {
  2234. class_req += pow(2.0, double(class_id - 1));
  2235. }
  2236. else if (class_id > 100 && class_id < 1000) {
  2237. race_req.push_back(class_id);
  2238. r++;
  2239. }
  2240. else {
  2241. faction_req.push_back(class_id);
  2242. f++;
  2243. }
  2244. i++;
  2245. }
  2246. if (value != 0 && type >= 0) {
  2247. if (luaspell && luaspell->spell && luaspell->caster) {
  2248. ZoneServer* zone = luaspell->caster->GetZone();
  2249. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2250. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2251. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2252. if (target) {
  2253. if (target->IsPlayer()) {
  2254. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2255. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2256. if (((Player*)target)->GetGroupMemberInfo())
  2257. ((Player*)target)->UpdateGroupMemberInfo();
  2258. ((Player*)target)->SetCharSheetChanged(true);
  2259. }
  2260. else if (target->IsNPC())
  2261. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2262. else
  2263. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2264. }
  2265. }
  2266. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2267. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2268. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2269. }
  2270. else if (spawn && spawn->IsEntity()) {
  2271. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2272. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2273. if (spawn->IsPlayer())
  2274. ((Player*)spawn)->SetCharSheetChanged(true);
  2275. }
  2276. else
  2277. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2278. }
  2279. else
  2280. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2281. return 0;
  2282. }
  2283. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2284. if (!lua_interface)
  2285. return 0;
  2286. Spawn* spawn = lua_interface->GetSpawn(state);
  2287. int16 type = lua_interface->GetInt16Value(state, 2);
  2288. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2289. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2290. if (!spawn) {
  2291. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2292. return 0;
  2293. }
  2294. if (!spawn->IsEntity()) {
  2295. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2296. return 0;
  2297. }
  2298. if (value == 0) {
  2299. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2300. return 0;
  2301. }
  2302. if (!luaspell || !luaspell->spell) {
  2303. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2304. return 0;
  2305. }
  2306. if(luaspell->resisted) {
  2307. lua_interface->ResetFunctionStack(state);
  2308. return 0;
  2309. }
  2310. int32 class_req = 0;
  2311. vector<int16> faction_req;
  2312. vector<int16> race_req;
  2313. int32 class_id = 0;
  2314. int32 i = 0;
  2315. int8 f = 0;
  2316. int8 r = 0;
  2317. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2318. if (class_id < 100) {
  2319. class_req += pow(2.0, double(class_id - 1));
  2320. }
  2321. else if (class_id > 100 && class_id < 1000) {
  2322. race_req.push_back(class_id);
  2323. r++;
  2324. }
  2325. else {
  2326. faction_req.push_back(class_id);
  2327. f++;
  2328. }
  2329. i++;
  2330. }
  2331. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2332. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2333. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2334. if (spawn->IsPlayer())
  2335. ((Player*)spawn)->SetCharSheetChanged(true);
  2336. return 0;
  2337. }
  2338. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2339. if (!lua_interface)
  2340. return 0;
  2341. Spawn* spawn = lua_interface->GetSpawn(state);
  2342. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2343. if (!spawn) {
  2344. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2345. return 0;
  2346. }
  2347. if (!spawn->IsEntity()) {
  2348. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2349. return 0;
  2350. }
  2351. if (!luaspell || !luaspell->spell) {
  2352. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2353. return 0;
  2354. }
  2355. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2356. if (spawn->IsPlayer())
  2357. ((Player*)spawn)->SetCharSheetChanged(true);
  2358. return 0;
  2359. }
  2360. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2361. if (!lua_interface)
  2362. return 0;
  2363. Spawn* spawn = lua_interface->GetSpawn(state);
  2364. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2365. if (luaspell && luaspell->spell) {
  2366. ZoneServer* zone = nullptr;
  2367. if (luaspell->caster != nullptr)
  2368. zone = luaspell->caster->GetZone();
  2369. if(!zone) {
  2370. zone = spawn->GetZone(); // workaround to try to establish a zone to find the targets and remove the spells
  2371. }
  2372. Spawn* target = 0;
  2373. if(zone) {
  2374. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2375. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2376. target = zone->GetSpawnByID(luaspell->targets[i]);
  2377. if (target && target->IsEntity()) {
  2378. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2379. if (target->IsPlayer())
  2380. ((Player*)target)->SetCharSheetChanged(true);
  2381. }
  2382. }
  2383. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2384. }
  2385. else {
  2386. 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());
  2387. }
  2388. }
  2389. else if (spawn && spawn->IsEntity()) {
  2390. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2391. if (spawn->IsPlayer())
  2392. ((Player*)spawn)->SetCharSheetChanged(true);
  2393. }
  2394. return 0;
  2395. }
  2396. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2397. if (!lua_interface)
  2398. return 0;
  2399. Spawn* spawn = lua_interface->GetSpawn(state);
  2400. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2401. float value = lua_interface->GetFloatValue(state, 3);
  2402. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2403. if (value != 0) {
  2404. int32 spell_id = 0;
  2405. if (luaspell && luaspell->spell && luaspell->caster) {
  2406. if(luaspell->resisted) {
  2407. lua_interface->ResetFunctionStack(state);
  2408. return 0;
  2409. }
  2410. spell_id = luaspell->spell->GetSpellID();
  2411. ZoneServer* zone = luaspell->caster->GetZone();
  2412. Spawn* target = 0;
  2413. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2414. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2415. target = zone->GetSpawnByID(luaspell->targets[i]);
  2416. if (target && target->Alive()) {
  2417. if (target->IsPlayer()) {
  2418. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2419. Client* client = ((Player*)target)->GetClient();
  2420. if (client) {
  2421. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2422. if (packet)
  2423. client->QueuePacket(packet);
  2424. }
  2425. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2426. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2427. }
  2428. else if (target->IsNPC()) {
  2429. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2430. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2431. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2432. }
  2433. else
  2434. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2435. }
  2436. }
  2437. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2438. }
  2439. else if (spawn) {
  2440. if (spawn->IsPlayer()) {
  2441. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2442. Client* client = ((Player*)spawn)->GetClient();
  2443. if (client) {
  2444. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2445. if (packet)
  2446. client->QueuePacket(packet);
  2447. }
  2448. }
  2449. else if (spawn->IsNPC())
  2450. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2451. else
  2452. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2453. }
  2454. }
  2455. else
  2456. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2457. return 0;
  2458. }
  2459. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2460. if (!lua_interface)
  2461. return 0;
  2462. Spawn* spawn = lua_interface->GetSpawn(state);
  2463. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2464. if (spawn && spawn->IsPlayer()) {
  2465. int32 spell_id = 0;
  2466. if (luaspell && luaspell->spell && luaspell->caster) {
  2467. if(luaspell->resisted) {
  2468. lua_interface->ResetFunctionStack(state);
  2469. return 0;
  2470. }
  2471. spell_id = luaspell->spell->GetSpellID();
  2472. ZoneServer* zone = luaspell->caster->GetZone();
  2473. Spawn* target = 0;
  2474. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2475. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2476. target = zone->GetSpawnByID(luaspell->targets[i]);
  2477. if (target) {
  2478. if (target->IsPlayer()) {
  2479. ((Player*)target)->RemoveSkillBonus(spell_id);
  2480. Client* client = ((Player*)target)->GetClient();
  2481. if (client) {
  2482. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2483. if (packet)
  2484. client->QueuePacket(packet);
  2485. }
  2486. }
  2487. else if (target->IsNPC())
  2488. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2489. else
  2490. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2491. }
  2492. }
  2493. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2494. }
  2495. else if (spawn) {
  2496. if (spawn->IsPlayer()) {
  2497. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2498. Client* client = ((Player*)spawn)->GetClient();
  2499. if (client) {
  2500. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2501. if (packet)
  2502. client->QueuePacket(packet);
  2503. }
  2504. }
  2505. else if (spawn->IsNPC())
  2506. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2507. else
  2508. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2509. }
  2510. }
  2511. return 0;
  2512. }
  2513. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2514. if (!lua_interface)
  2515. return 0;
  2516. Spawn* spawn = lua_interface->GetSpawn(state);
  2517. int8 type = lua_interface->GetInt32Value(state, 2);
  2518. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2519. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2520. if(luaspell && luaspell->resisted) {
  2521. lua_interface->ResetFunctionStack(state);
  2522. return 0;
  2523. }
  2524. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2525. ZoneServer* zone = luaspell->caster->GetZone();
  2526. Spawn* target = 0;
  2527. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2528. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2529. target = zone->GetSpawnByID(luaspell->targets[i]);
  2530. if (target && target->IsEntity()) {
  2531. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2532. ((Entity*)target)->AddMezSpell(luaspell);
  2533. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2534. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2535. if (target->IsNPC())
  2536. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2537. }
  2538. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2539. ((Entity*)target)->AddStifleSpell(luaspell);
  2540. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2541. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2542. if (target->IsNPC())
  2543. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2544. }
  2545. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2546. ((Entity*)target)->AddDazeSpell(luaspell);
  2547. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2548. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2549. if (target->IsNPC())
  2550. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2551. }
  2552. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2553. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2554. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2555. ((Entity*)target)->AddStunSpell(luaspell);
  2556. if (target->IsNPC())
  2557. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2558. }
  2559. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2560. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2561. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2562. ((Entity*)target)->AddRootSpell(luaspell);
  2563. if (target->IsNPC())
  2564. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2565. }
  2566. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2567. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2568. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2569. ((Entity*)target)->AddFearSpell(luaspell);
  2570. if (target->IsNPC())
  2571. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2572. }
  2573. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2574. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2575. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2576. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2577. }
  2578. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2579. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2580. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2581. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2582. }
  2583. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2584. ((Entity*)target)->AddSnareSpell(luaspell);
  2585. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2586. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2587. if (target->IsNPC())
  2588. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2589. }
  2590. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2591. ((Entity*)target)->AddFlightSpell(luaspell);
  2592. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2593. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2594. }
  2595. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2596. ((Entity*)target)->AddGlideSpell(luaspell);
  2597. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2598. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2599. }
  2600. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2601. ((Entity*)target)->AddSafefallSpell(luaspell);
  2602. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2603. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2604. }
  2605. else
  2606. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2607. }
  2608. else
  2609. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2610. }
  2611. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2612. }
  2613. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2614. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2615. ((Entity*)spawn)->AddMezSpell(luaspell);
  2616. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2617. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2618. }
  2619. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2620. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2621. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2622. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2623. }
  2624. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2625. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2626. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2627. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2628. }
  2629. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2630. ((Entity*)spawn)->AddStunSpell(luaspell);
  2631. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2632. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2633. }
  2634. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2635. ((Entity*)spawn)->AddRootSpell(luaspell);
  2636. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2637. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2638. }
  2639. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2640. ((Entity*)spawn)->AddFearSpell(luaspell);
  2641. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2642. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2643. }
  2644. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2645. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2646. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2647. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2648. }
  2649. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2650. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2651. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2652. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2653. }
  2654. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2655. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2656. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2657. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2658. }
  2659. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2660. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2661. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2662. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2663. }
  2664. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2665. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2666. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2667. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2668. }
  2669. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2670. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2671. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2672. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2673. }
  2674. else
  2675. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2676. }
  2677. else
  2678. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2679. return 0;
  2680. }
  2681. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2682. if (!lua_interface)
  2683. return 0;
  2684. Spawn* spawn = lua_interface->GetSpawn(state);
  2685. int8 type = lua_interface->GetInt8Value(state, 2);
  2686. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2687. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2688. if (spawn && spawn->IsEntity()) {
  2689. if (!only_remove_spawn && luaspell && luaspell->spell && luaspell->caster) {
  2690. ZoneServer* zone = luaspell->caster->GetZone();
  2691. Spawn* target = 0;
  2692. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2693. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2694. target = zone->GetSpawnByID(luaspell->targets[i]);
  2695. if (target) {
  2696. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2697. ((Entity*)target)->RemoveMezSpell(luaspell);
  2698. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2699. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2700. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2701. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2702. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2703. ((Entity*)target)->RemoveStunSpell(luaspell);
  2704. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2705. ((Entity*)target)->RemoveRootSpell(luaspell);
  2706. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2707. ((Entity*)target)->RemoveFearSpell(luaspell);
  2708. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2709. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2710. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2711. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2712. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2713. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2714. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2715. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2716. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2717. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2718. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2719. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2720. else
  2721. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2722. }
  2723. }
  2724. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2725. }
  2726. else if (only_remove_spawn) {
  2727. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2728. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2729. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2730. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2731. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2732. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2733. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2734. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2735. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2736. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2737. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2738. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2739. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2740. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2741. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2742. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2743. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2744. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2745. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2746. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2747. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2748. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2749. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2750. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2751. else
  2752. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2753. }
  2754. }
  2755. return 0;
  2756. }
  2757. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2758. if (!lua_interface)
  2759. return 0;
  2760. Spawn* spawn = lua_interface->GetSpawn(state);
  2761. int8 type = lua_interface->GetInt8Value(state, 2);
  2762. bool hasEffect = false;
  2763. if (!spawn)
  2764. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2765. else if (!spawn->IsEntity())
  2766. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2767. else if (type < CONTROL_MAX_EFFECTS)
  2768. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2769. else
  2770. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2771. lua_interface->SetBooleanValue(state, hasEffect);
  2772. return 1;
  2773. }
  2774. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2775. if (!lua_interface)
  2776. return 0;
  2777. Spawn* spawn = lua_interface->GetSpawn(state);
  2778. float distance = 0.0f;
  2779. if (!spawn)
  2780. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2781. else if (!spawn->IsNPC())
  2782. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2783. else
  2784. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2785. lua_interface->SetFloatValue(state, distance);
  2786. return 1;
  2787. }
  2788. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2789. if (!lua_interface)
  2790. return 0;
  2791. Spawn* spawn = lua_interface->GetSpawn(state);
  2792. float distance = 0.0f;
  2793. if (!spawn)
  2794. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2795. else if (!spawn->IsNPC())
  2796. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2797. else
  2798. distance = ((NPC*)spawn)->GetAggroRadius();
  2799. lua_interface->SetFloatValue(state, distance);
  2800. return 1;
  2801. }
  2802. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2803. if (!lua_interface)
  2804. return 0;
  2805. Spawn* spawn = lua_interface->GetSpawn(state);
  2806. float distance = lua_interface->GetFloatValue(state, 2);
  2807. bool override = lua_interface->GetBooleanValue(state, 3);
  2808. bool result = false;
  2809. lua_interface->ResetFunctionStack(state);
  2810. if (!spawn)
  2811. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2812. else if (!spawn->IsNPC())
  2813. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2814. else
  2815. {
  2816. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2817. result = true;
  2818. }
  2819. lua_interface->SetBooleanValue(state, result);
  2820. return 1;
  2821. }
  2822. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2823. if (!lua_interface)
  2824. return 0;
  2825. Spawn* spawn = lua_interface->GetSpawn(state);
  2826. int16 value = lua_interface->GetInt16Value(state, 2);
  2827. if (spawn && spawn->IsEntity()) {
  2828. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2829. if (spawn->IsPlayer())
  2830. ((Player*)spawn)->SetCharSheetChanged(true);
  2831. }
  2832. return 0;
  2833. }
  2834. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2835. if (!lua_interface)
  2836. return 0;
  2837. Spawn* spawn = lua_interface->GetSpawn(state);
  2838. int16 value = lua_interface->GetInt16Value(state, 2);
  2839. if (spawn && spawn->IsEntity()) {
  2840. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2841. if (spawn->IsPlayer())
  2842. ((Player*)spawn)->SetCharSheetChanged(true);
  2843. }
  2844. return 0;
  2845. }
  2846. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2847. if (!lua_interface)
  2848. return 0;
  2849. Spawn* spawn = lua_interface->GetSpawn(state);
  2850. int16 value = lua_interface->GetInt16Value(state, 2);
  2851. if (spawn && spawn->IsEntity()) {
  2852. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2853. if (spawn->IsPlayer())
  2854. ((Player*)spawn)->SetCharSheetChanged(true);
  2855. }
  2856. return 0;
  2857. }
  2858. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2859. if (!lua_interface)
  2860. return 0;
  2861. Spawn* spawn = lua_interface->GetSpawn(state);
  2862. int16 value = lua_interface->GetInt16Value(state, 2);
  2863. if (spawn && spawn->IsEntity()) {
  2864. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2865. if (spawn->IsPlayer())
  2866. ((Player*)spawn)->SetCharSheetChanged(true);
  2867. }
  2868. return 0;
  2869. }
  2870. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2871. if (!lua_interface)
  2872. return 0;
  2873. Spawn* spawn = lua_interface->GetSpawn(state);
  2874. int16 value = lua_interface->GetInt16Value(state, 2);
  2875. if (spawn && spawn->IsEntity()) {
  2876. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2877. if (spawn->IsPlayer())
  2878. ((Player*)spawn)->SetCharSheetChanged(true);
  2879. }
  2880. return 0;
  2881. }
  2882. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2883. if (!lua_interface)
  2884. return 0;
  2885. Spawn* spawn = lua_interface->GetSpawn(state);
  2886. int8 value = lua_interface->GetInt8Value(state, 2);
  2887. if (spawn && spawn->IsEntity()) {
  2888. ((Entity*)spawn)->SetDeity(value);
  2889. if (spawn->IsPlayer())
  2890. ((Player*)spawn)->SetCharSheetChanged(true);
  2891. }
  2892. lua_interface->ResetFunctionStack(state);
  2893. return 0;
  2894. }
  2895. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2896. if (!lua_interface)
  2897. return 0;
  2898. Spawn* spawn = lua_interface->GetSpawn(state);
  2899. if (spawn && spawn->IsEntity()) {
  2900. int8 deity = ((Entity*)spawn)->GetDeity();
  2901. lua_interface->SetInt32Value(state, deity);
  2902. return 1;
  2903. }
  2904. return 0;
  2905. }
  2906. int EQ2Emu_lua_SetInt(lua_State* state) {
  2907. if (!lua_interface)
  2908. return 0;
  2909. Spawn* spawn = lua_interface->GetSpawn(state);
  2910. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2911. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2912. if (spawn && spawn->IsEntity()) {
  2913. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_INT, value);
  2914. if (spawn->IsPlayer())
  2915. ((Player*)spawn)->SetCharSheetChanged(true);
  2916. }
  2917. return 0;
  2918. }
  2919. int EQ2Emu_lua_SetWis(lua_State* state) {
  2920. if (!lua_interface)
  2921. return 0;
  2922. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2923. Spawn* spawn = lua_interface->GetSpawn(state);
  2924. float value = lua_interface->GetFloatValue(state, 2);
  2925. if (spawn && spawn->IsEntity()) {
  2926. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_WIS, value);
  2927. if (spawn->IsPlayer())
  2928. ((Player*)spawn)->SetCharSheetChanged(true);
  2929. }
  2930. return 0;
  2931. }
  2932. int EQ2Emu_lua_SetSta(lua_State* state) {
  2933. if (!lua_interface)
  2934. return 0;
  2935. Spawn* spawn = lua_interface->GetSpawn(state);
  2936. float value = lua_interface->GetFloatValue(state, 2);
  2937. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2938. if (spawn && spawn->IsEntity()) {
  2939. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STA, value);
  2940. if (spawn->IsPlayer())
  2941. ((Player*)spawn)->SetCharSheetChanged(true);
  2942. }
  2943. return 0;
  2944. }
  2945. int EQ2Emu_lua_SetStr(lua_State* state) {
  2946. if (!lua_interface)
  2947. return 0;
  2948. Spawn* spawn = lua_interface->GetSpawn(state);
  2949. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2950. float value = lua_interface->GetFloatValue(state, 2);
  2951. if (spawn && spawn->IsEntity()) {
  2952. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STR, value);
  2953. if (spawn->IsPlayer())
  2954. ((Player*)spawn)->SetCharSheetChanged(true);
  2955. }
  2956. return 0;
  2957. }
  2958. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2959. if (!lua_interface)
  2960. return 0;
  2961. Spawn* spawn = lua_interface->GetSpawn(state);
  2962. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2963. float value = lua_interface->GetFloatValue(state, 2);
  2964. if (spawn && spawn->IsEntity()) {
  2965. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_AGI, value);
  2966. if (spawn->IsPlayer())
  2967. ((Player*)spawn)->SetCharSheetChanged(true);
  2968. }
  2969. return 0;
  2970. }
  2971. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2972. if (!lua_interface)
  2973. return 0;
  2974. Spawn* spawn = lua_interface->GetSpawn(state);
  2975. if (spawn) {
  2976. lua_interface->SetInt32Value(state, spawn->GetHP());
  2977. return 1;
  2978. }
  2979. return 0;
  2980. }
  2981. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2982. if (!lua_interface)
  2983. return 0;
  2984. Spawn* spawn = lua_interface->GetSpawn(state);
  2985. if (spawn) {
  2986. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2987. return 1;
  2988. }
  2989. return 0;
  2990. }
  2991. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2992. if (!lua_interface)
  2993. return 0;
  2994. Spawn* spawn = lua_interface->GetSpawn(state);
  2995. if (spawn) {
  2996. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2997. return 1;
  2998. }
  2999. return 0;
  3000. }
  3001. int EQ2Emu_lua_GetName(lua_State* state) {
  3002. if (!lua_interface)
  3003. return 0;
  3004. Spawn* spawn = lua_interface->GetSpawn(state);
  3005. if (spawn) {
  3006. lua_interface->SetStringValue(state, spawn->GetName());
  3007. return 1;
  3008. }
  3009. return 0;
  3010. }
  3011. int EQ2Emu_lua_GetLevel(lua_State* state) {
  3012. Spawn* spawn = lua_interface->GetSpawn(state);
  3013. if (spawn) {
  3014. lua_interface->SetInt32Value(state, spawn->GetLevel());
  3015. return 1;
  3016. }
  3017. return 0;
  3018. }
  3019. int EQ2Emu_lua_GetDifficulty(lua_State* state) {
  3020. Spawn* spawn = lua_interface->GetSpawn(state);
  3021. if (spawn) {
  3022. lua_interface->SetInt32Value(state, spawn->GetDifficulty());
  3023. return 1;
  3024. }
  3025. return 0;
  3026. }
  3027. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  3028. if (!lua_interface)
  3029. return 0;
  3030. Spawn* spawn = lua_interface->GetSpawn(state);
  3031. if (spawn) {
  3032. lua_interface->SetInt32Value(state, spawn->GetPower());
  3033. return 1;
  3034. }
  3035. return 0;
  3036. }
  3037. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  3038. if (!lua_interface)
  3039. return 0;
  3040. Spawn* spawn = lua_interface->GetSpawn(state);
  3041. if (spawn) {
  3042. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  3043. return 1;
  3044. }
  3045. return 0;
  3046. }
  3047. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  3048. if (!lua_interface)
  3049. return 0;
  3050. Spawn* spawn = lua_interface->GetSpawn(state);
  3051. if (spawn) {
  3052. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  3053. return 1;
  3054. }
  3055. return 0;
  3056. }
  3057. int EQ2Emu_lua_GetDistance(lua_State* state) {
  3058. if (!lua_interface)
  3059. return 0;
  3060. Spawn* spawn = lua_interface->GetSpawn(state);
  3061. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  3062. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  3063. if (spawn && spawn2) {
  3064. float distance = spawn->GetDistance(spawn2, false, include_radius);
  3065. lua_interface->SetFloatValue(state, distance);
  3066. return 1;
  3067. }
  3068. return 0;
  3069. }
  3070. int EQ2Emu_lua_GetX(lua_State* state) {
  3071. if (!lua_interface)
  3072. return 0;
  3073. Spawn* spawn = lua_interface->GetSpawn(state);
  3074. if (spawn) {
  3075. lua_interface->SetFloatValue(state, spawn->GetX());
  3076. return 1;
  3077. }
  3078. return 0;
  3079. }
  3080. int EQ2Emu_lua_GetY(lua_State* state) {
  3081. if (!lua_interface)
  3082. return 0;
  3083. Spawn* spawn = lua_interface->GetSpawn(state);
  3084. if (spawn) {
  3085. lua_interface->SetFloatValue(state, spawn->GetY());
  3086. return 1;
  3087. }
  3088. return 0;
  3089. }
  3090. int EQ2Emu_lua_GetZ(lua_State* state) {
  3091. if (!lua_interface)
  3092. return 0;
  3093. Spawn* spawn = lua_interface->GetSpawn(state);
  3094. if (spawn) {
  3095. lua_interface->SetFloatValue(state, spawn->GetZ());
  3096. return 1;
  3097. }
  3098. return 0;
  3099. }
  3100. int EQ2Emu_lua_GetHeading(lua_State* state) {
  3101. if (!lua_interface)
  3102. return 0;
  3103. Spawn* spawn = lua_interface->GetSpawn(state);
  3104. if (spawn) {
  3105. lua_interface->SetFloatValue(state, spawn->GetHeading());
  3106. return 1;
  3107. }
  3108. return 0;
  3109. }
  3110. int EQ2Emu_lua_GetModelType(lua_State* state) {
  3111. if (!lua_interface)
  3112. return 0;
  3113. Spawn* spawn = lua_interface->GetSpawn(state);
  3114. if (spawn) {
  3115. lua_interface->SetInt32Value(state, spawn->GetModelType());
  3116. return 1;
  3117. }
  3118. return 0;
  3119. }
  3120. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  3121. if (!lua_interface)
  3122. return 0;
  3123. Spawn* spawn = lua_interface->GetSpawn(state);
  3124. if (spawn) {
  3125. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  3126. return 1;
  3127. }
  3128. return 0;
  3129. }
  3130. int EQ2Emu_lua_HasMoved(lua_State* state) {
  3131. if (!lua_interface)
  3132. return 0;
  3133. Spawn* spawn = lua_interface->GetSpawn(state);
  3134. if (spawn && spawn->IsEntity()) {
  3135. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  3136. return 1;
  3137. }
  3138. return 0;
  3139. }
  3140. int EQ2Emu_lua_GetInt(lua_State* state) {
  3141. if (!lua_interface)
  3142. return 0;
  3143. Spawn* spawn = lua_interface->GetSpawn(state);
  3144. if (spawn && spawn->IsEntity()) {
  3145. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  3146. return 1;
  3147. }
  3148. return 0;
  3149. }
  3150. int EQ2Emu_lua_GetWis(lua_State* state) {
  3151. if (!lua_interface)
  3152. return 0;
  3153. Spawn* spawn = lua_interface->GetSpawn(state);
  3154. if (spawn && spawn->IsEntity()) {
  3155. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  3156. return 1;
  3157. }
  3158. return 0;
  3159. }
  3160. int EQ2Emu_lua_GetSta(lua_State* state) {
  3161. if (!lua_interface)
  3162. return 0;
  3163. Spawn* spawn = lua_interface->GetSpawn(state);
  3164. if (spawn && spawn->IsEntity()) {
  3165. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  3166. return 1;
  3167. }
  3168. return 0;
  3169. }
  3170. int EQ2Emu_lua_GetStr(lua_State* state) {
  3171. if (!lua_interface)
  3172. return 0;
  3173. Spawn* spawn = lua_interface->GetSpawn(state);
  3174. if (spawn && spawn->IsEntity()) {
  3175. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3176. return 1;
  3177. }
  3178. return 0;
  3179. }
  3180. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3181. if (!lua_interface)
  3182. return 0;
  3183. Spawn* spawn = lua_interface->GetSpawn(state);
  3184. if (spawn && spawn->IsEntity()) {
  3185. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3186. return 1;
  3187. }
  3188. return 0;
  3189. }
  3190. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3191. if (!lua_interface)
  3192. return 0;
  3193. Spawn* spawn = lua_interface->GetSpawn(state);
  3194. if (spawn && spawn->IsEntity()) {
  3195. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3196. return 1;
  3197. }
  3198. return 0;
  3199. }
  3200. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3201. if (!lua_interface)
  3202. return 0;
  3203. Spawn* spawn = lua_interface->GetSpawn(state);
  3204. if (spawn && spawn->IsEntity()) {
  3205. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3206. return 1;
  3207. }
  3208. return 0;
  3209. }
  3210. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3211. if (!lua_interface)
  3212. return 0;
  3213. Spawn* spawn = lua_interface->GetSpawn(state);
  3214. if (spawn && spawn->IsEntity()) {
  3215. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3216. return 1;
  3217. }
  3218. return 0;
  3219. }
  3220. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3221. if (!lua_interface)
  3222. return 0;
  3223. Spawn* spawn = lua_interface->GetSpawn(state);
  3224. if (spawn && spawn->IsEntity()) {
  3225. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3226. return 1;
  3227. }
  3228. return 0;
  3229. }
  3230. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3231. if (!lua_interface)
  3232. return 0;
  3233. Spawn* spawn = lua_interface->GetSpawn(state);
  3234. if (spawn && spawn->IsEntity()) {
  3235. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3236. return 1;
  3237. }
  3238. return 0;
  3239. }
  3240. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3241. if (!lua_interface)
  3242. return 0;
  3243. Spawn* player = lua_interface->GetSpawn(state);
  3244. if (!player || !player->IsPlayer()) {
  3245. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3246. return 0;
  3247. }
  3248. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3249. if (quest_id <= 0) {
  3250. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3251. return 0;
  3252. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3253. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3254. return 0;
  3255. }
  3256. int32 step = lua_interface->GetInt32Value(state, 3);
  3257. if (step > 0) {
  3258. Client* client = ((Player*)player)->GetClient();
  3259. if (client)
  3260. client->AddPendingQuestUpdate(quest_id, step);
  3261. } else {
  3262. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3263. }
  3264. return 0;
  3265. }
  3266. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3267. Spawn* player = lua_interface->GetSpawn(state);
  3268. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3269. int32 step = lua_interface->GetInt32Value(state, 3);
  3270. int32 progress = lua_interface->GetInt32Value(state, 4);
  3271. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3272. Client* client = ((Player*)player)->GetClient();
  3273. if (client)
  3274. client->AddPendingQuestUpdate(quest_id, step, progress);
  3275. }
  3276. return 0;
  3277. }
  3278. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3279. if (!lua_interface)
  3280. return 0;
  3281. Spawn* player = lua_interface->GetSpawn(state);
  3282. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3283. if (player && player->IsPlayer() && quest_id > 0) {
  3284. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3285. return 1;
  3286. }
  3287. return 0;
  3288. }
  3289. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3290. if (!lua_interface)
  3291. return 0;
  3292. Spawn* player = lua_interface->GetSpawn(state);
  3293. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3294. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3295. if (player && player->IsPlayer() && quest_id > 0) {
  3296. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3297. return 1;
  3298. }
  3299. return 0;
  3300. }
  3301. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3302. if (!lua_interface)
  3303. return 0;
  3304. Spawn* player = lua_interface->GetSpawn(state);
  3305. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3306. if (player && player->IsPlayer() && quest_id > 0) {
  3307. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3308. return 1;
  3309. }
  3310. return 0;
  3311. }
  3312. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3313. if (!lua_interface)
  3314. return 0;
  3315. Quest* quest = lua_interface->GetQuest(state);
  3316. string name = lua_interface->GetStringValue(state, 2);
  3317. string type = lua_interface->GetStringValue(state, 3);
  3318. string zone = lua_interface->GetStringValue(state, 4);
  3319. int16 level = lua_interface->GetInt16Value(state, 5);
  3320. string description = lua_interface->GetStringValue(state, 6);
  3321. bool load = true;
  3322. if (!quest) {
  3323. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3324. load = false;
  3325. }
  3326. if (load && name.length() == 0) {
  3327. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3328. load = false;
  3329. }
  3330. if (load && type.length() == 0) {
  3331. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3332. load = false;
  3333. }
  3334. if (load && zone.length() == 0) {
  3335. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3336. load = false;
  3337. }
  3338. if (load && description.length() == 0) {
  3339. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3340. load = false;
  3341. }
  3342. if (load && level == 0) {
  3343. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3344. load = false;
  3345. }
  3346. if (load)
  3347. quest->RegisterQuest(name, type, zone, level, description);
  3348. return 0;
  3349. }
  3350. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3351. if (!lua_interface)
  3352. return 0;
  3353. Quest* quest = lua_interface->GetQuest(state);
  3354. if (quest) {
  3355. int8 level = lua_interface->GetInt16Value(state, 2);
  3356. quest->SetPrereqLevel(level);
  3357. }
  3358. return 0;
  3359. }
  3360. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3361. if (!lua_interface)
  3362. return 0;
  3363. Quest* quest = lua_interface->GetQuest(state);
  3364. if (quest) {
  3365. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3366. quest->AddPrereqQuest(quest_id);
  3367. }
  3368. return 0;
  3369. }
  3370. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3371. if (!lua_interface)
  3372. return 0;
  3373. Quest* quest = lua_interface->GetQuest(state);
  3374. if (quest) {
  3375. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3376. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3377. if (quantity == 0)
  3378. quantity = 1;
  3379. Item* master_item = master_item_list.GetItem(item_id);
  3380. if (master_item) {
  3381. Item* item = new Item(master_item);
  3382. item->details.count = quantity;
  3383. quest->AddPrereqItem(item);
  3384. }
  3385. }
  3386. return 0;
  3387. }
  3388. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3389. if (!lua_interface)
  3390. return 0;
  3391. Spawn* player = lua_interface->GetSpawn(state);
  3392. if(!player || !player->IsPlayer()) {
  3393. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3394. return 0;
  3395. }
  3396. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3397. if (quest_id > 0) {
  3398. lua_interface->SetBooleanValue(state, (((Player*)player)->HasActiveQuest(quest_id) > 0));
  3399. return 1;
  3400. } else {
  3401. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3402. }
  3403. return 0;
  3404. }
  3405. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3406. if (!lua_interface)
  3407. return 0;
  3408. Quest* quest = lua_interface->GetQuest(state);
  3409. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3410. lua_interface->ResetFunctionStack(state);
  3411. if (quest && spawn_id > 0)
  3412. quest->SetQuestReturnNPC(spawn_id);
  3413. return 0;
  3414. }
  3415. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3416. if (!lua_interface)
  3417. return 0;
  3418. Spawn* spawn = lua_interface->GetSpawn(state);
  3419. int32 time = lua_interface->GetInt32Value(state, 2);
  3420. string function = lua_interface->GetStringValue(state, 3);
  3421. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3422. Spawn* player = lua_interface->GetSpawn(state, 5);
  3423. lua_interface->ResetFunctionStack(state);
  3424. if (!spawn) {
  3425. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3426. return 0;
  3427. }
  3428. if (time <= 0) {
  3429. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3430. return 0;
  3431. }
  3432. if (function.length() == 0) {
  3433. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3434. return 0;
  3435. }
  3436. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3437. if ( time < 10)
  3438. time = 10;
  3439. timer->timer = Timer::GetCurrentTime2() + time;
  3440. timer->function = function;
  3441. timer->spawn = spawn->GetID();
  3442. timer->player = player ? player->GetID() : 0;
  3443. if (max_count == 0)
  3444. max_count = 1;
  3445. timer->max_count = max_count;
  3446. timer->current_count = 0;
  3447. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3448. return 0;
  3449. }
  3450. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3451. if (!lua_interface)
  3452. return 0;
  3453. Spawn* spawn = lua_interface->GetSpawn(state);
  3454. string function = lua_interface->GetStringValue(state, 2);
  3455. lua_interface->ResetFunctionStack(state);
  3456. if (!spawn) {
  3457. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3458. return 0;
  3459. }
  3460. if(!spawn->GetZone()) {
  3461. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3462. return 0;
  3463. }
  3464. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3465. return 0;
  3466. }
  3467. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3468. if (!lua_interface)
  3469. return 0;
  3470. Spawn* player = lua_interface->GetSpawn(state);
  3471. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3472. lua_interface->ResetFunctionStack(state);
  3473. if (player && player->IsPlayer() && quest_id > 0) {
  3474. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3475. return 1;
  3476. }
  3477. return 0;
  3478. }
  3479. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3480. if (!lua_interface)
  3481. return 0;
  3482. Spawn* player = lua_interface->GetSpawn(state);
  3483. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3484. lua_interface->ResetFunctionStack(state);
  3485. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3486. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3487. if (quest)
  3488. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3489. return 1;
  3490. }
  3491. return 0;
  3492. }
  3493. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3494. if (!lua_interface)
  3495. return 0;
  3496. Spawn* player = lua_interface->GetSpawn(state);
  3497. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3498. lua_interface->ResetFunctionStack(state);
  3499. if (player && player->IsPlayer() && quest_id > 0) {
  3500. lua_interface->SetBooleanValue(state, (((Player*)player)->HasQuestBeenCompleted(quest_id) != 0));
  3501. return 1;
  3502. }
  3503. return 0;
  3504. }
  3505. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3506. if (!lua_interface)
  3507. return 0;
  3508. Spawn* npc = lua_interface->GetSpawn(state);
  3509. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3510. lua_interface->ResetFunctionStack(state);
  3511. if (npc && !npc->IsPlayer() && quest_id > 0)
  3512. npc->AddProvidedQuest(quest_id);
  3513. return 0;
  3514. }
  3515. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3516. if (!lua_interface)
  3517. return 0;
  3518. Spawn* npc = lua_interface->GetSpawn(state);
  3519. Spawn* player = lua_interface->GetSpawn(state, 2);
  3520. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3521. bool forced = lua_interface->GetBooleanValue(state, 4);
  3522. lua_interface->ResetFunctionStack(state);
  3523. /* NPC is allowed to be null */
  3524. if (player && player->IsPlayer() && quest_id > 0) {
  3525. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3526. if (master_quest) {
  3527. Client* client = ((Player*)player)->GetClient();
  3528. if (!client) {
  3529. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3530. }
  3531. Quest* quest = new Quest(master_quest);
  3532. if (!quest) {
  3533. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3534. }
  3535. if (client && quest) {
  3536. if (npc)
  3537. quest->SetQuestGiver(npc->GetDatabaseID());
  3538. else
  3539. quest->SetQuestGiver(0);
  3540. client->AddPendingQuest(quest, forced);
  3541. }
  3542. }
  3543. else {
  3544. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3545. }
  3546. }
  3547. else {
  3548. 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);
  3549. }
  3550. return 0;
  3551. }
  3552. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3553. if (!lua_interface)
  3554. return 0;
  3555. Quest* quest = lua_interface->GetQuest(state);
  3556. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3557. lua_interface->ResetFunctionStack(state);
  3558. if (quest) {
  3559. quest->AddPrereqClass(class_id);
  3560. }
  3561. return 0;
  3562. }
  3563. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3564. if (!lua_interface)
  3565. return 0;
  3566. Quest* quest = lua_interface->GetQuest(state);
  3567. int8 race = lua_interface->GetInt8Value(state, 2);
  3568. lua_interface->ResetFunctionStack(state);
  3569. if (quest) {
  3570. quest->AddPrereqRace(race);
  3571. }
  3572. return 0;
  3573. }
  3574. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3575. if (!lua_interface)
  3576. return 0;
  3577. Quest* quest = lua_interface->GetQuest(state);
  3578. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3579. lua_interface->ResetFunctionStack(state);
  3580. if (quest) {
  3581. quest->AddPrereqModelType(model_type);
  3582. }
  3583. return 0;
  3584. }
  3585. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3586. if (!lua_interface)
  3587. return 0;
  3588. Quest* quest = lua_interface->GetQuest(state);
  3589. int8 level = lua_interface->GetInt8Value(state, 2);
  3590. lua_interface->ResetFunctionStack(state);
  3591. if (!quest) {
  3592. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3593. return 0;
  3594. }
  3595. quest->SetPrereqTSLevel(level);
  3596. return 0;
  3597. }
  3598. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3599. if (!lua_interface)
  3600. return 0;
  3601. Quest* quest = lua_interface->GetQuest(state);
  3602. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3603. lua_interface->ResetFunctionStack(state);
  3604. if (!quest) {
  3605. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3606. return 0;
  3607. }
  3608. quest->AddPrereqTradeskillClass(class_id);
  3609. return 0;
  3610. }
  3611. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3612. if (!lua_interface)
  3613. return 0;
  3614. Quest* quest = lua_interface->GetQuest(state);
  3615. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3616. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3617. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3618. lua_interface->ResetFunctionStack(state);
  3619. if (quest) {
  3620. quest->AddPrereqFaction(faction_id, min, max);
  3621. }
  3622. return 0;
  3623. }
  3624. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3625. if (!lua_interface)
  3626. return 0;
  3627. Quest* quest = lua_interface->GetQuest(state);
  3628. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3629. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3630. lua_interface->ResetFunctionStack(state);
  3631. if (quest) {
  3632. if (quantity == 0)
  3633. quantity = 1;
  3634. Item* master_item = master_item_list.GetItem(item_id);
  3635. if (master_item) {
  3636. Item* item = new Item(master_item);
  3637. item->details.count = quantity;
  3638. quest->AddSelectableRewardItem(item);
  3639. }
  3640. }
  3641. return 0;
  3642. }
  3643. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3644. if (!lua_interface)
  3645. return 0;
  3646. Quest* quest = lua_interface->GetQuest(state);
  3647. if (quest) {
  3648. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3649. vector<Item*>* items = quest->GetRewardItems();
  3650. if (items) {
  3651. vector<Item*>::iterator itr;
  3652. for (itr = items->begin(); itr != items->end(); itr++) {
  3653. if (*itr && (*itr)->details.item_id == item_id) {
  3654. lua_interface->SetBooleanValue(state, true);
  3655. return 1;
  3656. }
  3657. }
  3658. }
  3659. }
  3660. lua_interface->SetBooleanValue(state, false);
  3661. return 1;
  3662. }
  3663. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3664. if (!lua_interface)
  3665. return 0;
  3666. Quest* quest = lua_interface->GetQuest(state);
  3667. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3668. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3669. lua_interface->ResetFunctionStack(state);
  3670. if (quest) {
  3671. if (quantity == 0)
  3672. quantity = 1;
  3673. Item* master_item = master_item_list.GetItem(item_id);
  3674. if (master_item) {
  3675. Item* item = new Item(master_item);
  3676. item->details.count = quantity;
  3677. quest->AddRewardItem(item);
  3678. }
  3679. }
  3680. return 0;
  3681. }
  3682. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3683. if (!lua_interface)
  3684. return 0;
  3685. Quest* quest = lua_interface->GetQuest(state);
  3686. int32 copper = lua_interface->GetInt32Value(state, 2);
  3687. int32 silver = lua_interface->GetInt32Value(state, 3);
  3688. int32 gold = lua_interface->GetInt32Value(state, 4);
  3689. int32 plat = lua_interface->GetInt32Value(state, 5);
  3690. lua_interface->ResetFunctionStack(state);
  3691. if (quest) {
  3692. quest->AddRewardCoins(copper, silver, gold, plat);
  3693. }
  3694. return 0;
  3695. }
  3696. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3697. if (!lua_interface)
  3698. return 0;
  3699. Quest* quest = lua_interface->GetQuest(state);
  3700. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3701. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3702. lua_interface->ResetFunctionStack(state);
  3703. if (quest && faction_id > 0 && amount != 0)
  3704. quest->AddRewardFaction(faction_id, amount);
  3705. return 0;
  3706. }
  3707. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3708. if (!lua_interface)
  3709. return 0;
  3710. Quest* quest = lua_interface->GetQuest(state);
  3711. int32 status = lua_interface->GetInt32Value(state, 2);
  3712. lua_interface->ResetFunctionStack(state);
  3713. if (quest) {
  3714. quest->SetRewardStatus(status);
  3715. }
  3716. return 0;
  3717. }
  3718. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3719. if (!lua_interface)
  3720. return 0;
  3721. Quest* quest = lua_interface->GetQuest(state);
  3722. int32 status = lua_interface->GetInt32Value(state, 2);
  3723. lua_interface->ResetFunctionStack(state);
  3724. if (quest) {
  3725. quest->SetStatusTmpReward(status);
  3726. }
  3727. return 0;
  3728. }
  3729. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3730. if (!lua_interface)
  3731. return 0;
  3732. Quest* quest = lua_interface->GetQuest(state);
  3733. int64 coins = lua_interface->GetInt64Value(state, 2);
  3734. lua_interface->ResetFunctionStack(state);
  3735. if (quest) {
  3736. quest->SetCoinTmpReward(coins);
  3737. }
  3738. return 0;
  3739. }
  3740. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3741. if (!lua_interface)
  3742. return 0;
  3743. Quest* quest = lua_interface->GetQuest(state);
  3744. string comment = lua_interface->GetStringValue(state, 2);
  3745. lua_interface->ResetFunctionStack(state);
  3746. if (quest) {
  3747. quest->SetRewardComment(comment);
  3748. }
  3749. return 0;
  3750. }
  3751. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3752. if (!lua_interface)
  3753. return 0;
  3754. Quest* quest = lua_interface->GetQuest(state);
  3755. int32 exp = lua_interface->GetInt32Value(state, 2);
  3756. lua_interface->ResetFunctionStack(state);
  3757. if (quest) {
  3758. quest->SetRewardXP(exp);
  3759. }
  3760. return 0;
  3761. }
  3762. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3763. Quest* quest = lua_interface->GetQuest(state);
  3764. int32 step = lua_interface->GetInt32Value(state, 2);
  3765. string description = lua_interface->GetStringValue(state, 3);
  3766. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3767. float percentage = lua_interface->GetFloatValue(state, 5);
  3768. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3769. int16 icon = lua_interface->GetInt16Value(state, 7);
  3770. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3771. if (quest) {
  3772. const char* taskgroup = 0;
  3773. if (str_taskgroup.length() > 0)
  3774. taskgroup = str_taskgroup.c_str();
  3775. int32 id = 0;
  3776. vector<int32>* ids = 0;
  3777. int i = 0;
  3778. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3779. if (ids == 0)
  3780. ids = new vector<int32>;
  3781. ids->push_back(id);
  3782. i++;
  3783. }
  3784. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3785. if (quest_step && icon && quantity > 0)
  3786. quest_step->SetIcon(icon);
  3787. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3788. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3789. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3790. }
  3791. }
  3792. lua_interface->ResetFunctionStack(state);
  3793. return 0;
  3794. }
  3795. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3796. {
  3797. if (!lua_interface)
  3798. return 0;
  3799. Quest* quest = lua_interface->GetQuest(state);
  3800. int32 step = lua_interface->GetInt32Value(state, 2);
  3801. string description = lua_interface->GetStringValue(state, 3);
  3802. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3803. float percentage = lua_interface->GetFloatValue(state, 5);
  3804. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3805. int16 icon = lua_interface->GetInt16Value(state, 7);
  3806. if (quest) {
  3807. const char* taskgroup = 0;
  3808. if (str_taskgroup.length() > 0)
  3809. taskgroup = str_taskgroup.c_str();
  3810. int32 id = 0;
  3811. vector<int32>* ids = 0;
  3812. int i = 0;
  3813. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3814. if (ids == 0)
  3815. ids = new vector<int32>;
  3816. ids->push_back(id);
  3817. i++;
  3818. }
  3819. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3820. if (quest_step && icon > 0 && quantity > 0)
  3821. quest_step->SetIcon(icon);
  3822. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3823. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3824. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3825. }
  3826. safe_delete(ids);
  3827. }
  3828. lua_interface->ResetFunctionStack(state);
  3829. return 0;
  3830. }
  3831. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3832. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3833. }
  3834. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3835. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3836. }
  3837. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3838. if (!lua_interface)
  3839. return 0;
  3840. Quest* quest = lua_interface->GetQuest(state);
  3841. int32 step = lua_interface->GetInt32Value(state, 2);
  3842. string description = lua_interface->GetStringValue(state, 3);
  3843. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3844. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3845. int16 icon = lua_interface->GetInt16Value(state, 6);
  3846. if (quest) {
  3847. const char* taskgroup = 0;
  3848. if (str_taskgroup.length() > 0)
  3849. taskgroup = str_taskgroup.c_str();
  3850. int32 npc_id = 0;
  3851. vector<int32>* ids = 0;
  3852. int i = 0;
  3853. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3854. if (ids == 0)
  3855. ids = new vector<int32>;
  3856. ids->push_back(npc_id);
  3857. i++;
  3858. }
  3859. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3860. if (quest_step && icon > 0)
  3861. quest_step->SetIcon(icon);
  3862. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3863. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3864. if(client)
  3865. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3866. }
  3867. safe_delete(ids);
  3868. }
  3869. lua_interface->ResetFunctionStack(state);
  3870. return 0;
  3871. }
  3872. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3873. if (!lua_interface)
  3874. return 0;
  3875. Quest* quest = lua_interface->GetQuest(state);
  3876. int32 step = lua_interface->GetInt32Value(state, 2);
  3877. string description = lua_interface->GetStringValue(state, 3);
  3878. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3879. float percentage = lua_interface->GetFloatValue(state, 5);
  3880. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3881. int16 icon = lua_interface->GetInt16Value(state, 7);
  3882. if (quest) {
  3883. const char* taskgroup = 0;
  3884. if (str_taskgroup.length() > 0)
  3885. taskgroup = str_taskgroup.c_str();
  3886. int32 item_id = 0;
  3887. vector<int32>* ids = 0;
  3888. int i = 0;
  3889. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3890. if (ids == 0)
  3891. ids = new vector<int32>;
  3892. ids->push_back(item_id);
  3893. i++;
  3894. }
  3895. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3896. if (quest_step && icon > 0 && quantity > 0)
  3897. quest_step->SetIcon(icon);
  3898. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3899. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3900. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3901. }
  3902. safe_delete(ids);
  3903. }
  3904. lua_interface->ResetFunctionStack(state);
  3905. return 0;
  3906. }
  3907. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3908. if (!lua_interface)
  3909. return 0;
  3910. Quest* quest = lua_interface->GetQuest(state);
  3911. int32 step = lua_interface->GetInt32Value(state, 2);
  3912. string description = lua_interface->GetStringValue(state, 3);
  3913. float max_variation = lua_interface->GetFloatValue(state, 4);
  3914. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3915. int16 icon = lua_interface->GetInt16Value(state, 6);
  3916. if (quest) {
  3917. const char* taskgroup = 0;
  3918. if (str_taskgroup.length() > 0)
  3919. taskgroup = str_taskgroup.c_str();
  3920. vector<Location>* locations = 0;
  3921. int8 i = 7;
  3922. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3923. while (true) {
  3924. Location loc;
  3925. loc.x = lua_interface->GetFloatValue(state, i);
  3926. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3927. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3928. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3929. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3930. break;
  3931. if (locations == 0)
  3932. locations = new vector<Location>;
  3933. locations->push_back(loc);
  3934. i += 4;
  3935. }
  3936. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3937. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3938. if (quest_step && icon > 0)
  3939. quest_step->SetIcon(icon);
  3940. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3941. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3942. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3943. }
  3944. }
  3945. lua_interface->ResetFunctionStack(state);
  3946. return 0;
  3947. }
  3948. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3949. if (!lua_interface)
  3950. return 0;
  3951. Quest* quest = lua_interface->GetQuest(state);
  3952. int32 step = lua_interface->GetInt32Value(state, 2);
  3953. string description = lua_interface->GetStringValue(state, 3);
  3954. float max_variation = lua_interface->GetFloatValue(state, 4);
  3955. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3956. int16 icon = lua_interface->GetInt16Value(state, 6);
  3957. if (quest) {
  3958. const char* taskgroup = 0;
  3959. if (str_taskgroup.length() > 0)
  3960. taskgroup = str_taskgroup.c_str();
  3961. vector<Location>* locations = 0;
  3962. int8 i = 7;
  3963. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3964. while (true) {
  3965. Location loc;
  3966. loc.x = lua_interface->GetFloatValue(state, i);
  3967. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3968. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3969. loc.zone_id = 0;
  3970. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3971. break;
  3972. if (locations == 0)
  3973. locations = new vector<Location>;
  3974. locations->push_back(loc);
  3975. i += 3;
  3976. }
  3977. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3978. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3979. if (quest_step && icon > 0)
  3980. quest_step->SetIcon(icon);
  3981. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3982. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3983. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3984. }
  3985. }
  3986. lua_interface->ResetFunctionStack(state);
  3987. return 0;
  3988. }
  3989. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3990. if (!lua_interface)
  3991. return 0;
  3992. Quest* quest = lua_interface->GetQuest(state);
  3993. int32 step = lua_interface->GetInt32Value(state, 2);
  3994. string description = lua_interface->GetStringValue(state, 3);
  3995. float max_variation = lua_interface->GetFloatValue(state, 4);
  3996. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3997. int16 icon = lua_interface->GetInt16Value(state, 6);
  3998. if (quest) {
  3999. const char* taskgroup = 0;
  4000. if (str_taskgroup.length() > 0)
  4001. taskgroup = str_taskgroup.c_str();
  4002. vector<Location>* locations = 0;
  4003. int i = 7;
  4004. while (true) {
  4005. Location loc;
  4006. loc.x = lua_interface->GetFloatValue(state, i);
  4007. loc.y = lua_interface->GetFloatValue(state, i + 1);
  4008. loc.z = lua_interface->GetFloatValue(state, i + 2);
  4009. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  4010. break;
  4011. if (locations == 0)
  4012. locations = new vector<Location>;
  4013. locations->push_back(loc);
  4014. i += 3;
  4015. }
  4016. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  4017. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  4018. if (quest_step && icon > 0)
  4019. quest_step->SetIcon(icon);
  4020. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4021. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4022. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4023. }
  4024. }
  4025. lua_interface->ResetFunctionStack(state);
  4026. return 0;
  4027. }
  4028. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  4029. Quest* quest = lua_interface->GetQuest(state);
  4030. int32 step = lua_interface->GetInt32Value(state, 2);
  4031. string description = lua_interface->GetStringValue(state, 3);
  4032. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4033. float percentage = lua_interface->GetFloatValue(state, 5);
  4034. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4035. int16 icon = lua_interface->GetInt16Value(state, 7);
  4036. if (quest) {
  4037. const char* taskgroup = 0;
  4038. if (str_taskgroup.length() > 0)
  4039. taskgroup = str_taskgroup.c_str();
  4040. int32 spell_id = 0;
  4041. vector<int32>* ids = 0;
  4042. int i = 0;
  4043. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4044. if (ids == 0)
  4045. ids = new vector<int32>;
  4046. ids->push_back(spell_id);
  4047. i++;
  4048. }
  4049. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4050. if (quest_step && icon > 0 && quantity > 0)
  4051. quest_step->SetIcon(icon);
  4052. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4053. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4054. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4055. }
  4056. safe_delete(ids);
  4057. }
  4058. lua_interface->ResetFunctionStack(state);
  4059. return 0;
  4060. }
  4061. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  4062. if (!lua_interface)
  4063. return 0;
  4064. Quest* quest = lua_interface->GetQuest(state);
  4065. int32 step = lua_interface->GetInt32Value(state, 2);
  4066. string description = lua_interface->GetStringValue(state, 3);
  4067. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4068. float percentage = lua_interface->GetFloatValue(state, 5);
  4069. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4070. int16 icon = lua_interface->GetInt16Value(state, 7);
  4071. if (quest) {
  4072. const char* taskgroup = 0;
  4073. if (str_taskgroup.length() > 0)
  4074. taskgroup = str_taskgroup.c_str();
  4075. int32 item_id = 0;
  4076. vector<int32>* ids = 0;
  4077. int i = 0;
  4078. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4079. if (ids == 0)
  4080. ids = new vector<int32>;
  4081. ids->push_back(item_id);
  4082. i++;
  4083. }
  4084. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4085. if (quest_step && icon > 0 && quantity > 0)
  4086. quest_step->SetIcon(icon);
  4087. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4088. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4089. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4090. }
  4091. safe_delete(ids);
  4092. }
  4093. lua_interface->ResetFunctionStack(state);
  4094. return 0;
  4095. }
  4096. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  4097. if (!lua_interface)
  4098. return 0;
  4099. Quest* quest = lua_interface->GetQuest(state);
  4100. int32 step = lua_interface->GetInt32Value(state, 2);
  4101. string description = lua_interface->GetStringValue(state, 3);
  4102. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4103. float percentage = lua_interface->GetFloatValue(state, 5);
  4104. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4105. int16 icon = lua_interface->GetInt16Value(state, 7);
  4106. if (quest) {
  4107. const char* taskgroup = 0;
  4108. if (str_taskgroup.length() > 0)
  4109. taskgroup = str_taskgroup.c_str();
  4110. int32 item_id = 0;
  4111. vector<int32>* ids = 0;
  4112. int i = 0;
  4113. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4114. if (ids == 0)
  4115. ids = new vector<int32>;
  4116. ids->push_back(item_id);
  4117. i++;
  4118. }
  4119. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4120. if (quest_step && icon > 0 && quantity > 0)
  4121. quest_step->SetIcon(icon);
  4122. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4123. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4124. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4125. }
  4126. safe_delete(ids);
  4127. }
  4128. lua_interface->ResetFunctionStack(state);
  4129. return 0;
  4130. }
  4131. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  4132. if (!lua_interface)
  4133. return 0;
  4134. Quest* quest = lua_interface->GetQuest(state);
  4135. string action = lua_interface->GetStringValue(state, 2);
  4136. lua_interface->ResetFunctionStack(state);
  4137. if (quest) {
  4138. if (action.length() > 0)
  4139. quest->SetCompleteAction(action);
  4140. }
  4141. return 0;
  4142. }
  4143. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  4144. if (!lua_interface)
  4145. return 0;
  4146. Quest* quest = lua_interface->GetQuest(state);
  4147. int32 step = lua_interface->GetInt32Value(state, 2);
  4148. string action = lua_interface->GetStringValue(state, 3);
  4149. lua_interface->ResetFunctionStack(state);
  4150. if (quest) {
  4151. if (step > 0 && action.length() > 0)
  4152. quest->AddCompleteAction(step, action);
  4153. }
  4154. return 0;
  4155. }
  4156. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  4157. if (!lua_interface)
  4158. return 0;
  4159. Quest* quest = lua_interface->GetQuest(state);
  4160. int32 step = lua_interface->GetInt32Value(state, 2);
  4161. string action = lua_interface->GetStringValue(state, 3);
  4162. lua_interface->ResetFunctionStack(state);
  4163. if (quest) {
  4164. if (step > 0 && action.length() > 0)
  4165. quest->AddProgressAction(step, action);
  4166. }
  4167. return 0;
  4168. }
  4169. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  4170. if (!lua_interface)
  4171. return 0;
  4172. Quest* quest = lua_interface->GetQuest(state);
  4173. string description = lua_interface->GetStringValue(state, 2);
  4174. lua_interface->ResetFunctionStack(state);
  4175. if (quest && description.length() > 0)
  4176. quest->SetDescription(description);
  4177. return 0;
  4178. }
  4179. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4180. if (!lua_interface)
  4181. return 0;
  4182. Quest* quest = lua_interface->GetQuest(state);
  4183. string description = lua_interface->GetStringValue(state, 2);
  4184. lua_interface->ResetFunctionStack(state);
  4185. if (quest && description.length() > 0)
  4186. quest->SetCompletedDescription(description);
  4187. return 0;
  4188. }
  4189. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4190. if (!lua_interface)
  4191. return 0;
  4192. Quest* quest = lua_interface->GetQuest(state);
  4193. int32 step = lua_interface->GetInt32Value(state, 2);
  4194. string description = lua_interface->GetStringValue(state, 3);
  4195. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4196. lua_interface->ResetFunctionStack(state);
  4197. if (quest && step > 0 && description.length() > 0) {
  4198. quest->SetTaskGroupDescription(step, description, display_bullets);
  4199. }
  4200. return 0;
  4201. }
  4202. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4203. if (!lua_interface)
  4204. return 0;
  4205. Quest* quest = lua_interface->GetQuest(state);
  4206. int32 step = lua_interface->GetInt32Value(state, 2);
  4207. string description = lua_interface->GetStringValue(state, 3);
  4208. lua_interface->ResetFunctionStack(state);
  4209. if (quest && step > 0 && description.length() > 0) {
  4210. quest->SetStepDescription(step, description);
  4211. }
  4212. return 0;
  4213. }
  4214. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4215. Quest* quest = lua_interface->GetQuest(state);
  4216. string zone = lua_interface->GetStringValue(state, 2);
  4217. lua_interface->ResetFunctionStack(state);
  4218. if (quest && zone.length() > 0)
  4219. quest->SetZone(zone);
  4220. return 0;
  4221. }
  4222. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4223. if (!lua_interface)
  4224. return 0;
  4225. Quest* quest = lua_interface->GetQuest(state);
  4226. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4227. lua_interface->ResetFunctionStack(state);
  4228. if (quest && spawn) {
  4229. if (spawn->IsPlayer()) {
  4230. Client* client = ((Player*)spawn)->GetClient();
  4231. if (client) {
  4232. client->AddPendingQuestReward(quest);
  4233. }
  4234. }
  4235. }
  4236. return 0;
  4237. }
  4238. int EQ2Emu_lua_Harvest(lua_State* state) {
  4239. if (!lua_interface)
  4240. return 0;
  4241. Spawn* player = lua_interface->GetSpawn(state);
  4242. Spawn* node = lua_interface->GetSpawn(state, 2);
  4243. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4244. Client* client = ((Player*)player)->GetClient();
  4245. if (client) {
  4246. ((GroundSpawn*)node)->ProcessHarvest(client);
  4247. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4248. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4249. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4250. }
  4251. }
  4252. }
  4253. else if (player && player->IsPlayer()) {
  4254. Client* client = ((Player*)player)->GetClient();
  4255. if (client)
  4256. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4257. }
  4258. lua_interface->ResetFunctionStack(state);
  4259. return 0;
  4260. }
  4261. int EQ2Emu_lua_Bind(lua_State* state) {
  4262. if (!lua_interface)
  4263. return 0;
  4264. Spawn* spawn = lua_interface->GetSpawn(state);
  4265. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4266. float x = lua_interface->GetFloatValue(state, 3);
  4267. float y = lua_interface->GetFloatValue(state, 4);
  4268. float z = lua_interface->GetFloatValue(state, 5);
  4269. float h = lua_interface->GetFloatValue(state, 6);
  4270. lua_interface->ResetFunctionStack(state);
  4271. if (!spawn) {
  4272. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4273. return 0;
  4274. }
  4275. if (!spawn->IsPlayer()) {
  4276. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4277. return 0;
  4278. }
  4279. if (zone_id == 0) {
  4280. Client* client = ((Player*)spawn)->GetClient();
  4281. if (!client) {
  4282. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4283. return 0;
  4284. }
  4285. if (!client->Bind())
  4286. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4287. }
  4288. else {
  4289. Player* player = (Player*)spawn;
  4290. player->GetPlayerInfo()->SetBindZone(zone_id);
  4291. player->GetPlayerInfo()->SetBindX(x);
  4292. player->GetPlayerInfo()->SetBindY(y);
  4293. player->GetPlayerInfo()->SetBindZ(z);
  4294. player->GetPlayerInfo()->SetBindHeading(h);
  4295. }
  4296. return 0;
  4297. }
  4298. int EQ2Emu_lua_Gate(lua_State* state) {
  4299. if (!lua_interface)
  4300. return 0;
  4301. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4302. Spawn* spawn = lua_interface->GetSpawn(state);
  4303. lua_interface->ResetFunctionStack(state);
  4304. if (spawn) {
  4305. if (spawn->IsPlayer()) {
  4306. Client* client = ((Player*)spawn)->GetClient();
  4307. if (client) {
  4308. if (!client->Gate((spell != nullptr) ? true : false))
  4309. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4310. }
  4311. }
  4312. }
  4313. return 0;
  4314. }
  4315. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4316. if (!lua_interface)
  4317. return 0;
  4318. bool ret = false;
  4319. Spawn* spawn = lua_interface->GetSpawn(state);
  4320. lua_interface->ResetFunctionStack(state);
  4321. if (spawn) {
  4322. if (spawn->IsPlayer()) {
  4323. Client* client = ((Player*)spawn)->GetClient();
  4324. if (client)
  4325. ret = client->BindAllowed();
  4326. }
  4327. }
  4328. lua_interface->SetBooleanValue(state, ret);
  4329. return 1;
  4330. }
  4331. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4332. if (!lua_interface)
  4333. return 0;
  4334. bool ret = false;
  4335. Spawn* spawn = lua_interface->GetSpawn(state);
  4336. lua_interface->ResetFunctionStack(state);
  4337. if (spawn) {
  4338. if (spawn->IsPlayer()) {
  4339. Client* client = ((Player*)spawn)->GetClient();
  4340. ZoneServer* zone = lua_interface->GetZone(state);
  4341. if (client && zone){
  4342. ret = zone->GetCanGate();
  4343. }
  4344. }
  4345. }
  4346. lua_interface->SetBooleanValue(state, ret);
  4347. return 1;
  4348. }
  4349. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4350. Spawn* spawn = lua_interface->GetSpawn(state);
  4351. lua_interface->ResetFunctionStack(state);
  4352. if (spawn) {
  4353. lua_interface->SetBooleanValue(state, spawn->Alive());
  4354. return 1;
  4355. }
  4356. return 0;
  4357. }
  4358. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4359. if (!lua_interface)
  4360. return 0;
  4361. Spawn* spawn = lua_interface->GetSpawn(state);
  4362. lua_interface->ResetFunctionStack(state);
  4363. if (spawn && spawn->IsEntity()) {
  4364. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4365. return 1;
  4366. }
  4367. return 0;
  4368. }
  4369. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4370. Spawn* spawn = lua_interface->GetSpawn(state);
  4371. string message = lua_interface->GetStringValue(state, 2);
  4372. string color_str = lua_interface->GetStringValue(state, 3);
  4373. lua_interface->ResetFunctionStack(state);
  4374. int8 color = CHANNEL_NARRATIVE;
  4375. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4376. Client* client = ((Player*)spawn)->GetClient();
  4377. if (client) {
  4378. if (color_str.length() > 0) {
  4379. // leave for backwards compat, but all future should just use the number
  4380. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4381. color = CHANNEL_COLOR_RED;
  4382. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4383. color = CHANNEL_COLOR_YELLOW;
  4384. else
  4385. {
  4386. // use a number to specify the channel as per Commands/Commands.h defines
  4387. color = (int8)atoul(color_str.c_str());
  4388. }
  4389. }
  4390. client->SimpleMessage(color, message.c_str());
  4391. }
  4392. }
  4393. return 0;
  4394. }
  4395. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4396. Spawn* spawn = lua_interface->GetSpawn(state);
  4397. string message = lua_interface->GetStringValue(state, 2);
  4398. int8 red = lua_interface->GetInt8Value(state, 3);
  4399. int8 green = lua_interface->GetInt8Value(state, 4);
  4400. int8 blue = lua_interface->GetInt8Value(state, 5);
  4401. lua_interface->ResetFunctionStack(state);
  4402. if (!spawn) {
  4403. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4404. return 0;
  4405. }
  4406. if (!spawn->IsPlayer()) {
  4407. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not a player.", lua_interface->GetScriptName(state));
  4408. return 0;
  4409. }
  4410. int32 words = ::CountWordsInString(message.c_str());
  4411. if (words < 5)
  4412. words = 5;
  4413. Client* client = ((Player*)spawn)->GetClient();
  4414. if (client)
  4415. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4416. return 0;
  4417. }
  4418. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4419. Spawn* spawn = lua_interface->GetSpawn(state);
  4420. int8 param = lua_interface->GetInt8Value(state, 2);
  4421. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4422. int8 value = lua_interface->GetInt8Value(state, 4);
  4423. lua_interface->ResetFunctionStack(state);
  4424. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4425. Client* client = ((Player*)spawn)->GetClient();
  4426. if (client) {
  4427. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4428. switch (param) {
  4429. case 1: {
  4430. packet->setDataByName("parameter1", param_value);
  4431. break;
  4432. }
  4433. case 2: {
  4434. packet->setDataByName("parameter2", param_value);
  4435. break;
  4436. }
  4437. case 3: {
  4438. packet->setDataByName("parameter3", param_value);
  4439. break;
  4440. }
  4441. case 4: {
  4442. packet->setDataByName("parameter4", param_value);
  4443. break;
  4444. }
  4445. case 5: {
  4446. packet->setDataByName("parameter5", param_value);
  4447. break;
  4448. }
  4449. }
  4450. packet->setDataByName("value", value);
  4451. client->QueuePacket(packet->serialize());
  4452. safe_delete(packet);
  4453. }
  4454. }
  4455. return 0;
  4456. }
  4457. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4458. Spawn* spawn = lua_interface->GetSpawn(state);
  4459. lua_interface->ResetFunctionStack(state);
  4460. if (spawn && spawn->IsPlayer()) {
  4461. if (((Player*)spawn)->GetIsTracking())
  4462. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4463. else
  4464. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4465. }
  4466. return 0;
  4467. }
  4468. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4469. Spawn* player = lua_interface->GetSpawn(state);
  4470. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4471. string name = lua_interface->GetStringValue(state, 3);
  4472. float distance = lua_interface->GetFloatValue(state, 4);
  4473. string command = lua_interface->GetStringValue(state, 5);
  4474. string error_text = lua_interface->GetStringValue(state, 6);
  4475. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4476. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4477. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4478. lua_interface->ResetFunctionStack(state);
  4479. if (spawn) {
  4480. if (distance == 0)
  4481. distance = 10.0f;
  4482. if (command.length() == 0)
  4483. command = name;
  4484. if (command.length() < 1 && name.length() < 1)
  4485. {
  4486. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4487. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4488. spawn->RemovePrimaryCommands();
  4489. }
  4490. else
  4491. {
  4492. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4493. }
  4494. }
  4495. return 0;
  4496. }
  4497. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4498. if (!lua_interface)
  4499. return 0;
  4500. Spawn* player = lua_interface->GetSpawn(state);
  4501. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4502. int16 tier = lua_interface->GetInt16Value(state, 3);
  4503. lua_interface->ResetFunctionStack(state);
  4504. if (player && player->IsPlayer()) {
  4505. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4506. return 1;
  4507. }
  4508. return 0;
  4509. }
  4510. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4511. if (!lua_interface)
  4512. return 0;
  4513. Spawn* player = lua_interface->GetSpawn(state);
  4514. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4515. int16 tier = lua_interface->GetInt16Value(state, 3);
  4516. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4517. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4518. bool add_to_hotbar = true;
  4519. if (num_args > 4) {
  4520. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4521. }
  4522. lua_interface->ResetFunctionStack(state);
  4523. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4524. if (player && spell && player->IsPlayer()) {
  4525. Client* client = player->GetClient();
  4526. if (client) {
  4527. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4528. {
  4529. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4530. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4531. client->GetPlayer()->UnlockSpell(spell);
  4532. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4533. }
  4534. else
  4535. {
  4536. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4537. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4538. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4539. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4540. client->GetPlayer()->UnlockSpell(spell);
  4541. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4542. }
  4543. //if (client ) {
  4544. // ((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);
  4545. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4546. if (outapp)
  4547. client->QueuePacket(outapp);
  4548. }
  4549. }
  4550. return 0;
  4551. }
  4552. int EQ2Emu_lua_DeleteSpellBook(lua_State* state) {
  4553. if (!lua_interface)
  4554. return 0;
  4555. Spawn* player = lua_interface->GetSpawn(state);
  4556. int8 type_selection = lua_interface->GetInt8Value(state, 2);
  4557. lua_interface->ResetFunctionStack(state);
  4558. if (player && player->IsPlayer()) {
  4559. Client* client = player->GetClient();
  4560. if (client) {
  4561. ((Player*)player)->DeleteSpellBook(type_selection);
  4562. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4563. if (outapp)
  4564. client->QueuePacket(outapp);
  4565. }
  4566. }
  4567. return 0;
  4568. }
  4569. int EQ2Emu_lua_SendNewAdventureSpells(lua_State* state) {
  4570. if (!lua_interface)
  4571. return 0;
  4572. Spawn* player = lua_interface->GetSpawn(state);
  4573. lua_interface->ResetFunctionStack(state);
  4574. if (player && player->IsPlayer()) {
  4575. Client* client = player->GetClient();
  4576. if (client) {
  4577. client->SendNewAdventureSpells();
  4578. }
  4579. }
  4580. return 0;
  4581. }
  4582. int EQ2Emu_lua_SendNewTradeskillSpells(lua_State* state) {
  4583. if (!lua_interface)
  4584. return 0;
  4585. Spawn* player = lua_interface->GetSpawn(state);
  4586. lua_interface->ResetFunctionStack(state);
  4587. if (player && player->IsPlayer()) {
  4588. Client* client = player->GetClient();
  4589. if (client) {
  4590. client->SendNewTradeskillSpells();
  4591. }
  4592. }
  4593. return 0;
  4594. }
  4595. int EQ2Emu_lua_RemoveSpellBookEntry(lua_State* state) {
  4596. if (!lua_interface)
  4597. return 0;
  4598. Spawn* player = lua_interface->GetSpawn(state);
  4599. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4600. lua_interface->ResetFunctionStack(state);
  4601. if (player && player->IsPlayer()) {
  4602. SpellBookEntry* sbe = ((Player*)player)->GetSpellBookSpell(spellid);
  4603. Client* client = player->GetClient();
  4604. if (sbe && client) {
  4605. ((Player*)player)->RemoveSpellBookEntry(spellid);
  4606. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4607. if (outapp)
  4608. client->QueuePacket(outapp);
  4609. }
  4610. }
  4611. return 0;
  4612. }
  4613. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4614. if (!lua_interface)
  4615. return 0;
  4616. Spawn* player = lua_interface->GetSpawn(state);
  4617. lua_interface->ResetFunctionStack(state);
  4618. if (player && player->IsPlayer()) {
  4619. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4620. return 1;
  4621. }
  4622. return 0;
  4623. }
  4624. int EQ2Emu_lua_Attack(lua_State* state) {
  4625. if (lua_interface) {
  4626. Spawn* npc = lua_interface->GetSpawn(state);
  4627. Spawn* player = lua_interface->GetSpawn(state, 2);
  4628. lua_interface->ResetFunctionStack(state);
  4629. if (npc && player && npc->IsNPC() && player->IsEntity())
  4630. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4631. }
  4632. return 0;
  4633. }
  4634. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4635. if (lua_interface) {
  4636. Spawn* target = lua_interface->GetSpawn(state);
  4637. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4638. lua_interface->ResetFunctionStack(state);
  4639. if (target && target->GetZone())
  4640. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4641. }
  4642. return 0;
  4643. }
  4644. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4645. Spawn* player;
  4646. if (lua_interface) {
  4647. player = lua_interface->GetSpawn(state);
  4648. lua_interface->ResetFunctionStack(state);
  4649. if (player && player->IsPlayer()) {
  4650. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4651. return 1;
  4652. }
  4653. }
  4654. return 0;
  4655. }
  4656. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4657. Spawn* player;
  4658. Client* client;
  4659. if (lua_interface) {
  4660. player = lua_interface->GetSpawn(state);
  4661. lua_interface->ResetFunctionStack(state);
  4662. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4663. if ((client = ((Player*)player)->GetClient()))
  4664. client->HandInCollections();
  4665. }
  4666. return 0;
  4667. }
  4668. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4669. Spawn* widget;
  4670. if (lua_interface) {
  4671. widget = lua_interface->GetSpawn(state);
  4672. lua_interface->ResetFunctionStack(state);
  4673. if (widget && widget->IsWidget())
  4674. ((Widget*)widget)->HandleUse(nullptr, "");
  4675. }
  4676. return 0;
  4677. }
  4678. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4679. Spawn* spawn = 0;
  4680. int32 primary_list = 0;
  4681. int32 secondary_list = 0;
  4682. if (lua_interface) {
  4683. spawn = lua_interface->GetSpawn(state);
  4684. primary_list = lua_interface->GetInt32Value(state, 2);
  4685. secondary_list = lua_interface->GetInt32Value(state, 3);
  4686. lua_interface->ResetFunctionStack(state);
  4687. if (!spawn->IsNPC()) {
  4688. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4689. return 0;
  4690. }
  4691. NPC* npc = (NPC*)spawn;
  4692. npc->SetPrimarySpellList(primary_list);
  4693. npc->SetSecondarySpellList(secondary_list);
  4694. npc->SetSpells(world.GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4695. }
  4696. return 0;
  4697. }
  4698. int EQ2Emu_lua_GetPet(lua_State* state) {
  4699. if (!lua_interface)
  4700. return 0;
  4701. Spawn* spawn = lua_interface->GetSpawn(state);
  4702. lua_interface->ResetFunctionStack(state);
  4703. if (spawn) {
  4704. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4705. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4706. return 1;
  4707. }
  4708. }
  4709. return 0;
  4710. }
  4711. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4712. if (!lua_interface)
  4713. return 0;
  4714. Spawn* spawn = lua_interface->GetSpawn(state);
  4715. lua_interface->ResetFunctionStack(state);
  4716. if (spawn) {
  4717. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4718. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4719. return 1;
  4720. }
  4721. }
  4722. return 0;
  4723. }
  4724. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4725. if (!lua_interface)
  4726. return 0;
  4727. Spawn* spawn = lua_interface->GetSpawn(state);
  4728. lua_interface->ResetFunctionStack(state);
  4729. if (spawn) {
  4730. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4731. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4732. return 1;
  4733. }
  4734. }
  4735. return 0;
  4736. }
  4737. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4738. if (!lua_interface)
  4739. return 0;
  4740. Spawn* spawn = lua_interface->GetSpawn(state);
  4741. lua_interface->ResetFunctionStack(state);
  4742. if (spawn) {
  4743. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4744. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4745. return 1;
  4746. }
  4747. }
  4748. return 0;
  4749. }
  4750. int EQ2Emu_lua_Charm(lua_State* state) {
  4751. if (!lua_interface)
  4752. return 0;
  4753. Spawn* owner = lua_interface->GetSpawn(state);
  4754. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4755. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4756. lua_interface->ResetFunctionStack(state);
  4757. if (!luaspell) {
  4758. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4759. return 0;
  4760. }
  4761. if(luaspell->resisted) {
  4762. return 0;
  4763. }
  4764. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4765. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4766. pet->SetPet(true);
  4767. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4768. ((NPC*)pet)->SetOwner((Entity*)owner);
  4769. // If owner is player and player does not have a summoned pet set the players charsheet
  4770. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4771. Player* player = (Player*)owner;
  4772. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4773. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4774. player->GetInfoStruct()->set_pet_movement(2);
  4775. player->GetInfoStruct()->set_pet_behavior(3);
  4776. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4777. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4778. // Make sure the values get sent to the client
  4779. player->SetCharSheetChanged(true);
  4780. }
  4781. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4782. pet->SetSpawnScript("");
  4783. // Set faction to the same as the owner
  4784. pet->SetFactionID(owner->GetFactionID());
  4785. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4786. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4787. // Clear hate list
  4788. ((NPC*)pet)->Brain()->ClearHate();
  4789. // Set the brain to a pet brain
  4790. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4791. }
  4792. return 0;
  4793. }
  4794. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4795. if (!lua_interface)
  4796. return 0;
  4797. Spawn* spawn = lua_interface->GetSpawn(state);
  4798. lua_interface->ResetFunctionStack(state);
  4799. if (!spawn) {
  4800. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4801. return 0;
  4802. }
  4803. vector<Spawn*> groupMembers;
  4804. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4805. groupMembers = *spawn->GetSpawnGroup();
  4806. }
  4807. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4808. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4809. deque<GroupMemberInfo*>::iterator itr;
  4810. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4811. if (group)
  4812. {
  4813. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4814. deque<GroupMemberInfo*>* members = group->GetMembers();
  4815. GroupMemberInfo* info = 0;
  4816. for (itr = members->begin(); itr != members->end(); itr++) {
  4817. info = *itr;
  4818. if (info->client)
  4819. groupMembers.push_back(info->client->GetPlayer());
  4820. }
  4821. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4822. }
  4823. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4824. }
  4825. else
  4826. return 0;
  4827. lua_createtable(state, groupMembers.size(), 0);
  4828. int newTable = lua_gettop(state);
  4829. for (int32 i = 0; i < groupMembers.size(); i++) {
  4830. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4831. lua_rawseti(state, newTable, i + 1);
  4832. }
  4833. return 1;
  4834. }
  4835. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4836. if (!lua_interface)
  4837. return 0;
  4838. lua_interface->ResetFunctionStack(state);
  4839. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4840. lua_interface->SetOptionWindowValue(state, option_window);
  4841. return 1;
  4842. }
  4843. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4844. if (!lua_interface)
  4845. return 0;
  4846. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4847. if (option_window) {
  4848. OptionWindowOption option_window_option;
  4849. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4850. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4851. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4852. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4853. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4854. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4855. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4856. option_window->push_back(option_window_option);
  4857. }
  4858. lua_interface->ResetFunctionStack(state);
  4859. return 0;
  4860. }
  4861. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4862. if (!lua_interface)
  4863. return 0;
  4864. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4865. Spawn* player = lua_interface->GetSpawn(state, 2);
  4866. string window_title = lua_interface->GetStringValue(state, 3);
  4867. string cancel_command = lua_interface->GetStringValue(state, 4);
  4868. lua_interface->ResetFunctionStack(state);
  4869. if (!player->IsPlayer()) {
  4870. lua_interface->LogError("%s: LUA SendOptionWindow command error: spawn is not a player", lua_interface->GetScriptName(state));
  4871. return 0;
  4872. }
  4873. Client* client = ((Player*)player)->GetClient();
  4874. if (option_window && window_title.length() > 0 && client) {
  4875. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4876. if (!packet)
  4877. return 0;
  4878. packet->setDataByName("title_text", window_title.c_str());
  4879. if (cancel_command.length() > 0)
  4880. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4881. packet->setArrayLengthByName("num_selections", option_window->size());
  4882. vector<OptionWindowOption>::iterator itr;
  4883. int8 i = 0;
  4884. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4885. OptionWindowOption opt = *itr;
  4886. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4887. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4888. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4889. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4890. if (opt.optionCommand.length() > 0)
  4891. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4892. if (opt.optionConfirmTitle.length() > 0)
  4893. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4894. i++;
  4895. }
  4896. client->QueuePacket(packet->serialize());
  4897. lua_interface->SetLuaUserDataStale(option_window);
  4898. safe_delete(option_window);
  4899. safe_delete(packet);
  4900. }
  4901. return 0;
  4902. }
  4903. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4904. if (!lua_interface)
  4905. return 0;
  4906. Spawn* spawn = lua_interface->GetSpawn(state);
  4907. lua_interface->ResetFunctionStack(state);
  4908. if (spawn) {
  4909. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4910. return 1;
  4911. }
  4912. else
  4913. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4914. return 0;
  4915. }
  4916. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4917. if (!lua_interface)
  4918. return 0;
  4919. Spawn* spawn = lua_interface->GetSpawn(state);
  4920. lua_interface->ResetFunctionStack(state);
  4921. if (spawn) {
  4922. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4923. return 1;
  4924. }
  4925. else
  4926. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4927. return 0;
  4928. }
  4929. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4930. if (!lua_interface)
  4931. return 0;
  4932. Spawn* spawn = lua_interface->GetSpawn(state);
  4933. lua_interface->ResetFunctionStack(state);
  4934. if (spawn) {
  4935. int8 class_id = spawn->GetTradeskillClass();
  4936. // Need to add 42 for the offset in the array
  4937. class_id += 44;
  4938. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4939. return 1;
  4940. }
  4941. else
  4942. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4943. return 0;
  4944. }
  4945. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4946. if (!lua_interface)
  4947. return 0;
  4948. Spawn* spawn = lua_interface->GetSpawn(state);
  4949. int16 level = lua_interface->GetInt8Value(state, 2);
  4950. lua_interface->ResetFunctionStack(state);
  4951. if (spawn) {
  4952. if (spawn->IsPlayer() && ((Player*)spawn)->GetClient())
  4953. ((Player*)spawn)->GetClient()->ChangeTSLevel(spawn->GetTSLevel(), level);
  4954. else
  4955. spawn->SetTSLevel(level);
  4956. }
  4957. else
  4958. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4959. return 0;
  4960. }
  4961. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4962. if (!lua_interface)
  4963. return 0;
  4964. Spawn* spawn = lua_interface->GetSpawn(state);
  4965. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4966. lua_interface->ResetFunctionStack(state);
  4967. if (spawn) {
  4968. spawn->SetAttackable(attackable);
  4969. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4970. }
  4971. return 0;
  4972. }
  4973. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4974. // Check to see if we have a valid lua_interface
  4975. if (!lua_interface)
  4976. return 0;
  4977. // Get the spawn that is getting the pet
  4978. Spawn* spawn = lua_interface->GetSpawn(state);
  4979. // Get the DB ID of the pet
  4980. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4981. // The max level the pet can gain
  4982. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4983. // Get the spell that this command was called from
  4984. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4985. lua_interface->ResetFunctionStack(state);
  4986. // Check to make sure the spawn pointer is valid
  4987. if (!spawn) {
  4988. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4989. return 0;
  4990. }
  4991. // Check to make sure the spawn is an entity
  4992. if (!spawn->IsEntity()) {
  4993. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4994. return 0;
  4995. }
  4996. // Check to make sure the spawn doesn't already have a pet of this type
  4997. if (((Entity*)spawn)->GetPet()) {
  4998. if (spawn->IsPlayer()) {
  4999. Client* client = ((Player*)spawn)->GetClient();
  5000. if (client)
  5001. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  5002. }
  5003. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5004. return 0;
  5005. }
  5006. // Check to see if the DB ID for the pet is set
  5007. if (pet_id == 0) {
  5008. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5009. return 0;
  5010. }
  5011. // Check to see if the pointer to the spell is valid
  5012. if (!luaspell) {
  5013. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5014. return 0;
  5015. }
  5016. if(luaspell->resisted) {
  5017. return 0;
  5018. }
  5019. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  5020. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5021. if (!pet) {
  5022. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5023. return 0;
  5024. }
  5025. // Check to make sure the pet is an npc
  5026. if (!pet->IsNPC()) {
  5027. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  5028. return 0;
  5029. }
  5030. // Spawn the pet at the same location as the owner
  5031. pet->SetX(spawn->GetX());
  5032. pet->SetY(spawn->GetY());
  5033. pet->SetZ(spawn->GetZ());
  5034. pet->SetLocation(spawn->GetLocation());
  5035. pet->SetHeading(spawn->GetHeading());
  5036. std::string petName = std::string("");
  5037. if(spawn->IsEntity()) {
  5038. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  5039. }
  5040. if(petName.size() < 1) {
  5041. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5042. petName = spawn->GetZone()->pet_names.at(rand_index);
  5043. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  5044. }
  5045. // If player set various values for the char sheet (pet window)
  5046. if (spawn->IsPlayer()) {
  5047. Player* player = (Player*)spawn;
  5048. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  5049. player->GetInfoStruct()->set_pet_name(petName);
  5050. player->GetInfoStruct()->set_pet_movement(2);
  5051. player->GetInfoStruct()->set_pet_behavior(3);
  5052. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  5053. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  5054. // Make sure the values get sent to the client
  5055. player->SetCharSheetChanged(true);
  5056. }
  5057. // Set the pets name
  5058. pet->SetName(petName.c_str());
  5059. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  5060. if (max_level > 0)
  5061. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  5062. else
  5063. pet->SetLevel(spawn->GetLevel());
  5064. // Set the max level this pet can reach
  5065. ((NPC*)pet)->SetMaxPetLevel(max_level);
  5066. ((NPC*)pet)->UpdateWeapons();
  5067. // Set the faction of the pet to the same faction as the owner
  5068. pet->SetFactionID(spawn->GetFactionID());
  5069. // Set the spawn as a pet
  5070. pet->SetPet(true);
  5071. // Give a pointer of the owner to the pet
  5072. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5073. // Give a pointer of the pet to the owner
  5074. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  5075. // Set the pet type
  5076. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  5077. // Set the spell id used to create this pet
  5078. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5079. // Set the spell tier used to create this pet
  5080. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5081. // Set the pets spawn type to 6
  5082. pet->SetSpawnType(6);
  5083. // Set the pets brain
  5084. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  5085. // Check to see if the pet has a subtitle
  5086. if (strlen(pet->GetSubTitle()) > 0) {
  5087. // Add the players name to the front of the sub title
  5088. string pet_subtitle;
  5089. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5090. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5091. // Set the pets subtitle to the new one
  5092. pet->SetSubTitle(pet_subtitle.c_str());
  5093. }
  5094. // Add the "Pet Options" entity command to the pet
  5095. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5096. const char* spawn_script = world.GetSpawnScript(pet_id);
  5097. bool runScript = false;
  5098. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  5099. runScript = true;
  5100. pet->SetSpawnScript(string(spawn_script));
  5101. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_PRESPAWN);
  5102. }
  5103. spawn->GetZone()->AddSpawn(pet);
  5104. if(runScript){
  5105. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_SPAWN);
  5106. }
  5107. // Set the pet as the return value for this function
  5108. lua_interface->SetSpawnValue(state, pet);
  5109. return 1;
  5110. }
  5111. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  5112. if (!lua_interface)
  5113. return 0;
  5114. Spawn* spawn = lua_interface->GetSpawn(state);
  5115. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5116. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5117. lua_interface->ResetFunctionStack(state);
  5118. if (!spawn) {
  5119. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5120. return 0;
  5121. }
  5122. if (!spawn->IsEntity()) {
  5123. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5124. return 0;
  5125. }
  5126. if (((Entity*)spawn)->GetDeityPet()) {
  5127. if (spawn->IsPlayer()) {
  5128. Client* client = ((Player*)spawn)->GetClient();
  5129. if (client)
  5130. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  5131. }
  5132. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5133. return 0;
  5134. }
  5135. if (pet_id == 0) {
  5136. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5137. return 0;
  5138. }
  5139. if (!luaspell) {
  5140. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5141. return 0;
  5142. }
  5143. if(luaspell->resisted) {
  5144. return 0;
  5145. }
  5146. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5147. if (!pet) {
  5148. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5149. return 0;
  5150. }
  5151. if (!pet->IsNPC()) {
  5152. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5153. return 0;
  5154. }
  5155. pet->SetX(spawn->GetX());
  5156. pet->SetY(spawn->GetY());
  5157. pet->SetZ(spawn->GetZ());
  5158. pet->SetLocation(spawn->GetLocation());
  5159. pet->SetHeading(spawn->GetHeading());
  5160. spawn->GetZone()->AddSpawn(pet);
  5161. string random_pet_name;
  5162. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5163. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5164. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5165. pet->SetName(random_pet_name.c_str());
  5166. pet->SetLevel(spawn->GetLevel());
  5167. pet->SetFactionID(spawn->GetFactionID());
  5168. pet->SetPet(true);
  5169. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  5170. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5171. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  5172. pet->SetSpawnType(6);
  5173. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5174. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5175. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5176. if (strlen(pet->GetSubTitle()) > 0) {
  5177. string pet_subtitle;
  5178. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5179. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5180. pet->SetSubTitle(pet_subtitle.c_str());
  5181. }
  5182. // deity and cosmetic pets are not attackable
  5183. pet->SetAttackable(false);
  5184. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5185. lua_interface->SetSpawnValue(state, pet);
  5186. return 1;
  5187. }
  5188. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  5189. if (!lua_interface)
  5190. return 0;
  5191. Spawn* spawn = lua_interface->GetSpawn(state);
  5192. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5193. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5194. lua_interface->ResetFunctionStack(state);
  5195. if (!spawn) {
  5196. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5197. return 0;
  5198. }
  5199. if (!spawn->IsEntity()) {
  5200. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5201. return 0;
  5202. }
  5203. if (((Entity*)spawn)->GetCosmeticPet()) {
  5204. if (spawn->IsPlayer()) {
  5205. Client* client = ((Player*)spawn)->GetClient();
  5206. if (client)
  5207. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  5208. }
  5209. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5210. return 0;
  5211. }
  5212. if (pet_id == 0) {
  5213. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5214. return 0;
  5215. }
  5216. if (!luaspell) {
  5217. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5218. return 0;
  5219. }
  5220. if(luaspell->resisted) {
  5221. return 0;
  5222. }
  5223. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5224. if (!pet) {
  5225. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5226. return 0;
  5227. }
  5228. if (!pet->IsNPC()) {
  5229. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5230. return 0;
  5231. }
  5232. pet->SetX(spawn->GetX());
  5233. pet->SetY(spawn->GetY());
  5234. pet->SetZ(spawn->GetZ());
  5235. pet->SetLocation(spawn->GetLocation());
  5236. pet->SetHeading(spawn->GetHeading());
  5237. spawn->GetZone()->AddSpawn(pet);
  5238. string random_pet_name;
  5239. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5240. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5241. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5242. pet->SetName(random_pet_name.c_str());
  5243. pet->SetLevel(spawn->GetLevel());
  5244. pet->SetFactionID(spawn->GetFactionID());
  5245. pet->SetPet(true);
  5246. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  5247. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5248. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5249. pet->SetSpawnType(6);
  5250. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5251. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5252. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5253. if (strlen(pet->GetSubTitle()) > 0) {
  5254. string pet_subtitle;
  5255. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5256. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5257. pet->SetSubTitle(pet_subtitle.c_str());
  5258. }
  5259. pet->SetAttackable(false);
  5260. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5261. lua_interface->SetSpawnValue(state, pet);
  5262. return 1;
  5263. }
  5264. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5265. if (!lua_interface)
  5266. return 0;
  5267. Spawn* spawn = lua_interface->GetSpawn(state);
  5268. lua_interface->ResetFunctionStack(state);
  5269. if (!spawn) {
  5270. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5271. return 0;
  5272. }
  5273. if (!spawn->IsPet()) {
  5274. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5275. return 0;
  5276. }
  5277. if (!((NPC*)spawn)->IsDismissing() && ((NPC*)spawn)->GetOwner())
  5278. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5279. return 0;
  5280. }
  5281. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5282. if (!lua_interface)
  5283. return 0;
  5284. Quest* quest = lua_interface->GetQuest(state);
  5285. if (!quest) {
  5286. 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));
  5287. lua_interface->ResetFunctionStack(state);
  5288. return 0;
  5289. }
  5290. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5291. lua_interface->ResetFunctionStack(state);
  5292. if (feather_color > 0)
  5293. quest->SetFeatherColor(feather_color);
  5294. return 0;
  5295. }
  5296. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5297. if (!lua_interface)
  5298. return 0;
  5299. Spawn* spawn = lua_interface->GetSpawn(state);
  5300. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5301. lua_interface->ResetFunctionStack(state);
  5302. if (!spawn) {
  5303. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5304. return 0;
  5305. }
  5306. if (!spawn2) {
  5307. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5308. return 0;
  5309. }
  5310. spawn->RemoveSpawnAccess(spawn2);
  5311. return 0;
  5312. }
  5313. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5314. if (!lua_interface)
  5315. return 0;
  5316. ZoneServer* zone = lua_interface->GetZone(state);
  5317. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5318. lua_interface->ResetFunctionStack(state);
  5319. if (!zone) {
  5320. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5321. return 0;
  5322. }
  5323. if (location_id == 0) {
  5324. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5325. return 0;
  5326. }
  5327. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5328. if (!location) {
  5329. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5330. return 0;
  5331. }
  5332. Spawn* spawn = 0;
  5333. if (location->entities[0]) {
  5334. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5335. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5336. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5337. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5338. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5339. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5340. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5341. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5342. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5343. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5344. if(spawn && spawn->IsOmittedByDBFlag())
  5345. {
  5346. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5347. safe_delete(spawn);
  5348. spawn = 0;
  5349. return 0;
  5350. }
  5351. if (spawn) {
  5352. const char* script = 0;
  5353. for (int x = 0; x < 3; x++) {
  5354. switch (x) {
  5355. case 0:
  5356. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5357. break;
  5358. case 1:
  5359. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5360. break;
  5361. case 2:
  5362. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5363. break;
  5364. }
  5365. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5366. spawn->SetSpawnScript(string(script));
  5367. break;
  5368. }
  5369. }
  5370. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5371. lua_interface->SetSpawnValue(state, spawn);
  5372. return 1;
  5373. }
  5374. else {
  5375. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5376. safe_delete(spawn);
  5377. }
  5378. }
  5379. return 0;
  5380. }
  5381. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5382. if (!lua_interface)
  5383. return 0;
  5384. Spawn* caster = lua_interface->GetSpawn(state);
  5385. Spawn* target = lua_interface->GetSpawn(state, 2);
  5386. int32 id = lua_interface->GetInt32Value(state, 3);
  5387. string command = lua_interface->GetStringValue(state, 4);
  5388. lua_interface->ResetFunctionStack(state);
  5389. if (!caster) {
  5390. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5391. return 0;
  5392. }
  5393. if (!target) {
  5394. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5395. return 0;
  5396. }
  5397. if (!caster->IsPlayer()) {
  5398. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5399. return 0;
  5400. }
  5401. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5402. if (!entity_command) {
  5403. 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());
  5404. return 0;
  5405. }
  5406. Client* client = ((Player*)caster)->GetClient();
  5407. if (!client) {
  5408. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5409. return 0;
  5410. }
  5411. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5412. return 0;
  5413. }
  5414. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5415. if (!lua_interface)
  5416. return 0;
  5417. Spawn* spawn = lua_interface->GetSpawn(state);
  5418. lua_interface->ResetFunctionStack(state);
  5419. if (!spawn) {
  5420. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5421. return 0;
  5422. }
  5423. if (!spawn->IsNPC()) {
  5424. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5425. return 0;
  5426. }
  5427. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5428. return 0;
  5429. }
  5430. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5431. if (!lua_interface)
  5432. return 0;
  5433. Spawn* spawn = lua_interface->GetSpawn(state);
  5434. int16 tick = lua_interface->GetInt16Value(state, 2);
  5435. lua_interface->ResetFunctionStack(state);
  5436. if (!spawn) {
  5437. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5438. return 0;
  5439. }
  5440. if (!spawn->IsNPC()) {
  5441. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5442. return 0;
  5443. }
  5444. if (tick < 20) {
  5445. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5446. return 0;
  5447. }
  5448. ((NPC*)spawn)->Brain()->SetTick(tick);
  5449. return 0;
  5450. }
  5451. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5452. if (!lua_interface)
  5453. return 0;
  5454. Spawn* spawn = lua_interface->GetSpawn(state);
  5455. Spawn* target = lua_interface->GetSpawn(state, 2);
  5456. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5457. lua_interface->ResetFunctionStack(state);
  5458. if (!spawn) {
  5459. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5460. return 0;
  5461. }
  5462. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5463. spawn->SetFollowTarget(target, follow_distance);
  5464. return 0;
  5465. }
  5466. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5467. if (!lua_interface)
  5468. return 0;
  5469. Spawn* spawn = lua_interface->GetSpawn(state);
  5470. lua_interface->ResetFunctionStack(state);
  5471. if (!spawn) {
  5472. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5473. return 0;
  5474. }
  5475. Spawn* target = spawn->GetFollowTarget();
  5476. if (target) {
  5477. lua_interface->SetSpawnValue(state, target);
  5478. return 1;
  5479. }
  5480. return 0;
  5481. }
  5482. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5483. if (!lua_interface)
  5484. return 0;
  5485. Spawn* spawn = lua_interface->GetSpawn(state);
  5486. lua_interface->ResetFunctionStack(state);
  5487. if (!spawn) {
  5488. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5489. return 0;
  5490. }
  5491. if (spawn->following)
  5492. spawn->following = false;
  5493. else
  5494. spawn->following = true;
  5495. return 0;
  5496. }
  5497. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5498. if (!lua_interface)
  5499. return 0;
  5500. Spawn* spawn = lua_interface->GetSpawn(state);
  5501. lua_interface->ResetFunctionStack(state);
  5502. if (!spawn) {
  5503. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5504. return 0;
  5505. }
  5506. lua_interface->SetBooleanValue(state, spawn->following);
  5507. return 1;
  5508. }
  5509. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5510. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5511. // I will attempt to explain how this function works for future refrence
  5512. // Fist lets make sure lua_interface is valid, if not return out
  5513. if (!lua_interface)
  5514. return 0;
  5515. // Next we grab the first 2 params same as we usually would
  5516. Spawn* spawn = lua_interface->GetSpawn(state);
  5517. string var = lua_interface->GetStringValue(state, 2);
  5518. // 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
  5519. // 1 = Spawn
  5520. // 2 = Zone
  5521. // 3 = Item
  5522. // 4 = Quest
  5523. // 5 = String
  5524. // 6 = nil (null)
  5525. int8 dataType = 0;
  5526. // Define pointers for each potential type
  5527. Spawn* spawnVal = 0;
  5528. ZoneServer* zone = 0;
  5529. Item* item = 0;
  5530. Quest* quest = 0;
  5531. string val;
  5532. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5533. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5534. // options window are also light user data be we do not handle those.
  5535. // We check with lua_islightuserdata(lua_State*, index)
  5536. if (lua_islightuserdata(state, 3)) {
  5537. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5538. // and convert it to LUAUserData*
  5539. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5540. // Check to make sure the data we got is valid, if not give an error
  5541. if (!data || !data->IsCorrectlyInitialized()) {
  5542. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5543. }
  5544. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5545. else if (data->IsSpawn()) {
  5546. spawnVal = data->spawn;
  5547. dataType = 1;
  5548. }
  5549. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5550. else if (data->IsZone()) {
  5551. zone = data->zone;
  5552. dataType = 2;
  5553. }
  5554. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5555. else if (data->IsItem()) {
  5556. item = data->item;
  5557. dataType = 3;
  5558. }
  5559. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5560. else if (data->IsQuest()) {
  5561. quest = data->quest;
  5562. dataType = 4;
  5563. }
  5564. }
  5565. // Wasn't light user data, check if it is nil(null)
  5566. else if (lua_isnil(state, 3)) {
  5567. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5568. dataType = 6;
  5569. }
  5570. // Wasn't light user data or nil (null), must be a string
  5571. else {
  5572. // Set the string and dataType variable
  5573. val = lua_interface->GetStringValue(state, 3);
  5574. dataType = 5;
  5575. }
  5576. lua_interface->ResetFunctionStack(state);
  5577. // We now have all the params, lets check to make sure they are valid
  5578. if (!spawn) {
  5579. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5580. return 0;
  5581. }
  5582. if (var.length() == 0) {
  5583. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5584. return 0;
  5585. }
  5586. if (dataType == 0) {
  5587. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5588. return 0;
  5589. }
  5590. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5591. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5592. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5593. switch (dataType) {
  5594. case 1:
  5595. // 1 = Spawn
  5596. spawn->AddTempVariable(var, spawnVal);
  5597. break;
  5598. case 2:
  5599. // 2 = Zone
  5600. spawn->AddTempVariable(var, zone);
  5601. break;
  5602. case 3:
  5603. // 3 = Item
  5604. spawn->AddTempVariable(var, item);
  5605. break;
  5606. case 4:
  5607. // 4 = Quest
  5608. spawn->AddTempVariable(var, quest);
  5609. break;
  5610. case 5:
  5611. // 5 = String
  5612. spawn->AddTempVariable(var, val);
  5613. break;
  5614. case 6:
  5615. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5616. spawn->DeleteTempVariable(var);
  5617. break;
  5618. }
  5619. // And we are done so return out
  5620. return 0;
  5621. }
  5622. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5623. if (!lua_interface)
  5624. return 0;
  5625. Spawn* spawn = lua_interface->GetSpawn(state);
  5626. string var = lua_interface->GetStringValue(state, 2);
  5627. lua_interface->ResetFunctionStack(state);
  5628. if (!spawn) {
  5629. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5630. return 0;
  5631. }
  5632. if (var.length() == 0) {
  5633. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5634. return 0;
  5635. }
  5636. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5637. int8 type = spawn->GetTempVariableType(var);
  5638. Spawn* spawn2 = 0;
  5639. ZoneServer* zone = 0;
  5640. Item* item = 0;
  5641. Quest* quest = 0;
  5642. // Set the lua function return value based on the type of data the variable contains
  5643. switch (type) {
  5644. case 1:
  5645. spawn2 = spawn->GetTempVariableSpawn(var);
  5646. if (!spawn2)
  5647. return 0;
  5648. lua_interface->SetSpawnValue(state, spawn2);
  5649. break;
  5650. case 2:
  5651. zone = spawn->GetTempVariableZone(var);
  5652. if (!zone)
  5653. return 0;
  5654. lua_interface->SetZoneValue(state, zone);
  5655. break;
  5656. case 3:
  5657. item = spawn->GetTempVariableItem(var);
  5658. if (!item)
  5659. return 0;
  5660. lua_interface->SetItemValue(state, item);
  5661. break;
  5662. case 4:
  5663. quest = spawn->GetTempVariableQuest(var);
  5664. if (!quest)
  5665. return 0;
  5666. lua_interface->SetQuestValue(state, quest);
  5667. break;
  5668. case 5:
  5669. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5670. break;
  5671. default:
  5672. // Not a valid type then the variable was not set so return out
  5673. return 0;
  5674. }
  5675. // Return value was set so return out
  5676. return 1;
  5677. }
  5678. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5679. {
  5680. if (!lua_interface)
  5681. return 0;
  5682. Quest* quest = lua_interface->GetQuest(state);
  5683. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5684. string description = lua_interface->GetStringValue(state, 3);
  5685. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5686. if (!quest) {
  5687. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5688. lua_interface->ResetFunctionStack(state);
  5689. lua_interface->SetBooleanValue(state, false);
  5690. return 1;
  5691. }
  5692. if (!spawn) {
  5693. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5694. lua_interface->ResetFunctionStack(state);
  5695. lua_interface->SetBooleanValue(state, false);
  5696. return 1;
  5697. }
  5698. if (!spawn->IsPlayer()) {
  5699. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5700. lua_interface->ResetFunctionStack(state);
  5701. lua_interface->SetBooleanValue(state, false);
  5702. return 1;
  5703. }
  5704. if (item_id == 0) {
  5705. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5706. lua_interface->ResetFunctionStack(state);
  5707. lua_interface->SetBooleanValue(state, false);
  5708. return 1;
  5709. }
  5710. Client* client = ((Player*)spawn)->GetClient();
  5711. if (!client) {
  5712. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given player spawn", lua_interface->GetScriptName(state));
  5713. lua_interface->ResetFunctionStack(state);
  5714. lua_interface->SetBooleanValue(state, false);
  5715. return 1;
  5716. }
  5717. Item* item = master_item_list.GetItem(item_id);
  5718. if (!item) {
  5719. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5720. lua_interface->ResetFunctionStack(state);
  5721. lua_interface->SetBooleanValue(state, false);
  5722. return 1;
  5723. }
  5724. Item* firstItem = new Item(item);
  5725. quest->AddTmpRewardItem(firstItem);
  5726. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5727. bool itemsAddedSuccessfully = true;
  5728. if(num_args > 4)
  5729. {
  5730. for(int8 n=5;n<num_args+1;n++)
  5731. {
  5732. int32 new_item = lua_interface->GetInt32Value(state, n);
  5733. Item* tmpItem = master_item_list.GetItem(new_item);
  5734. if(tmpItem)
  5735. {
  5736. Item* newTmpItem = new Item(tmpItem);
  5737. quest->AddTmpRewardItem(newTmpItem);
  5738. }
  5739. else
  5740. itemsAddedSuccessfully = false;
  5741. }
  5742. }
  5743. client->AddPendingQuestReward(quest, true, true, description); // queue for display
  5744. lua_interface->ResetFunctionStack(state);
  5745. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5746. return 1;
  5747. }
  5748. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5749. if (!lua_interface)
  5750. return 0;
  5751. Quest* quest = lua_interface->GetQuest(state);
  5752. lua_interface->ResetFunctionStack(state);
  5753. if (!quest) {
  5754. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5755. return 0;
  5756. }
  5757. quest->SetRepeatable(true);
  5758. return 0;
  5759. }
  5760. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5761. if (!lua_interface)
  5762. return 0;
  5763. Spawn* spawn = lua_interface->GetSpawn(state);
  5764. lua_interface->ResetFunctionStack(state);
  5765. if (!spawn) {
  5766. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5767. return 0;
  5768. }
  5769. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5770. string ret = classes.GetClassNameCase(base_class);
  5771. if (ret.length() > 0) {
  5772. lua_interface->SetStringValue(state, ret.c_str());
  5773. return 1;
  5774. }
  5775. return 0;
  5776. }
  5777. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5778. if (!lua_interface)
  5779. return 0;
  5780. Spawn* player = lua_interface->GetSpawn(state);
  5781. lua_interface->ResetFunctionStack(state);
  5782. if (player && player->IsPlayer()) {
  5783. Client* client = player->GetClient();
  5784. if (client)
  5785. client->SendWaypoints();
  5786. }
  5787. return 0;
  5788. }
  5789. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5790. if (!lua_interface)
  5791. return 0;
  5792. Spawn* player = lua_interface->GetSpawn(state);
  5793. string name = lua_interface->GetStringValue(state, 2);
  5794. int32 type = lua_interface->GetInt32Value(state, 3);
  5795. lua_interface->ResetFunctionStack(state);
  5796. if (type == 0)
  5797. type = 2;
  5798. if (name.length() > 0) {
  5799. if (player && player->IsPlayer()) {
  5800. Client* client = player->GetClient();
  5801. if (client)
  5802. client->AddWaypoint(name, type);
  5803. }
  5804. }
  5805. return 0;
  5806. }
  5807. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5808. if (!lua_interface)
  5809. return 0;
  5810. Spawn* player = lua_interface->GetSpawn(state);
  5811. string name = lua_interface->GetStringValue(state, 2);
  5812. lua_interface->ResetFunctionStack(state);
  5813. if (name.length() > 0) {
  5814. if (player && player->IsPlayer()) {
  5815. Client* client = player->GetClient();
  5816. if (client)
  5817. client->RemoveWaypoint(name);
  5818. }
  5819. }
  5820. return 0;
  5821. }
  5822. int EQ2Emu_lua_AddWard(lua_State* state) {
  5823. if (!lua_interface)
  5824. return 0;
  5825. int32 damage = lua_interface->GetInt32Value(state);
  5826. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5827. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5828. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5829. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5830. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5831. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5832. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5833. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5834. lua_interface->ResetFunctionStack(state);
  5835. if(!spell || spell->resisted) {
  5836. return 0;
  5837. }
  5838. bool ward_was_added = false;
  5839. ZoneServer* zone = spell->caster->GetZone();
  5840. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5841. for (int32 i = 0; i < spell->targets.size(); i++) {
  5842. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5843. if (!target)
  5844. continue;
  5845. if (target->IsEntity()) {
  5846. // If the ward is already active remove it
  5847. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5848. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5849. // Create new ward info
  5850. WardInfo* ward = new WardInfo;
  5851. ward->Spell = spell;
  5852. ward->BaseDamage = damage;
  5853. ward->DamageLeft = damage;
  5854. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5855. ward->keepWard = keepWard;
  5856. ward->WardType = wardType;
  5857. if (damageAbsorptionPercent > 100)
  5858. damageAbsorptionPercent = 100;
  5859. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5860. if (damageAbsorptionMaxHealthPercent > 100)
  5861. damageAbsorptionMaxHealthPercent = 100;
  5862. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5863. ward->RedirectDamagePercent = redirectDamagePercent;
  5864. ward->LastRedirectDamage = 0;
  5865. ward->LastAbsorbedDamage = 0;
  5866. ward->HitCount = 0;
  5867. spell->num_triggers = maxHitCount;
  5868. spell->had_triggers = true;
  5869. spell->cancel_after_all_triggers = false;
  5870. ward->MaxHitCount = maxHitCount;
  5871. ward->RoundTriggered = false;
  5872. if (wardType == WARD_TYPE_MAGICAL)
  5873. ward->DamageType = damageTypes;
  5874. // Add the ward to the entity
  5875. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5876. ward_was_added = true;
  5877. }
  5878. }
  5879. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5880. if (ward_was_added && spell->caster->IsPlayer()) {
  5881. spell->had_dmg_remaining = true;
  5882. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, damage, 1);
  5883. }
  5884. return 0;
  5885. }
  5886. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5887. if (!lua_interface)
  5888. return 0;
  5889. int32 amount = lua_interface->GetInt32Value(state);
  5890. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5891. lua_interface->ResetFunctionStack(state);
  5892. WardInfo* ward = 0;
  5893. if(!spell || spell->resisted) {
  5894. return 0;
  5895. }
  5896. ZoneServer* zone = spell->caster->GetZone();
  5897. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5898. if (spell->targets.size() > 0 && zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5899. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5900. ward = target->GetWard(spell->spell->GetSpellID());
  5901. if (target && ward) {
  5902. ward->DamageLeft += amount;
  5903. if (ward->DamageLeft > ward->BaseDamage)
  5904. ward->DamageLeft = ward->BaseDamage;
  5905. for (int32 i = 0; i < spell->targets.size(); i++) {
  5906. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5907. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5908. }
  5909. }
  5910. }
  5911. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5912. if (ward && spell->caster->IsPlayer())
  5913. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
  5914. return 0;
  5915. }
  5916. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5917. if (!lua_interface)
  5918. return 0;
  5919. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5920. lua_interface->ResetFunctionStack(state);
  5921. if (!spell) {
  5922. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5923. return 0;
  5924. }
  5925. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5926. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5927. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5928. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5929. if (ward) {
  5930. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5931. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5932. return 1;
  5933. }
  5934. }
  5935. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5936. return 0;
  5937. }
  5938. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5939. if (!lua_interface)
  5940. return 0;
  5941. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5942. if (!spell) {
  5943. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5944. lua_interface->ResetFunctionStack(state);
  5945. return 0;
  5946. }
  5947. string type = lua_interface->GetStringValue(state, 2);
  5948. lua_interface->ResetFunctionStack(state);
  5949. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5950. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5951. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5952. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5953. if (ward) {
  5954. if (boost::iequals(type, "damageleft"))
  5955. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5956. else if (boost::iequals(type, "basedamage"))
  5957. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5958. else if (boost::iequals(type, "keepward"))
  5959. lua_interface->SetBooleanValue(state, ward->keepWard);
  5960. else if (boost::iequals(type, "wardtype"))
  5961. lua_interface->SetInt32Value(state, ward->WardType);
  5962. else if (boost::iequals(type, "dmgabsorptionpct"))
  5963. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5964. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5965. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5966. else if (boost::iequals(type, "redirectdamagepercent"))
  5967. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5968. else if (boost::iequals(type, "lastredirectdamage"))
  5969. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5970. else if (boost::iequals(type, "lastabsorbeddamage"))
  5971. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5972. else if (boost::iequals(type, "hitcount"))
  5973. lua_interface->SetInt32Value(state, ward->HitCount);
  5974. else if (boost::iequals(type, "maxhitcount"))
  5975. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5976. else
  5977. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5978. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5979. return 1;
  5980. }
  5981. }
  5982. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5983. return 0;
  5984. }
  5985. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5986. if (!lua_interface)
  5987. return 0;
  5988. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5989. lua_interface->ResetFunctionStack(state);
  5990. if(!spell) {
  5991. return 0;
  5992. }
  5993. ZoneServer* zone = spell->caster->GetZone();
  5994. Spawn* target = 0;
  5995. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5996. for (int32 i = 0; i < spell->targets.size(); i++) {
  5997. target = zone->GetSpawnByID(spell->targets.at(i));
  5998. if (target && target->IsEntity()) {
  5999. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  6000. }
  6001. }
  6002. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6003. return 0;
  6004. }
  6005. int EQ2Emu_lua_Interrupt(lua_State* state)
  6006. {
  6007. if (!lua_interface)
  6008. return 0;
  6009. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  6010. Spawn* target = lua_interface->GetSpawn(state, 2);
  6011. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6012. lua_interface->ResetFunctionStack(state);
  6013. if (!caster)
  6014. {
  6015. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6016. return 0;
  6017. }
  6018. if (!target)
  6019. {
  6020. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6021. return 0;
  6022. }
  6023. if (!spell) {
  6024. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  6025. return 0;
  6026. }
  6027. if (!target->IsEntity() && !spell)
  6028. {
  6029. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  6030. return 0;
  6031. }
  6032. if (!target && spell) {
  6033. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6034. for (int8 i = 0; i < spell->targets.size(); i++) {
  6035. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6036. if (!target || !target->IsEntity())
  6037. continue;
  6038. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  6039. }
  6040. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6041. }
  6042. else
  6043. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  6044. return 0;
  6045. }
  6046. int EQ2Emu_lua_Stealth(lua_State* state) {
  6047. if (!lua_interface)
  6048. return 0;
  6049. int8 type = lua_interface->GetInt8Value(state);
  6050. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6051. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6052. lua_interface->ResetFunctionStack(state);
  6053. if (!spell) {
  6054. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  6055. return 0;
  6056. }
  6057. ZoneServer* zone = spell->caster->GetZone();
  6058. if (spawn) {
  6059. if (spawn->IsEntity()) {
  6060. if (type == 1) {
  6061. ((Entity*)spawn)->AddStealthSpell(spell);
  6062. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  6063. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  6064. }
  6065. else if (type == 2) {
  6066. ((Entity*)spawn)->AddInvisSpell(spell);
  6067. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  6068. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  6069. }
  6070. return 0;
  6071. }
  6072. else {
  6073. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  6074. return 0;
  6075. }
  6076. }
  6077. else {
  6078. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6079. for (int32 i = 0; i < spell->targets.size(); i++) {
  6080. spawn = zone->GetSpawnByID(spell->targets.at(i));
  6081. if (!spawn || !spawn->IsEntity())
  6082. continue;
  6083. if (type == 1) {
  6084. ((Entity*)spawn)->AddStealthSpell(spell);
  6085. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  6086. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  6087. }
  6088. else if (type == 2) {
  6089. ((Entity*)spawn)->AddInvisSpell(spell);
  6090. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  6091. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  6092. }
  6093. else {
  6094. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  6095. break;
  6096. }
  6097. }
  6098. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6099. }
  6100. return 0;
  6101. }
  6102. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  6103. if (!lua_interface)
  6104. return 0;
  6105. Spawn* spawn = lua_interface->GetSpawn(state);
  6106. lua_interface->ResetFunctionStack(state);
  6107. if (!spawn) {
  6108. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6109. return 0;
  6110. }
  6111. if (spawn->IsEntity()) {
  6112. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  6113. return 1;
  6114. }
  6115. else
  6116. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  6117. return 0;
  6118. }
  6119. int EQ2Emu_lua_IsInvis(lua_State* state) {
  6120. if (!lua_interface)
  6121. return 0;
  6122. Spawn* spawn = lua_interface->GetSpawn(state);
  6123. lua_interface->ResetFunctionStack(state);
  6124. if (!spawn) {
  6125. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  6126. return 0;
  6127. }
  6128. if (spawn->IsEntity()) {
  6129. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  6130. return 1;
  6131. }
  6132. else
  6133. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  6134. return 0;
  6135. }
  6136. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  6137. if (!lua_interface)
  6138. return 0;
  6139. Spawn* player = lua_interface->GetSpawn(state);
  6140. int32 item_id = lua_interface->GetInt32Value(state, 2);
  6141. lua_interface->ResetFunctionStack(state);
  6142. if (!player->IsPlayer()) {
  6143. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  6144. return 0;
  6145. }
  6146. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  6147. return 1;
  6148. }
  6149. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  6150. if (!lua_interface)
  6151. return 0;
  6152. Spawn* spawn = lua_interface->GetSpawn(state);
  6153. int8 slot = lua_interface->GetInt8Value(state, 2);
  6154. lua_interface->ResetFunctionStack(state);
  6155. if (!spawn) {
  6156. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6157. return 0;
  6158. }
  6159. if (!spawn->IsEntity()) {
  6160. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6161. return 0;
  6162. }
  6163. Item* item = ((Entity*)spawn)->GetEquipmentList()->GetItem(slot);
  6164. if (!item) {
  6165. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  6166. return 0;
  6167. }
  6168. lua_interface->SetItemValue(state, item);
  6169. return 1;
  6170. }
  6171. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  6172. if (!lua_interface)
  6173. return 0;
  6174. Spawn* player = lua_interface->GetSpawn(state);
  6175. int32 id = lua_interface->GetInt32Value(state, 2);
  6176. lua_interface->ResetFunctionStack(state);
  6177. if (!player) {
  6178. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6179. return 0;
  6180. }
  6181. if (!player->IsPlayer()) {
  6182. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6183. return 0;
  6184. }
  6185. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  6186. if (!item) {
  6187. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  6188. return 0;
  6189. }
  6190. lua_interface->SetItemValue(state, item);
  6191. return 1;
  6192. }
  6193. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  6194. if (!lua_interface)
  6195. return 0;
  6196. Spawn* spawn = lua_interface->GetSpawn(state);
  6197. int8 slot = lua_interface->GetInt8Value(state, 2);
  6198. int32 item_id = lua_interface->GetInt32Value(state, 3);
  6199. lua_interface->ResetFunctionStack(state);
  6200. if (!spawn) {
  6201. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6202. return 0;
  6203. }
  6204. if (!spawn->IsEntity()) {
  6205. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6206. return 0;
  6207. }
  6208. Item* item = master_item_list.GetItem(item_id);
  6209. if (!item) {
  6210. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  6211. return 0;
  6212. }
  6213. Item* copy = new Item(item);
  6214. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  6215. if(result)
  6216. {
  6217. ((Entity*)spawn)->SetEquipment(copy, slot);
  6218. spawn->vis_changed = true;
  6219. if(spawn->IsPlayer())
  6220. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6221. }
  6222. else
  6223. {
  6224. safe_delete(copy);
  6225. }
  6226. lua_interface->SetBooleanValue(state, result);
  6227. return 1;
  6228. }
  6229. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  6230. if (!lua_interface)
  6231. return 0;
  6232. Spawn* spawn = lua_interface->GetSpawn(state);
  6233. int8 slot = lua_interface->GetInt8Value(state, 2);
  6234. Item* item = lua_interface->GetItem(state, 3);
  6235. lua_interface->ResetFunctionStack(state);
  6236. if (!spawn) {
  6237. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  6238. return 0;
  6239. }
  6240. if (!spawn->IsEntity()) {
  6241. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6242. return 0;
  6243. }
  6244. if (!item) {
  6245. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  6246. return 0;
  6247. }
  6248. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  6249. if(result)
  6250. {
  6251. ((Entity*)spawn)->SetEquipment(item, slot);
  6252. spawn->vis_changed = true;
  6253. if(spawn->IsPlayer())
  6254. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6255. }
  6256. lua_interface->SetBooleanValue(state, result);
  6257. return 1;
  6258. }
  6259. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  6260. if (!lua_interface)
  6261. return 0;
  6262. Spawn* spawn = lua_interface->GetSpawn(state);
  6263. int8 slot = lua_interface->GetInt8Value(state, 2);
  6264. 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
  6265. lua_interface->ResetFunctionStack(state);
  6266. if (!spawn) {
  6267. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6268. return 0;
  6269. }
  6270. if (!spawn->IsEntity()) {
  6271. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6272. return 0;
  6273. }
  6274. if(slot >= NUM_SLOTS) {
  6275. lua_interface->LogError("%s: LUA UnequipSlot command error: wrong slot id given %u, max %u", lua_interface->GetScriptName(state), slot, NUM_SLOTS);
  6276. return 0;
  6277. }
  6278. if(spawn->IsPlayer() && ((Player*)spawn)->GetClient()) {
  6279. Item* item = ((Player*)spawn)->GetEquipmentList()->GetItem(slot);
  6280. if(item) {
  6281. item->save_needed = true;
  6282. if(no_delete_item) {
  6283. database.DeleteItem(((Player*)spawn)->GetClient()->GetCharacterID(), item, 0);
  6284. ((Player*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6285. }
  6286. else{
  6287. Client* client = ((Player*)spawn)->GetClient();
  6288. client->UnequipItem(item->details.index);
  6289. }
  6290. }
  6291. }
  6292. else
  6293. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6294. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  6295. spawn->vis_changed = true;
  6296. if(spawn->IsPlayer())
  6297. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6298. lua_interface->SetBooleanValue(state, true);
  6299. return 1;
  6300. }
  6301. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  6302. if (!lua_interface)
  6303. return 0;
  6304. Spawn* spawn = lua_interface->GetSpawn(state);
  6305. int8 slot = lua_interface->GetInt8Value(state, 2);
  6306. int16 type = lua_interface->GetInt16Value(state, 3);
  6307. int8 r = lua_interface->GetInt8Value(state, 4);
  6308. int8 g = lua_interface->GetInt8Value(state, 5);
  6309. int8 b = lua_interface->GetInt8Value(state, 6);
  6310. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6311. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6312. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6313. lua_interface->ResetFunctionStack(state);
  6314. if (!spawn) {
  6315. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6316. return 0;
  6317. }
  6318. if (!spawn->IsEntity()) {
  6319. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6320. return 0;
  6321. }
  6322. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6323. spawn->vis_changed = true;
  6324. lua_interface->SetBooleanValue(state, true);
  6325. return 1;
  6326. }
  6327. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6328. if (!lua_interface)
  6329. return 0;
  6330. Spawn* player = lua_interface->GetSpawn(state);
  6331. int32 id = lua_interface->GetInt32Value(state, 2);
  6332. int8 count = lua_interface->GetInt8Value(state, 3);
  6333. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6334. lua_interface->ResetFunctionStack(state);
  6335. if (!player) {
  6336. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6337. return 0;
  6338. }
  6339. if (!player->IsPlayer()) {
  6340. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6341. return 0;
  6342. }
  6343. if (!count)
  6344. count = 1;
  6345. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6346. if (!item) {
  6347. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6348. return 0;
  6349. }
  6350. lua_interface->SetItemValue(state, item);
  6351. return 1;
  6352. }
  6353. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6354. if (!lua_interface)
  6355. return 0;
  6356. Spawn* spawn = lua_interface->GetSpawn(state);
  6357. int32 anim = lua_interface->GetInt32Value(state, 2);
  6358. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6359. int8 type = lua_interface->GetInt8Value(state, 4);
  6360. lua_interface->ResetFunctionStack(state);
  6361. if (!spawn) {
  6362. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6363. return 0;
  6364. }
  6365. if (spawn2) {
  6366. if (spawn2->IsPlayer()) {
  6367. if (type != 1 && type != 2)
  6368. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6369. else
  6370. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6371. return 0;
  6372. }
  6373. else {
  6374. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6375. return 0;
  6376. }
  6377. }
  6378. else
  6379. spawn->GetZone()->PlayAnimation(spawn, anim);
  6380. return 0;
  6381. }
  6382. int EQ2Emu_lua_IsPet(lua_State* state) {
  6383. if (!lua_interface)
  6384. return 0;
  6385. Spawn* spawn = lua_interface->GetSpawn(state);
  6386. lua_interface->ResetFunctionStack(state);
  6387. if (!spawn) {
  6388. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6389. return 0;
  6390. }
  6391. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6392. return 1;
  6393. }
  6394. int EQ2Emu_lua_GetOwner(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 GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6401. return 0;
  6402. }
  6403. if (!spawn->IsNPC()) {
  6404. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6405. return 0;
  6406. }
  6407. if (((NPC*)spawn)->GetOwner()) {
  6408. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6409. return 1;
  6410. }
  6411. return 0;
  6412. }
  6413. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6414. if (!lua_interface)
  6415. return 0;
  6416. Spawn* spawn = lua_interface->GetSpawn(state);
  6417. Spawn* target = lua_interface->GetSpawn(state, 2);
  6418. lua_interface->ResetFunctionStack(state);
  6419. if (!spawn) {
  6420. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6421. return 0;
  6422. }
  6423. if (!spawn) {
  6424. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6425. return 0;
  6426. }
  6427. spawn->SetTarget(target);
  6428. return 0;
  6429. }
  6430. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6431. if (!lua_interface)
  6432. return 0;
  6433. Spawn* spawn = lua_interface->GetSpawn(state);
  6434. bool val = lua_interface->GetBooleanValue(state, 2);
  6435. lua_interface->ResetFunctionStack(state);
  6436. if (!spawn) {
  6437. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6438. return 0;
  6439. }
  6440. if (!spawn->IsEntity()) {
  6441. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6442. return 0;
  6443. }
  6444. ((Entity*)spawn)->InCombat(val);
  6445. if (val) {
  6446. spawn->ClearRunningLocations();
  6447. spawn->CalculateRunningLocation(true);
  6448. }
  6449. return 0;
  6450. }
  6451. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6452. if (!lua_interface)
  6453. return 0;
  6454. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6455. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6456. lua_interface->ResetFunctionStack(state);
  6457. if (!spawn1) {
  6458. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6459. return 0;
  6460. }
  6461. if (!spawn2) {
  6462. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6463. return 0;
  6464. }
  6465. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6466. return 1;
  6467. }
  6468. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6469. if (!lua_interface)
  6470. return 0;
  6471. Spawn* spawn = lua_interface->GetSpawn(state);
  6472. lua_interface->ResetFunctionStack(state);
  6473. if (!spawn) {
  6474. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6475. return 0;
  6476. }
  6477. if (!spawn->IsNPC()) {
  6478. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6479. return 0;
  6480. }
  6481. ((NPC*)spawn)->ClearRunback();
  6482. return 0;
  6483. }
  6484. int EQ2Emu_lua_Runback(lua_State* state) {
  6485. if (!lua_interface)
  6486. return 0;
  6487. Spawn* spawn = lua_interface->GetSpawn(state);
  6488. lua_interface->ResetFunctionStack(state);
  6489. if (!spawn) {
  6490. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6491. return 0;
  6492. }
  6493. if (!spawn->IsNPC()) {
  6494. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6495. return 0;
  6496. }
  6497. ((NPC*)spawn)->Runback();
  6498. return 0;
  6499. }
  6500. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6501. if (!lua_interface)
  6502. return 0;
  6503. Spawn* spawn = lua_interface->GetSpawn(state);
  6504. lua_interface->ResetFunctionStack(state);
  6505. if (!spawn) {
  6506. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6507. return 0;
  6508. }
  6509. if (!spawn->IsNPC()) {
  6510. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6511. return 0;
  6512. }
  6513. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6514. return 1;
  6515. }
  6516. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6517. if (!lua_interface)
  6518. return 0;
  6519. Spawn* spawn = lua_interface->GetSpawn(state);
  6520. lua_interface->ResetFunctionStack(state);
  6521. if (!spawn) {
  6522. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6523. return 0;
  6524. }
  6525. if (!spawn->IsEntity()) {
  6526. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6527. return 0;
  6528. }
  6529. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6530. return 1;
  6531. }
  6532. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6533. if (!lua_interface)
  6534. return 0;
  6535. Spawn* spawn = lua_interface->GetSpawn(state);
  6536. lua_interface->ResetFunctionStack(state);
  6537. if (!spawn) {
  6538. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6539. return 0;
  6540. }
  6541. if (!spawn->IsEntity()) {
  6542. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6543. return 0;
  6544. }
  6545. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6546. return 1;
  6547. }
  6548. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6549. if (!lua_interface)
  6550. return 0;
  6551. Spawn* spawn = lua_interface->GetSpawn(state);
  6552. lua_interface->ResetFunctionStack(state);
  6553. if (!spawn) {
  6554. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6555. return 0;
  6556. }
  6557. if (!spawn->IsEntity()) {
  6558. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6559. return 0;
  6560. }
  6561. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6562. return 1;
  6563. }
  6564. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6565. if (!lua_interface)
  6566. return 0;
  6567. Spawn* spawn = lua_interface->GetSpawn(state);
  6568. lua_interface->ResetFunctionStack(state);
  6569. if (!spawn) {
  6570. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6571. return 0;
  6572. }
  6573. if (!spawn->IsEntity()) {
  6574. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6575. return 0;
  6576. }
  6577. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6578. return 1;
  6579. }
  6580. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6581. if (!lua_interface)
  6582. return 0;
  6583. Spawn* spawn = lua_interface->GetSpawn(state);
  6584. Spawn* target = lua_interface->GetSpawn(state, 2);
  6585. float distance = lua_interface->GetFloatValue(state, 3);
  6586. lua_interface->ResetFunctionStack(state);
  6587. if (!spawn) {
  6588. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6589. return 0;
  6590. }
  6591. if (!target) {
  6592. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6593. return 0;
  6594. }
  6595. if (!spawn->IsNPC()) {
  6596. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6597. return 0;
  6598. }
  6599. if (!target->IsEntity()) {
  6600. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6601. return 0;
  6602. }
  6603. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6604. return 1;
  6605. }
  6606. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6607. if (!lua_interface)
  6608. return 0;
  6609. Spawn* spawn = lua_interface->GetSpawn(state);
  6610. Spawn* target = lua_interface->GetSpawn(state, 2);
  6611. float distance = lua_interface->GetFloatValue(state, 3);
  6612. lua_interface->ResetFunctionStack(state);
  6613. if (!spawn) {
  6614. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6615. return 0;
  6616. }
  6617. if (!target) {
  6618. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6619. return 0;
  6620. }
  6621. if (!spawn->IsNPC()) {
  6622. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6623. return 0;
  6624. }
  6625. if (!target->IsEntity()) {
  6626. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6627. return 0;
  6628. }
  6629. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6630. return 0;
  6631. }
  6632. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6633. if (!lua_interface)
  6634. return 0;
  6635. Spawn* spawn = lua_interface->GetSpawn(state);
  6636. lua_interface->ResetFunctionStack(state);
  6637. if (!spawn) {
  6638. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6639. return 0;
  6640. }
  6641. if (!spawn->IsNPC()) {
  6642. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6643. return 0;
  6644. }
  6645. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6646. return 1;
  6647. }
  6648. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6649. if (!lua_interface)
  6650. return 0;
  6651. Spawn* spawn = lua_interface->GetSpawn(state);
  6652. lua_interface->ResetFunctionStack(state);
  6653. if (!spawn) {
  6654. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6655. return 0;
  6656. }
  6657. if (!spawn->IsNPC()) {
  6658. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6659. return 0;
  6660. }
  6661. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6662. return 1;
  6663. }
  6664. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6665. if (!lua_interface)
  6666. return 0;
  6667. Spawn* spawn = lua_interface->GetSpawn(state);
  6668. lua_interface->ResetFunctionStack(state);
  6669. if (!spawn) {
  6670. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6671. return 0;
  6672. }
  6673. if (!spawn->IsNPC()) {
  6674. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6675. return 0;
  6676. }
  6677. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6678. if (hated) {
  6679. lua_interface->SetSpawnValue(state, hated);
  6680. return 1;
  6681. }
  6682. return 0;
  6683. }
  6684. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6685. if (!lua_interface)
  6686. return 0;
  6687. Spawn* spawn = lua_interface->GetSpawn(state);
  6688. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6689. lua_interface->ResetFunctionStack(state);
  6690. if (!spawn) {
  6691. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6692. return 0;
  6693. }
  6694. if (!spawn->IsNPC()) {
  6695. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6696. return 0;
  6697. }
  6698. if (!hated) {
  6699. ((NPC*)spawn)->Brain()->ClearHate();
  6700. return 0;
  6701. }
  6702. else
  6703. {
  6704. if (!hated->IsEntity()) {
  6705. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6706. return 0;
  6707. }
  6708. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6709. return 0;
  6710. }
  6711. return 0;
  6712. }
  6713. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6714. if (!lua_interface)
  6715. return 0;
  6716. Spawn* spawn = lua_interface->GetSpawn(state);
  6717. lua_interface->ResetFunctionStack(state);
  6718. if (!spawn) {
  6719. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6720. return 0;
  6721. }
  6722. if (!spawn->IsNPC()) {
  6723. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6724. return 0;
  6725. }
  6726. ((NPC*)spawn)->Brain()->ClearEncounter();
  6727. return 0;
  6728. }
  6729. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6730. if (!lua_interface)
  6731. return 0;
  6732. Spawn* spawn = lua_interface->GetSpawn(state);
  6733. lua_interface->ResetFunctionStack(state);
  6734. if (!spawn) {
  6735. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6736. return 0;
  6737. }
  6738. if (!spawn->IsNPC()) {
  6739. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6740. return 0;
  6741. }
  6742. // Temp list to store hate list
  6743. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6744. if (encounterList->size() == 0) {
  6745. safe_delete(encounterList);
  6746. return 0;
  6747. }
  6748. lua_createtable(state, encounterList->size(), 0);
  6749. int newTable = lua_gettop(state);
  6750. for (int32 i = 0; i < encounterList->size(); i++) {
  6751. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6752. if (temp)
  6753. lua_interface->SetSpawnValue(state, temp);
  6754. lua_rawseti(state, newTable, i + 1);
  6755. }
  6756. safe_delete(encounterList);
  6757. return 1;
  6758. }
  6759. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6760. if (!lua_interface)
  6761. return 0;
  6762. Spawn* spawn = lua_interface->GetSpawn(state);
  6763. lua_interface->ResetFunctionStack(state);
  6764. if (!spawn) {
  6765. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6766. return 0;
  6767. }
  6768. if (!spawn->IsNPC()) {
  6769. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6770. return 0;
  6771. }
  6772. // Temp list to store hate list
  6773. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6774. if (hateList->size() == 0) {
  6775. safe_delete(hateList);
  6776. return 0;
  6777. }
  6778. lua_createtable(state, hateList->size(), 0);
  6779. int newTable = lua_gettop(state);
  6780. for (int32 i = 0; i < hateList->size(); i++) {
  6781. lua_interface->SetSpawnValue(state, hateList->at(i));
  6782. lua_rawseti(state, newTable, i + 1);
  6783. }
  6784. safe_delete(hateList);
  6785. return 1;
  6786. }
  6787. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6788. if (!lua_interface)
  6789. return 0;
  6790. Spawn* spawn = lua_interface->GetSpawn(state);
  6791. lua_interface->ResetFunctionStack(state);
  6792. if (!spawn) {
  6793. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6794. return 0;
  6795. }
  6796. if (spawn->IsPlayer()) {
  6797. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6798. lua_interface->SetBooleanValue(state, true);
  6799. else
  6800. lua_interface->SetBooleanValue(state, false);
  6801. return 1;
  6802. }
  6803. else {
  6804. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6805. return 1;
  6806. }
  6807. }
  6808. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6809. if (!lua_interface)
  6810. return 0;
  6811. Quest* quest = lua_interface->GetQuest(state);
  6812. lua_interface->ResetFunctionStack(state);
  6813. if (!quest) {
  6814. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6815. return 0;
  6816. }
  6817. quest->SetCompletedFlag(true);
  6818. return 0;
  6819. }
  6820. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6821. if (!lua_interface)
  6822. return 0;
  6823. Spawn* spawn = lua_interface->GetSpawn(state);
  6824. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6825. int8 tier = lua_interface->GetInt8Value(state, 3);
  6826. lua_interface->ResetFunctionStack(state);
  6827. if (!spawn) {
  6828. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6829. return 0;
  6830. }
  6831. if (!spawn->IsEntity()) {
  6832. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6833. return 0;
  6834. }
  6835. if (spellID == 0) {
  6836. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6837. return 0;
  6838. }
  6839. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6840. if (effect) {
  6841. if (tier > 0) {
  6842. // If a tier was passed chec to see if it is the same as the effect
  6843. if (tier == effect->tier)
  6844. lua_interface->SetBooleanValue(state, true);
  6845. else
  6846. lua_interface->SetBooleanValue(state, false);
  6847. return 1;
  6848. }
  6849. else {
  6850. // Have an effect but no tier was passed so return true
  6851. lua_interface->SetBooleanValue(state, true);
  6852. }
  6853. return 1;
  6854. }
  6855. // no effect so return false
  6856. lua_interface->SetBooleanValue(state, false);
  6857. return 1;
  6858. }
  6859. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6860. if (!lua_interface)
  6861. return 0;
  6862. Spawn* spawn = lua_interface->GetSpawn(state);
  6863. int32 id = lua_interface->GetInt32Value(state, 2);
  6864. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6865. lua_interface->ResetFunctionStack(state);
  6866. Spawn* spawn2 = 0;
  6867. vector<Spawn*> list;
  6868. if (!spawn) {
  6869. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6870. return 0;
  6871. }
  6872. //If zone not provided, use spawn's zone
  6873. if (!zone)
  6874. zone = spawn->GetZone();
  6875. list = zone->GetSpawnsByID(id);
  6876. if (list.size() == 0) {
  6877. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6878. return 0;
  6879. }
  6880. vector<Spawn*>::iterator itr = list.begin();
  6881. for (int8 i = 0; i < list.size(); i++) {
  6882. spawn2 = itr[i];
  6883. if (spawn2)
  6884. spawn2->AddAllowAccessSpawn(spawn);
  6885. }
  6886. return 0;
  6887. }
  6888. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6889. if (!lua_interface)
  6890. return 0;
  6891. Spawn* spawn = lua_interface->GetSpawn(state);
  6892. int32 id = lua_interface->GetInt32Value(state, 2);
  6893. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6894. lua_interface->ResetFunctionStack(state);
  6895. Spawn* spawn2 = 0;
  6896. if (!spawn) {
  6897. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6898. return 0;
  6899. }
  6900. //If zone not provided, use spawn's zone
  6901. if (!zone)
  6902. zone = spawn->GetZone();
  6903. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6904. vector<Spawn*>::iterator itr = list.begin();
  6905. if (list.size() == 0) {
  6906. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6907. return 0;
  6908. }
  6909. for (int8 i = 0; i < list.size(); i++) {
  6910. spawn2 = itr[i];
  6911. if (spawn2)
  6912. spawn2->RemoveSpawnAccess(spawn);
  6913. }
  6914. return 0;
  6915. }
  6916. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6917. if (!lua_interface)
  6918. return 0;
  6919. Quest* quest = lua_interface->GetQuest(state);
  6920. lua_interface->ResetFunctionStack(state);
  6921. if (!quest) {
  6922. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6923. return 0;
  6924. }
  6925. quest->SetYellowName(true);
  6926. return 0;
  6927. }
  6928. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6929. if (!lua_interface)
  6930. return 0;
  6931. Spawn* spawn = lua_interface->GetSpawn(state);
  6932. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6933. lua_interface->ResetFunctionStack(state);
  6934. if (!spawn) {
  6935. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6936. return 0;
  6937. }
  6938. if (!spawn->IsPlayer()) {
  6939. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6940. return 0;
  6941. }
  6942. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6943. return 1;
  6944. }
  6945. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6946. if (!lua_interface)
  6947. return 0;
  6948. Spawn* spawn = lua_interface->GetSpawn(state);
  6949. lua_interface->ResetFunctionStack(state);
  6950. if (!spawn) {
  6951. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6952. return 0;
  6953. }
  6954. if (!spawn->IsPlayer()) {
  6955. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6956. return 0;
  6957. }
  6958. ZoneServer* zone = spawn->GetZone();
  6959. if (!zone) {
  6960. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6961. return 0;
  6962. }
  6963. Instance_Type iType = zone->GetInstanceType();
  6964. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6965. iType == GROUP_LOCKOUT_INSTANCE ||
  6966. iType == RAID_LOCKOUT_INSTANCE ||
  6967. iType == SOLO_PERSIST_INSTANCE ||
  6968. iType == GROUP_PERSIST_INSTANCE ||
  6969. iType == RAID_PERSIST_INSTANCE) {
  6970. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6971. if (data) {
  6972. // Check to see if the timer has already been set, if it has return out.
  6973. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6974. return 0;
  6975. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6976. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6977. if(spawn->IsPlayer()) {
  6978. Client* client = ((Player*)spawn)->GetClient();
  6979. if (client) {
  6980. string time_msg = "";
  6981. int32 time = data->success_lockout_time;
  6982. int16 hour;
  6983. int8 min;
  6984. int8 sec;
  6985. hour = time / 3600;
  6986. time = time % 3600;
  6987. min = time / 60;
  6988. time = time % 60;
  6989. sec = time;
  6990. if (hour > 0) {
  6991. char temp[10];
  6992. sprintf(temp, " %i", hour);
  6993. time_msg.append(temp);
  6994. time_msg.append(" hour");
  6995. time_msg.append((hour > 1) ? "s" : "");
  6996. }
  6997. if (min > 0) {
  6998. char temp[5];
  6999. sprintf(temp, " %i", min);
  7000. time_msg.append(temp);
  7001. time_msg.append(" minute");
  7002. time_msg.append((min > 1) ? "s" : "");
  7003. }
  7004. // Only add seconds if minutes and hours are 0
  7005. if (hour == 0 && min == 0 && sec > 0) {
  7006. char temp[5];
  7007. sprintf(temp, " %i", sec);
  7008. time_msg.append(temp);
  7009. time_msg.append(" second");
  7010. time_msg.append((sec > 1) ? "s" : "");
  7011. }
  7012. 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());
  7013. }
  7014. else {
  7015. lua_interface->LogError("LUA SetSuccessTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7016. }
  7017. }
  7018. }
  7019. else
  7020. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7021. }
  7022. else
  7023. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  7024. return 0;
  7025. }
  7026. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  7027. if (!lua_interface)
  7028. return 0;
  7029. Spawn* spawn = lua_interface->GetSpawn(state);
  7030. lua_interface->ResetFunctionStack(state);
  7031. if (!spawn) {
  7032. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7033. return 0;
  7034. }
  7035. if (!spawn->IsPlayer()) {
  7036. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  7037. return 0;
  7038. }
  7039. ZoneServer* zone = spawn->GetZone();
  7040. if (!zone) {
  7041. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  7042. return 0;
  7043. }
  7044. Instance_Type iType = zone->GetInstanceType();
  7045. if (iType == SOLO_LOCKOUT_INSTANCE ||
  7046. iType == GROUP_LOCKOUT_INSTANCE ||
  7047. iType == RAID_LOCKOUT_INSTANCE ||
  7048. iType == SOLO_PERSIST_INSTANCE ||
  7049. iType == GROUP_PERSIST_INSTANCE ||
  7050. iType == RAID_PERSIST_INSTANCE) {
  7051. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  7052. if (data) {
  7053. // Check to see if the timer has already been set, if it has return out.
  7054. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  7055. return 0;
  7056. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  7057. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  7058. if(spawn->IsPlayer()) {
  7059. Client* client = ((Player*)spawn)->GetClient();
  7060. if (client) {
  7061. string time_msg = "";
  7062. int32 time = data->failure_lockout_time;
  7063. int16 hour;
  7064. int8 min;
  7065. int8 sec;
  7066. hour = time / 3600;
  7067. time = time % 3600;
  7068. min = time / 60;
  7069. time = time % 60;
  7070. sec = time;
  7071. if (hour > 0) {
  7072. char temp[10];
  7073. sprintf(temp, " %i", hour);
  7074. time_msg.append(temp);
  7075. time_msg.append(" hour");
  7076. time_msg.append((hour > 1) ? "s" : "");
  7077. }
  7078. if (min > 0) {
  7079. char temp[5];
  7080. sprintf(temp, " %i", min);
  7081. time_msg.append(temp);
  7082. time_msg.append(" minute");
  7083. time_msg.append((min > 1) ? "s" : "");
  7084. }
  7085. // Only add seconds if minutes and hours are 0
  7086. if (hour == 0 && min == 0 && sec > 0) {
  7087. char temp[5];
  7088. sprintf(temp, " %i", sec);
  7089. time_msg.append(temp);
  7090. time_msg.append(" second");
  7091. time_msg.append((sec > 1) ? "s" : "");
  7092. }
  7093. 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());
  7094. }
  7095. }
  7096. else {
  7097. lua_interface->LogError("LUA SetFailureTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7098. }
  7099. }
  7100. else
  7101. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7102. }
  7103. else
  7104. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  7105. return 0;
  7106. }
  7107. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  7108. if (!lua_interface)
  7109. return 0;
  7110. Spawn* spawn = lua_interface->GetSpawn(state);
  7111. lua_interface->ResetFunctionStack(state);
  7112. if (!spawn) {
  7113. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  7114. return 0;
  7115. }
  7116. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  7117. return 1;
  7118. }
  7119. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  7120. if (!lua_interface)
  7121. return 0;
  7122. Spawn* player = lua_interface->GetSpawn(state);
  7123. Spawn* ground = lua_interface->GetSpawn(state, 2);
  7124. if (!player) {
  7125. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7126. lua_interface->ResetFunctionStack(state);
  7127. return 0;
  7128. }
  7129. if (!player->IsPlayer()) {
  7130. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  7131. lua_interface->ResetFunctionStack(state);
  7132. return 0;
  7133. }
  7134. if (!ground) {
  7135. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7136. lua_interface->ResetFunctionStack(state);
  7137. return 0;
  7138. }
  7139. if (!ground->IsGroundSpawn()) {
  7140. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  7141. lua_interface->ResetFunctionStack(state);
  7142. return 0;
  7143. }
  7144. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7145. if (!groundspawn_entries) {
  7146. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7147. lua_interface->ResetFunctionStack(state);
  7148. return 0;
  7149. }
  7150. Skill* skill = 0;
  7151. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  7152. if (collection_skill == "Collecting")
  7153. skill = ((Player*)player)->GetSkillByName("Gathering");
  7154. else
  7155. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  7156. if (!skill) {
  7157. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  7158. lua_interface->ResetFunctionStack(state);
  7159. return 0;
  7160. }
  7161. vector<GroundSpawnEntry*>::iterator itr;
  7162. GroundSpawnEntry* entry = 0;
  7163. bool can_harvest = false;
  7164. sint32 min_skill = -1;
  7165. int16 totalSkill = skill->current_val;
  7166. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  7167. if(skillID != 0xFFFFFFFF)
  7168. {
  7169. ((Entity*)player)->MStats.lock();
  7170. totalSkill += ((Entity*)player)->stats[skillID];
  7171. ((Entity*)player)->MStats.unlock();
  7172. }
  7173. // first, iterate through groundspawn_entries, discard tables player cannot use
  7174. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  7175. {
  7176. entry = *itr;
  7177. if (min_skill == -1 || entry->min_skill_level < min_skill)
  7178. min_skill = entry->min_skill_level;
  7179. // if player lacks skill, skip table
  7180. if (entry->min_skill_level > totalSkill)
  7181. continue;
  7182. // if bonus, but player lacks level, skip table
  7183. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  7184. continue;
  7185. can_harvest = true;
  7186. break;
  7187. }
  7188. lua_interface->SetBooleanValue(state, can_harvest);
  7189. // If false, send the message to the client
  7190. if (!can_harvest) {
  7191. Client* client = ((Player*)player)->GetClient();
  7192. if (client) {
  7193. string msg = "You do not have enough skill to ";
  7194. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  7195. msg.append("gather");
  7196. else if (collection_skill == "Mining")
  7197. msg.append("mine");
  7198. else if (collection_skill == "Trapping")
  7199. msg.append("trap");
  7200. else if (collection_skill == "Foresting")
  7201. msg.append("forest");
  7202. else if (collection_skill == "Fishing")
  7203. msg.append("catch");
  7204. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  7205. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  7206. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  7207. }
  7208. }
  7209. lua_interface->ResetFunctionStack(state);
  7210. return 1;
  7211. }
  7212. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  7213. if (!lua_interface)
  7214. return 0;
  7215. Spawn* player = lua_interface->GetSpawn(state);
  7216. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  7217. lua_interface->ResetFunctionStack(state);
  7218. if (!player) {
  7219. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  7220. return 0;
  7221. }
  7222. if (!player->IsPlayer()) {
  7223. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  7224. return 0;
  7225. }
  7226. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  7227. lua_interface->SetBooleanValue(state, ret);
  7228. return 1;
  7229. }
  7230. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  7231. // Check to see if we have a valid lua_interface
  7232. if (!lua_interface)
  7233. return 0;
  7234. // Get the spawn that is getting the pet
  7235. Spawn* spawn = lua_interface->GetSpawn(state);
  7236. Spawn* target = lua_interface->GetSpawn(state, 2);
  7237. // Get the DB ID of the pet
  7238. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  7239. float x = lua_interface->GetFloatValue(state, 4);
  7240. float y = lua_interface->GetFloatValue(state, 5);
  7241. float z = lua_interface->GetFloatValue(state, 6);
  7242. // Get the spell that this command was called from
  7243. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7244. lua_interface->ResetFunctionStack(state);
  7245. // Check to make sure the spawn pointer is valid
  7246. if (!spawn) {
  7247. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  7248. return 0;
  7249. }
  7250. // Check to make sure the spawn is an entity
  7251. if (!spawn->IsEntity()) {
  7252. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  7253. return 0;
  7254. }
  7255. if (!target) {
  7256. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  7257. return 0;
  7258. }
  7259. if (!target->IsEntity()) {
  7260. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  7261. return 0;
  7262. }
  7263. // Check to see if the DB ID for the pet is set
  7264. if (pet_id == 0) {
  7265. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  7266. return 0;
  7267. }
  7268. // Check to see if the pointer to the spell is valid
  7269. if (!luaspell) {
  7270. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  7271. return 0;
  7272. }
  7273. if(luaspell->resisted) {
  7274. return 0;
  7275. }
  7276. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  7277. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  7278. if (!pet) {
  7279. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  7280. return 0;
  7281. }
  7282. // Check to make sure the pet is an npc
  7283. if (!pet->IsNPC()) {
  7284. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  7285. return 0;
  7286. }
  7287. if (x == 0)
  7288. x = spawn->GetX();
  7289. if (y == 0)
  7290. y = spawn->GetY();
  7291. if (z == 0)
  7292. z = spawn->GetZ();
  7293. // Spawn the pet at the same location as the owner
  7294. pet->SetX(x);
  7295. pet->SetY(y);
  7296. pet->SetZ(z);
  7297. pet->SetLocation(spawn->GetLocation());
  7298. pet->SetHeading(spawn->GetHeading());
  7299. spawn->GetZone()->AddSpawn(pet);
  7300. const char* spawn_script = world.GetSpawnScript(pet_id);
  7301. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  7302. spawn->SetSpawnScript(string(spawn_script));
  7303. spawn->GetZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7304. }
  7305. std::string petName = std::string("");
  7306. if(spawn->IsEntity()) {
  7307. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  7308. }
  7309. if(petName.size() < 1) {
  7310. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  7311. petName = spawn->GetZone()->pet_names.at(rand_index);
  7312. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  7313. }
  7314. // Set the pets name
  7315. pet->SetName(petName.c_str());
  7316. // Set the level of the pet to the owners level
  7317. pet->SetLevel(spawn->GetLevel());
  7318. // Set the faction of the pet to the same faction as the owner
  7319. pet->SetFactionID(spawn->GetFactionID());
  7320. // Set the spawn as a pet
  7321. pet->SetPet(true);
  7322. // Give a pointer of the owner to the pet
  7323. ((NPC*)pet)->SetOwner((Entity*)spawn);
  7324. // Set the pet type
  7325. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  7326. // Set the spell id used to create this pet
  7327. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  7328. // Set the spell tier used to create this pet
  7329. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  7330. // Set the pets spawn type to 6
  7331. pet->SetSpawnType(6);
  7332. // Set the pets brain
  7333. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  7334. // Check to see if the pet has a subtitle
  7335. if (strlen(pet->GetSubTitle()) > 0) {
  7336. // Add the players name to the front of the sub title
  7337. string pet_subtitle;
  7338. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  7339. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  7340. // Set the pets subtitle to the new one
  7341. pet->SetSubTitle(pet_subtitle.c_str());
  7342. }
  7343. // Set the pet as the return value for this function
  7344. lua_interface->SetSpawnValue(state, pet);
  7345. return 1;
  7346. }
  7347. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  7348. if (!lua_interface)
  7349. return 0;
  7350. Spawn* spawn = lua_interface->GetSpawn(state);
  7351. Spawn* player = lua_interface->GetSpawn(state, 2);
  7352. float max_distance = lua_interface->GetFloatValue(state, 3);
  7353. string type = lua_interface->GetStringValue(state, 4);
  7354. lua_interface->ResetFunctionStack(state);
  7355. if (!spawn || (spawn && spawn->IsPlayer())) {
  7356. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  7357. return 0;
  7358. }
  7359. if (!player || !player->IsPlayer()) {
  7360. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  7361. return 0;
  7362. }
  7363. Client* client = ((Player*)player)->GetClient();
  7364. if (!client) {
  7365. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7366. return 0;
  7367. }
  7368. //Set max_distance to default if not set or not proper value
  7369. if (max_distance <= 0)
  7370. max_distance = 500;
  7371. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7372. if (packet) {
  7373. float unknown2_3 = 0;
  7374. int8 placement_mode = 0;
  7375. if (type == "wall") {
  7376. placement_mode = 2;
  7377. unknown2_3 = 150;
  7378. }
  7379. else if (type == "ceiling")
  7380. placement_mode = 1;
  7381. packet->setDataByName("placement_mode", placement_mode);
  7382. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7383. packet->setDataByName("model_type", spawn->GetModelType());
  7384. packet->setDataByName("unknown", 1); //size
  7385. packet->setDataByName("unknown2", 1); //size 2
  7386. packet->setDataByName("unknown2", .5, 1); //size 3
  7387. packet->setDataByName("unknown2", 3, 2);
  7388. packet->setDataByName("unknown2", unknown2_3, 3);
  7389. packet->setDataByName("max_distance", max_distance);
  7390. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7391. client->QueuePacket(packet->serialize());
  7392. safe_delete(packet);
  7393. }
  7394. return 0;
  7395. }
  7396. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7397. if (!lua_interface)
  7398. return 0;
  7399. Item* item = lua_interface->GetItem(state);
  7400. lua_interface->ResetFunctionStack(state);
  7401. if (!item) {
  7402. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7403. return 0;
  7404. }
  7405. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7406. return 1;
  7407. }
  7408. int EQ2Emu_lua_GetItemEffectType(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 GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7415. return 0;
  7416. }
  7417. lua_interface->SetInt32Value(state, item->effect_type);
  7418. return 1;
  7419. }
  7420. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7421. if (!lua_interface)
  7422. return 0;
  7423. Spawn* spawn = lua_interface->GetSpawn(state);
  7424. lua_interface->ResetFunctionStack(state);
  7425. if (!spawn) {
  7426. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7427. return 0;
  7428. }
  7429. if (spawn->GetZone())
  7430. spawn->GetZone()->AddTransportSpawn(spawn);
  7431. return 0;
  7432. }
  7433. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7434. if (!lua_interface)
  7435. return 0;
  7436. Spawn* spawn = lua_interface->GetSpawn(state);
  7437. lua_interface->ResetFunctionStack(state);
  7438. if (!spawn) {
  7439. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7440. return 0;
  7441. }
  7442. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7443. return 1;
  7444. }
  7445. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7446. if (!lua_interface)
  7447. return 0;
  7448. Skill* skill = lua_interface->GetSkill(state);
  7449. lua_interface->ResetFunctionStack(state);
  7450. if (!skill) {
  7451. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7452. return 0;
  7453. }
  7454. lua_interface->SetInt32Value(state, skill->current_val);
  7455. return 1;
  7456. }
  7457. int EQ2Emu_lua_GetSkillMaxValue(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 GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7464. return 0;
  7465. }
  7466. lua_interface->SetInt32Value(state, skill->max_val);
  7467. return 1;
  7468. }
  7469. int EQ2Emu_lua_GetSkillName(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 GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7476. return 0;
  7477. }
  7478. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7479. return 1;
  7480. }
  7481. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7482. if (!lua_interface)
  7483. return 0;
  7484. Skill* skill = lua_interface->GetSkill(state);
  7485. int16 value = lua_interface->GetInt16Value(state, 2);
  7486. lua_interface->ResetFunctionStack(state);
  7487. if (!skill) {
  7488. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7489. return 0;
  7490. }
  7491. skill->max_val = value;
  7492. if (skill->max_val < skill->current_val)
  7493. skill->current_val = skill->max_val;
  7494. return 0;
  7495. }
  7496. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7497. if (!lua_interface)
  7498. return 0;
  7499. Skill* skill = lua_interface->GetSkill(state);
  7500. int16 value = lua_interface->GetInt16Value(state, 2);
  7501. lua_interface->ResetFunctionStack(state);
  7502. if (!skill) {
  7503. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7504. return 0;
  7505. }
  7506. if (value > skill->max_val)
  7507. skill->current_val = skill->max_val;
  7508. else
  7509. skill->current_val = value;
  7510. return 0;
  7511. }
  7512. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7513. if (!lua_interface)
  7514. return 0;
  7515. Spawn* player = lua_interface->GetSpawn(state);
  7516. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7517. lua_interface->ResetFunctionStack(state);
  7518. if (skill_id > 0 && player && player->IsPlayer()) {
  7519. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7520. return 1;
  7521. }
  7522. return 0;
  7523. }
  7524. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7525. if (!lua_interface)
  7526. return 0;
  7527. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7528. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7529. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7530. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7531. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7532. lua_interface->ResetFunctionStack(state);
  7533. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7534. if (player_spawn && player_spawn->IsPlayer()) {
  7535. Player* player = (Player*)player_spawn;
  7536. bool added = false;
  7537. if (!player->skill_list.HasSkill(skill_id)) {
  7538. player->AddSkill(skill_id, current_val, max_val, true);
  7539. added = true;
  7540. }
  7541. 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
  7542. Client* client = player->GetClient();
  7543. if (client) {
  7544. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7545. if (packet)
  7546. client->QueuePacket(packet);
  7547. }
  7548. }
  7549. if (added) {
  7550. lua_interface->SetBooleanValue(state, true);
  7551. return 1;
  7552. }
  7553. }
  7554. else {
  7555. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7556. }
  7557. }
  7558. else {
  7559. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7560. }
  7561. lua_interface->SetBooleanValue(state, false);
  7562. return 1;
  7563. }
  7564. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7565. if (!lua_interface)
  7566. return 0;
  7567. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7568. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7569. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7570. lua_interface->ResetFunctionStack(state);
  7571. if (skill_id > 0) {
  7572. if (player_spawn && player_spawn->IsPlayer()) {
  7573. Player* player = (Player*)player_spawn;
  7574. if (player->skill_list.HasSkill(skill_id)) {
  7575. player->RemovePlayerSkill(skill_id, true);
  7576. if (!more_to_remove) {
  7577. Client* client = player->GetClient();
  7578. if (client) {
  7579. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7580. if (packet)
  7581. client->QueuePacket(packet);
  7582. }
  7583. }
  7584. }
  7585. }
  7586. else {
  7587. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7588. }
  7589. }
  7590. else {
  7591. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7592. }
  7593. return 0;
  7594. }
  7595. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7596. if (!lua_interface)
  7597. return 0;
  7598. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7599. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7600. int16 amount = lua_interface->GetInt8Value(state, 3);
  7601. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7602. lua_interface->ResetFunctionStack(state);
  7603. if (amount > 0 && skill_type < 100) {
  7604. if (player_spawn && player_spawn->IsPlayer()) {
  7605. Player* player = (Player*)player_spawn;
  7606. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7607. if (!more_to_increase) {
  7608. Client* client = player->GetClient();
  7609. if (client) {
  7610. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7611. if (packet)
  7612. client->QueuePacket(packet);
  7613. }
  7614. }
  7615. }
  7616. else {
  7617. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7618. }
  7619. }
  7620. else {
  7621. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7622. }
  7623. return 0;
  7624. }
  7625. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7626. if (!lua_interface)
  7627. return 0;
  7628. Spawn* spawn = lua_interface->GetSpawn(state);
  7629. string name = lua_interface->GetStringValue(state, 2);
  7630. lua_interface->ResetFunctionStack(state);
  7631. if (!spawn) {
  7632. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7633. return 0;
  7634. }
  7635. if (!spawn->IsEntity()) {
  7636. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7637. return 0;
  7638. }
  7639. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7640. if (skill) {
  7641. lua_interface->SetSkillValue(state, skill);
  7642. return 1;
  7643. }
  7644. return 0;
  7645. }
  7646. int EQ2Emu_lua_AddProc(lua_State* state) {
  7647. if (!lua_interface)
  7648. return 0;
  7649. Spawn* spawn = lua_interface->GetSpawn(state);
  7650. int8 type = lua_interface->GetInt8Value(state, 2);
  7651. float chance = lua_interface->GetFloatValue(state, 3);
  7652. Item* item = lua_interface->GetItem(state, 4);
  7653. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7654. LuaSpell* spell = 0;
  7655. if (!spawn && (!spell || !use_all_spelltargets)) {
  7656. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7657. return 0;
  7658. }
  7659. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7660. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7661. return 0;
  7662. }
  7663. if (!item)
  7664. spell = lua_interface->GetCurrentSpell(state);
  7665. if (!item && !spell) {
  7666. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7667. return 0;
  7668. }
  7669. if(spell && spell->resisted) {
  7670. return 0;
  7671. }
  7672. if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
  7673. Spawn* target;
  7674. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7675. for (int8 i = 0; i < spell->targets.size(); i++) {
  7676. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7677. if (!target || !target->IsEntity())
  7678. continue;
  7679. ((Entity*)target)->AddProc(type, chance, item, spell);
  7680. }
  7681. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7682. }
  7683. else
  7684. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7685. return 0;
  7686. }
  7687. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7688. if (!lua_interface)
  7689. return 0;
  7690. Spawn* spawn = lua_interface->GetSpawn(state);
  7691. Item* item = lua_interface->GetItem(state, 2);
  7692. LuaSpell* spell = 0;
  7693. if (!spawn) {
  7694. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7695. lua_interface->ResetFunctionStack(state);
  7696. return 0;
  7697. }
  7698. if (!spawn->IsEntity()) {
  7699. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7700. lua_interface->ResetFunctionStack(state);
  7701. return 0;
  7702. }
  7703. if (!item)
  7704. spell = lua_interface->GetCurrentSpell(state);
  7705. lua_interface->ResetFunctionStack(state);
  7706. if (!item && !spell) {
  7707. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7708. return 0;
  7709. }
  7710. if (spell && spell->caster && spell->caster->GetZone()) {
  7711. Spawn* target;
  7712. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7713. for (int8 i = 0; i < spell->targets.size(); i++) {
  7714. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7715. if (!target || !target->IsEntity())
  7716. continue;
  7717. ((Entity*)target)->RemoveProc(item, spell);
  7718. }
  7719. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7720. spell->caster->RemoveProc(item, spell);
  7721. }
  7722. else
  7723. ((Entity*)spawn)->RemoveProc(item, spell);
  7724. return 0;
  7725. }
  7726. int EQ2Emu_lua_Knockback(lua_State* state) {
  7727. if (!lua_interface)
  7728. return 0;
  7729. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7730. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7731. int32 duration = lua_interface->GetInt32Value(state, 3);
  7732. float vertical = lua_interface->GetFloatValue(state, 4);
  7733. float horizontal = lua_interface->GetFloatValue(state, 5);
  7734. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7735. lua_interface->ResetFunctionStack(state);
  7736. if (!target_spawn) {
  7737. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7738. return 0;
  7739. }
  7740. if (!spawn) {
  7741. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7742. return 0;
  7743. }
  7744. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7745. Client* client = ((Player*)spawn)->GetClient();
  7746. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7747. if (packet) {
  7748. packet->setDataByName("target_x", target_spawn->GetX());
  7749. packet->setDataByName("target_y", target_spawn->GetY());
  7750. packet->setDataByName("target_z", target_spawn->GetZ());
  7751. packet->setDataByName("vertical_movement", vertical);
  7752. packet->setDataByName("horizontal_movement", horizontal);
  7753. if (use_heading)
  7754. packet->setDataByName("use_player_heading", 1);
  7755. client->QueuePacket(packet->serialize());
  7756. }
  7757. safe_delete(packet);
  7758. }
  7759. return 0;
  7760. }
  7761. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7762. if (!lua_interface)
  7763. return 0;
  7764. Spawn* spawn = lua_interface->GetSpawn(state);
  7765. lua_interface->ResetFunctionStack(state);
  7766. if (!spawn) {
  7767. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7768. return 0;
  7769. }
  7770. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7771. return 1;
  7772. }
  7773. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7774. if (!lua_interface)
  7775. return 0;
  7776. Spawn* caster = lua_interface->GetSpawn(state);
  7777. Spawn* target = lua_interface->GetSpawn(state, 2);
  7778. string name = lua_interface->GetStringValue(state, 3);
  7779. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7780. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7781. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7782. string success_msg = lua_interface->GetStringValue(state, 7);
  7783. string effect_msg = lua_interface->GetStringValue(state, 8);
  7784. lua_interface->ResetFunctionStack(state);
  7785. if (!caster) {
  7786. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7787. return 0;
  7788. }
  7789. if (!caster->IsEntity()) {
  7790. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7791. return 0;
  7792. }
  7793. if (!target) {
  7794. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7795. return 0;
  7796. }
  7797. if (!target->IsEntity()) {
  7798. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7799. return 0;
  7800. }
  7801. if (name.length() == 0) {
  7802. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7803. return 0;
  7804. }
  7805. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7806. return 0;
  7807. }
  7808. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7809. if (!lua_interface)
  7810. return 0;
  7811. string name = lua_interface->GetStringValue(state);
  7812. lua_interface->ResetFunctionStack(state);
  7813. if (name.length() == 0) {
  7814. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7815. return 0;
  7816. }
  7817. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7818. if (!skill) {
  7819. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7820. return 0;
  7821. }
  7822. lua_interface->SetInt32Value(state, skill->skill_id);
  7823. return 1;
  7824. }
  7825. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7826. if (!lua_interface)
  7827. return 0;
  7828. Spawn* spawn = lua_interface->GetSpawn(state);
  7829. lua_interface->ResetFunctionStack(state);
  7830. if (!spawn) {
  7831. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7832. return 0;
  7833. }
  7834. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7835. return 1;
  7836. }
  7837. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7838. if (!lua_interface)
  7839. return 0;
  7840. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7841. lua_interface->ResetFunctionStack(state);
  7842. if (!luaspell) {
  7843. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7844. return 0;
  7845. }
  7846. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7847. return 1;
  7848. }
  7849. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7850. if (!lua_interface)
  7851. return 0;
  7852. Spawn* spawn = lua_interface->GetSpawn(state);
  7853. Spawn* target = lua_interface->GetSpawn(state, 2);
  7854. lua_interface->ResetFunctionStack(state);
  7855. if (!spawn) {
  7856. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7857. return 0;
  7858. }
  7859. if (!spawn->IsEntity()) {
  7860. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7861. return 0;
  7862. }
  7863. if (!target) {
  7864. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7865. return 0;
  7866. }
  7867. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7868. return 1;
  7869. }
  7870. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7871. if (!lua_interface)
  7872. return 0;
  7873. Spawn* spawn = lua_interface->GetSpawn(state);
  7874. Spawn* target = lua_interface->GetSpawn(state, 2);
  7875. lua_interface->ResetFunctionStack(state);
  7876. if (!spawn) {
  7877. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7878. return 0;
  7879. }
  7880. if (!spawn->IsEntity()) {
  7881. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7882. return 0;
  7883. }
  7884. if (!target) {
  7885. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7886. return 0;
  7887. }
  7888. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7889. return 1;
  7890. }
  7891. int EQ2Emu_lua_InFront(lua_State* state) {
  7892. if (!lua_interface)
  7893. return 0;
  7894. Spawn* spawn = lua_interface->GetSpawn(state);
  7895. Spawn* target = lua_interface->GetSpawn(state, 2);
  7896. lua_interface->ResetFunctionStack(state);
  7897. if (!spawn) {
  7898. lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7899. return 0;
  7900. }
  7901. if (!spawn->IsEntity()) {
  7902. lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7903. return 0;
  7904. }
  7905. if (!target) {
  7906. lua_interface->LogError("%s: LUA InFrontSpawn command error: target is not valid", lua_interface->GetScriptName(state));
  7907. return 0;
  7908. }
  7909. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->InFrontSpawn(target, spawn->GetX(), spawn->GetZ()));
  7910. return 1;
  7911. }
  7912. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7913. if (!lua_interface)
  7914. return 0;
  7915. Item* item = lua_interface->GetItem(state);
  7916. lua_interface->ResetFunctionStack(state);
  7917. if (!item) {
  7918. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7919. return 0;
  7920. }
  7921. lua_interface->SetInt32Value(state, item->details.count);
  7922. return 1;
  7923. }
  7924. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7925. if (!lua_interface)
  7926. return 0;
  7927. Item* item = lua_interface->GetItem(state);
  7928. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7929. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7930. lua_interface->ResetFunctionStack(state);
  7931. if (!item) {
  7932. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7933. return 0;
  7934. }
  7935. if (!owner) {
  7936. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7937. return 0;
  7938. }
  7939. if (!owner->IsPlayer()) {
  7940. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7941. return 0;
  7942. }
  7943. if (item->stack_count < new_count) {
  7944. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7945. return 0;
  7946. }
  7947. if (new_count > 0) {
  7948. item->details.count = new_count;
  7949. item->save_needed = true;
  7950. }
  7951. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7952. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7953. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7954. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7955. else
  7956. {
  7957. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7958. return 0;
  7959. }
  7960. Client* client = ((Player*)owner)->GetClient();
  7961. if (!client)
  7962. return 0;
  7963. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7964. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7965. if (app)
  7966. client->QueuePacket(app);
  7967. return 0;
  7968. }
  7969. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7970. if (!lua_interface)
  7971. return 0;
  7972. int32 time = lua_interface->GetInt32Value(state);
  7973. string function = lua_interface->GetStringValue(state, 2);
  7974. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7975. Spawn* target = lua_interface->GetSpawn(state, 4);
  7976. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7977. lua_interface->ResetFunctionStack(state);
  7978. if (time == 0) {
  7979. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7980. return 0;
  7981. }
  7982. if (function.length() == 0) {
  7983. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7984. return 0;
  7985. }
  7986. if (!spell || (!spell->caster || !spell->caster->GetZone())) {
  7987. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7988. return 0;
  7989. }
  7990. SpellScriptTimer* timer = new SpellScriptTimer;
  7991. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7992. #ifdef WIN32
  7993. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7994. #else
  7995. bzero(timer, sizeof(SpellScriptTimer));
  7996. #endif*/
  7997. timer->caster = 0;
  7998. timer->deleteWhenDone = false;
  7999. timer->target = 0;
  8000. timer->time = Timer::GetCurrentTime2() + time;
  8001. timer->customFunction = function;
  8002. timer->spell = spell;
  8003. if (caster)
  8004. timer->caster = caster->GetID();
  8005. if (target)
  8006. timer->target = target->GetID();
  8007. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  8008. return 0;
  8009. }
  8010. int EQ2Emu_lua_Resurrect(lua_State* state) {
  8011. if (!lua_interface)
  8012. return 0;
  8013. float hp_perc = lua_interface->GetFloatValue(state);
  8014. float power_perc = lua_interface->GetFloatValue(state, 2);
  8015. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  8016. Spawn* target = lua_interface->GetSpawn(state, 4);
  8017. string heal_name = lua_interface->GetStringValue(state, 5);
  8018. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  8019. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  8020. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8021. lua_interface->ResetFunctionStack(state);
  8022. if (!spell) {
  8023. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  8024. return 0;
  8025. }
  8026. Entity* caster = spell->caster;
  8027. if (!caster) {
  8028. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  8029. return 0;
  8030. }
  8031. Client* client = 0;
  8032. PendingResurrection* rez = 0;
  8033. ZoneServer* zone = spell->caster->GetZone();
  8034. if (!target) {
  8035. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8036. if (spell->targets.size() > 0) {
  8037. vector<int32> spell_targets = spell->targets;
  8038. for (int8 i = 0; i < spell_targets.size(); i++) {
  8039. target = zone->GetSpawnByID(spell_targets.at(i));
  8040. if (!target)
  8041. continue;
  8042. if (!target->IsPlayer())
  8043. continue;
  8044. client = ((Player*)target)->GetClient();
  8045. if (!client)
  8046. continue;
  8047. rez = client->GetCurrentRez();
  8048. if (rez->active)
  8049. continue;
  8050. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  8051. rez->active = true;
  8052. rez->caster = caster;
  8053. rez->expire_timer = new Timer;
  8054. int32 duration = spell->spell->GetSpellDuration();
  8055. rez->expire_timer->Start(duration * 100);
  8056. rez->hp_perc = hp_perc;
  8057. rez->mp_perc = power_perc;
  8058. rez->range = spell->spell->GetSpellData()->range;
  8059. rez->spell_name = spell->spell->GetName();
  8060. if (heal_name.length() > 0)
  8061. rez->heal_name = heal_name;
  8062. else
  8063. rez->heal_name = rez->spell_name;
  8064. rez->no_calcs = no_calcs;
  8065. rez->crit_mod = crit_mod;
  8066. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  8067. if (send_window)
  8068. client->SendResurrectionWindow();
  8069. else {
  8070. target->GetZone()->ResurrectSpawn(target, client);
  8071. rez->should_delete = true;
  8072. }
  8073. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  8074. }
  8075. }
  8076. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8077. }
  8078. else {
  8079. if(!target->IsPlayer())
  8080. return 0;
  8081. client = ((Player*)target)->GetClient();
  8082. if (!client)
  8083. return 0;
  8084. rez = client->GetCurrentRez();
  8085. if (rez->active)
  8086. return 0;
  8087. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  8088. rez->active = true;
  8089. rez->caster = caster;
  8090. rez->expire_timer = new Timer;
  8091. int32 duration = spell->spell->GetSpellDuration();
  8092. rez->expire_timer->Start(duration * 100);
  8093. rez->hp_perc = hp_perc;
  8094. rez->mp_perc = power_perc;
  8095. rez->range = spell->spell->GetSpellData()->range;
  8096. rez->spell_name = spell->spell->GetName();
  8097. if (heal_name.length() > 0)
  8098. rez->heal_name = heal_name;
  8099. else
  8100. rez->heal_name = rez->spell_name;
  8101. rez->no_calcs = no_calcs;
  8102. rez->crit_mod = crit_mod;
  8103. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  8104. if (send_window)
  8105. client->SendResurrectionWindow();
  8106. else {
  8107. target->GetZone()->ResurrectSpawn(target, client);
  8108. rez->should_delete = true;
  8109. }
  8110. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  8111. }
  8112. return 0;
  8113. }
  8114. int EQ2Emu_lua_SetVision(lua_State* state) {
  8115. if (!lua_interface)
  8116. return 0;
  8117. Spawn* spawn = lua_interface->GetSpawn(state);
  8118. int32 vision = lua_interface->GetInt32Value(state, 2);
  8119. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8120. lua_interface->ResetFunctionStack(state);
  8121. if (!spawn) {
  8122. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8123. return 0;
  8124. }
  8125. if (!spawn->IsEntity()) {
  8126. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8127. return 0;
  8128. }
  8129. if (spell && spell->targets.size() > 0) {
  8130. ZoneServer* zone = spell->caster->GetZone();
  8131. for (int8 i = 0; i < spell->targets.size(); i++) {
  8132. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8133. if (target && target->IsEntity()) {
  8134. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  8135. if (target->IsPlayer())
  8136. ((Player*)target)->SetCharSheetChanged(true);
  8137. }
  8138. }
  8139. }
  8140. else {
  8141. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  8142. if (spawn->IsPlayer())
  8143. ((Player*)spawn)->SetCharSheetChanged(true);
  8144. }
  8145. return 0;
  8146. }
  8147. int EQ2Emu_lua_BlurVision(lua_State* state) {
  8148. if (!lua_interface)
  8149. return 0;
  8150. Spawn* spawn = lua_interface->GetSpawn(state);
  8151. float intensity = lua_interface->GetFloatValue(state, 2);
  8152. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8153. lua_interface->ResetFunctionStack(state);
  8154. if (!spawn) {
  8155. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8156. return 0;
  8157. }
  8158. if (!spawn->IsEntity()) {
  8159. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8160. return 0;
  8161. }
  8162. if (spell && spell->targets.size() > 0) {
  8163. ZoneServer* zone = spell->caster->GetZone();
  8164. for (int8 i = 0; i < spell->targets.size(); i++) {
  8165. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8166. if (target && target->IsEntity()) {
  8167. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  8168. if (target->IsPlayer())
  8169. ((Player*)target)->SetCharSheetChanged(true);
  8170. }
  8171. }
  8172. }
  8173. else {
  8174. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  8175. if (spawn->IsPlayer())
  8176. ((Player*)spawn)->SetCharSheetChanged(true);
  8177. }
  8178. return 0;
  8179. }
  8180. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  8181. if (!lua_interface)
  8182. return 0;
  8183. Spawn* spawn = lua_interface->GetSpawn(state);
  8184. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  8185. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8186. lua_interface->ResetFunctionStack(state);
  8187. if (!spawn) {
  8188. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  8189. return 0;
  8190. }
  8191. if (!spawn->IsEntity()) {
  8192. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  8193. return 0;
  8194. }
  8195. if (spell && spell->targets.size() > 0) {
  8196. ZoneServer* zone = spell->caster->GetZone();
  8197. for (int8 i = 0; i < spell->targets.size(); i++) {
  8198. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8199. if (target && target->IsEntity()) {
  8200. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8201. if (target->IsPlayer())
  8202. ((Player*)target)->SetCharSheetChanged(true);
  8203. }
  8204. }
  8205. }
  8206. else {
  8207. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8208. if (spawn->IsPlayer())
  8209. ((Player*)spawn)->SetCharSheetChanged(true);
  8210. }
  8211. return 0;
  8212. }
  8213. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  8214. if (!lua_interface)
  8215. return 0;
  8216. Item* item = lua_interface->GetItem(state);
  8217. int8 type = lua_interface->GetInt32Value(state, 2);
  8218. lua_interface->ResetFunctionStack(state);
  8219. if (!item) {
  8220. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  8221. return 0;
  8222. }
  8223. if (type == 1)
  8224. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  8225. else if (type == 2)
  8226. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  8227. return 1;
  8228. }
  8229. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  8230. if (!lua_interface)
  8231. return 0;
  8232. Spawn* target = lua_interface->GetSpawn(state);
  8233. float val = lua_interface->GetFloatValue(state, 2);
  8234. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8235. lua_interface->ResetFunctionStack(state);
  8236. // Added from Gangrenous post
  8237. if (spell && spell->resisted)
  8238. return 0;
  8239. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  8240. if (val > 1.0f)
  8241. val = 1.0f - (val / 100.0f);
  8242. if (spell && spell->spell && spell->targets.size() > 0) {
  8243. ZoneServer* zone = spell->caster->GetZone();
  8244. for (int32 i = 0; i != spell->targets.size(); i++) {
  8245. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  8246. if (spawn && spawn->IsEntity()) {
  8247. ((Entity*)spawn)->SetSpeedMultiplier(val);
  8248. if (spawn->IsPlayer())
  8249. ((Player*)spawn)->SetCharSheetChanged(true);
  8250. }
  8251. }
  8252. }
  8253. else {
  8254. if (target && target->IsEntity()) {
  8255. ((Entity*)target)->SetSpeedMultiplier(val);
  8256. if (target->IsPlayer())
  8257. ((Player*)target)->SetCharSheetChanged(true);
  8258. }
  8259. }
  8260. return 0;
  8261. }
  8262. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  8263. if (!lua_interface)
  8264. return 0;
  8265. Spawn* spawn = lua_interface->GetSpawn(state);
  8266. int16 model = lua_interface->GetInt16Value(state, 2);
  8267. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8268. lua_interface->ResetFunctionStack(state);
  8269. if (spell && spell->spell && spell->targets.size() > 0) {
  8270. ZoneServer* zone = spell->caster->GetZone();
  8271. for (int32 i = 0; i < spell->targets.size(); i++) {
  8272. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8273. if (target)
  8274. target->SetIllusionModel(model);
  8275. }
  8276. }
  8277. else {
  8278. if (!spawn) {
  8279. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8280. return 0;
  8281. }
  8282. spawn->SetIllusionModel(model);
  8283. }
  8284. return 0;
  8285. }
  8286. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  8287. if (!lua_interface)
  8288. return 0;
  8289. Spawn* spawn = lua_interface->GetSpawn(state);
  8290. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8291. lua_interface->ResetFunctionStack(state);
  8292. if (spell && spell->spell && spell->targets.size() > 0) {
  8293. ZoneServer* zone = spell->caster->GetZone();
  8294. for (int32 i = 0; i < spell->targets.size(); i++) {
  8295. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8296. if (target)
  8297. target->SetIllusionModel(0);
  8298. }
  8299. }
  8300. else {
  8301. if (!spawn) {
  8302. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8303. return 0;
  8304. }
  8305. spawn->SetIllusionModel(0);
  8306. }
  8307. return 0;
  8308. }
  8309. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  8310. if (!lua_interface)
  8311. return 0;
  8312. Spawn* caster = lua_interface->GetSpawn(state);
  8313. Spawn* target = lua_interface->GetSpawn(state, 2);
  8314. float chance = lua_interface->GetFloatValue(state, 3);
  8315. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8316. lua_interface->ResetFunctionStack(state);
  8317. if (!caster) {
  8318. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8319. return 0;
  8320. }
  8321. if (!caster->IsEntity()) {
  8322. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  8323. return 0;
  8324. }
  8325. if (!target) {
  8326. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8327. return 0;
  8328. }
  8329. if (!target->IsEntity()) {
  8330. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  8331. return 0;
  8332. }
  8333. if (chance <= 0) {
  8334. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  8335. return 0;
  8336. }
  8337. if (!spell) {
  8338. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8339. return 0;
  8340. }
  8341. if(spell->resisted) {
  8342. return 0;
  8343. }
  8344. if (((Entity*)caster)->GetThreatTransfer()) {
  8345. return 0;
  8346. }
  8347. ThreatTransfer* transfer = new ThreatTransfer;
  8348. transfer->Target = target->GetID();
  8349. transfer->Amount = chance;
  8350. transfer->Spell = spell;
  8351. ((Entity*)caster)->SetThreatTransfer(transfer);
  8352. return 0;
  8353. }
  8354. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  8355. if (!lua_interface)
  8356. return 0;
  8357. Spawn* spawn = lua_interface->GetSpawn(state);
  8358. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8359. lua_interface->ResetFunctionStack(state);
  8360. if (!spawn) {
  8361. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  8362. return 0;
  8363. }
  8364. if (!spell) {
  8365. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8366. return 0;
  8367. }
  8368. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  8369. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  8370. if(transfer && transfer->Spell != spell) {
  8371. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  8372. return 0;
  8373. }
  8374. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  8375. }
  8376. return 0;
  8377. }
  8378. int EQ2Emu_lua_CureByType(lua_State* state) {
  8379. if (!lua_interface)
  8380. return 0;
  8381. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8382. int8 cure_count = lua_interface->GetInt8Value(state);
  8383. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8384. string cure_name = lua_interface->GetStringValue(state, 3);
  8385. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8386. Spawn* target = lua_interface->GetSpawn(state, 5);
  8387. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  8388. lua_interface->ResetFunctionStack(state);
  8389. if(spell && spell->resisted) {
  8390. return 0;
  8391. }
  8392. if (target) {
  8393. if (!target->IsEntity()) {
  8394. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8395. return 0;
  8396. }
  8397. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8398. std::string alternate_name = "item";
  8399. if(spell)
  8400. alternate_name = std::string(spell->spell->GetName());
  8401. if(!caster && spell)
  8402. caster = (Spawn*)spell->caster;
  8403. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  8404. }
  8405. }
  8406. else {
  8407. ZoneServer* zone = spell->caster->GetZone();
  8408. vector<int32> targets = spell->targets;
  8409. vector<Entity*> targets_to_cure;
  8410. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8411. for (int8 i = 0; i < targets.size(); i++) {
  8412. target = zone->GetSpawnByID(targets.at(i));
  8413. if (!target || !target->IsEntity())
  8414. continue;
  8415. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8416. targets_to_cure.push_back((Entity*)target);
  8417. }
  8418. }
  8419. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8420. vector<Entity*>::iterator itr;
  8421. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  8422. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8423. }
  8424. }
  8425. return 0;
  8426. }
  8427. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  8428. if (!lua_interface)
  8429. return 0;
  8430. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8431. if (!spell) {
  8432. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8433. lua_interface->ResetFunctionStack(state);
  8434. return 0;
  8435. }
  8436. if(spell->resisted) {
  8437. lua_interface->ResetFunctionStack(state);
  8438. return 0;
  8439. }
  8440. int8 cure_count = lua_interface->GetInt8Value(state);
  8441. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8442. string cure_name = lua_interface->GetStringValue(state, 3);
  8443. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8444. Spawn* target = lua_interface->GetSpawn(state, 5);
  8445. lua_interface->ResetFunctionStack(state);
  8446. if (target) {
  8447. if (!target->IsEntity()) {
  8448. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8449. return 0;
  8450. }
  8451. if (((Entity*)target)->GetDetCount() > 0)
  8452. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8453. }
  8454. else {
  8455. ZoneServer* zone = spell->caster->GetZone();
  8456. vector<int32> targets = spell->targets;
  8457. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8458. for (int8 i = 0; i < targets.size(); i++) {
  8459. target = zone->GetSpawnByID(targets.at(i));
  8460. if (!target || !target->IsEntity())
  8461. continue;
  8462. if (((Entity*)target)->GetDetCount() > 0)
  8463. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8464. }
  8465. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8466. }
  8467. return 0;
  8468. }
  8469. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8470. if (!lua_interface)
  8471. return 0;
  8472. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8473. lua_interface->ResetFunctionStack(state);
  8474. if (!spell) {
  8475. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8476. return 0;
  8477. }
  8478. if (!spell->caster) {
  8479. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8480. return 0;
  8481. }
  8482. if (!spell->caster->GetZone()) {
  8483. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8484. return 0;
  8485. }
  8486. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8487. return 0;
  8488. }
  8489. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8490. if (!lua_interface)
  8491. return 0;
  8492. Spawn* spawn = lua_interface->GetSpawn(state);
  8493. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8494. lua_interface->ResetFunctionStack(state);
  8495. if (!spell) {
  8496. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8497. return 0;
  8498. }
  8499. if (spawn && spawn->IsEntity())
  8500. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8501. else {
  8502. ZoneServer* zone = spell->caster->GetZone();
  8503. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8504. for (int32 i = 0; i < spell->targets.size(); i++) {
  8505. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8506. if (!spawn || !spawn->IsEntity())
  8507. continue;
  8508. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8509. }
  8510. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8511. }
  8512. return 0;
  8513. }
  8514. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8515. if (!lua_interface)
  8516. return 0;
  8517. Spawn* spawn = lua_interface->GetSpawn(state);
  8518. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8519. lua_interface->ResetFunctionStack(state);
  8520. if (!spell) {
  8521. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8522. return 0;
  8523. }
  8524. if (spawn && spawn->IsEntity())
  8525. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8526. else {
  8527. ZoneServer* zone = spell->caster->GetZone();
  8528. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8529. for (int32 i = 0; i < spell->targets.size(); i++) {
  8530. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8531. if (!spawn || !spawn->IsEntity())
  8532. continue;
  8533. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8534. }
  8535. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8536. }
  8537. return 0;
  8538. }
  8539. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8540. if (!lua_interface)
  8541. return 0;
  8542. Spawn* caster = lua_interface->GetSpawn(state);
  8543. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8544. lua_interface->ResetFunctionStack(state);
  8545. if (!caster) {
  8546. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8547. return 0;
  8548. }
  8549. if (!caster->IsPlayer()) {
  8550. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8551. return 0;
  8552. }
  8553. Spawn* target = caster->GetTarget();
  8554. if (!target) {
  8555. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8556. return 0;
  8557. }
  8558. Client* client = ((Player*)caster)->GetClient();
  8559. if (!client) {
  8560. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8561. return 0;
  8562. }
  8563. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8564. if (ho) {
  8565. ho->SetTarget(target->GetID());
  8566. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8567. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8568. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8569. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8570. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8571. deque<GroupMemberInfo*>::iterator itr;
  8572. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8573. if (group)
  8574. {
  8575. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8576. deque<GroupMemberInfo*>* members = group->GetMembers();
  8577. for (itr = members->begin(); itr != members->end(); itr++) {
  8578. if ((*itr)->client)
  8579. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8580. }
  8581. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8582. }
  8583. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8584. }
  8585. else
  8586. safe_delete(ho);
  8587. }
  8588. else {
  8589. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8590. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8591. }
  8592. else
  8593. safe_delete(ho);
  8594. }
  8595. }
  8596. return 0;
  8597. }
  8598. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8599. if (!lua_interface)
  8600. return 0;
  8601. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8602. if (!spell) {
  8603. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8604. return 0;
  8605. }
  8606. int16 triggerCount = lua_interface->GetInt16Value(state);
  8607. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8608. if (!triggerCount) {
  8609. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8610. return 0;
  8611. }
  8612. spell->num_triggers = triggerCount;
  8613. spell->had_triggers = true;
  8614. spell->cancel_after_all_triggers = cancel_after_triggers;
  8615. return 0;
  8616. }
  8617. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8618. if (!lua_interface)
  8619. return 0;
  8620. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8621. lua_interface->ResetFunctionStack(state);
  8622. if (!spell) {
  8623. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8624. return 0;
  8625. }
  8626. lua_interface->SetInt32Value(state, spell->num_triggers);
  8627. return 1;
  8628. }
  8629. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8630. if (!lua_interface)
  8631. return 0;
  8632. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8633. if (!spell) {
  8634. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8635. lua_interface->ResetFunctionStack(state);
  8636. return 0;
  8637. }
  8638. if (!spell->caster || !spell->caster->GetZone()) {
  8639. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: caster / caster zone must be set!", lua_interface->GetScriptName(state));
  8640. lua_interface->ResetFunctionStack(state);
  8641. return 0;
  8642. }
  8643. int16 remove_count = lua_interface->GetInt16Value(state);
  8644. lua_interface->ResetFunctionStack(state);
  8645. if (!remove_count)
  8646. remove_count = 1;
  8647. if (remove_count >= spell->num_triggers) {
  8648. spell->num_triggers = 0;
  8649. if (spell->cancel_after_all_triggers)
  8650. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8651. }
  8652. else {
  8653. spell->num_triggers -= remove_count;
  8654. Client* client = spell->caster->IsPlayer() ? ((Player*)spell->caster)->GetClient() : nullptr;
  8655. ClientPacketFunctions::SendMaintainedExamineUpdate(client, spell->slot_pos, spell->num_triggers, 0);
  8656. }
  8657. return 0;
  8658. }
  8659. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8660. if (!lua_interface)
  8661. return 0;
  8662. Spawn* spawn = lua_interface->GetSpawn(state);
  8663. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8664. lua_interface->ResetFunctionStack(state);
  8665. if (!spawn) {
  8666. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8667. return 0;
  8668. }
  8669. if (!copy_spawn) {
  8670. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8671. return 0;
  8672. }
  8673. spawn->CopySpawnAppearance(copy_spawn);
  8674. return 0;
  8675. }
  8676. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8677. Spawn* spawn = lua_interface->GetSpawn(state);
  8678. int8 type = lua_interface->GetInt8Value(state, 2);
  8679. lua_interface->ResetFunctionStack(state);
  8680. if (!spawn) {
  8681. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8682. return 0;
  8683. }
  8684. else if (!spawn->IsEntity()) {
  8685. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8686. return 0;
  8687. }
  8688. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8689. return 1;
  8690. }
  8691. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8692. if (!lua_interface)
  8693. return 0;
  8694. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8695. int8 type = lua_interface->GetInt8Value(state);
  8696. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8697. lua_interface->ResetFunctionStack(state);
  8698. if (!spell) {
  8699. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8700. return 0;
  8701. }
  8702. if(spell->resisted) {
  8703. return 0;
  8704. }
  8705. if (spawn) {
  8706. if (!spawn->IsEntity()) {
  8707. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8708. return 0;
  8709. }
  8710. Entity* entity = ((Entity*)spawn);
  8711. entity->AddImmunity(spell, type);
  8712. }
  8713. else if(spell->caster && spell->caster->GetZone()) {
  8714. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8715. for (int8 i = 0; i < spell->targets.size(); i++) {
  8716. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8717. if (!spawn || !spawn->IsEntity())
  8718. continue;
  8719. Entity* entity = ((Entity*)spawn);
  8720. entity->AddImmunity(spell, type);
  8721. }
  8722. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8723. }
  8724. return 0;
  8725. }
  8726. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8727. if (!lua_interface)
  8728. return 0;
  8729. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8730. int8 type = lua_interface->GetInt8Value(state);
  8731. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8732. lua_interface->ResetFunctionStack(state);
  8733. if (!spell) {
  8734. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8735. return 0;
  8736. }
  8737. if (spawn) {
  8738. if (!spawn->IsEntity()) {
  8739. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8740. return 0;
  8741. }
  8742. Entity* entity = ((Entity*)spawn);
  8743. entity->RemoveImmunity(spell, type);
  8744. }
  8745. else if(spell->caster && spell->caster->GetZone()) {
  8746. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8747. for (int8 i = 0; i < spell->targets.size(); i++) {
  8748. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8749. if (!spawn || !spawn->IsEntity())
  8750. continue;
  8751. Entity* entity = ((Entity*)spawn);
  8752. entity->RemoveImmunity(spell, type);
  8753. }
  8754. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8755. }
  8756. return 0;
  8757. }
  8758. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8759. if (!lua_interface)
  8760. return 0;
  8761. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8762. if (!spell) {
  8763. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8764. lua_interface->ResetFunctionStack(state);
  8765. return 0;
  8766. }
  8767. if(spell->resisted) {
  8768. lua_interface->ResetFunctionStack(state);
  8769. return 0;
  8770. }
  8771. float snare = lua_interface->GetFloatValue(state);
  8772. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8773. lua_interface->ResetFunctionStack(state);
  8774. // convert the val to the speed multipler value (100 - val)
  8775. float val = 100.0 - snare;
  8776. val /= 100.0;
  8777. if (spawn) {
  8778. if (!spawn->IsEntity()) {
  8779. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8780. return 0;
  8781. }
  8782. ((Entity*)spawn)->SetSnareValue(spell, val);
  8783. }
  8784. else if(spell->caster && spell->caster->GetZone()) {
  8785. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8786. for (int8 i = 0; i < spell->targets.size(); i++) {
  8787. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8788. if (!spawn || !spawn->IsEntity())
  8789. continue;
  8790. ((Entity*)spawn)->SetSnareValue(spell, val);
  8791. }
  8792. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8793. }
  8794. return 0;
  8795. }
  8796. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8797. if (!lua_interface)
  8798. return 0;
  8799. Spawn* spawn = lua_interface->GetSpawn(state);
  8800. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8801. lua_interface->ResetFunctionStack(state);
  8802. if (!spawn) {
  8803. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8804. return 0;
  8805. }
  8806. if (race_id == 0) {
  8807. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8808. return 0;
  8809. }
  8810. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8811. return 1;
  8812. }
  8813. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8814. if (!lua_interface)
  8815. return 0;
  8816. Spawn* spawn = lua_interface->GetSpawn(state);
  8817. lua_interface->ResetFunctionStack(state);
  8818. if (!spawn) {
  8819. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8820. return 0;
  8821. }
  8822. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8823. return 1;
  8824. }
  8825. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8826. if (!lua_interface)
  8827. return 0;
  8828. Spawn* spawn = lua_interface->GetSpawn(state);
  8829. lua_interface->ResetFunctionStack(state);
  8830. if (!spawn) {
  8831. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8832. return 0;
  8833. }
  8834. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8835. return 1;
  8836. }
  8837. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8838. if (!lua_interface)
  8839. return 0;
  8840. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8841. lua_interface->ResetFunctionStack(state);
  8842. if (!spell) {
  8843. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8844. return 0;
  8845. }
  8846. lua_interface->SetStringValue(state, spell->spell->GetName());
  8847. return 1;
  8848. }
  8849. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8850. if (!lua_interface)
  8851. return 0;
  8852. Quest* quest = lua_interface->GetQuest(state);
  8853. lua_interface->ResetFunctionStack(state);
  8854. if (!quest) {
  8855. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8856. return 0;
  8857. }
  8858. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8859. return 1;
  8860. }
  8861. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8862. if (!lua_interface)
  8863. return 0;
  8864. Quest* quest = lua_interface->GetQuest(state);
  8865. int32 flags = lua_interface->GetInt32Value(state, 2);
  8866. lua_interface->ResetFunctionStack(state);
  8867. if (!quest) {
  8868. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8869. return 0;
  8870. }
  8871. quest->SetQuestFlags(flags);
  8872. return 0;
  8873. }
  8874. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8875. if (!lua_interface)
  8876. return 0;
  8877. Quest* quest = lua_interface->GetQuest(state);
  8878. Spawn* player = lua_interface->GetSpawn(state, 2);
  8879. int32 step = lua_interface->GetInt32Value(state, 3);
  8880. int32 duration = lua_interface->GetInt32Value(state, 4);
  8881. string action = lua_interface->GetStringValue(state, 5);
  8882. lua_interface->ResetFunctionStack(state);
  8883. if (!quest) {
  8884. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8885. return 0;
  8886. }
  8887. if (!player) {
  8888. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8889. return 0;
  8890. }
  8891. if (!player->IsPlayer()) {
  8892. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8893. return 0;
  8894. }
  8895. if (step == 0) {
  8896. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8897. return 0;
  8898. }
  8899. if (duration == 0) {
  8900. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8901. return 0;
  8902. }
  8903. if (action.length() == 0) {
  8904. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8905. return 0;
  8906. }
  8907. Client* client = ((Player*)player)->GetClient();
  8908. if (!client) {
  8909. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8910. return 0;
  8911. }
  8912. quest->SetTimerStep(step);
  8913. quest->AddFailedAction(step, action);
  8914. quest->SetStepTimer(duration);
  8915. client->AddQuestTimer(quest->GetQuestID());
  8916. return 0;
  8917. }
  8918. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8919. if (!lua_interface)
  8920. return 0;
  8921. Quest* quest = lua_interface->GetQuest(state);
  8922. Spawn* player = lua_interface->GetSpawn(state, 2);
  8923. lua_interface->ResetFunctionStack(state);
  8924. if (!quest) {
  8925. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8926. return 0;
  8927. }
  8928. if (!player) {
  8929. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8930. return 0;
  8931. }
  8932. if (!player->IsPlayer()) {
  8933. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8934. return 0;
  8935. }
  8936. Client* client = ((Player*)player)->GetClient();
  8937. if (!client) {
  8938. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8939. return 0;
  8940. }
  8941. quest->SetTimerStep(0);
  8942. quest->SetStepTimer(0);
  8943. client->RemoveQuestTimer(quest->GetQuestID());
  8944. return 0;
  8945. }
  8946. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8947. if (!lua_interface)
  8948. return 0;
  8949. Spawn* player = lua_interface->GetSpawn(state);
  8950. Quest* quest = lua_interface->GetQuest(state, 2);
  8951. int32 step = lua_interface->GetInt32Value(state, 3);
  8952. lua_interface->ResetFunctionStack(state);
  8953. if (!player) {
  8954. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8955. return 0;
  8956. }
  8957. if (!player->IsPlayer()) {
  8958. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8959. return 0;
  8960. }
  8961. if (!quest) {
  8962. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8963. return 0;
  8964. }
  8965. if (step == 0) {
  8966. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8967. return 0;
  8968. }
  8969. Client* client = ((Player*)player)->GetClient();
  8970. if (!client) {
  8971. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8972. return 0;
  8973. }
  8974. if (quest->RemoveQuestStep(step, client)) {
  8975. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8976. client->GetCurrentZone()->SendQuestUpdates(client);
  8977. }
  8978. else
  8979. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8980. return 0;
  8981. }
  8982. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8983. if (!lua_interface)
  8984. return 0;
  8985. Quest* quest = lua_interface->GetQuest(state, 1);
  8986. int32 step = lua_interface->GetInt32Value(state, 2);
  8987. string desc = lua_interface->GetStringValue(state, 3);
  8988. string task_group = lua_interface->GetStringValue(state, 4);
  8989. lua_interface->ResetFunctionStack(state);
  8990. if (!quest) {
  8991. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8992. return 0;
  8993. }
  8994. if (step == 0) {
  8995. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8996. return 0;
  8997. }
  8998. QuestStep* quest_step = quest->GetQuestStep(step);
  8999. if (!quest_step) {
  9000. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  9001. return 0;
  9002. }
  9003. quest_step->SetStepProgress(0);
  9004. quest_step->SetTaskGroup(task_group);
  9005. quest_step->SetDescription(desc);
  9006. return 0;
  9007. }
  9008. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  9009. if (!lua_interface)
  9010. return 0;
  9011. Quest* quest = lua_interface->GetQuest(state);
  9012. int32 step = lua_interface->GetInt32Value(state, 2);
  9013. string action = lua_interface->GetStringValue(state, 3);
  9014. lua_interface->ResetFunctionStack(state);
  9015. if (!quest) {
  9016. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  9017. return 0;
  9018. }
  9019. if (step == 0) {
  9020. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  9021. return 0;
  9022. }
  9023. if (action.length() == 0) {
  9024. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  9025. return 0;
  9026. }
  9027. quest->AddFailedAction(step, action);
  9028. return 0;
  9029. }
  9030. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  9031. if (!lua_interface)
  9032. return 0;
  9033. Spawn* player = lua_interface->GetSpawn(state);
  9034. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9035. int32 step = lua_interface->GetInt32Value(state, 3);
  9036. lua_interface->ResetFunctionStack(state);
  9037. if (!player) {
  9038. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  9039. return 0;
  9040. }
  9041. if (!player->IsPlayer()) {
  9042. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9043. return 0;
  9044. }
  9045. if (quest_id == 0) {
  9046. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  9047. return 0;
  9048. }
  9049. if (step == 0) {
  9050. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  9051. return 0;
  9052. }
  9053. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  9054. if (!quest) {
  9055. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  9056. return 0;
  9057. }
  9058. quest->StepFailed(step);
  9059. return 0;
  9060. }
  9061. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  9062. if (!lua_interface)
  9063. return 0;
  9064. Spawn* player = lua_interface->GetSpawn(state);
  9065. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9066. lua_interface->ResetFunctionStack(state);
  9067. if (!player) {
  9068. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  9069. return 0;
  9070. }
  9071. if (!player->IsPlayer()) {
  9072. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  9073. return 0;
  9074. }
  9075. if (quest_id == 0) {
  9076. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  9077. return 0;
  9078. }
  9079. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestCompletedCount(quest_id));
  9080. return 1;
  9081. }
  9082. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  9083. if (!lua_interface)
  9084. return 0;
  9085. string name = lua_interface->GetStringValue(state);
  9086. string value = lua_interface->GetStringValue(state, 2);
  9087. string comment = lua_interface->GetStringValue(state, 3);
  9088. lua_interface->ResetFunctionStack(state);
  9089. if (name.length() == 0) {
  9090. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  9091. return 0;
  9092. }
  9093. if (value.length() == 0) {
  9094. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  9095. return 0;
  9096. }
  9097. string varname = string("lua_").append(name);
  9098. Variable* var = variables.FindVariable(varname);
  9099. if (var)
  9100. var->SetValue(value.c_str());
  9101. else {
  9102. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  9103. variables.AddVariable(var);
  9104. }
  9105. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  9106. return 0;
  9107. }
  9108. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  9109. if (!lua_interface)
  9110. return 0;
  9111. string name = lua_interface->GetStringValue(state);
  9112. lua_interface->ResetFunctionStack(state);
  9113. if (name.length() == 0) {
  9114. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  9115. return 0;
  9116. }
  9117. string varname = string("lua_").append(name);
  9118. Variable* var = variables.FindVariable(varname);
  9119. if (var)
  9120. lua_interface->SetStringValue(state, var->GetValue());
  9121. else
  9122. lua_interface->SetStringValue(state, "NULL");
  9123. return 1;
  9124. }
  9125. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  9126. if (!lua_interface)
  9127. return 0;
  9128. Spawn* player = lua_interface->GetSpawn(state);
  9129. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9130. lua_interface->ResetFunctionStack(state);
  9131. if (!player) {
  9132. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9133. return 0;
  9134. }
  9135. if (!player->IsPlayer()) {
  9136. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9137. return 0;
  9138. }
  9139. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  9140. return 1;
  9141. }
  9142. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  9143. if (!lua_interface)
  9144. return 0;
  9145. Spawn* player = lua_interface->GetSpawn(state);
  9146. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9147. lua_interface->ResetFunctionStack(state);
  9148. if (!player) {
  9149. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9150. return 0;
  9151. }
  9152. if (!player->IsPlayer()) {
  9153. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9154. return 0;
  9155. }
  9156. Language* language = master_languages_list.GetLanguage(language_id);
  9157. if (language)
  9158. {
  9159. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  9160. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID(), 0);
  9161. }
  9162. return 0;
  9163. }
  9164. int EQ2Emu_lua_IsNight(lua_State* state) {
  9165. if (!lua_interface)
  9166. return 0;
  9167. ZoneServer* zone = lua_interface->GetZone(state);
  9168. lua_interface->ResetFunctionStack(state);
  9169. if (!zone) {
  9170. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  9171. return 0;
  9172. }
  9173. lua_interface->SetBooleanValue(state, zone->IsDusk());
  9174. return 1;
  9175. }
  9176. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  9177. if (!lua_interface)
  9178. return 0;
  9179. Spawn* spawn = lua_interface->GetSpawn(state);
  9180. lua_interface->ResetFunctionStack(state);
  9181. if (!spawn) {
  9182. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  9183. return 0;
  9184. }
  9185. if (!spawn->IsWidget()) {
  9186. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  9187. return 0;
  9188. }
  9189. ((Widget*)spawn)->SetMultiFloorLift(true);
  9190. if (spawn->GetZone())
  9191. spawn->GetZone()->AddTransportSpawn(spawn);
  9192. return 0;
  9193. }
  9194. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  9195. if (!lua_interface)
  9196. return 0;
  9197. Spawn* player = lua_interface->GetSpawn(state);
  9198. int32 path = lua_interface->GetInt32Value(state, 2);
  9199. lua_interface->ResetFunctionStack(state);
  9200. if (!player) {
  9201. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9202. return 0;
  9203. }
  9204. if (!player->IsPlayer()) {
  9205. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9206. return 0;
  9207. }
  9208. if (path == 0) {
  9209. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  9210. return 0;
  9211. }
  9212. Client* client = ((Player*)player)->GetClient();
  9213. if (!client) {
  9214. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9215. return 0;
  9216. }
  9217. client->SendFlightAutoMount(path);
  9218. return 0;
  9219. }
  9220. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  9221. if (!lua_interface)
  9222. return 0;
  9223. Spawn* player = lua_interface->GetSpawn(state);
  9224. if (!player) {
  9225. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9226. return 0;
  9227. }
  9228. if (!player->IsPlayer()) {
  9229. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9230. return 0;
  9231. }
  9232. Client* client = ((Player*)player)->GetClient();
  9233. if (!client) {
  9234. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9235. return 0;
  9236. }
  9237. client->EndAutoMount();
  9238. return 0;
  9239. }
  9240. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  9241. if (!lua_interface)
  9242. return 0;
  9243. Spawn* player = lua_interface->GetSpawn(state);
  9244. lua_interface->ResetFunctionStack(state);
  9245. if (!player) {
  9246. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  9247. return 0;
  9248. }
  9249. if (!player->IsPlayer()) {
  9250. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9251. return 0;
  9252. }
  9253. Client* client = ((Player*)player)->GetClient();
  9254. if (!client) {
  9255. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9256. return 0;
  9257. }
  9258. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  9259. return 1;
  9260. }
  9261. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  9262. if (!lua_interface)
  9263. return 0;
  9264. Spawn* player = lua_interface->GetSpawn(state);
  9265. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9266. int32 value = lua_interface->GetInt32Value(state, 3);
  9267. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9268. lua_interface->ResetFunctionStack(state);
  9269. if (!player) {
  9270. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9271. return 0;
  9272. }
  9273. if (!player->IsPlayer()) {
  9274. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9275. return 0;
  9276. }
  9277. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  9278. return 0;
  9279. }
  9280. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  9281. if (!lua_interface)
  9282. return 0;
  9283. Spawn* player = lua_interface->GetSpawn(state);
  9284. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9285. lua_interface->ResetFunctionStack(state);
  9286. if (!player) {
  9287. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9288. return 0;
  9289. }
  9290. if (!player->IsPlayer()) {
  9291. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9292. return 0;
  9293. }
  9294. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  9295. if (!hd)
  9296. return 0;
  9297. lua_interface->SetInt32Value(state, hd->Value);
  9298. lua_interface->SetInt32Value(state, hd->Value2);
  9299. return 2;
  9300. }
  9301. int EQ2Emu_lua_SetGridID(lua_State* state) {
  9302. if (!lua_interface)
  9303. return 0;
  9304. Spawn* spawn = lua_interface->GetSpawn(state);
  9305. int32 grid = lua_interface->GetInt32Value(state, 2);
  9306. lua_interface->ResetFunctionStack(state);
  9307. if (!spawn) {
  9308. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9309. return 0;
  9310. }
  9311. if (grid == 0) {
  9312. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  9313. return 0;
  9314. }
  9315. spawn->SetLocation(grid);
  9316. return 0;
  9317. }
  9318. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  9319. if (!lua_interface)
  9320. return 0;
  9321. Spawn* spawn = lua_interface->GetSpawn(state);
  9322. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9323. int32 value1 = lua_interface->GetInt32Value(state, 3);
  9324. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9325. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  9326. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  9327. lua_interface->ResetFunctionStack(state);
  9328. if (!spawn) {
  9329. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9330. return 0;
  9331. }
  9332. //Add this quest to the list of required quests for this spawn
  9333. spawn->SetRequiredHistory(event_id, value1, value2);
  9334. //If private spawn value set
  9335. if (private_spawn) {
  9336. //Set the spawn to be private when not granted access via history
  9337. spawn->AddAllowAccessSpawn(spawn);
  9338. spawn->SetPrivateQuestSpawn(true);
  9339. }
  9340. //This value will override vis_flags in the vis packet
  9341. if (flag_override > 0)
  9342. spawn->SetQuestsRequiredOverride(flag_override);
  9343. return 0;
  9344. }
  9345. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  9346. if (!lua_interface)
  9347. return 0;
  9348. Spawn* player = lua_interface->GetSpawn(state);
  9349. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9350. int32 step_id = lua_interface->GetInt32Value(state, 3);
  9351. lua_interface->ResetFunctionStack(state);
  9352. if (!player) {
  9353. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  9354. return 0;
  9355. }
  9356. if (!player->IsPlayer()) {
  9357. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  9358. return 0;
  9359. }
  9360. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  9361. return 1;
  9362. }
  9363. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  9364. if (!lua_interface)
  9365. return 0;
  9366. Spawn* player = lua_interface->GetSpawn(state);
  9367. int8 level = lua_interface->GetInt8Value(state, 2);
  9368. lua_interface->ResetFunctionStack(state);
  9369. if (!player) {
  9370. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  9371. return 0;
  9372. }
  9373. if (!player->IsPlayer()) {
  9374. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  9375. return 0;
  9376. }
  9377. if (level == 0) {
  9378. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  9379. return 0;
  9380. }
  9381. Client* client = ((Player*)player)->GetClient();
  9382. if (!client) {
  9383. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  9384. return 0;
  9385. }
  9386. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  9387. return 0;
  9388. }
  9389. int EQ2Emu_lua_AddCoin(lua_State* state) {
  9390. if (!lua_interface)
  9391. return 0;
  9392. Spawn* player = lua_interface->GetSpawn(state);
  9393. int32 amount = lua_interface->GetInt32Value(state, 2);
  9394. lua_interface->ResetFunctionStack(state);
  9395. if (!player) {
  9396. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9397. return 0;
  9398. }
  9399. if (!player->IsPlayer()) {
  9400. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9401. return 0;
  9402. }
  9403. if (amount == 0) {
  9404. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9405. return 0;
  9406. }
  9407. ((Player*)player)->AddCoins(amount);
  9408. return 0;
  9409. }
  9410. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  9411. if (!lua_interface)
  9412. return 0;
  9413. Spawn* player = lua_interface->GetSpawn(state);
  9414. int32 amount = lua_interface->GetInt32Value(state, 2);
  9415. lua_interface->ResetFunctionStack(state);
  9416. if (!player) {
  9417. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9418. return 0;
  9419. }
  9420. if (!player->IsPlayer()) {
  9421. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9422. return 0;
  9423. }
  9424. if (amount == 0) {
  9425. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9426. return 0;
  9427. }
  9428. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  9429. return 1;
  9430. }
  9431. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  9432. if (!lua_interface)
  9433. return 0;
  9434. ZoneServer* zone = lua_interface->GetZone(state);
  9435. lua_interface->ResetFunctionStack(state);
  9436. if (!zone) {
  9437. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9438. return 0;
  9439. }
  9440. vector<Entity*> players = zone->GetPlayers();
  9441. if (players.size() == 0)
  9442. return 0;
  9443. lua_createtable(state, players.size(), 0);
  9444. int newTable = lua_gettop(state);
  9445. for (int32 i = 0; i < players.size(); i++) {
  9446. lua_interface->SetSpawnValue(state, players.at(i));
  9447. lua_rawseti(state, newTable, i + 1);
  9448. }
  9449. return 1;
  9450. }
  9451. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  9452. if (!lua_interface)
  9453. return 0;
  9454. ZoneServer* zone = lua_interface->GetZone(state, 1);
  9455. if (!zone) {
  9456. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9457. return 0;
  9458. }
  9459. int32 group_id = lua_interface->GetInt32Value(state, 2);
  9460. lua_interface->ResetFunctionStack(state);
  9461. //Map of <placement_id, location_id>
  9462. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  9463. map<int32, int32>::iterator itr;
  9464. vector<Spawn*> group;
  9465. for (itr = locs->begin(); itr != locs->end(); itr++) {
  9466. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  9467. if (!location) {
  9468. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  9469. return 0;
  9470. }
  9471. Spawn* spawn = 0;
  9472. if (location->entities[0]) {
  9473. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  9474. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  9475. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  9476. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  9477. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  9478. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  9479. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  9480. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  9481. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9482. spawn = zone->AddSignSpawn(location, location->entities[0]);
  9483. if(spawn && spawn->IsOmittedByDBFlag())
  9484. {
  9485. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met (LUA SpawnGroupByID).", location->entities[0]->spawn_id);
  9486. safe_delete(spawn);
  9487. continue;
  9488. }
  9489. if (spawn) {
  9490. const char* script = 0;
  9491. for (int x = 0; x < 3; x++) {
  9492. switch (x) {
  9493. case 0:
  9494. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  9495. break;
  9496. case 1:
  9497. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  9498. break;
  9499. case 2:
  9500. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  9501. break;
  9502. }
  9503. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9504. spawn->SetSpawnScript(string(script));
  9505. break;
  9506. }
  9507. }
  9508. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9509. lua_interface->SetSpawnValue(state, spawn);
  9510. group.push_back(spawn);
  9511. }
  9512. else {
  9513. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  9514. safe_delete(spawn);
  9515. }
  9516. }
  9517. }
  9518. if (!group.empty()) {
  9519. lua_createtable(state, group.size(), 0);
  9520. int newTable = lua_gettop(state);
  9521. for (int32 i = 0; i < group.size(); i++) {
  9522. lua_interface->SetSpawnValue(state, group[i]);
  9523. lua_rawseti(state, newTable, i + 1);
  9524. }
  9525. }
  9526. else
  9527. lua_pushnil(state);
  9528. return 1;
  9529. }
  9530. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9531. if (!lua_interface)
  9532. return 0;
  9533. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9534. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9535. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9536. lua_interface->ResetFunctionStack(state);
  9537. if (!spawn) {
  9538. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9539. return 0;
  9540. }
  9541. if (anim_id == 0) {
  9542. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9543. return 0;
  9544. }
  9545. if (leeway == 0)
  9546. leeway = 5000;
  9547. spawn->SetSpawnAnim(anim_id);
  9548. spawn->SetSpawnAnimLeeway(leeway);
  9549. return 0;
  9550. }
  9551. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9552. if (!lua_interface)
  9553. return 0;
  9554. Spawn* player = lua_interface->GetSpawn(state);
  9555. lua_interface->ResetFunctionStack(state);
  9556. if (!player || !player->IsPlayer()) {
  9557. return 0;
  9558. }
  9559. Client* client = ((Player*)player)->GetClient();
  9560. if (!client) {
  9561. return 0;
  9562. }
  9563. lua_interface->SetInt32Value(state, client->GetVersion());
  9564. return 1;
  9565. }
  9566. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9567. if (!lua_interface)
  9568. return 0;
  9569. Item* item = lua_interface->GetItem(state);
  9570. lua_interface->ResetFunctionStack(state);
  9571. if (!item) {
  9572. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9573. return 0;
  9574. }
  9575. lua_interface->SetInt32Value(state, item->details.item_id);
  9576. return 1;
  9577. }
  9578. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9579. if (!lua_interface)
  9580. return 0;
  9581. Spawn* spawn = lua_interface->GetSpawn(state);
  9582. lua_interface->ResetFunctionStack(state);
  9583. if (!spawn) {
  9584. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9585. return 0;
  9586. }
  9587. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9588. return 1;
  9589. }
  9590. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9591. if (!lua_interface)
  9592. return 0;
  9593. Spawn* spawn = lua_interface->GetSpawn(state);
  9594. lua_interface->ResetFunctionStack(state);
  9595. if (!spawn) {
  9596. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9597. return 0;
  9598. }
  9599. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9600. return 1;
  9601. }
  9602. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9603. if (!lua_interface)
  9604. return 0;
  9605. Spawn* spawn = lua_interface->GetSpawn(state);
  9606. lua_interface->ResetFunctionStack(state);
  9607. if (!spawn) {
  9608. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9609. return 0;
  9610. }
  9611. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9612. return 1;
  9613. }
  9614. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9615. if (!lua_interface)
  9616. return 0;
  9617. Spawn* spawn = lua_interface->GetSpawn(state);
  9618. lua_interface->ResetFunctionStack(state);
  9619. if (!spawn) {
  9620. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9621. return 0;
  9622. }
  9623. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9624. return 1;
  9625. }
  9626. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9627. if (!lua_interface)
  9628. return 0;
  9629. Spawn* spawn = lua_interface->GetSpawn(state);
  9630. float pct = lua_interface->GetFloatValue(state, 2);
  9631. lua_interface->ResetFunctionStack(state);
  9632. if (!spawn) {
  9633. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9634. return 0;
  9635. }
  9636. if (pct == 0) {
  9637. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9638. return 0;
  9639. }
  9640. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9641. lua_interface->SetInt32Value(state, amount);
  9642. return 1;
  9643. }
  9644. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9645. if (!lua_interface)
  9646. return 0;
  9647. Spawn* spawn = lua_interface->GetSpawn(state);
  9648. float pct = lua_interface->GetFloatValue(state, 2);
  9649. lua_interface->ResetFunctionStack(state);
  9650. if (!spawn) {
  9651. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9652. return 0;
  9653. }
  9654. if (pct == 0) {
  9655. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9656. return 0;
  9657. }
  9658. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9659. lua_interface->SetInt32Value(state, amount);
  9660. return 1;
  9661. }
  9662. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9663. if (!lua_interface)
  9664. return 0;
  9665. Spawn* spawn = lua_interface->GetSpawn(state);
  9666. lua_interface->ResetFunctionStack(state);
  9667. if (!spawn) {
  9668. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9669. return 0;
  9670. }
  9671. if (!spawn->IsPlayer()) {
  9672. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9673. return 0;
  9674. }
  9675. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9676. return 1;
  9677. }
  9678. int EQ2Emu_lua_Evac(lua_State* state) {
  9679. if (!lua_interface)
  9680. return 0;
  9681. Spawn* target = lua_interface->GetSpawn(state);
  9682. if (target) {
  9683. float x = target->GetZone()->GetSafeX();
  9684. float y = target->GetZone()->GetSafeY();
  9685. float z = target->GetZone()->GetSafeZ();
  9686. float h = target->GetZone()->GetSafeHeading();
  9687. target->SetX(x);
  9688. target->SetY(y);
  9689. target->SetZ(z);
  9690. target->SetHeading(h);
  9691. target->SetSpawnOrigX(x);
  9692. target->SetSpawnOrigY(y);
  9693. target->SetSpawnOrigZ(z);
  9694. target->SetSpawnOrigHeading(h);
  9695. if (target->IsPlayer()) {
  9696. Client* client = ((Player*)target)->GetClient();
  9697. if (client) {
  9698. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9699. int numargs = lua_interface->GetNumberOfArgs(state);
  9700. if(numargs == 4) {
  9701. x = lua_interface->GetFloatValue(state,1);
  9702. y = lua_interface->GetFloatValue(state,2);
  9703. z = lua_interface->GetFloatValue(state,3);
  9704. h = lua_interface->GetFloatValue(state,4);
  9705. }
  9706. client->SetReloadingZone(true);
  9707. target->SetX(x);
  9708. target->SetY(y);
  9709. target->SetZ(z);
  9710. target->SetHeading(h);
  9711. target->SetSpawnOrigX(x);
  9712. target->SetSpawnOrigY(y);
  9713. target->SetSpawnOrigZ(z);
  9714. target->SetSpawnOrigHeading(h);
  9715. target->SetAppearancePosition(x,y,z);
  9716. client->SetZoningCoords(x,y,z,h);
  9717. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9718. if (packet)
  9719. {
  9720. packet->setDataByName("x", x);
  9721. packet->setDataByName("y", y);
  9722. packet->setDataByName("z", z);
  9723. client->QueuePacket(packet->serialize());
  9724. safe_delete(packet);
  9725. }
  9726. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9727. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9728. }
  9729. }
  9730. lua_interface->ResetFunctionStack(state);
  9731. }
  9732. else {
  9733. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9734. if(!spell || !spell->caster || !spell->caster->GetZone()) {
  9735. lua_interface->ResetFunctionStack(state);
  9736. return 0;
  9737. }
  9738. ZoneServer* zone = spell->caster->GetZone();
  9739. float x = spell->caster->GetZone()->GetSafeX();
  9740. float y = spell->caster->GetZone()->GetSafeY();
  9741. float z = spell->caster->GetZone()->GetSafeZ();
  9742. float h = spell->caster->GetZone()->GetSafeHeading();
  9743. int numargs = lua_interface->GetNumberOfArgs(state);
  9744. if(numargs == 4) {
  9745. x = lua_interface->GetFloatValue(state,1);
  9746. y = lua_interface->GetFloatValue(state,2);
  9747. z = lua_interface->GetFloatValue(state,3);
  9748. h = lua_interface->GetFloatValue(state,4);
  9749. }
  9750. lua_interface->ResetFunctionStack(state);
  9751. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9752. for (int32 i = 0; i < spell->targets.size(); i++) {
  9753. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9754. if (!target2)
  9755. continue;
  9756. if (target2->IsPlayer()) {
  9757. Client* client = ((Player*)target2)->GetClient();
  9758. if (client) {
  9759. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9760. client->SetReloadingZone(true);
  9761. target2->SetX(x);
  9762. target2->SetY(y);
  9763. target2->SetZ(z);
  9764. target2->SetHeading(h);
  9765. target2->SetSpawnOrigX(x);
  9766. target2->SetSpawnOrigY(y);
  9767. target2->SetSpawnOrigZ(z);
  9768. target2->SetSpawnOrigHeading(h);
  9769. target2->SetAppearancePosition(x,y,z);
  9770. client->SetZoningCoords(x,y,z,h);
  9771. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9772. if (packet)
  9773. {
  9774. packet->setDataByName("x", x);
  9775. packet->setDataByName("y", y);
  9776. packet->setDataByName("z", z);
  9777. client->QueuePacket(packet->serialize());
  9778. safe_delete(packet);
  9779. }
  9780. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9781. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9782. }
  9783. }
  9784. }
  9785. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9786. }
  9787. return 0;
  9788. }
  9789. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9790. if (!lua_interface)
  9791. return 0;
  9792. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9793. lua_interface->ResetFunctionStack(state);
  9794. if (!luaspell || !luaspell->spell) {
  9795. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9796. return 0;
  9797. }
  9798. int8 tier = luaspell->spell->GetSpellTier();
  9799. lua_interface->SetInt32Value(state, tier);
  9800. return 1;
  9801. }
  9802. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9803. if (!lua_interface)
  9804. return 0;
  9805. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9806. lua_interface->ResetFunctionStack(state);
  9807. if (!luaspell || !luaspell->spell) {
  9808. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9809. return 0;
  9810. }
  9811. int32 spell_id = luaspell->spell->GetSpellID();
  9812. lua_interface->SetInt32Value(state, spell_id);
  9813. return 1;
  9814. }
  9815. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9816. if (!lua_interface)
  9817. return 0;
  9818. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9819. lua_interface->ResetFunctionStack(state);
  9820. if (!spawn) {
  9821. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9822. return 0;
  9823. }
  9824. if (!spawn->IsPlayer()) {
  9825. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9826. return 0;
  9827. }
  9828. ZoneServer* zone = spawn->GetZone();
  9829. if (!zone) {
  9830. return 0;
  9831. }
  9832. Client* client = ((Player*)spawn)->GetClient();
  9833. if (!client) {
  9834. return 0;
  9835. }
  9836. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9837. return 0;
  9838. }
  9839. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9840. if (!lua_interface)
  9841. return 0;
  9842. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9843. lua_interface->ResetFunctionStack(state);
  9844. if (!spawn) {
  9845. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9846. return 0;
  9847. }
  9848. if (!spawn->IsPlayer()) {
  9849. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9850. return 0;
  9851. }
  9852. ZoneServer* zone = spawn->GetZone();
  9853. if (!zone) {
  9854. return 0;
  9855. }
  9856. Client* client = ((Player*)spawn)->GetClient();
  9857. if (!client) {
  9858. return 0;
  9859. }
  9860. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9861. return 0;
  9862. }
  9863. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9864. if (!lua_interface)
  9865. return 0;
  9866. Spawn* caster = lua_interface->GetSpawn(state);
  9867. Spawn* target = lua_interface->GetSpawn(state, 2);
  9868. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9869. string spell_name = lua_interface->GetStringValue(state, 4);
  9870. lua_interface->ResetFunctionStack(state);
  9871. if (!caster) {
  9872. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9873. return 0;
  9874. }
  9875. if (!caster->IsEntity()) {
  9876. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9877. return 0;
  9878. }
  9879. if (!target) {
  9880. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9881. return 0;
  9882. }
  9883. if (!target->IsEntity()) {
  9884. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9885. return 0;
  9886. }
  9887. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9888. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9889. return 0;
  9890. }
  9891. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9892. if (!lua_interface)
  9893. return 0;
  9894. Spawn* player = lua_interface->GetSpawn(state);
  9895. int32 amount = lua_interface->GetInt32Value(state, 2);
  9896. lua_interface->ResetFunctionStack(state);
  9897. if (player && player->IsPlayer() && amount > 0) {
  9898. ((Player*)player)->AddXP(amount);
  9899. }
  9900. return 0;
  9901. }
  9902. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9903. if (!lua_interface)
  9904. return 0;
  9905. Spawn* player = lua_interface->GetSpawn(state);
  9906. int8 type = lua_interface->GetInt8Value(state, 2);
  9907. string text = lua_interface->GetStringValue(state, 3);
  9908. lua_interface->ResetFunctionStack(state);
  9909. Client* client = 0;
  9910. if (player && player->IsPlayer())
  9911. client = ((Player*)player)->GetClient();
  9912. if (!client || text.length() == 0) {
  9913. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9914. return 0;
  9915. }
  9916. client->SimpleMessage(type, text.c_str());
  9917. return 0;
  9918. }
  9919. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9920. if (!lua_interface)
  9921. return 0;
  9922. Spawn* player = lua_interface->GetSpawn(state);
  9923. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9924. lua_interface->ResetFunctionStack(state);
  9925. Client* client = 0;
  9926. if (player && player->IsPlayer())
  9927. client = ((Player*)player)->GetClient();
  9928. if (!client || !spawn) {
  9929. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9930. return 0;
  9931. }
  9932. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9933. if (!items) {
  9934. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9935. return 0;
  9936. }
  9937. client->SendLootResponsePacket(spawn->GetLootCoins(), items, spawn, true);
  9938. return 0;
  9939. }
  9940. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9941. if (!lua_interface)
  9942. return 0;
  9943. Spawn* spawnref = lua_interface->GetSpawn(state);
  9944. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9945. lua_interface->ResetFunctionStack(state);
  9946. if (spawn_id > 0 && spawnref) {
  9947. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9948. if (spawns.size() == 0) {
  9949. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9950. return 0;
  9951. }
  9952. Spawn* spawn = 0;
  9953. int16 index = MakeRandomInt(0, spawns.size());
  9954. if (index >= spawns.size() || index < 0)
  9955. index = 0;
  9956. spawn = spawns[index];
  9957. lua_interface->SetSpawnValue(state, spawn);
  9958. return 1;
  9959. }
  9960. else {
  9961. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9962. }
  9963. return 0;
  9964. }
  9965. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9966. Spawn* player = lua_interface->GetSpawn(state);
  9967. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9968. string name = lua_interface->GetStringValue(state, 3);
  9969. float distance = lua_interface->GetFloatValue(state, 4);
  9970. string command = lua_interface->GetStringValue(state, 5);
  9971. string error_text = lua_interface->GetStringValue(state, 6);
  9972. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9973. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9974. lua_interface->ResetFunctionStack(state);
  9975. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9976. if (distance == 0)
  9977. distance = 10.0f;
  9978. if (command.length() == 0)
  9979. command = name;
  9980. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9981. if (spawns.size() == 0) {
  9982. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9983. return 0;
  9984. }
  9985. Spawn* spawn = 0;
  9986. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9987. spawn = *itr;
  9988. if (spawn) {
  9989. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9990. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9991. }
  9992. }
  9993. }
  9994. return 0;
  9995. }
  9996. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9997. if (!lua_interface)
  9998. return 0;
  9999. Client* client = 0;
  10000. Spawn* player = lua_interface->GetSpawn(state);
  10001. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  10002. lua_interface->ResetFunctionStack(state);
  10003. if (player && player->IsPlayer() && player->GetZone())
  10004. client = ((Player*)player)->GetClient();
  10005. else{
  10006. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  10007. return 0;
  10008. }
  10009. if (client) {
  10010. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  10011. if (packet) {
  10012. packet->setDataByName("goal_num", goal_num);
  10013. client->QueuePacket(packet->serialize());
  10014. safe_delete(packet);
  10015. }
  10016. }
  10017. return 0;
  10018. }
  10019. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  10020. if (!lua_interface)
  10021. return 0;
  10022. Client* client = 0;
  10023. Spawn* player = lua_interface->GetSpawn(state);
  10024. lua_interface->ResetFunctionStack(state);
  10025. if (player && player->IsPlayer() && player->GetZone())
  10026. client = ((Player*)player)->GetClient();
  10027. else {
  10028. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  10029. return 0;
  10030. }
  10031. if (client) {
  10032. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  10033. }
  10034. return 0;
  10035. }
  10036. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  10037. if (!lua_interface)
  10038. return 0;
  10039. Client* client = 0;
  10040. Spawn* player = lua_interface->GetSpawn(state);
  10041. float duration = lua_interface->GetFloatValue(state, 2);
  10042. string text = lua_interface->GetStringValue(state, 3);
  10043. string voice = lua_interface->GetStringValue(state, 4);
  10044. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  10045. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  10046. string signal = lua_interface->GetStringValue(state, 7);
  10047. string goal1 = lua_interface->GetStringValue(state, 8);
  10048. string task1 = lua_interface->GetStringValue(state, 9);
  10049. string goal2 = lua_interface->GetStringValue(state, 10);
  10050. string task2 = lua_interface->GetStringValue(state, 11);
  10051. string goal3 = lua_interface->GetStringValue(state, 12);
  10052. string task3 = lua_interface->GetStringValue(state, 13);
  10053. string goal4 = lua_interface->GetStringValue(state, 14);
  10054. string task4 = lua_interface->GetStringValue(state, 15);
  10055. lua_interface->ResetFunctionStack(state);
  10056. if (!player) {
  10057. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  10058. return 0;
  10059. }
  10060. if (!player->IsPlayer()) {
  10061. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  10062. return 0;
  10063. }
  10064. else
  10065. client = ((Player*)player)->GetClient();
  10066. if (!client) {
  10067. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  10068. return 0;
  10069. }
  10070. if (text.length() == 0) {
  10071. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  10072. return 0;
  10073. }
  10074. if (duration >= 0 && duration < 2)
  10075. duration = 2;
  10076. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  10077. if (packet) {
  10078. packet->setDataByName("open_seconds_max", duration);
  10079. packet->setDataByName("text", text.c_str());
  10080. packet->setDataByName("voice", voice.c_str());
  10081. int8 num_goals = 1;
  10082. if (task2.length() > 0)
  10083. num_goals++;
  10084. if (task3.length() > 0)
  10085. num_goals++;
  10086. if (task4.length() > 0)
  10087. num_goals++;
  10088. packet->setArrayLengthByName("num_goals", num_goals);
  10089. for (int8 i = 0; i < num_goals; i++) {
  10090. packet->setSubArrayLengthByName("num_tasks", 1, i);
  10091. }
  10092. if (goal1.length() > 0)
  10093. packet->setArrayDataByName("goal_text", goal1.c_str());
  10094. if (goal2.length() > 0)
  10095. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  10096. if (goal3.length() > 0)
  10097. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  10098. if (goal4.length() > 0)
  10099. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  10100. packet->setSubArrayDataByName("task_text", task1.c_str());
  10101. if (task2.length() > 0)
  10102. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  10103. if (task3.length() > 0)
  10104. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  10105. if (task4.length() > 0)
  10106. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  10107. packet->setDataByName("complete_sound", "click");
  10108. packet->setDataByName("signal", signal.c_str());
  10109. packet->setDataByName("voice_key1", voice_key1);
  10110. packet->setDataByName("voice_key2", voice_key2);
  10111. client->QueuePacket(packet->serialize());
  10112. safe_delete(packet);
  10113. }
  10114. return 0;
  10115. }
  10116. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  10117. if (!lua_interface)
  10118. return 0;
  10119. Client* client = 0;
  10120. Spawn* player = lua_interface->GetSpawn(state);
  10121. string window = lua_interface->GetStringValue(state, 2);
  10122. int8 show = lua_interface->GetInt8Value(state, 3);
  10123. lua_interface->ResetFunctionStack(state);
  10124. if (!player) {
  10125. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  10126. return 0;
  10127. }
  10128. if (!player->IsPlayer()) {
  10129. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  10130. return 0;
  10131. }
  10132. else
  10133. client = ((Player*)player)->GetClient();
  10134. if (!client) {
  10135. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  10136. return 0;
  10137. }
  10138. if (window.length() == 0) {
  10139. lua_interface->LogError("LUA ShowWindow required parameters not given");
  10140. return 0;
  10141. }
  10142. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  10143. if (packet) {
  10144. packet->setDataByName("window", window.c_str());
  10145. packet->setDataByName("show", show);
  10146. client->QueuePacket(packet->serialize());
  10147. safe_delete(packet);
  10148. }
  10149. return 0;
  10150. }
  10151. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  10152. //See GameEvents.txt for options that can be used for this function
  10153. if (!lua_interface)
  10154. return 0;
  10155. Client* client = 0;
  10156. Spawn* player = lua_interface->GetSpawn(state);
  10157. string event_name = lua_interface->GetStringValue(state, 2);
  10158. int8 enabled = lua_interface->GetInt8Value(state, 3);
  10159. lua_interface->ResetFunctionStack(state);
  10160. if (!player || !player->IsPlayer()) {
  10161. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  10162. return 0;
  10163. }
  10164. client = ((Player*)player)->GetClient();
  10165. if (!client) {
  10166. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  10167. return 0;
  10168. }
  10169. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  10170. if (packet) {
  10171. packet->setDataByName("event_name", event_name.c_str());
  10172. packet->setDataByName("enabled", enabled);
  10173. client->QueuePacket(packet->serialize());
  10174. safe_delete(packet);
  10175. }
  10176. return 0;
  10177. }
  10178. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  10179. if (!lua_interface)
  10180. return 0;
  10181. Spawn* player = lua_interface->GetSpawn(state);
  10182. lua_interface->ResetFunctionStack(state);
  10183. if (player && player->IsPlayer()) {
  10184. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  10185. return 1;
  10186. }
  10187. return 0;
  10188. }
  10189. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  10190. if (!lua_interface)
  10191. return 0;
  10192. Spawn* player = lua_interface->GetSpawn(state);
  10193. int8 step = lua_interface->GetInt8Value(state, 2);
  10194. lua_interface->ResetFunctionStack(state);
  10195. if (player && player->IsPlayer() && step > 0) {
  10196. ((Player*)player)->SetTutorialStep(step);
  10197. }
  10198. return 0;
  10199. }
  10200. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  10201. if (!lua_interface)
  10202. return 0;
  10203. Client* client = 0;
  10204. Spawn* player = lua_interface->GetSpawn(state);
  10205. string window = lua_interface->GetStringValue(state, 2);
  10206. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  10207. lua_interface->ResetFunctionStack(state);
  10208. if (!player) {
  10209. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  10210. return 0;
  10211. }
  10212. if (!player->IsPlayer()) {
  10213. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  10214. return 0;
  10215. }
  10216. else
  10217. client = ((Player*)player)->GetClient();
  10218. if (!client) {
  10219. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  10220. return 0;
  10221. }
  10222. if (window.length() == 0) {
  10223. lua_interface->LogError("LUA FlashWindow required parameters not given");
  10224. return 0;
  10225. }
  10226. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  10227. if (packet) {
  10228. packet->setDataByName("window", window.c_str());
  10229. packet->setDataByName("flash_seconds", flash_seconds);
  10230. client->QueuePacket(packet->serialize());
  10231. safe_delete(packet);
  10232. }
  10233. return 0;
  10234. }
  10235. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  10236. if (!lua_interface)
  10237. return 0;
  10238. Spawn* spawn = lua_interface->GetSpawn(state);
  10239. Spawn* target = lua_interface->GetSpawn(state, 2);
  10240. lua_interface->ResetFunctionStack(state);
  10241. if (spawn && target)
  10242. return spawn->CheckLoS(target);
  10243. return 0;
  10244. }
  10245. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  10246. if (!lua_interface)
  10247. return 0;
  10248. Spawn* spawn = lua_interface->GetSpawn(state);
  10249. float x = lua_interface->GetFloatValue(state, 2);
  10250. float y = lua_interface->GetFloatValue(state, 3);
  10251. float z = lua_interface->GetFloatValue(state, 4);
  10252. lua_interface->ResetFunctionStack(state);
  10253. if (spawn)
  10254. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  10255. return 0;
  10256. }
  10257. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  10258. if (!lua_interface)
  10259. return 0;
  10260. ZoneServer* zone = lua_interface->GetZone(state);
  10261. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  10262. lua_interface->ResetFunctionStack(state);
  10263. if (zone)
  10264. zone->SetExpansionFlag(xpackFlag);
  10265. return 0;
  10266. }
  10267. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  10268. if (!lua_interface)
  10269. return 0;
  10270. ZoneServer* zone = lua_interface->GetZone(state);
  10271. lua_interface->ResetFunctionStack(state);
  10272. if (zone) {
  10273. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  10274. return 1;
  10275. }
  10276. return 0;
  10277. }
  10278. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  10279. if (!lua_interface)
  10280. return 0;
  10281. ZoneServer* zone = lua_interface->GetZone(state);
  10282. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  10283. lua_interface->ResetFunctionStack(state);
  10284. if (zone)
  10285. zone->SetHolidayFlag(holidayFlag);
  10286. return 0;
  10287. }
  10288. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  10289. if (!lua_interface)
  10290. return 0;
  10291. ZoneServer* zone = lua_interface->GetZone(state);
  10292. lua_interface->ResetFunctionStack(state);
  10293. if (zone) {
  10294. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  10295. return 1;
  10296. }
  10297. return 0;
  10298. }
  10299. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  10300. if (!lua_interface)
  10301. return 0;
  10302. Spawn* spawn = lua_interface->GetSpawn(state);
  10303. bool canbind = lua_interface->GetInt32Value(state, 2);
  10304. lua_interface->ResetFunctionStack(state);
  10305. if(!spawn) {
  10306. lua_interface->LogError("%s: LUA SetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10307. return 0;
  10308. }
  10309. ZoneServer* zone = spawn->GetZone();
  10310. if (zone)
  10311. zone->SetCanBind(canbind);
  10312. return 0;
  10313. }
  10314. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  10315. if (!lua_interface)
  10316. return 0;
  10317. Spawn* spawn = lua_interface->GetSpawn(state);
  10318. lua_interface->ResetFunctionStack(state);
  10319. if(!spawn) {
  10320. lua_interface->LogError("%s: LUA GetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10321. return 0;
  10322. }
  10323. ZoneServer* zone = spawn->GetZone();
  10324. if (zone) {
  10325. lua_interface->SetInt32Value(state, zone->GetCanBind());
  10326. return 1;
  10327. }
  10328. return 0;
  10329. }
  10330. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  10331. if (!lua_interface)
  10332. return 0;
  10333. Spawn* spawn = lua_interface->GetSpawn(state);
  10334. bool cangate = lua_interface->GetInt32Value(state, 2);
  10335. lua_interface->ResetFunctionStack(state);
  10336. if(!spawn) {
  10337. lua_interface->LogError("%s: LUA SetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10338. return 0;
  10339. }
  10340. ZoneServer* zone = spawn->GetZone();
  10341. if (zone)
  10342. zone->SetCanGate(cangate);
  10343. return 0;
  10344. }
  10345. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  10346. if (!lua_interface)
  10347. return 0;
  10348. Spawn* spawn = lua_interface->GetSpawn(state);
  10349. lua_interface->ResetFunctionStack(state);
  10350. if(!spawn) {
  10351. lua_interface->LogError("%s: LUA GetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10352. return 0;
  10353. }
  10354. ZoneServer* zone = spawn->GetZone();
  10355. if (zone) {
  10356. lua_interface->SetInt32Value(state, zone->GetCanGate());
  10357. return 1;
  10358. }
  10359. return 0;
  10360. }
  10361. int EQ2Emu_lua_SetCanEvac(lua_State* state) {
  10362. if (!lua_interface)
  10363. return 0;
  10364. Spawn* spawn = lua_interface->GetSpawn(state);
  10365. bool canevac = lua_interface->GetInt32Value(state, 2);
  10366. lua_interface->ResetFunctionStack(state);
  10367. if(!spawn) {
  10368. lua_interface->LogError("%s: LUA SetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10369. return 0;
  10370. }
  10371. ZoneServer* zone = spawn->GetZone();
  10372. if (zone)
  10373. zone->SetCanEvac(canevac);
  10374. return 0;
  10375. }
  10376. int EQ2Emu_lua_GetCanEvac(lua_State* state) {
  10377. if (!lua_interface)
  10378. return 0;
  10379. Spawn* spawn = lua_interface->GetSpawn(state);
  10380. lua_interface->ResetFunctionStack(state);
  10381. if(!spawn) {
  10382. lua_interface->LogError("%s: LUA GetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10383. return 0;
  10384. }
  10385. ZoneServer* zone = spawn->GetZone();
  10386. if (zone) {
  10387. lua_interface->SetInt32Value(state, zone->GetCanEvac());
  10388. return 1;
  10389. }
  10390. return 0;
  10391. }
  10392. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  10393. if (!lua_interface)
  10394. return 0;
  10395. Spawn* spawn = lua_interface->GetSpawn(state);
  10396. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  10397. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  10398. float distance = lua_interface->GetFloatValue(state, 4);
  10399. string in_range_function = lua_interface->GetStringValue(state, 5);
  10400. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  10401. lua_interface->ResetFunctionStack(state);
  10402. if (spawn && distance > 0 && in_range_function.length() > 0)
  10403. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  10404. return 0;
  10405. }
  10406. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  10407. if (!lua_interface)
  10408. return 0;
  10409. Spawn* spawn = lua_interface->GetSpawn(state);
  10410. Spawn* target = lua_interface->GetSpawn(state, 2);
  10411. lua_interface->ResetFunctionStack(state);
  10412. if (spawn && target)
  10413. {
  10414. if (spawn->IsPlayer() && target->IsEntity())
  10415. {
  10416. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  10417. return 1;
  10418. }
  10419. else if (spawn->IsEntity() && target->IsEntity())
  10420. {
  10421. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  10422. return 1;
  10423. }
  10424. }
  10425. return 0;
  10426. }
  10427. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  10428. if (!lua_interface)
  10429. return 0;
  10430. Spawn* spawn = lua_interface->GetSpawn(state);
  10431. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10432. lua_interface->ResetFunctionStack(state);
  10433. if (spawn && spawn->IsEntity())
  10434. {
  10435. ((Entity*)spawn)->SetSeeInvisSpell(val);
  10436. if (spawn->IsPlayer())
  10437. {
  10438. Client* client = ((Player*)spawn)->GetClient();
  10439. if (client)
  10440. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  10441. }
  10442. }
  10443. return 0;
  10444. }
  10445. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  10446. if (!lua_interface)
  10447. return 0;
  10448. Spawn* spawn = lua_interface->GetSpawn(state);
  10449. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10450. lua_interface->ResetFunctionStack(state);
  10451. if (spawn && spawn->IsEntity())
  10452. {
  10453. ((Entity*)spawn)->SetSeeHideSpell(val);
  10454. if (spawn->IsPlayer())
  10455. {
  10456. Client* client = ((Player*)spawn)->GetClient();
  10457. if (client)
  10458. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  10459. }
  10460. }
  10461. return 0;
  10462. }
  10463. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  10464. {
  10465. if (!lua_interface)
  10466. return 0;
  10467. Spawn* player = lua_interface->GetSpawn(state);
  10468. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10469. string command = lua_interface->GetStringValue(state, 3);
  10470. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10471. lua_interface->ResetFunctionStack(state);
  10472. if (spawn && player && player->IsPlayer())
  10473. {
  10474. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10475. bool res = false;
  10476. if (cmd)
  10477. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  10478. lua_interface->SetBooleanValue(state, res);
  10479. return 1;
  10480. }
  10481. return 0;
  10482. }
  10483. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  10484. {
  10485. if (!lua_interface)
  10486. return 0;
  10487. Spawn* spawn = lua_interface->GetSpawn(state);
  10488. int32 charID = lua_interface->GetInt32Value(state, 2);
  10489. string command = lua_interface->GetStringValue(state, 3);
  10490. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10491. lua_interface->ResetFunctionStack(state);
  10492. if (spawn && charID)
  10493. {
  10494. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10495. bool res = false;
  10496. if (cmd)
  10497. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  10498. lua_interface->SetBooleanValue(state, res);
  10499. return 1;
  10500. }
  10501. return 0;
  10502. }
  10503. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  10504. {
  10505. if (!lua_interface)
  10506. return 0;
  10507. Spawn* spawn = lua_interface->GetSpawn(state);
  10508. string command = lua_interface->GetStringValue(state, 2);
  10509. lua_interface->ResetFunctionStack(state);
  10510. if (spawn && command.length() > 0)
  10511. spawn->RemovePrimaryEntityCommand(command.c_str());
  10512. return 0;
  10513. }
  10514. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  10515. if (!lua_interface)
  10516. return 0;
  10517. Spawn* spawn = lua_interface->GetSpawn(state);
  10518. float distance = lua_interface->GetFloatValue(state, 2);
  10519. string command = lua_interface->GetStringValue(state, 3);
  10520. Spawn* player = lua_interface->GetSpawn(state, 4);
  10521. lua_interface->ResetFunctionStack(state);
  10522. if (spawn) {
  10523. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  10524. }
  10525. return 0;
  10526. }
  10527. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  10528. if (!lua_interface)
  10529. return 0;
  10530. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10531. Spawn* spawn = lua_interface->GetSpawn(state);
  10532. Spawn* player = lua_interface->GetSpawn(state, 2);
  10533. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  10534. lua_interface->ResetFunctionStack(state);
  10535. if (spawn && player && transport_id && player->IsPlayer()) {
  10536. Client* client = 0;
  10537. if (player && player->IsPlayer())
  10538. client = ((Player*)player)->GetClient();
  10539. if (!client)
  10540. return 0;
  10541. vector<TransportDestination*> destinations;
  10542. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  10543. if (destinations.size())
  10544. {
  10545. client->SetTemporaryTransportID(transport_id);
  10546. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  10547. }
  10548. else
  10549. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  10550. }
  10551. return 0;
  10552. }
  10553. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  10554. if (!lua_interface)
  10555. return 0;
  10556. Spawn* player = lua_interface->GetSpawn(state);
  10557. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  10558. lua_interface->ResetFunctionStack(state);
  10559. if (player && player->IsPlayer()) {
  10560. Client* client = 0;
  10561. if (player && player->IsPlayer())
  10562. client = ((Player*)player)->GetClient();
  10563. if (!client)
  10564. return 0;
  10565. client->SetTemporaryTransportID(transport_id);
  10566. }
  10567. return 0;
  10568. }
  10569. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10570. if (!lua_interface)
  10571. return 0;
  10572. Spawn* player = lua_interface->GetSpawn(state);
  10573. lua_interface->ResetFunctionStack(state);
  10574. if (player && player->IsPlayer()) {
  10575. Client* client = 0;
  10576. if (player && player->IsPlayer())
  10577. client = ((Player*)player)->GetClient();
  10578. if (!client)
  10579. return 0;
  10580. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10581. return 1;
  10582. }
  10583. return 0;
  10584. }
  10585. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10586. if (!lua_interface)
  10587. return 0;
  10588. Spawn* spawn = lua_interface->GetSpawn(state);
  10589. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10590. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10591. if (!spawn) {
  10592. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10593. return 0;
  10594. }
  10595. if (!spawn->IsEntity()) {
  10596. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10597. return 0;
  10598. }
  10599. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10600. {
  10601. 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);
  10602. return 0;
  10603. }
  10604. lua_interface->ResetFunctionStack(state);
  10605. if (spell && spell->targets.size() > 0) {
  10606. ZoneServer* zone = spell->caster->GetZone();
  10607. for (int8 i = 0; i < spell->targets.size(); i++) {
  10608. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10609. if (target && target->IsEntity()) {
  10610. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10611. if (target->IsPlayer())
  10612. ((Player*)target)->SetCharSheetChanged(true);
  10613. }
  10614. }
  10615. }
  10616. else {
  10617. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10618. if (spawn->IsPlayer())
  10619. ((Player*)spawn)->SetCharSheetChanged(true);
  10620. }
  10621. return 0;
  10622. }
  10623. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10624. if (!lua_interface)
  10625. return 0;
  10626. Spawn* spawn = lua_interface->GetSpawn(state);
  10627. lua_interface->ResetFunctionStack(state);
  10628. if (!spawn) {
  10629. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10630. return 0;
  10631. }
  10632. if (!spawn->IsEntity()) {
  10633. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10634. return 0;
  10635. }
  10636. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10637. return 1;
  10638. }
  10639. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10640. if (!lua_interface)
  10641. return 0;
  10642. int32 spell_id = lua_interface->GetInt32Value(state);
  10643. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10644. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10645. if (spell_id > 0) {
  10646. if (spell_tier == 0)
  10647. spell_tier = 1;
  10648. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10649. if(!spell) {
  10650. lua_interface->LogError("%s: GetSpell: Failed, spell id %u spell tier %u does not exist.", lua_interface->GetScriptName(state), spell_id, spell_tier);
  10651. lua_interface->ResetFunctionStack(state);
  10652. return 0;
  10653. }
  10654. LuaSpell* lua_spell = 0;
  10655. if(custom_lua_script.size() > 0)
  10656. {
  10657. // attempt to load the custom script since it isn't already loaded
  10658. // we will re-obtain the lua_spell further below
  10659. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10660. {
  10661. 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());
  10662. lua_interface->LoadLuaSpell(custom_lua_script);
  10663. }
  10664. }
  10665. else
  10666. custom_lua_script = spell->GetSpellData()->lua_script;
  10667. if (!lua_spell && lua_interface)
  10668. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10669. lua_interface->ResetFunctionStack(state);
  10670. if (!lua_spell)
  10671. {
  10672. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10673. return 0;
  10674. }
  10675. lua_spell->spell = new Spell(spell);
  10676. lua_interface->AddCustomSpell(lua_spell);
  10677. lua_interface->SetSpellValue(state, lua_spell);
  10678. return 1;
  10679. }
  10680. return 0;
  10681. }
  10682. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10683. if (!lua_interface)
  10684. return 0;
  10685. LuaSpell* spell = lua_interface->GetSpell(state);
  10686. string field = lua_interface->GetStringValue(state, 2);
  10687. lua_interface->ResetFunctionStack(state);
  10688. if (!spell) {
  10689. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10690. return 0;
  10691. }
  10692. if (!spell->spell || !spell->spell->GetSpellData()) {
  10693. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10694. return 0;
  10695. }
  10696. boost::to_lower(field);
  10697. return spell->spell->GetSpellData(state, field);
  10698. }
  10699. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10700. if (!lua_interface)
  10701. return 0;
  10702. LuaSpell* spell = lua_interface->GetSpell(state);
  10703. string field = lua_interface->GetStringValue(state, 2);
  10704. int8 fieldArg = 3; // field value after the initial set
  10705. if (!spell) {
  10706. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10707. lua_interface->ResetFunctionStack(state);
  10708. return 0;
  10709. }
  10710. if (!spell->spell || !spell->spell->GetSpellData()) {
  10711. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10712. lua_interface->ResetFunctionStack(state);
  10713. return 0;
  10714. }
  10715. boost::to_lower(field);
  10716. bool valSet = false;
  10717. spell->spell->SetSpellData(state, field, fieldArg);
  10718. lua_interface->ResetFunctionStack(state);
  10719. return valSet;
  10720. }
  10721. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10722. if (!lua_interface)
  10723. return 0;
  10724. LuaSpell* spell = lua_interface->GetSpell(state);
  10725. int8 idx = lua_interface->GetInt32Value(state, 2);
  10726. if (!spell) {
  10727. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10728. lua_interface->ResetFunctionStack(state);
  10729. return 0;
  10730. }
  10731. if (!spell->spell || !spell->spell->GetSpellData()) {
  10732. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10733. lua_interface->ResetFunctionStack(state);
  10734. return 0;
  10735. }
  10736. if (spell->spell->lua_data.size() <= idx)
  10737. {
  10738. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10739. lua_interface->ResetFunctionStack(state);
  10740. return 0;
  10741. }
  10742. bool setVal = true;
  10743. LUAData* data = spell->spell->lua_data[idx];
  10744. switch (data->type)
  10745. {
  10746. case 0:
  10747. {
  10748. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10749. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10750. data->int_value = value;
  10751. data->int_value2 = value2;
  10752. break;
  10753. }
  10754. case 1:
  10755. {
  10756. float value = lua_interface->GetFloatValue(state, 3);
  10757. float value2 = lua_interface->GetFloatValue(state, 4);
  10758. data->float_value = value;
  10759. data->float_value2 = value2;
  10760. break;
  10761. }
  10762. case 2:
  10763. {
  10764. bool value = lua_interface->GetBooleanValue(state, 3);
  10765. data->bool_value = value;
  10766. break;
  10767. }
  10768. case 3:
  10769. {
  10770. string value = lua_interface->GetStringValue(state, 3);
  10771. string value2 = lua_interface->GetStringValue(state, 4);
  10772. data->string_value = value;
  10773. data->string_value2 = value2;
  10774. break;
  10775. }
  10776. default:
  10777. setVal = false;
  10778. }
  10779. lua_interface->ResetFunctionStack(state);
  10780. return setVal;
  10781. }
  10782. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10783. if (!lua_interface)
  10784. return 0;
  10785. LuaSpell* spell = lua_interface->GetSpell(state);
  10786. int8 idx = lua_interface->GetInt32Value(state, 2);
  10787. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10788. lua_interface->ResetFunctionStack(state);
  10789. if (!spell) {
  10790. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10791. return 0;
  10792. }
  10793. if (!spell->spell || !spell->spell->GetSpellData()) {
  10794. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10795. return 0;
  10796. }
  10797. if (spell->spell->lua_data.size() <= idx)
  10798. {
  10799. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10800. return 0;
  10801. }
  10802. bool setVal = true;
  10803. LUAData* data = spell->spell->lua_data[idx];
  10804. switch (data->type)
  10805. {
  10806. case 0:
  10807. {
  10808. if(!secondfield)
  10809. lua_interface->SetSInt32Value(state, data->int_value);
  10810. else
  10811. lua_interface->SetSInt32Value(state, data->int_value2);
  10812. break;
  10813. }
  10814. case 1:
  10815. {
  10816. if (!secondfield)
  10817. lua_interface->SetFloatValue(state, data->float_value);
  10818. else
  10819. lua_interface->SetFloatValue(state, data->float_value2);
  10820. break;
  10821. }
  10822. case 2:
  10823. {
  10824. lua_interface->SetBooleanValue(state, data->bool_value);
  10825. break;
  10826. }
  10827. case 3:
  10828. {
  10829. if (!secondfield)
  10830. lua_interface->SetStringValue(state, data->string_value.c_str());
  10831. else
  10832. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10833. break;
  10834. }
  10835. default:
  10836. setVal = false;
  10837. }
  10838. return setVal;
  10839. }
  10840. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10841. if (!lua_interface)
  10842. return 0;
  10843. LuaSpell* spell = lua_interface->GetSpell(state);
  10844. int8 idx = lua_interface->GetInt32Value(state, 2);
  10845. string field = lua_interface->GetStringValue(state, 3);
  10846. boost::to_lower(field);
  10847. if (!spell) {
  10848. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10849. lua_interface->ResetFunctionStack(state);
  10850. return 0;
  10851. }
  10852. if (!spell->spell || !spell->spell->GetSpellData()) {
  10853. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10854. lua_interface->ResetFunctionStack(state);
  10855. return 0;
  10856. }
  10857. if (spell->spell->effects.size() <= idx)
  10858. {
  10859. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10860. lua_interface->ResetFunctionStack(state);
  10861. return 0;
  10862. }
  10863. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10864. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10865. if (field == "description")
  10866. effect->description = string(lua_interface->GetStringValue(state, 4));
  10867. else if (field == "bullet")
  10868. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10869. else if (field == "percentage")
  10870. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10871. else { // no match
  10872. lua_interface->ResetFunctionStack(state);
  10873. return 0;
  10874. }
  10875. lua_interface->ResetFunctionStack(state);
  10876. return 1;
  10877. }
  10878. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10879. if (!lua_interface)
  10880. return 0;
  10881. LuaSpell* spell = lua_interface->GetSpell(state);
  10882. int8 idx = lua_interface->GetInt32Value(state, 2);
  10883. string field = lua_interface->GetStringValue(state, 3);
  10884. lua_interface->ResetFunctionStack(state);
  10885. boost::to_lower(field);
  10886. if (!spell) {
  10887. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10888. return 0;
  10889. }
  10890. if (!spell->spell || !spell->spell->GetSpellData()) {
  10891. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10892. return 0;
  10893. }
  10894. if (spell->spell->effects.size() <= idx)
  10895. {
  10896. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10897. return 0;
  10898. }
  10899. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10900. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10901. if (field == "description")
  10902. lua_interface->SetStringValue(state, effect->description.c_str());
  10903. else if (field == "bullet")
  10904. lua_interface->SetInt32Value(state, effect->subbullet);
  10905. else if (field == "percentage")
  10906. lua_interface->SetInt32Value(state, effect->percentage);
  10907. else // no match
  10908. return 0;
  10909. return 1;
  10910. }
  10911. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10912. if (!lua_interface)
  10913. return 0;
  10914. LuaSpell* spell = lua_interface->GetSpell(state);
  10915. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10916. Spawn* target = lua_interface->GetSpawn(state, 3);
  10917. lua_interface->ResetFunctionStack(state);
  10918. if (!target) {
  10919. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10920. return 0;
  10921. }
  10922. if (!target->IsEntity()) {
  10923. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10924. return 0;
  10925. }
  10926. if (!spell) {
  10927. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10928. return 0;
  10929. }
  10930. if (caster && !caster->IsEntity()) {
  10931. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10932. return 0;
  10933. }
  10934. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10935. return 0;
  10936. }
  10937. int EQ2Emu_lua_InWater(lua_State* state) {
  10938. if (!lua_interface)
  10939. return 0;
  10940. Spawn* spawn = lua_interface->GetSpawn(state);
  10941. lua_interface->ResetFunctionStack(state);
  10942. if (spawn) {
  10943. lua_interface->SetBooleanValue(state, spawn->InWater());
  10944. return 1;
  10945. }
  10946. return 0;
  10947. }
  10948. int EQ2Emu_lua_InLava(lua_State* state) {
  10949. if (!lua_interface)
  10950. return 0;
  10951. Spawn* spawn = lua_interface->GetSpawn(state);
  10952. lua_interface->ResetFunctionStack(state);
  10953. if (spawn) {
  10954. lua_interface->SetBooleanValue(state, spawn->InLava());
  10955. return 1;
  10956. }
  10957. return 0;
  10958. }
  10959. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10960. if (!lua_interface)
  10961. return 0;
  10962. Spawn* attacker = lua_interface->GetSpawn(state);
  10963. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10964. int8 type = lua_interface->GetInt8Value(state, 3);
  10965. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10966. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10967. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10968. string spell_name = lua_interface->GetStringValue(state, 7);
  10969. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10970. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10971. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10972. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10973. bool take_power = (lua_interface->GetInt8Value(state, 12) == 1);
  10974. lua_interface->ResetFunctionStack(state);
  10975. if (!attacker) {
  10976. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10977. lua_interface->SetBooleanValue(state, false);
  10978. return 1;
  10979. }
  10980. if (!attacker->IsEntity()) {
  10981. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10982. lua_interface->SetBooleanValue(state, false);
  10983. return 1;
  10984. }
  10985. if (!victim) {
  10986. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10987. lua_interface->SetBooleanValue(state, false);
  10988. return 1;
  10989. }
  10990. if (!victim->IsEntity()) {
  10991. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10992. lua_interface->SetBooleanValue(state, false);
  10993. return 1;
  10994. }
  10995. 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);
  10996. lua_interface->SetBooleanValue(state, has_damaged);
  10997. return 1;
  10998. }
  10999. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  11000. if (!lua_interface)
  11001. return 0;
  11002. Spawn* spawn = lua_interface->GetSpawn(state);
  11003. lua_interface->ResetFunctionStack(state);
  11004. if (spawn) {
  11005. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  11006. return 1;
  11007. }
  11008. return 0;
  11009. }
  11010. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  11011. if (!lua_interface)
  11012. return 0;
  11013. Spawn* spawn = lua_interface->GetSpawn(state);
  11014. bool invul = lua_interface->GetBooleanValue(state, 2);
  11015. lua_interface->ResetFunctionStack(state);
  11016. if (spawn) {
  11017. spawn->SetInvulnerable(invul);
  11018. }
  11019. return 0;
  11020. }
  11021. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  11022. if (!lua_interface)
  11023. return 0;
  11024. string category = lua_interface->GetStringValue(state);
  11025. string name = lua_interface->GetStringValue(state, 2);
  11026. lua_interface->ResetFunctionStack(state);
  11027. Rule *ret = 0;
  11028. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11029. lua_interface->SetBooleanValue(state, ret->GetBool());
  11030. return 1;
  11031. }
  11032. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11033. return 0;
  11034. }
  11035. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  11036. if (!lua_interface)
  11037. return 0;
  11038. string category = lua_interface->GetStringValue(state);
  11039. string name = lua_interface->GetStringValue(state, 2);
  11040. lua_interface->ResetFunctionStack(state);
  11041. Rule *ret = 0;
  11042. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11043. lua_interface->SetInt32Value(state, ret->GetInt32());
  11044. return 1;
  11045. }
  11046. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11047. return 0;
  11048. }
  11049. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  11050. if (!lua_interface)
  11051. return 0;
  11052. string category = lua_interface->GetStringValue(state);
  11053. string name = lua_interface->GetStringValue(state, 2);
  11054. lua_interface->ResetFunctionStack(state);
  11055. Rule *ret = 0;
  11056. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11057. lua_interface->SetFloatValue(state, ret->GetFloat());
  11058. return 1;
  11059. }
  11060. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11061. return 0;
  11062. }
  11063. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  11064. if (!lua_interface)
  11065. return 0;
  11066. Spawn* spawn = lua_interface->GetSpawn(state);
  11067. string type = lua_interface->GetStringValue(state, 2);
  11068. lua_interface->ResetFunctionStack(state);
  11069. if (spawn) {
  11070. int res = 1;
  11071. boost::to_lower(type);
  11072. if(type == "assigned_aa")
  11073. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  11074. else if ( type == "unassigned_aa")
  11075. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  11076. else if ( type == "assigned_tradeskill_aa")
  11077. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  11078. else if ( type == "unassigned_tradeskill_aa")
  11079. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  11080. else if ( type == "assigned_prestige_aa")
  11081. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  11082. else if ( type == "unassigned_prestige_aa")
  11083. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  11084. else if ( type == "assigned_tradeskill_prestige_aa")
  11085. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  11086. else if ( type == "unassigned_tradeskill_prestige_aa")
  11087. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  11088. else
  11089. res = 0;
  11090. return res;
  11091. }
  11092. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  11093. return 0;
  11094. }
  11095. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  11096. if (!lua_interface)
  11097. return 0;
  11098. Spawn* spawn = lua_interface->GetSpawn(state);
  11099. string type = lua_interface->GetStringValue(state, 2);
  11100. sint32 value = lua_interface->GetSInt32Value(state, 3);
  11101. lua_interface->ResetFunctionStack(state);
  11102. if (spawn) {
  11103. boost::to_lower(type);
  11104. if(type == "assigned_aa")
  11105. spawn->SetAssignedAA((sint16)value);
  11106. else if ( type == "unassigned_aa")
  11107. spawn->SetUnassignedAA((sint16)value);
  11108. else if ( type == "assigned_tradeskill_aa")
  11109. spawn->SetTradeskillAA((sint16)value);
  11110. else if ( type == "unassigned_tradeskill_aa")
  11111. spawn->SetUnassignedTradeskillAA((sint16)value);
  11112. else if ( type == "assigned_prestige_aa")
  11113. spawn->SetPrestigeAA((sint16)value);
  11114. else if ( type == "unassigned_prestige_aa")
  11115. spawn->SetUnassignedPrestigeAA((sint16)value);
  11116. else if ( type == "assigned_tradeskill_prestige_aa")
  11117. spawn->SetTradeskillPrestigeAA((sint16)value);
  11118. else if ( type == "unassigned_tradeskill_prestige_aa")
  11119. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  11120. if(spawn->IsPlayer())
  11121. ((Player*)spawn)->SetCharSheetChanged(true);
  11122. }
  11123. return 0;
  11124. }
  11125. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  11126. if (!lua_interface)
  11127. return 0;
  11128. string titleName = lua_interface->GetStringValue(state);
  11129. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  11130. lua_interface->ResetFunctionStack(state);
  11131. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  11132. lua_interface->SetSInt32Value(state, index);
  11133. return 1;
  11134. }
  11135. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  11136. if (!lua_interface)
  11137. return 0;
  11138. Spawn* spawn = lua_interface->GetSpawn(state);
  11139. string titleName = lua_interface->GetStringValue(state, 2);
  11140. lua_interface->ResetFunctionStack(state);
  11141. if(!spawn->IsPlayer())
  11142. {
  11143. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  11144. lua_interface->SetSInt32Value(state, -1);
  11145. return 1;
  11146. }
  11147. Player* player = (Player*)spawn;
  11148. // check if player already has the title, don't need to add twice
  11149. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11150. if ( playerHasTitle)
  11151. {
  11152. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  11153. return 1;
  11154. }
  11155. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  11156. if(!title)
  11157. {
  11158. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11159. lua_interface->SetSInt32Value(state, -1);
  11160. return 1;
  11161. }
  11162. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  11163. if(returnIdx < 0)
  11164. {
  11165. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11166. }
  11167. lua_interface->SetSInt32Value(state, returnIdx);
  11168. player->GetClient()->SendTitleUpdate();
  11169. return 1;
  11170. }
  11171. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  11172. if (!lua_interface)
  11173. return 0;
  11174. Spawn* spawn = lua_interface->GetSpawn(state);
  11175. string titleName = lua_interface->GetStringValue(state, 2);
  11176. lua_interface->ResetFunctionStack(state);
  11177. if(!spawn->IsPlayer())
  11178. {
  11179. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11180. return 0;
  11181. }
  11182. Player* player = (Player*)spawn;
  11183. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11184. if(!title)
  11185. {
  11186. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11187. return 0;
  11188. }
  11189. if(title->GetPrefix())
  11190. {
  11191. 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());
  11192. return 0;
  11193. }
  11194. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  11195. player->GetClient()->SendTitleUpdate();
  11196. return 1;
  11197. }
  11198. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  11199. if (!lua_interface)
  11200. return 0;
  11201. Spawn* spawn = lua_interface->GetSpawn(state);
  11202. string titleName = lua_interface->GetStringValue(state, 2);
  11203. lua_interface->ResetFunctionStack(state);
  11204. if(!spawn->IsPlayer())
  11205. {
  11206. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11207. return 0;
  11208. }
  11209. Player* player = (Player*)spawn;
  11210. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11211. if(!title)
  11212. {
  11213. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11214. return 0;
  11215. }
  11216. if(!title->GetPrefix())
  11217. {
  11218. 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());
  11219. return 0;
  11220. }
  11221. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  11222. player->GetClient()->SendTitleUpdate();
  11223. return 1;
  11224. }
  11225. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  11226. if (!lua_interface)
  11227. return 0;
  11228. Spawn* spawn = lua_interface->GetSpawn(state);
  11229. lua_interface->ResetFunctionStack(state);
  11230. if(!spawn->IsPlayer())
  11231. {
  11232. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11233. return 0;
  11234. }
  11235. Player* player = (Player*)spawn;
  11236. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  11237. player->GetClient()->SendTitleUpdate();
  11238. return 1;
  11239. }
  11240. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  11241. if (!lua_interface)
  11242. return 0;
  11243. Spawn* spawn = lua_interface->GetSpawn(state);
  11244. lua_interface->ResetFunctionStack(state);
  11245. if(!spawn->IsPlayer())
  11246. {
  11247. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11248. return 0;
  11249. }
  11250. Player* player = (Player*)spawn;
  11251. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  11252. player->GetClient()->SendTitleUpdate();
  11253. return 1;
  11254. }
  11255. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  11256. if (!lua_interface)
  11257. return 0;
  11258. Spawn* spawn = lua_interface->GetSpawn(state);
  11259. string field = lua_interface->GetStringValue(state, 2);
  11260. lua_interface->ResetFunctionStack(state);
  11261. if(!spawn || !spawn->IsEntity())
  11262. {
  11263. 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));
  11264. return 0;
  11265. }
  11266. Entity* ent = (Entity*)spawn;
  11267. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  11268. return 1;
  11269. }
  11270. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  11271. if (!lua_interface)
  11272. return 0;
  11273. Spawn* spawn = lua_interface->GetSpawn(state);
  11274. string field = lua_interface->GetStringValue(state, 2);
  11275. lua_interface->ResetFunctionStack(state);
  11276. if(!spawn || !spawn->IsEntity())
  11277. {
  11278. 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));
  11279. return 0;
  11280. }
  11281. Entity* ent = (Entity*)spawn;
  11282. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  11283. return 1;
  11284. }
  11285. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  11286. if (!lua_interface)
  11287. return 0;
  11288. Spawn* spawn = lua_interface->GetSpawn(state);
  11289. string field = lua_interface->GetStringValue(state, 2);
  11290. lua_interface->ResetFunctionStack(state);
  11291. if(!spawn || !spawn->IsEntity())
  11292. {
  11293. 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));
  11294. return 0;
  11295. }
  11296. Entity* ent = (Entity*)spawn;
  11297. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  11298. return 1;
  11299. }
  11300. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  11301. if (!lua_interface)
  11302. return 0;
  11303. Spawn* spawn = lua_interface->GetSpawn(state);
  11304. string field = lua_interface->GetStringValue(state, 2);
  11305. lua_interface->ResetFunctionStack(state);
  11306. if(!spawn || !spawn->IsEntity())
  11307. {
  11308. 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));
  11309. return 0;
  11310. }
  11311. Entity* ent = (Entity*)spawn;
  11312. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  11313. return 1;
  11314. }
  11315. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  11316. if (!lua_interface)
  11317. return 0;
  11318. Spawn* spawn = lua_interface->GetSpawn(state);
  11319. string field = lua_interface->GetStringValue(state, 2);
  11320. string value = lua_interface->GetStringValue(state, 3);
  11321. lua_interface->ResetFunctionStack(state);
  11322. if(!spawn || !spawn->IsEntity())
  11323. {
  11324. 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));
  11325. return 0;
  11326. }
  11327. Entity* ent = (Entity*)spawn;
  11328. bool set_ = ent->SetInfoStructString(field, value);
  11329. lua_interface->SetBooleanValue(state, set_);
  11330. return 1;
  11331. }
  11332. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  11333. if (!lua_interface)
  11334. return 0;
  11335. Spawn* spawn = lua_interface->GetSpawn(state);
  11336. string field = lua_interface->GetStringValue(state, 2);
  11337. int64 value = lua_interface->GetInt64Value(state, 3);
  11338. lua_interface->ResetFunctionStack(state);
  11339. if(!spawn || !spawn->IsEntity())
  11340. {
  11341. 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));
  11342. return 0;
  11343. }
  11344. Entity* ent = (Entity*)spawn;
  11345. bool set_ = ent->SetInfoStructUInt(field, value);
  11346. lua_interface->SetBooleanValue(state, set_);
  11347. return 1;
  11348. }
  11349. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  11350. if (!lua_interface)
  11351. return 0;
  11352. Spawn* spawn = lua_interface->GetSpawn(state);
  11353. string field = lua_interface->GetStringValue(state, 2);
  11354. sint64 value = lua_interface->GetSInt64Value(state, 3);
  11355. lua_interface->ResetFunctionStack(state);
  11356. if(!spawn || !spawn->IsEntity())
  11357. {
  11358. 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));
  11359. return 0;
  11360. }
  11361. Entity* ent = (Entity*)spawn;
  11362. bool set_ = ent->SetInfoStructSInt(field, value);
  11363. lua_interface->SetBooleanValue(state, set_);
  11364. return 1;
  11365. }
  11366. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  11367. if (!lua_interface)
  11368. return 0;
  11369. Spawn* spawn = lua_interface->GetSpawn(state);
  11370. string field = lua_interface->GetStringValue(state, 2);
  11371. float value = lua_interface->GetFloatValue(state, 3);
  11372. lua_interface->ResetFunctionStack(state);
  11373. if(!spawn || !spawn->IsEntity())
  11374. {
  11375. 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));
  11376. return 0;
  11377. }
  11378. Entity* ent = (Entity*)spawn;
  11379. bool set_ = ent->SetInfoStructFloat(field, value);
  11380. lua_interface->SetBooleanValue(state, set_);
  11381. return 1;
  11382. }
  11383. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  11384. if (!lua_interface)
  11385. return 0;
  11386. Spawn* spawn = lua_interface->GetSpawn(state);
  11387. bool value = lua_interface->GetBooleanValue(state, 2);
  11388. lua_interface->ResetFunctionStack(state);
  11389. if(!spawn || !spawn->IsPlayer())
  11390. {
  11391. 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));
  11392. return 0;
  11393. }
  11394. ((Player*)spawn)->SetCharSheetChanged(value);
  11395. return 0;
  11396. }
  11397. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  11398. if (!lua_interface)
  11399. return 0;
  11400. Spawn* spawn = lua_interface->GetSpawn(state);
  11401. std::string fromName = lua_interface->GetStringValue(state, 2);
  11402. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11403. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11404. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11405. int32 copper = lua_interface->GetInt32Value(state, 6);
  11406. int32 silver = lua_interface->GetInt32Value(state, 7);
  11407. int32 gold = lua_interface->GetInt32Value(state, 8);
  11408. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11409. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11410. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11411. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11412. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11413. lua_interface->ResetFunctionStack(state);
  11414. if(!spawn || !spawn->IsPlayer())
  11415. {
  11416. 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));
  11417. lua_interface->SetBooleanValue(state, false);
  11418. return 1;
  11419. }
  11420. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11421. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11422. lua_interface->SetBooleanValue(state, true);
  11423. return 1;
  11424. }
  11425. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  11426. if (!lua_interface)
  11427. return 0;
  11428. int32 char_id = lua_interface->GetInt32Value(state);
  11429. std::string fromName = lua_interface->GetStringValue(state, 2);
  11430. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11431. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11432. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11433. int32 copper = lua_interface->GetInt32Value(state, 6);
  11434. int32 silver = lua_interface->GetInt32Value(state, 7);
  11435. int32 gold = lua_interface->GetInt32Value(state, 8);
  11436. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11437. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11438. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11439. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11440. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11441. lua_interface->ResetFunctionStack(state);
  11442. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11443. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11444. lua_interface->SetBooleanValue(state, true);
  11445. return 1;
  11446. }
  11447. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  11448. Spawn* widget;
  11449. if (lua_interface) {
  11450. widget = lua_interface->GetSpawn(state);
  11451. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  11452. lua_interface->ResetFunctionStack(state);
  11453. if (widget && widget->IsWidget())
  11454. {
  11455. ((Widget*)widget)->OpenDoor();
  11456. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  11457. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11458. }
  11459. else
  11460. 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));
  11461. }
  11462. return 0;
  11463. }
  11464. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  11465. Spawn* widget;
  11466. if (lua_interface) {
  11467. widget = lua_interface->GetSpawn(state);
  11468. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  11469. lua_interface->ResetFunctionStack(state);
  11470. if (widget && widget->IsWidget())
  11471. {
  11472. ((Widget*)widget)->CloseDoor();
  11473. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  11474. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11475. }
  11476. else
  11477. 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));
  11478. }
  11479. return 0;
  11480. }
  11481. int EQ2Emu_lua_IsOpen(lua_State* state) {
  11482. if (!lua_interface)
  11483. return 0;
  11484. Spawn* widget = lua_interface->GetSpawn(state);
  11485. lua_interface->ResetFunctionStack(state);
  11486. if (widget && widget->IsWidget())
  11487. {
  11488. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  11489. return 1;
  11490. }
  11491. return 0;
  11492. }
  11493. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  11494. if (!lua_interface)
  11495. return 0;
  11496. sint32 min = lua_interface->GetSInt32Value(state);
  11497. sint32 max = lua_interface->GetSInt32Value(state, 2);
  11498. lua_interface->ResetFunctionStack(state);
  11499. sint32 result = MakeRandomInt(min, max);
  11500. lua_interface->SetSInt32Value(state, result);
  11501. return 1;
  11502. }
  11503. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  11504. if (!lua_interface)
  11505. return 0;
  11506. float min = lua_interface->GetFloatValue(state);
  11507. float max = lua_interface->GetFloatValue(state, 2);
  11508. lua_interface->ResetFunctionStack(state);
  11509. float result = MakeRandomFloat(min, max);
  11510. lua_interface->SetFloatValue(state, result);
  11511. return 1;
  11512. }
  11513. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  11514. if (!lua_interface)
  11515. return 0;
  11516. Spawn* spawn = lua_interface->GetSpawn(state);
  11517. int32 value = lua_interface->GetInt32Value(state, 2);
  11518. lua_interface->ResetFunctionStack(state);
  11519. if(!spawn)
  11520. {
  11521. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11522. lua_interface->SetBooleanValue(state, false);
  11523. return 1;
  11524. }
  11525. spawn->AddIconValue(value);
  11526. lua_interface->SetBooleanValue(state, true);
  11527. return 1;
  11528. }
  11529. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  11530. if (!lua_interface)
  11531. return 0;
  11532. Spawn* spawn = lua_interface->GetSpawn(state);
  11533. int32 value = lua_interface->GetInt32Value(state, 2);
  11534. lua_interface->ResetFunctionStack(state);
  11535. if(!spawn)
  11536. {
  11537. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11538. lua_interface->SetBooleanValue(state, false);
  11539. return 1;
  11540. }
  11541. spawn->RemoveIconValue(value);
  11542. lua_interface->SetBooleanValue(state, true);
  11543. return 1;
  11544. }
  11545. int EQ2Emu_lua_GetShardID(lua_State* state) {
  11546. Spawn* npc = lua_interface->GetSpawn(state);
  11547. lua_interface->ResetFunctionStack(state);
  11548. if (npc && npc->IsNPC()) {
  11549. NPC* shard = (NPC*)npc;
  11550. int32 shardid = shard->GetShardID();
  11551. lua_interface->SetInt32Value(state, shardid);
  11552. return 1;
  11553. }
  11554. lua_interface->SetInt32Value(state, 0);
  11555. return 1;
  11556. }
  11557. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  11558. Spawn* npc = lua_interface->GetSpawn(state);
  11559. lua_interface->ResetFunctionStack(state);
  11560. if (npc && npc->IsNPC()) {
  11561. NPC* shard = (NPC*)npc;
  11562. int32 charid = shard->GetShardCharID();
  11563. lua_interface->SetInt32Value(state, charid);
  11564. return 1;
  11565. }
  11566. lua_interface->SetInt32Value(state, 0);
  11567. return 1;
  11568. }
  11569. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  11570. Spawn* npc = lua_interface->GetSpawn(state);
  11571. lua_interface->ResetFunctionStack(state);
  11572. if (npc && npc->IsNPC()) {
  11573. NPC* shard = (NPC*)npc;
  11574. int64 timestamp = shard->GetShardCreatedTimestamp();
  11575. lua_interface->SetSInt64Value(state, timestamp);
  11576. return 1;
  11577. }
  11578. lua_interface->SetSInt64Value(state, 0);
  11579. return 1;
  11580. }
  11581. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  11582. if (!lua_interface)
  11583. return 0;
  11584. int32 shardid = lua_interface->GetInt32Value(state);
  11585. lua_interface->ResetFunctionStack(state);
  11586. if(shardid < 1)
  11587. lua_interface->SetBooleanValue(state, false);
  11588. else
  11589. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  11590. return 1;
  11591. }
  11592. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  11593. if (!lua_interface)
  11594. return 0;
  11595. Spawn* spawn = lua_interface->GetSpawn(state);
  11596. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11597. if (spawn) {
  11598. spawn->PauseMovement(delay_in_ms);
  11599. }
  11600. lua_interface->ResetFunctionStack(state);
  11601. return 0;
  11602. }
  11603. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11604. if (!lua_interface)
  11605. return 0;
  11606. Spawn* spawn = lua_interface->GetSpawn(state);
  11607. if (spawn) {
  11608. spawn->StopMovement();
  11609. }
  11610. lua_interface->ResetFunctionStack(state);
  11611. return 0;
  11612. }
  11613. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11614. Player* player = (Player*)lua_interface->GetSpawn(state);
  11615. int8 level = lua_interface->GetInt8Value(state, 2);
  11616. lua_interface->ResetFunctionStack(state);
  11617. if (player && player->IsPlayer() && level > 0) {
  11618. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11619. return 1;
  11620. }
  11621. return 0;
  11622. }
  11623. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11624. Player* player = (Player*)lua_interface->GetSpawn(state);
  11625. int8 level = lua_interface->GetInt8Value(state, 2);
  11626. lua_interface->ResetFunctionStack(state);
  11627. if (player && player->IsPlayer() && level > 0) {
  11628. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11629. return 1;
  11630. }
  11631. return 0;
  11632. }
  11633. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11634. ZoneServer* zone = lua_interface->GetZone(state);
  11635. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11636. lua_interface->ResetFunctionStack(state);
  11637. if (zone) {
  11638. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11639. if (spawn) {
  11640. lua_interface->SetSpawnValue(state, spawn);
  11641. return 1;
  11642. }
  11643. }
  11644. return 0;
  11645. }
  11646. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11647. if (!lua_interface)
  11648. return 0;
  11649. Spawn* spawn = lua_interface->GetSpawn(state);
  11650. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11651. lua_interface->ResetFunctionStack(state);
  11652. bool res = false;
  11653. if(spawn && spawn->IsTransportSpawn())
  11654. {
  11655. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11656. spawn->SetRailID(rail_id);
  11657. res = true;
  11658. }
  11659. else if (!spawn) {
  11660. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11661. }
  11662. else if(!spawn->IsTransportSpawn()) {
  11663. 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());
  11664. }
  11665. lua_interface->SetBooleanValue(state, res);
  11666. return 1;
  11667. }
  11668. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11669. if (!lua_interface)
  11670. return 0;
  11671. ZoneServer* zone = lua_interface->GetZone(state);
  11672. lua_interface->ResetFunctionStack(state);
  11673. if (zone) {
  11674. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11675. return 1;
  11676. }
  11677. return 0;
  11678. }
  11679. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11680. if (!lua_interface)
  11681. return 0;
  11682. Spawn* spawn = lua_interface->GetSpawn(state);
  11683. lua_interface->ResetFunctionStack(state);
  11684. if (spawn) {
  11685. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11686. return 1;
  11687. }
  11688. return 0;
  11689. }
  11690. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11691. if (!lua_interface)
  11692. return 0;
  11693. Spawn* player = lua_interface->GetSpawn(state);
  11694. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11695. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11696. lua_interface->ResetFunctionStack(state);
  11697. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11698. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11699. }
  11700. else if(!zoneID) {
  11701. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11702. }
  11703. else
  11704. {
  11705. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11706. return 1;
  11707. }
  11708. return 0;
  11709. }
  11710. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11711. if (!lua_interface)
  11712. return 0;
  11713. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11714. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11715. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11716. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11717. lua_interface->ResetFunctionStack(state);
  11718. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11719. world.GetWorldTimeStruct()->year = newYear;
  11720. world.GetWorldTimeStruct()->month = newMonth;
  11721. world.GetWorldTimeStruct()->hour = newHour;
  11722. world.GetWorldTimeStruct()->minute = newMinute;
  11723. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11724. return 0;
  11725. }
  11726. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11727. if (!lua_interface)
  11728. return 0;
  11729. lua_interface->ResetFunctionStack(state);
  11730. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11731. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11732. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11733. return 1;
  11734. }
  11735. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11736. if (!lua_interface)
  11737. return 0;
  11738. lua_interface->ResetFunctionStack(state);
  11739. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11740. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11741. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11742. return 1;
  11743. }
  11744. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11745. if (!lua_interface)
  11746. return 0;
  11747. lua_interface->ResetFunctionStack(state);
  11748. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11749. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11750. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11751. return 1;
  11752. }
  11753. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11754. if (!lua_interface)
  11755. return 0;
  11756. lua_interface->ResetFunctionStack(state);
  11757. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11758. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11759. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11760. return 1;
  11761. }
  11762. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11763. if (!lua_interface)
  11764. return 0;
  11765. lua_interface->ResetFunctionStack(state);
  11766. world.SendTimeUpdate();
  11767. return 0;
  11768. }
  11769. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11770. bool update_result = false;
  11771. Faction* faction = 0;
  11772. Spawn* spawn = lua_interface->GetSpawn(state);
  11773. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11774. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11775. lua_interface->ResetFunctionStack(state);
  11776. if(!spawn || !spawn->IsPlayer()) {
  11777. lua_interface->LogError("LUA ChangeFaction command error: player is not valid");
  11778. return 0;
  11779. }
  11780. Player* player = (Player*)spawn;
  11781. Client* client = player->GetClient();
  11782. if (faction_id > 0) {
  11783. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11784. if(hasfaction == 0) {
  11785. //they do not have the faction. Lets get the default value and feed it in.
  11786. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11787. //add the default faction for the player.
  11788. player->SetFactionValue(faction_id, defaultfaction);
  11789. }
  11790. if(increase >= 0) {
  11791. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11792. faction = master_faction_list.GetFaction(faction_id);
  11793. if(faction && update_result)
  11794. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11795. else if(faction)
  11796. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11797. lua_interface->SetBooleanValue(state, true);
  11798. return 1;
  11799. }
  11800. if(increase < 0){
  11801. //change the negative to a positive, since thats how decreasefaction() likes it.
  11802. increase *= -1;
  11803. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11804. faction = master_faction_list.GetFaction(faction_id);
  11805. if(faction && update_result)
  11806. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11807. else if(faction)
  11808. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11809. lua_interface->SetBooleanValue(state, true);
  11810. return 1;
  11811. }
  11812. }
  11813. lua_interface->SetBooleanValue(state, false);
  11814. return 1;
  11815. }
  11816. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11817. bool hascoin = 0;
  11818. Player* player = (Player*)lua_interface->GetSpawn(state);
  11819. int32 coins = lua_interface->GetInt32Value(state, 2);
  11820. lua_interface->ResetFunctionStack(state);
  11821. if (player && player->IsPlayer()) {
  11822. hascoin = player->HasCoins(coins);
  11823. if(hascoin == 0) {
  11824. lua_interface->SetBooleanValue(state, false);
  11825. return 1;
  11826. }
  11827. if(hascoin == 1) {
  11828. lua_interface->SetBooleanValue(state, true);
  11829. return 1;
  11830. }
  11831. }
  11832. return 0;
  11833. }
  11834. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11835. int32 loot_tier = 0;
  11836. Spawn* spawn = lua_interface->GetSpawn(state);
  11837. lua_interface->ResetFunctionStack(state);
  11838. if (spawn) {
  11839. loot_tier = spawn->GetLootTier();
  11840. lua_interface->SetInt32Value(state, loot_tier);
  11841. return 1;
  11842. }
  11843. return 0;
  11844. }
  11845. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11846. if (!lua_interface)
  11847. return 0;
  11848. Spawn* spawn = lua_interface->GetSpawn(state);
  11849. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11850. lua_interface->ResetFunctionStack(state);
  11851. if (spawn) {
  11852. spawn->SetLootTier(loot_tier);
  11853. lua_interface->SetBooleanValue(state, true);
  11854. return 1;
  11855. }
  11856. lua_interface->SetBooleanValue(state, false);
  11857. return 1;
  11858. }
  11859. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11860. int32 loot_drop_type = 0;
  11861. Spawn* spawn = lua_interface->GetSpawn(state);
  11862. lua_interface->ResetFunctionStack(state);
  11863. if (spawn) {
  11864. loot_drop_type = spawn->GetLootDropType();
  11865. lua_interface->SetInt32Value(state, loot_drop_type);
  11866. return 1;
  11867. }
  11868. return 0;
  11869. }
  11870. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11871. if (!lua_interface)
  11872. return 0;
  11873. Spawn* spawn = lua_interface->GetSpawn(state);
  11874. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11875. lua_interface->ResetFunctionStack(state);
  11876. if (spawn) {
  11877. spawn->SetLootDropType(loot_drop_type);
  11878. lua_interface->SetBooleanValue(state, true);
  11879. return 1;
  11880. }
  11881. lua_interface->SetBooleanValue(state, false);
  11882. return 1;
  11883. }
  11884. int EQ2Emu_lua_DamageEquippedItems(lua_State* state) {
  11885. if (!lua_interface)
  11886. return 0;
  11887. Spawn* spawn = lua_interface->GetSpawn(state);
  11888. int8 damage_amount = lua_interface->GetInt32Value(state, 2);
  11889. if(damage_amount > 100) {
  11890. damage_amount = 100;
  11891. }
  11892. if (!spawn) {
  11893. lua_interface->LogError("%s: LUA DamageEquippedItems command error: spawn is not valid", lua_interface->GetScriptName(state));
  11894. lua_interface->ResetFunctionStack(state);
  11895. return 0;
  11896. }
  11897. lua_interface->ResetFunctionStack(state);
  11898. if (spawn->IsPlayer()) {
  11899. if (((Player*)spawn)->GetClient() && ((Player*)spawn)->DamageEquippedItems(damage_amount, ((Player*)spawn)->GetClient()))
  11900. lua_interface->SetBooleanValue(state, true);
  11901. else
  11902. lua_interface->SetBooleanValue(state, false);
  11903. }
  11904. else {
  11905. lua_interface->SetBooleanValue(state, false);
  11906. }
  11907. return 1;
  11908. }
  11909. int EQ2Emu_lua_CreateWidgetRegion(lua_State* state) {
  11910. ZoneServer* zone = lua_interface->GetZone(state);
  11911. int32 version = lua_interface->GetInt32Value(state, 2);
  11912. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11913. if(region_map == nullptr) {
  11914. lua_interface->LogError("%s: LUA CreateWidgetRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11915. lua_interface->ResetFunctionStack(state);
  11916. return 0;
  11917. }
  11918. string region_name = lua_interface->GetStringValue(state, 3);
  11919. string env_name = lua_interface->GetStringValue(state, 4);
  11920. int32 grid_id = lua_interface->GetInt32Value(state, 5);
  11921. int32 widget_id = lua_interface->GetInt32Value(state, 6);
  11922. float dist = lua_interface->GetFloatValue(state, 7);
  11923. region_map->InsertRegionNode(zone, version, region_name, env_name, grid_id, widget_id, dist);
  11924. lua_interface->ResetFunctionStack(state);
  11925. lua_interface->SetBooleanValue(state, true);
  11926. return 1;
  11927. }
  11928. int EQ2Emu_lua_RemoveRegion(lua_State* state) {
  11929. ZoneServer* zone = lua_interface->GetZone(state);
  11930. int32 version = lua_interface->GetInt32Value(state, 2);
  11931. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11932. if(region_map == nullptr) {
  11933. lua_interface->LogError("%s: LUA RemoveRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11934. lua_interface->ResetFunctionStack(state);
  11935. return 0;
  11936. }
  11937. string region_name = lua_interface->GetStringValue(state, 3);
  11938. region_map->RemoveRegionNode(region_name);
  11939. lua_interface->ResetFunctionStack(state);
  11940. lua_interface->SetBooleanValue(state, true);
  11941. return 1;
  11942. }
  11943. int EQ2Emu_lua_SetPlayerPOVGhost(lua_State* state) {
  11944. Client* client = nullptr;
  11945. Spawn* player = lua_interface->GetSpawn(state);
  11946. if (!player) {
  11947. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not valid");
  11948. lua_interface->SetBooleanValue(state, false);
  11949. lua_interface->ResetFunctionStack(state);
  11950. return 1;
  11951. }
  11952. if (!player->IsPlayer()) {
  11953. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
  11954. lua_interface->SetBooleanValue(state, false);
  11955. lua_interface->ResetFunctionStack(state);
  11956. return 1;
  11957. }
  11958. client = player->GetClient();
  11959. if (!client) {
  11960. lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
  11961. lua_interface->SetBooleanValue(state, false);
  11962. lua_interface->ResetFunctionStack(state);
  11963. return 1;
  11964. }
  11965. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  11966. bool success_sight = client->SetPlayerPOVGhost(spawn);
  11967. lua_interface->ResetFunctionStack(state);
  11968. lua_interface->SetBooleanValue(state, success_sight);
  11969. return 1;
  11970. }
  11971. int EQ2Emu_lua_SetCastOnAggroComplete(lua_State* state) {
  11972. if (!lua_interface)
  11973. return 0;
  11974. bool result = false;
  11975. Spawn* spawn = lua_interface->GetSpawn(state);
  11976. bool cast_completed = (lua_interface->GetInt8Value(state, 2) == 1);
  11977. lua_interface->ResetFunctionStack(state);
  11978. if (!spawn)
  11979. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11980. else if (!spawn->IsNPC())
  11981. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11982. else
  11983. {
  11984. ((NPC*)spawn)->cast_on_aggro_completed = cast_completed;
  11985. result = true;
  11986. }
  11987. lua_interface->SetBooleanValue(state, result);
  11988. return 1;
  11989. }
  11990. int EQ2Emu_lua_IsCastOnAggroComplete(lua_State* state) {
  11991. if (!lua_interface)
  11992. return 0;
  11993. bool result = false;
  11994. Spawn* spawn = lua_interface->GetSpawn(state);
  11995. lua_interface->ResetFunctionStack(state);
  11996. if (!spawn)
  11997. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11998. else if (!spawn->IsNPC())
  11999. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  12000. else
  12001. {
  12002. if(((NPC*)spawn)->cast_on_aggro_completed)
  12003. result = true;
  12004. }
  12005. lua_interface->SetBooleanValue(state, result);
  12006. return 1;
  12007. }
  12008. int EQ2Emu_lua_AddRecipeBookToPlayer(lua_State* state) {
  12009. Client* client = nullptr;
  12010. Spawn* player = lua_interface->GetSpawn(state);
  12011. int32 recipe_book_id = lua_interface->GetInt32Value(state, 2);
  12012. lua_interface->ResetFunctionStack(state);
  12013. if (!player) {
  12014. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not valid");
  12015. lua_interface->SetBooleanValue(state, false);
  12016. return 1;
  12017. }
  12018. if (!player->IsPlayer()) {
  12019. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not a player");
  12020. lua_interface->SetBooleanValue(state, false);
  12021. return 1;
  12022. }
  12023. client = player->GetClient();
  12024. if (!client) {
  12025. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: could not find client");
  12026. lua_interface->SetBooleanValue(state, false);
  12027. return 1;
  12028. }
  12029. bool result = client->AddRecipeBookToPlayer(recipe_book_id);
  12030. lua_interface->SetBooleanValue(state, result);
  12031. return 1;
  12032. }
  12033. int EQ2Emu_lua_RemoveRecipeFromPlayer(lua_State* state) {
  12034. Client* client = nullptr;
  12035. Spawn* player = lua_interface->GetSpawn(state);
  12036. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  12037. lua_interface->ResetFunctionStack(state);
  12038. if (!player) {
  12039. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not valid");
  12040. lua_interface->SetBooleanValue(state, false);
  12041. return 1;
  12042. }
  12043. if (!player->IsPlayer()) {
  12044. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not a player");
  12045. lua_interface->SetBooleanValue(state, false);
  12046. return 1;
  12047. }
  12048. client = player->GetClient();
  12049. if (!client) {
  12050. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: could not find client");
  12051. lua_interface->SetBooleanValue(state, false);
  12052. return 1;
  12053. }
  12054. bool result = client->RemoveRecipeFromPlayer(recipe_id);
  12055. lua_interface->SetBooleanValue(state, result);
  12056. return 1;
  12057. }
  12058. int EQ2Emu_lua_ReplaceWidgetFromClient(lua_State* state) {
  12059. Client* client = nullptr;
  12060. Spawn* player = lua_interface->GetSpawn(state);
  12061. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12062. bool delete_widget = (lua_interface->GetInt8Value(state, 3) == 1);
  12063. // rest are all optional fields
  12064. float x = lua_interface->GetFloatValue(state, 4);
  12065. float y = lua_interface->GetFloatValue(state, 5);
  12066. float z = lua_interface->GetFloatValue(state, 6);
  12067. int32 grid_id = lua_interface->GetInt32Value(state, 7);
  12068. lua_interface->ResetFunctionStack(state);
  12069. if (!player) {
  12070. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not valid");
  12071. lua_interface->SetBooleanValue(state, false);
  12072. return 1;
  12073. }
  12074. if (!player->IsPlayer()) {
  12075. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not a player");
  12076. lua_interface->SetBooleanValue(state, false);
  12077. return 1;
  12078. }
  12079. if(!player->GetZone()) {
  12080. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  12081. lua_interface->SetBooleanValue(state, false);
  12082. return 1;
  12083. }
  12084. client = player->GetClient();
  12085. if (!client) {
  12086. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: could not find client");
  12087. lua_interface->SetBooleanValue(state, false);
  12088. return 1;
  12089. }
  12090. if(!client->IsReadyForUpdates()) {
  12091. lua_interface->LogError("LUA ReplaceWidgetFromClient command failed: client has not signaled sys_client_avatar_ready");
  12092. lua_interface->SetBooleanValue(state, false);
  12093. return 1;
  12094. }
  12095. client->SendReplaceWidget(widget_id, delete_widget, x, y, z, grid_id);
  12096. lua_interface->SetBooleanValue(state, true);
  12097. return 1;
  12098. }
  12099. int EQ2Emu_lua_RemoveWidgetFromSpawnMap(lua_State* state) {
  12100. Client* client = nullptr;
  12101. Spawn* spawn = lua_interface->GetSpawn(state);
  12102. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12103. lua_interface->ResetFunctionStack(state);
  12104. if (!spawn) {
  12105. lua_interface->LogError("LUA RemoveWidgetFromSpawnMap command error: spawn is not valid");
  12106. lua_interface->SetBooleanValue(state, false);
  12107. return 1;
  12108. }
  12109. if(!spawn->GetZone()) {
  12110. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  12111. lua_interface->SetBooleanValue(state, false);
  12112. return 1;
  12113. }
  12114. spawn->AddIgnoredWidget(widget_id);
  12115. lua_interface->SetBooleanValue(state, true);
  12116. return 1;
  12117. }
  12118. int EQ2Emu_lua_RemoveWidgetFromZoneMap(lua_State* state) {
  12119. ZoneServer* zone = lua_interface->GetZone(state);
  12120. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12121. lua_interface->ResetFunctionStack(state);
  12122. if(!zone) {
  12123. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: zone is not valid");
  12124. lua_interface->SetBooleanValue(state, false);
  12125. return 1;
  12126. }
  12127. if(!zone->IsLoading()) {
  12128. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: can only be called during zone loading, in preinit_zone_script ZoneScript function");
  12129. lua_interface->SetBooleanValue(state, false);
  12130. return 1;
  12131. }
  12132. zone->AddIgnoredWidget(widget_id);
  12133. lua_interface->SetBooleanValue(state, true);
  12134. return 1;
  12135. }
  12136. int EQ2Emu_lua_SendHearCast(lua_State* state) {
  12137. if (!lua_interface)
  12138. return 0;
  12139. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  12140. Spawn* spawn = lua_interface->GetSpawn(state);
  12141. int32 spell_visual_id = lua_interface->GetInt32Value(state, 2);
  12142. int16 cast_time = lua_interface->GetInt16Value(state, 3);
  12143. Spawn* caster = lua_interface->GetSpawn(state, 4);
  12144. Spawn* target = lua_interface->GetSpawn(state, 5);
  12145. lua_interface->ResetFunctionStack(state);
  12146. if(spell && spawn && spawn->IsEntity()) {
  12147. ZoneServer* zone = spawn->GetZone();
  12148. if(zone) {
  12149. zone->SendCastSpellPacket(spell, caster && caster->IsEntity() ? (Entity*)caster : (Entity*)spawn, spell_visual_id, cast_time > 0 ? cast_time : 0xFFFF);
  12150. }
  12151. }
  12152. else if (spawn) {
  12153. if (spawn->IsPlayer()) {
  12154. Client* client = ((Player*)spawn)->GetClient();
  12155. if (client) {
  12156. client->SendHearCast(caster ? caster : client->GetPlayer(), target ? target : client->GetPlayer(), spell_visual_id, cast_time);
  12157. }
  12158. }
  12159. }
  12160. return 0;
  12161. }