LuaFunctions.cpp 431 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "Rules/Rules.h"
  29. #include "../common/Log.h"
  30. #include <math.h>
  31. #include "HeroicOp/HeroicOp.h"
  32. #include "RaceTypes/RaceTypes.h"
  33. #include "ClientPacketFunctions.h"
  34. #include "Transmute.h"
  35. #include "Titles.h"
  36. #include <boost/algorithm/string/predicate.hpp>
  37. #include <sstream>
  38. #include <boost/algorithm/string.hpp>
  39. extern MasterFactionList master_faction_list;
  40. extern WorldDatabase database;
  41. extern LuaInterface* lua_interface;
  42. extern ConfigReader configReader;
  43. extern MasterQuestList master_quest_list;
  44. extern MasterItemList master_item_list;
  45. extern MasterSpellList master_spell_list;
  46. extern World world;
  47. extern Commands commands;
  48. extern ZoneList zone_list;
  49. extern Races races;
  50. extern Classes classes;
  51. extern Variables variables;
  52. extern MasterSkillList master_skill_list;
  53. extern MasterHeroicOPList master_ho_list;
  54. extern MasterRaceTypeList race_types_list;
  55. extern MasterLanguagesList master_languages_list;
  56. extern MasterTitlesList master_titles_list;
  57. extern RuleManager rule_manager;
  58. vector<string> ParseString(string strVal, char delim) {
  59. stringstream ss(strVal);
  60. vector<string> ret;
  61. while (ss.good())
  62. {
  63. string substr;
  64. getline(ss, substr, delim);
  65. ret.push_back(substr);
  66. }
  67. return ret;
  68. }
  69. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  70. stringstream ss(strVal);
  71. vector<unsigned int> ret;
  72. while (ss.good())
  73. {
  74. string substr;
  75. getline(ss, substr, delim);
  76. stringstream valss(substr);
  77. unsigned int val = 0;
  78. valss >> val;
  79. ret.push_back(val);
  80. }
  81. return ret;
  82. }
  83. map<string, signed int> ParseStringMap(string strVal, char delim) {
  84. vector<string> pairs = ParseString(strVal, delim);
  85. vector<string>::iterator itr;
  86. map<string, signed int> ret;
  87. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  88. vector<string> keyvaluepair = ParseString(*itr, ':');
  89. if (keyvaluepair.size() == 2) {
  90. stringstream valss(keyvaluepair[1]);
  91. int32 val = 0;
  92. valss >> val;
  93. ret[keyvaluepair[0]] = val;
  94. }
  95. }
  96. return ret;
  97. }
  98. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  99. vector<string> pairs = ParseString(strVal, delim);
  100. vector<string>::iterator itr;
  101. map<unsigned int, unsigned short> ret;
  102. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  103. vector<string> keyvaluepair = ParseString(*itr, ':');
  104. int32 key = 0;
  105. if (keyvaluepair.size() > 0) {
  106. stringstream keyss(keyvaluepair[0]);
  107. keyss >> key;
  108. }
  109. if (keyvaluepair.size() == 1) {
  110. ret[key] = 1;
  111. }
  112. else if (keyvaluepair.size() == 2) {
  113. stringstream valss(keyvaluepair[1]);
  114. unsigned short val = 0;
  115. valss >> val;
  116. ret[key] = val;
  117. }
  118. }
  119. return ret;
  120. }
  121. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  122. vector<string> pairs = ParseString(strVal, delim);
  123. vector<string>::iterator itr;
  124. map<unsigned int, signed int> ret;
  125. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  126. vector<string> keyvaluepair = ParseString(*itr, ':');
  127. int32 key = 0;
  128. if (keyvaluepair.size() > 0) {
  129. stringstream keyss(keyvaluepair[0]);
  130. keyss >> key;
  131. }
  132. if (keyvaluepair.size() == 1) {
  133. ret[key] = 1;
  134. }
  135. else if (keyvaluepair.size() == 2) {
  136. stringstream valss(keyvaluepair[1]);
  137. signed int val = 0;
  138. valss >> val;
  139. ret[key] = val;
  140. }
  141. }
  142. return ret;
  143. }
  144. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  145. if (!lua_interface)
  146. return 0;
  147. Spawn* spawn = lua_interface->GetSpawn(state);
  148. string mp3_string = lua_interface->GetStringValue(state, 2);
  149. string text_string = lua_interface->GetStringValue(state, 3);
  150. string emote_string = lua_interface->GetStringValue(state, 4);
  151. int32 key1 = lua_interface->GetInt32Value(state, 5);
  152. int32 key2 = lua_interface->GetInt32Value(state, 6);
  153. Spawn* player = lua_interface->GetSpawn(state, 7);
  154. int8 language = lua_interface->GetInt8Value(state, 8);
  155. lua_interface->ResetFunctionStack(state);
  156. if (spawn) {
  157. const char* mp3 = 0;
  158. const char* text = 0;
  159. const char* emote = 0;
  160. if (mp3_string.length() > 0)
  161. mp3 = mp3_string.c_str();
  162. if (text_string.length() > 0)
  163. text = text_string.c_str();
  164. if (emote_string.length() > 0)
  165. emote = emote_string.c_str();
  166. Client* client = 0;
  167. if (player && player->IsPlayer())
  168. client = ((Player*)player)->GetClient();
  169. if (client) {
  170. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  171. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  172. }
  173. else
  174. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  175. }
  176. return 0;
  177. }
  178. int EQ2Emu_lua_PlayFlavorID(lua_State* state) {
  179. if (!lua_interface)
  180. return 0;
  181. Spawn* spawn = lua_interface->GetSpawn(state);
  182. int8 type = lua_interface->GetInt8Value(state, 2);
  183. int32 id = lua_interface->GetInt32Value(state, 3);
  184. int16 index = lua_interface->GetInt16Value(state, 4);
  185. Spawn* player = lua_interface->GetSpawn(state, 5);
  186. int8 language = lua_interface->GetInt8Value(state, 6);
  187. lua_interface->ResetFunctionStack(state);
  188. if (spawn) {
  189. Client* client = 0;
  190. if (player && player->IsPlayer())
  191. client = ((Player*)player)->GetClient();
  192. if (client) {
  193. VoiceOverStruct non_garble, garble;
  194. bool garble_success = false;
  195. bool success = world.FindVoiceOver(type, id, index, &non_garble, &garble_success, &garble);
  196. client->SendPlayFlavor(spawn, language, &non_garble, &garble, success, garble_success);
  197. }
  198. else
  199. spawn->GetZone()->PlayFlavorID(spawn, type, id, index, language);
  200. }
  201. return 0;
  202. }
  203. int EQ2Emu_lua_PlaySound(lua_State* state) {
  204. if (!lua_interface)
  205. return 0;
  206. Spawn* spawn = lua_interface->GetSpawn(state);
  207. string sound_string = lua_interface->GetStringValue(state, 2);
  208. float x = lua_interface->GetFloatValue(state, 3);
  209. float y = lua_interface->GetFloatValue(state, 4);
  210. float z = lua_interface->GetFloatValue(state, 5);
  211. Spawn* player = lua_interface->GetSpawn(state, 6);
  212. lua_interface->ResetFunctionStack(state);
  213. if (spawn && sound_string.length() > 0) {
  214. Client* client = 0;
  215. if (player && player->IsPlayer())
  216. client = ((Player*)player)->GetClient();
  217. if (client)
  218. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  219. else
  220. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  221. }
  222. return 0;
  223. }
  224. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  225. if (!lua_interface)
  226. return 0;
  227. Spawn* spawn = lua_interface->GetSpawn(state);
  228. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  229. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  230. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  231. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  232. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  233. lua_interface->ResetFunctionStack(state);
  234. if (!spawn) {
  235. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  236. return 0;
  237. }
  238. if (quest_id > 0) {
  239. //Add this quest to the list of required quests for this spawn
  240. spawn->SetQuestsRequired(quest_id, quest_step);
  241. //If private spawn value set
  242. if (private_spawn) {
  243. //Set the spawn to be private when not granted access through this quest
  244. spawn->AddAllowAccessSpawn(spawn);
  245. spawn->SetPrivateQuestSpawn(true);
  246. }
  247. //This value allows access after a quest step, or the whole quest has been completed
  248. if (continued_access)
  249. spawn->SetQuestsRequiredContinuedAccess(true);
  250. //This value will override vis_flags in the vis packet
  251. if (flag_override > 0)
  252. spawn->SetQuestsRequiredOverride(flag_override);
  253. }
  254. return 0;
  255. }
  256. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  257. if (!lua_interface)
  258. return 0;
  259. Spawn* spawn = lua_interface->GetSpawn(state);
  260. float max_distance = lua_interface->GetFloatValue(state, 2);
  261. string variable = lua_interface->GetStringValue(state, 3);
  262. string value = lua_interface->GetStringValue(state, 4);
  263. lua_interface->ResetFunctionStack(state);
  264. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  265. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  266. return 0;
  267. }
  268. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  269. if (!lua_interface)
  270. return 0;
  271. Client* client = 0;
  272. Spawn* player = lua_interface->GetSpawn(state);
  273. float intensity = lua_interface->GetFloatValue(state, 2);
  274. int8 direction = lua_interface->GetInt8Value(state, 3);
  275. lua_interface->ResetFunctionStack(state);
  276. if (!player) {
  277. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  278. return 0;
  279. }
  280. if (!player->IsPlayer()) {
  281. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  282. return 0;
  283. }
  284. if (player->GetZone())
  285. client = ((Player*)player)->GetClient();
  286. if (!client) {
  287. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  288. return 0;
  289. }
  290. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  291. if (packet) {
  292. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  293. v1 = *(float *)(a1 + 4);
  294. if ( v1 > 0.0 )
  295. v2 = fminf(v1, 1.0);
  296. else
  297. v2 = 0.1;
  298. */
  299. packet->setDataByName("intensity", intensity);
  300. if ( client->GetVersion() > 561 )
  301. packet->setDataByName("direction", direction);
  302. client->QueuePacket(packet->serialize());
  303. safe_delete(packet);
  304. }
  305. return 0;
  306. }
  307. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* dead = lua_interface->GetSpawn(state);
  311. Spawn* killer = lua_interface->GetSpawn(state, 2);
  312. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  313. lua_interface->ResetFunctionStack(state);
  314. if (dead && dead->Alive() && dead->GetZone())
  315. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  316. return 0;
  317. }
  318. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  319. if (!lua_interface)
  320. return 0;
  321. Spawn* spawn = lua_interface->GetSpawn(state);
  322. float max_distance = lua_interface->GetFloatValue(state, 2);
  323. bool include_players = lua_interface->GetInt8Value(state, 3);
  324. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  325. lua_interface->ResetFunctionStack(state);
  326. if (max_distance > 0 && spawn && spawn->GetZone())
  327. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  328. return 0;
  329. }
  330. int EQ2Emu_lua_Despawn(lua_State* state) {
  331. if (!lua_interface)
  332. return 0;
  333. Spawn* spawn = lua_interface->GetSpawn(state);
  334. int32 delay = lua_interface->GetInt32Value(state, 2);
  335. lua_interface->ResetFunctionStack(state);
  336. if (spawn && spawn->GetZone())
  337. spawn->GetZone()->Despawn(spawn, delay);
  338. return 0;
  339. }
  340. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  341. if (!lua_interface)
  342. return 0;
  343. Spawn* spawn = lua_interface->GetSpawn(state);
  344. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  345. lua_interface->ResetFunctionStack(state);
  346. if (spawn) {
  347. spawn->info_changed = true;
  348. spawn->SetShowHandIcon(displayHandIcon);
  349. }
  350. return 0;
  351. }
  352. //this function is used to force an update packet to be sent.
  353. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  354. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  355. if (!lua_interface)
  356. return 0;
  357. Spawn* spawn = lua_interface->GetSpawn(state);
  358. lua_interface->ResetFunctionStack(state);
  359. if (spawn) {
  360. spawn->vis_changed = true;
  361. spawn->GetZone()->AddChangedSpawn(spawn);
  362. }
  363. return 0;
  364. }
  365. //this function is used to force an update packet to be sent.
  366. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  367. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  368. if (!lua_interface)
  369. return 0;
  370. Spawn* spawn = lua_interface->GetSpawn(state);
  371. lua_interface->ResetFunctionStack(state);
  372. if (spawn) {
  373. spawn->info_changed = true;
  374. spawn->GetZone()->AddChangedSpawn(spawn);
  375. }
  376. return 0;
  377. }
  378. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  379. if (!lua_interface)
  380. return 0;
  381. Spawn* spawn = lua_interface->GetSpawn(state);
  382. int32 new_state = lua_interface->GetInt32Value(state, 2);
  383. Spawn* player = lua_interface->GetSpawn(state, 3);
  384. lua_interface->ResetFunctionStack(state);
  385. if (spawn) {
  386. if(player)
  387. {
  388. if(player->IsPlayer())
  389. {
  390. Client* client = ((Player*)player)->GetClient();
  391. if(client)
  392. {
  393. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  394. lua_interface->SetBooleanValue(state, true);
  395. return 1;
  396. }
  397. else
  398. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument does not have active client.", spawn->GetName());
  399. }
  400. else
  401. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument is NOT a player.", spawn->GetName());
  402. }
  403. else
  404. {
  405. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  406. lua_interface->SetBooleanValue(state, true);
  407. return 1;
  408. }
  409. }
  410. lua_interface->SetBooleanValue(state, false);
  411. return 1;
  412. }
  413. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  414. if (!lua_interface)
  415. return 0;
  416. Spawn* spawn = lua_interface->GetSpawn(state);
  417. string variable = lua_interface->GetStringValue(state, 2);
  418. string value = lua_interface->GetStringValue(state, 3);
  419. bool no_update = lua_interface->GetBooleanValue(state, 4); // send update is true by default in SetSpawnCommand, so allow user to specify 'true' to disable send update.
  420. bool temporary_flag = true;
  421. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  422. int8 index = 0;
  423. if(num_args >= 5)
  424. {
  425. temporary_flag = lua_interface->GetBooleanValue(state, 5); // this used to be false, but no one bothered to set it temporary, we don't need to update the DB
  426. index = lua_interface->GetInt8Value(state, 6);
  427. }
  428. lua_interface->ResetFunctionStack(state);
  429. int32 type = commands.GetSpawnSetType(variable);
  430. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  431. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  432. return 0;
  433. }
  434. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  435. if (!lua_interface)
  436. return 0;
  437. Spawn* spawn = lua_interface->GetSpawn(state);
  438. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  439. lua_interface->ResetFunctionStack(state);
  440. if (spawn && spawn_id > 0) {
  441. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  442. if (closest_spawn) {
  443. lua_interface->SetSpawnValue(state, closest_spawn);
  444. return 1;
  445. }
  446. }
  447. return 0;
  448. }
  449. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  450. if (!lua_interface)
  451. return 0;
  452. vector<Spawn*> spawns;
  453. int32 position = 0;
  454. if(lua_istable(state, 1)) {
  455. size_t len = lua_rawlen(state, 1);
  456. for(int i=1;i <= len; i++)
  457. {
  458. // get the entry to stack
  459. lua_rawgeti(state, 1, i);
  460. int Top = lua_gettop(state);
  461. if(lua_islightuserdata(state,Top)) {
  462. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  463. if(data->IsSpawn()) {
  464. spawns.push_back(data->spawn);
  465. }
  466. }
  467. // remove entry from stack
  468. lua_pop(state,1);
  469. }
  470. }
  471. position = lua_interface->GetInt32Value(state, 2);
  472. lua_interface->ResetFunctionStack(state);
  473. Spawn* spawn = 0;
  474. if(position < spawns.size()) {
  475. spawn = spawns.at(position);
  476. }
  477. if(spawn) {
  478. lua_interface->SetSpawnValue(state, spawn);
  479. return 1;
  480. }
  481. return 0;
  482. }
  483. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  484. if (!lua_interface)
  485. return 0;
  486. vector<Spawn*> spawns;
  487. if(lua_istable(state, 1)) {
  488. size_t len = lua_rawlen(state, 1);
  489. for(int i=1;i <= len; i++)
  490. {
  491. // get the entry to stack
  492. lua_rawgeti(state, 1, i);
  493. int Top = lua_gettop(state);
  494. if(lua_islightuserdata(state,Top)) {
  495. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  496. if(data->IsSpawn()) {
  497. spawns.push_back(data->spawn);
  498. }
  499. }
  500. // remove entry from stack
  501. lua_pop(state,1);
  502. }
  503. }
  504. lua_interface->ResetFunctionStack(state);
  505. lua_interface->SetInt32Value(state, spawns.size());
  506. return 1;
  507. }
  508. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  509. if (!lua_interface)
  510. return 0;
  511. Spawn* spawn = lua_interface->GetSpawn(state);
  512. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  513. lua_interface->ResetFunctionStack(state);
  514. if (spawn) {
  515. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  516. if (spawns.size() > 0) {
  517. lua_createtable(state, spawns.size(), 0);
  518. int newTable = lua_gettop(state);
  519. for (int32 i = 0; i < spawns.size(); i++) {
  520. lua_interface->SetSpawnValue(state, spawns.at(i));
  521. lua_rawseti(state, newTable, i + 1);
  522. }
  523. return 1;
  524. }
  525. }
  526. return 0;
  527. }
  528. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  529. if (!lua_interface)
  530. return 0;
  531. Spawn* spawn = lua_interface->GetSpawn(state);
  532. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  533. lua_interface->ResetFunctionStack(state);
  534. if (spawn) {
  535. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  536. if (spawns.size() > 0) {
  537. lua_createtable(state, spawns.size(), 0);
  538. int newTable = lua_gettop(state);
  539. for (int32 i = 0; i < spawns.size(); i++) {
  540. lua_interface->SetSpawnValue(state, spawns.at(i));
  541. lua_rawseti(state, newTable, i + 1);
  542. }
  543. return 1;
  544. }
  545. }
  546. return 0;
  547. }
  548. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  549. if (!lua_interface)
  550. return 0;
  551. Spawn* spawn = lua_interface->GetSpawn(state);
  552. lua_interface->ResetFunctionStack(state);
  553. if (spawn) {
  554. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  555. if (spawns.size() > 0) {
  556. lua_createtable(state, spawns.size(), 0);
  557. int newTable = lua_gettop(state);
  558. for (int32 i = 0; i < spawns.size(); i++) {
  559. lua_interface->SetSpawnValue(state, spawns.at(i));
  560. lua_rawseti(state, newTable, i + 1);
  561. }
  562. return 1;
  563. }
  564. }
  565. return 0;
  566. }
  567. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  568. if (!lua_interface)
  569. return 0;
  570. string variable_name = lua_interface->GetStringValue(state);
  571. lua_interface->ResetFunctionStack(state);
  572. Variable* var = variables.FindVariable(variable_name);
  573. if (var) {
  574. lua_interface->SetStringValue(state, var->GetValue());
  575. return 1;
  576. }
  577. return 0;
  578. }
  579. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  580. if (!lua_interface)
  581. return 0;
  582. int32 total_coins = lua_interface->GetInt32Value(state);
  583. lua_interface->ResetFunctionStack(state);
  584. if (total_coins == 0) {
  585. lua_interface->SetStringValue(state, "0 copper");
  586. return 1;
  587. }
  588. char tmp[64] = { 0 };
  589. string message = "";
  590. int32 val = 0;
  591. if (total_coins >= 1000000) {
  592. val = total_coins / 1000000;
  593. total_coins -= 1000000 * val;
  594. sprintf(tmp, " %u Platinum", val);
  595. message.append(tmp);
  596. memset(tmp, 0, 64);
  597. }
  598. if (total_coins >= 10000) {
  599. val = total_coins / 10000;
  600. total_coins -= 10000 * val;
  601. sprintf(tmp, " %u Gold", val);
  602. message.append(tmp);
  603. memset(tmp, 0, 64);
  604. }
  605. if (total_coins >= 100) {
  606. val = total_coins / 100;
  607. total_coins -= 100 * val;
  608. sprintf(tmp, " %u Silver", val);
  609. message.append(tmp);
  610. memset(tmp, 0, 64);
  611. }
  612. if (total_coins > 0) {
  613. sprintf(tmp, " %u Copper", (int32)total_coins);
  614. message.append(tmp);
  615. }
  616. lua_interface->SetStringValue(state, message.c_str());
  617. return 1;
  618. }
  619. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  620. ZoneServer* zone = lua_interface->GetZone(state);
  621. int32 group_id = lua_interface->GetInt32Value(state, 2);
  622. lua_interface->ResetFunctionStack(state);
  623. if (zone) {
  624. Spawn* spawn = zone->GetSpawnGroup(group_id);
  625. if (spawn) {
  626. lua_interface->SetSpawnValue(state, spawn);
  627. return 1;
  628. }
  629. }
  630. return 0;
  631. }
  632. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  633. ZoneServer* zone = lua_interface->GetZone(state);
  634. int32 location_id = lua_interface->GetInt32Value(state, 2);
  635. lua_interface->ResetFunctionStack(state);
  636. if (zone) {
  637. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  638. if (spawn) {
  639. lua_interface->SetSpawnValue(state, spawn);
  640. return 1;
  641. }
  642. }
  643. return 0;
  644. }
  645. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  646. Spawn* spawn = lua_interface->GetSpawn(state);
  647. lua_interface->ResetFunctionStack(state);
  648. if (spawn) {
  649. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  650. return 1;
  651. }
  652. return 0;
  653. }
  654. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  655. Spawn* spawn = lua_interface->GetSpawn(state);
  656. lua_interface->ResetFunctionStack(state);
  657. if (spawn) {
  658. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  659. return 1;
  660. }
  661. return 0;
  662. }
  663. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  664. if (!lua_interface)
  665. return 0;
  666. Spawn* spawn = lua_interface->GetSpawn(state);
  667. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  668. lua_interface->ResetFunctionStack(state);
  669. if (spawn) {
  670. spawn->SetSpawnGroupID(new_group_id);
  671. lua_interface->SetBooleanValue(state, true);
  672. return 1;
  673. }
  674. lua_interface->SetBooleanValue(state, false);
  675. return 1;
  676. }
  677. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  678. if (!lua_interface)
  679. return 0;
  680. Spawn* spawn = lua_interface->GetSpawn(state);
  681. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  682. lua_interface->ResetFunctionStack(state);
  683. if (spawn) {
  684. 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. ZoneServer* zone = lua_interface->GetZone(state);
  1609. Spawn* player = lua_interface->GetSpawn(state, 2);
  1610. Client* client = 0;
  1611. if (player && player->IsPlayer())
  1612. client = ((Player*)player)->GetClient();
  1613. float x = lua_interface->GetFloatValue(state, 3);
  1614. float y = lua_interface->GetFloatValue(state, 4);
  1615. float z = lua_interface->GetFloatValue(state, 5);
  1616. float heading = lua_interface->GetFloatValue(state, 6);
  1617. if (zone && client) {
  1618. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1619. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1620. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1621. {
  1622. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1623. return 0;
  1624. }
  1625. if (x != 0 || y != 0 || z != 0) {
  1626. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1627. player->SetX(x);
  1628. player->SetY(y);
  1629. player->SetZ(z);
  1630. player->SetHeading(heading);
  1631. client->Zone(zone->GetZoneName(), false);
  1632. }
  1633. else
  1634. client->Zone(zone->GetZoneName());
  1635. }
  1636. else
  1637. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1638. lua_interface->ResetFunctionStack(state);
  1639. return 0;
  1640. }
  1641. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1642. if (!lua_interface)
  1643. return 0;
  1644. Spawn* spawn = lua_interface->GetSpawn(state);
  1645. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1646. if (spawn && spawn2)
  1647. spawn->AddAllowAccessSpawn(spawn2);
  1648. lua_interface->ResetFunctionStack(state);
  1649. return 0;
  1650. }
  1651. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1652. if (!lua_interface)
  1653. return 0;
  1654. Spawn* target = lua_interface->GetSpawn(state);
  1655. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1656. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1657. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1658. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1659. lua_interface->ResetFunctionStack(state);
  1660. if (!target) {
  1661. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1662. return 0;
  1663. }
  1664. if (!target->IsEntity()) {
  1665. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1666. return 0;
  1667. }
  1668. if (spell_id <= 0) {
  1669. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1670. return 0;
  1671. }
  1672. if (caster && !caster->IsEntity()) {
  1673. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1674. return 0;
  1675. }
  1676. if (spell_tier == 0)
  1677. spell_tier = 1;
  1678. if (!caster)
  1679. caster = target;
  1680. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1681. return 0;
  1682. }
  1683. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1684. if (!lua_interface)
  1685. return 0;
  1686. Spawn* target = lua_interface->GetSpawn(state);
  1687. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1688. if(!luaspell || luaspell->resisted) {
  1689. lua_interface->ResetFunctionStack(state);
  1690. lua_interface->SetBooleanValue(state, false);
  1691. return 1;
  1692. }
  1693. Spawn* caster = luaspell->caster;
  1694. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1695. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1696. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1697. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1698. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1699. //lua_interface->ResetFunctionStack(state);
  1700. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1701. vector<int16> faction_req;
  1702. vector<int16> race_req;
  1703. int32 class_req = 0;
  1704. int32 i = 0;
  1705. int8 f = 0;
  1706. int8 r = 0;
  1707. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1708. if (class_id < 100) {
  1709. class_req += pow(2.0, double(class_id - 1));
  1710. }
  1711. else if (class_id > 100 && class_id < 1000) {
  1712. race_req.push_back(class_id);
  1713. r++;
  1714. }
  1715. else {
  1716. faction_req.push_back(class_id);
  1717. f++;
  1718. }
  1719. i++;
  1720. }
  1721. lua_interface->ResetFunctionStack(state);
  1722. if (caster && caster->IsEntity()) {
  1723. bool race_match = false;
  1724. bool success = false;
  1725. luaspell->resisted = false;
  1726. if (luaspell->targets.size() > 0) {
  1727. ZoneServer* zone = luaspell->caster->GetZone();
  1728. Spawn* target = 0;
  1729. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1730. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1731. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1732. if (race_req.size() > 0) {
  1733. for (int8 i = 0; i < race_req.size(); i++) {
  1734. if(race_req[i] == target->GetRace() ||
  1735. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1736. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1737. race_match = true;
  1738. }
  1739. }
  1740. }
  1741. else
  1742. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1743. if (race_match == true) {
  1744. float distance = caster->GetDistance(target, true);
  1745. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1746. }
  1747. }
  1748. }
  1749. success = true;
  1750. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1751. }
  1752. else if (target) {
  1753. //check class and race/faction here
  1754. if (race_req.size() > 0) {
  1755. for (int8 i = 0; i < race_req.size(); i++) {
  1756. if(race_req[i] == target->GetRace() ||
  1757. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1758. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1759. race_match = true;
  1760. }
  1761. }
  1762. }
  1763. else
  1764. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1765. if (race_match == true) {
  1766. float distance = caster->GetDistance(target, true);
  1767. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1768. success = true;
  1769. }
  1770. }
  1771. lua_interface->SetBooleanValue(state, luaspell->has_damaged);
  1772. if (success) {
  1773. Spell* spell = luaspell->spell;
  1774. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1775. ((Player*)caster)->InCombat(true);
  1776. if (caster->GetZone())
  1777. caster->GetZone()->TriggerCharSheetTimer();
  1778. }
  1779. }
  1780. }
  1781. else {
  1782. lua_interface->SetBooleanValue(state, false);
  1783. }
  1784. return 1;
  1785. }
  1786. int EQ2Emu_lua_SpellDamageExt(lua_State* state) {
  1787. if (!lua_interface)
  1788. return 0;
  1789. Spawn* target = lua_interface->GetSpawn(state);
  1790. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1791. if(!luaspell || luaspell->resisted) {
  1792. lua_interface->ResetFunctionStack(state);
  1793. lua_interface->SetBooleanValue(state, false);
  1794. return 1;
  1795. }
  1796. Spawn* caster = luaspell->caster;
  1797. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1798. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1799. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1800. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1801. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1802. int32 override_packet_type = lua_interface->GetInt32Value(state, 7);
  1803. bool take_power = lua_interface->GetInt32Value(state, 8) == 1;
  1804. //lua_interface->ResetFunctionStack(state);
  1805. int32 class_id = lua_interface->GetInt32Value(state, 9);
  1806. vector<int16> faction_req;
  1807. vector<int16> race_req;
  1808. int32 class_req = 0;
  1809. int32 i = 0;
  1810. int8 f = 0;
  1811. int8 r = 0;
  1812. while ((class_id = lua_interface->GetInt32Value(state, 9 + i))) {
  1813. if (class_id < 100) {
  1814. class_req += pow(2.0, double(class_id - 1));
  1815. }
  1816. else if (class_id > 100 && class_id < 1000) {
  1817. race_req.push_back(class_id);
  1818. r++;
  1819. }
  1820. else {
  1821. faction_req.push_back(class_id);
  1822. f++;
  1823. }
  1824. i++;
  1825. }
  1826. lua_interface->ResetFunctionStack(state);
  1827. if (caster && caster->IsEntity()) {
  1828. bool race_match = false;
  1829. bool success = false;
  1830. luaspell->resisted = false;
  1831. if (luaspell->targets.size() > 0) {
  1832. ZoneServer* zone = luaspell->caster->GetZone();
  1833. Spawn* target = 0;
  1834. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1835. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1836. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1837. if (race_req.size() > 0) {
  1838. for (int8 i = 0; i < race_req.size(); i++) {
  1839. if(race_req[i] == target->GetRace() ||
  1840. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1841. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1842. race_match = true;
  1843. }
  1844. }
  1845. }
  1846. else
  1847. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1848. if (race_match == true) {
  1849. float distance = caster->GetDistance(target, true);
  1850. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power);
  1851. }
  1852. }
  1853. }
  1854. success = true;
  1855. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1856. }
  1857. else if (target) {
  1858. //check class and race/faction here
  1859. if (race_req.size() > 0) {
  1860. for (int8 i = 0; i < race_req.size(); i++) {
  1861. if(race_req[i] == target->GetRace() ||
  1862. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1863. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1864. race_match = true;
  1865. }
  1866. }
  1867. }
  1868. else
  1869. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1870. if (race_match == true) {
  1871. float distance = caster->GetDistance(target, true);
  1872. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power))
  1873. success = true;
  1874. }
  1875. }
  1876. lua_interface->SetBooleanValue(state, luaspell->has_damaged);
  1877. if (success) {
  1878. Spell* spell = luaspell->spell;
  1879. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1880. ((Player*)caster)->InCombat(true);
  1881. if (caster->GetZone())
  1882. caster->GetZone()->TriggerCharSheetTimer();
  1883. }
  1884. }
  1885. }
  1886. else {
  1887. lua_interface->SetBooleanValue(state, false);
  1888. }
  1889. return 1;
  1890. }
  1891. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1892. if (!lua_interface)
  1893. return 0;
  1894. Spawn* spawn = lua_interface->GetSpawn(state);
  1895. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1896. lua_interface->ResetFunctionStack(state);
  1897. if (spawn && value != 0) {
  1898. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1899. spawn->SetPower(spawn->GetTotalPower());
  1900. else
  1901. spawn->SetPower(spawn->GetPower() + value);
  1902. }
  1903. return 0;
  1904. }
  1905. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1906. if (!lua_interface)
  1907. return 0;
  1908. Spawn* spawn = lua_interface->GetSpawn(state);
  1909. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1910. lua_interface->ResetFunctionStack(state);
  1911. if (spawn && value != 0) {
  1912. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1913. spawn->SetHP(spawn->GetTotalHP());
  1914. else
  1915. spawn->SetHP(spawn->GetHP() + value);
  1916. }
  1917. return 0;
  1918. }
  1919. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1920. if (!lua_interface)
  1921. return 0;
  1922. Spawn* spawn = lua_interface->GetSpawn(state);
  1923. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1924. lua_interface->ResetFunctionStack(state);
  1925. if (spawn && value != 0) {
  1926. spawn->SetTotalPower(value);
  1927. spawn->SetTotalPowerBaseInstance(value);
  1928. }
  1929. return 0;
  1930. }
  1931. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1932. if (!lua_interface)
  1933. return 0;
  1934. Spawn* spawn = lua_interface->GetSpawn(state);
  1935. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1936. lua_interface->ResetFunctionStack(state);
  1937. if (spawn && value != 0) {
  1938. spawn->SetTotalHP(value);
  1939. spawn->SetTotalHPBaseInstance(value);
  1940. }
  1941. return 0;
  1942. }
  1943. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1944. if (!lua_interface)
  1945. return 0;
  1946. Spawn* spawn = lua_interface->GetSpawn(state);
  1947. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1948. lua_interface->ResetFunctionStack(state);
  1949. if (spawn) {
  1950. spawn->SetHP(value);
  1951. if (value > spawn->GetTotalHPBase())
  1952. spawn->SetTotalHP(value);
  1953. }
  1954. return 0;
  1955. }
  1956. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1957. if (!lua_interface)
  1958. return 0;
  1959. Spawn* spawn = lua_interface->GetSpawn(state);
  1960. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1961. float value = lua_interface->GetFloatValue(state, 2);
  1962. lua_interface->ResetFunctionStack(state);
  1963. if (spawn && spawn->IsEntity() && value > 0)
  1964. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1965. if (spawn && spawn->IsPlayer())
  1966. ((Player*)spawn)->SetCharSheetChanged(true);
  1967. return 0;
  1968. }
  1969. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1970. if (!lua_interface)
  1971. return 0;
  1972. Spawn* spawn = lua_interface->GetSpawn(state);
  1973. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1974. lua_interface->ResetFunctionStack(state);
  1975. if (spawn && spawn->IsEntity() && value > 0)
  1976. ((Entity*)spawn)->SetTotalHPBase(value);
  1977. return 0;
  1978. }
  1979. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1980. if (!lua_interface)
  1981. return 0;
  1982. Spawn* spawn = lua_interface->GetSpawn(state);
  1983. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1984. lua_interface->ResetFunctionStack(state);
  1985. if (spawn && value > 0) {
  1986. spawn->SetPower(value);
  1987. if (value > spawn->GetTotalPowerBase())
  1988. spawn->SetTotalPower(value);
  1989. }
  1990. return 0;
  1991. }
  1992. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1993. if (!lua_interface)
  1994. return 0;
  1995. Spawn* spawn = lua_interface->GetSpawn(state);
  1996. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1997. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1998. lua_interface->ResetFunctionStack(state);
  1999. if (spawn && spawn->IsEntity() && value > 0)
  2000. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  2001. return 0;
  2002. }
  2003. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  2004. if (!lua_interface)
  2005. return 0;
  2006. Spawn* spawn = lua_interface->GetSpawn(state);
  2007. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2008. lua_interface->ResetFunctionStack(state);
  2009. if (spawn && spawn->IsEntity() && value > 0)
  2010. ((Entity*)spawn)->SetTotalPowerBase(value);
  2011. return 0;
  2012. }
  2013. int EQ2Emu_lua_SetPosition(lua_State* state) {
  2014. if (!lua_interface)
  2015. return 0;
  2016. Spawn* spawn = lua_interface->GetSpawn(state);
  2017. float x = lua_interface->GetFloatValue(state, 2);
  2018. float y = lua_interface->GetFloatValue(state, 3);
  2019. float z = lua_interface->GetFloatValue(state, 4);
  2020. float heading = lua_interface->GetFloatValue(state, 5);
  2021. lua_interface->ResetFunctionStack(state);
  2022. if (spawn) {
  2023. spawn->SetX(x);
  2024. spawn->SetY(y);
  2025. spawn->SetZ(z);
  2026. if (heading != 0)
  2027. spawn->SetHeading(heading);
  2028. spawn->SetSpawnOrigX(spawn->GetX());
  2029. spawn->SetSpawnOrigY(spawn->GetY());
  2030. spawn->SetSpawnOrigZ(spawn->GetZ());
  2031. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  2032. if (spawn->IsPlayer()) {
  2033. Client* client = ((Player*)spawn)->GetClient();
  2034. if (client) {
  2035. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  2036. client->QueuePacket(packet);
  2037. }
  2038. }
  2039. }
  2040. return 0;
  2041. }
  2042. int EQ2Emu_lua_SetHeading(lua_State* state) {
  2043. if (!lua_interface)
  2044. return 0;
  2045. Spawn* spawn = lua_interface->GetSpawn(state);
  2046. float value = lua_interface->GetFloatValue(state, 2);
  2047. lua_interface->ResetFunctionStack(state);
  2048. if (spawn) {
  2049. spawn->SetHeading(value);
  2050. if (spawn->IsPlayer()) {
  2051. Client* client = ((Player*)spawn)->GetClient();
  2052. if (client) {
  2053. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  2054. client->QueuePacket(packet);
  2055. }
  2056. }
  2057. }
  2058. return 0;
  2059. }
  2060. int EQ2Emu_lua_SetModelType(lua_State* state) {
  2061. if (!lua_interface)
  2062. return 0;
  2063. Spawn* spawn = lua_interface->GetSpawn(state);
  2064. int16 value = lua_interface->GetInt16Value(state, 2);
  2065. lua_interface->ResetFunctionStack(state);
  2066. if (spawn)
  2067. spawn->SetModelType(value);
  2068. return 0;
  2069. }
  2070. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  2071. if (!lua_interface)
  2072. return 0;
  2073. Spawn* spawn = lua_interface->GetSpawn(state);
  2074. int8 value = lua_interface->GetInt8Value(state, 2);
  2075. lua_interface->ResetFunctionStack(state);
  2076. if (spawn) {
  2077. if (spawn->IsPlayer())
  2078. ((Player*)spawn)->SetPlayerAdventureClass(value);
  2079. else
  2080. spawn->SetAdventureClass(value);
  2081. }
  2082. return 0;
  2083. }
  2084. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  2085. if (!lua_interface)
  2086. return 0;
  2087. Spawn* spawn = lua_interface->GetSpawn(state);
  2088. int8 value = lua_interface->GetInt8Value(state, 2);
  2089. lua_interface->ResetFunctionStack(state);
  2090. if (spawn) {
  2091. spawn->SetTradeskillClass(value);
  2092. if (spawn->IsEntity()) {
  2093. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  2094. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  2095. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  2096. }
  2097. if (spawn->IsPlayer())
  2098. ((Player*)spawn)->SetCharSheetChanged(true);
  2099. }
  2100. return 0;
  2101. }
  2102. int EQ2Emu_lua_SetMount(lua_State* state) {
  2103. if (!lua_interface)
  2104. return 0;
  2105. Spawn* spawn = lua_interface->GetSpawn(state);
  2106. int16 value = lua_interface->GetInt16Value(state, 2);
  2107. if (spawn && spawn->IsEntity()) {
  2108. ((Entity*)spawn)->SetMount(value);
  2109. EQ2_Color color;
  2110. color.red = 255;
  2111. color.green = 255;
  2112. color.blue = 255;
  2113. ((Entity*)spawn)->SetMountColor(&color);
  2114. ((Entity*)spawn)->SetMountSaddleColor(&color);
  2115. }
  2116. return 0;
  2117. }
  2118. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  2119. if (!lua_interface)
  2120. return 0;
  2121. Spawn* spawn = lua_interface->GetSpawn(state);
  2122. EQ2_Color mount_color;
  2123. EQ2_Color saddle_color;
  2124. mount_color.red = lua_interface->GetInt8Value(state, 2);
  2125. mount_color.green = lua_interface->GetInt8Value(state, 3);
  2126. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  2127. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  2128. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  2129. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  2130. if (spawn && spawn->IsEntity()) {
  2131. ((Entity*)spawn)->SetMountColor(&mount_color);
  2132. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  2133. }
  2134. return 0;
  2135. }
  2136. int EQ2Emu_lua_GetMount(lua_State* state) {
  2137. if (!lua_interface)
  2138. return 0;
  2139. Spawn* spawn = lua_interface->GetSpawn(state);
  2140. if (spawn && spawn->IsEntity()) {
  2141. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2142. return 1;
  2143. }
  2144. return 0;
  2145. }
  2146. int EQ2Emu_lua_GetRace(lua_State* state) {
  2147. if (!lua_interface)
  2148. return 0;
  2149. Spawn* spawn = lua_interface->GetSpawn(state);
  2150. if (spawn)
  2151. {
  2152. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2153. lua_interface->SetInt32Value(state, spawn->GetRace());
  2154. return 1;
  2155. }
  2156. return 0;
  2157. }
  2158. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2159. if (!lua_interface)
  2160. return 0;
  2161. Spawn* spawn = lua_interface->GetSpawn(state);
  2162. if (spawn) {
  2163. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2164. return 1;
  2165. }
  2166. return 0;
  2167. }
  2168. int EQ2Emu_lua_GetClass(lua_State* state) {
  2169. Spawn* spawn = lua_interface->GetSpawn(state);
  2170. if (spawn) {
  2171. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2172. return 1;
  2173. }
  2174. return 0;
  2175. }
  2176. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2177. Spawn* spawn = lua_interface->GetSpawn(state);
  2178. if (spawn) {
  2179. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2180. return 1;
  2181. }
  2182. return 0;
  2183. }
  2184. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2185. if (!lua_interface)
  2186. return 0;
  2187. Spawn* spawn = lua_interface->GetSpawn(state);
  2188. float value = lua_interface->GetFloatValue(state, 2);
  2189. lua_interface->ResetFunctionStack(state);
  2190. if (spawn) {
  2191. spawn->SetSpeed(value);
  2192. if(spawn->IsEntity())
  2193. ((Entity*)spawn)->SetSpeed(value);
  2194. if (spawn->IsPlayer()) {
  2195. Client* client = ((Player*)spawn)->GetClient();
  2196. if (client) {
  2197. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2198. if (packet) {
  2199. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2200. packet->setDataByName("speed", value);
  2201. packet->setDataByName("size", 0.51);
  2202. EQ2Packet* app = packet->serialize();
  2203. client->QueuePacket(app);
  2204. safe_delete(packet);
  2205. }
  2206. }
  2207. }
  2208. }
  2209. return 0;
  2210. }
  2211. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2212. if (!lua_interface)
  2213. return 0;
  2214. Spawn* spawn = lua_interface->GetSpawn(state);
  2215. const int16 type = lua_interface->GetInt16Value(state, 2);
  2216. const float value = lua_interface->GetFloatValue(state, 3);
  2217. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2218. if(!luaspell || luaspell->resisted) {
  2219. lua_interface->ResetFunctionStack(state);
  2220. return 0;
  2221. }
  2222. int64 class_req = 0;
  2223. int32 class_id = 0;
  2224. vector<int16> faction_req;
  2225. vector<int16> race_req;
  2226. int32 i = 0;
  2227. int8 f = 0;
  2228. int8 r = 0;
  2229. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2230. if (class_id < 100) {
  2231. class_req += pow(2.0, double(class_id - 1));
  2232. }
  2233. else if (class_id > 100 && class_id < 1000) {
  2234. race_req.push_back(class_id);
  2235. r++;
  2236. }
  2237. else {
  2238. faction_req.push_back(class_id);
  2239. f++;
  2240. }
  2241. i++;
  2242. }
  2243. if (value != 0 && type >= 0) {
  2244. if (luaspell && luaspell->spell && luaspell->caster) {
  2245. ZoneServer* zone = luaspell->caster->GetZone();
  2246. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2247. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2248. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2249. if (target) {
  2250. if (target->IsPlayer()) {
  2251. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2252. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2253. if (((Player*)target)->GetGroupMemberInfo())
  2254. ((Player*)target)->UpdateGroupMemberInfo();
  2255. ((Player*)target)->SetCharSheetChanged(true);
  2256. }
  2257. else if (target->IsNPC())
  2258. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2259. else
  2260. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2261. }
  2262. }
  2263. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2264. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2265. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2266. }
  2267. else if (spawn && spawn->IsEntity()) {
  2268. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2269. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2270. if (spawn->IsPlayer())
  2271. ((Player*)spawn)->SetCharSheetChanged(true);
  2272. }
  2273. else
  2274. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2275. }
  2276. else
  2277. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2278. return 0;
  2279. }
  2280. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2281. if (!lua_interface)
  2282. return 0;
  2283. Spawn* spawn = lua_interface->GetSpawn(state);
  2284. int16 type = lua_interface->GetInt16Value(state, 2);
  2285. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2286. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2287. if (!spawn) {
  2288. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2289. return 0;
  2290. }
  2291. if (!spawn->IsEntity()) {
  2292. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2293. return 0;
  2294. }
  2295. if (value == 0) {
  2296. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2297. return 0;
  2298. }
  2299. if (!luaspell || !luaspell->spell) {
  2300. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2301. return 0;
  2302. }
  2303. if(luaspell->resisted) {
  2304. lua_interface->ResetFunctionStack(state);
  2305. return 0;
  2306. }
  2307. int32 class_req = 0;
  2308. vector<int16> faction_req;
  2309. vector<int16> race_req;
  2310. int32 class_id = 0;
  2311. int32 i = 0;
  2312. int8 f = 0;
  2313. int8 r = 0;
  2314. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2315. if (class_id < 100) {
  2316. class_req += pow(2.0, double(class_id - 1));
  2317. }
  2318. else if (class_id > 100 && class_id < 1000) {
  2319. race_req.push_back(class_id);
  2320. r++;
  2321. }
  2322. else {
  2323. faction_req.push_back(class_id);
  2324. f++;
  2325. }
  2326. i++;
  2327. }
  2328. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2329. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2330. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2331. if (spawn->IsPlayer())
  2332. ((Player*)spawn)->SetCharSheetChanged(true);
  2333. return 0;
  2334. }
  2335. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2336. if (!lua_interface)
  2337. return 0;
  2338. Spawn* spawn = lua_interface->GetSpawn(state);
  2339. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2340. if (!spawn) {
  2341. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2342. return 0;
  2343. }
  2344. if (!spawn->IsEntity()) {
  2345. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2346. return 0;
  2347. }
  2348. if (!luaspell || !luaspell->spell) {
  2349. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2350. return 0;
  2351. }
  2352. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2353. if (spawn->IsPlayer())
  2354. ((Player*)spawn)->SetCharSheetChanged(true);
  2355. return 0;
  2356. }
  2357. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2358. if (!lua_interface)
  2359. return 0;
  2360. Spawn* spawn = lua_interface->GetSpawn(state);
  2361. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2362. if (luaspell && luaspell->spell) {
  2363. ZoneServer* zone = nullptr;
  2364. if (luaspell->caster != nullptr)
  2365. zone = luaspell->caster->GetZone();
  2366. if(!zone && spawn) {
  2367. zone = spawn->GetZone(); // workaround to try to establish a zone to find the targets and remove the spells
  2368. }
  2369. Spawn* target = 0;
  2370. if(zone) {
  2371. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2372. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2373. target = zone->GetSpawnByID(luaspell->targets[i]);
  2374. if (target && target->IsEntity()) {
  2375. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2376. if (target->IsPlayer())
  2377. ((Player*)target)->SetCharSheetChanged(true);
  2378. }
  2379. }
  2380. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2381. }
  2382. else {
  2383. 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());
  2384. }
  2385. }
  2386. else if (spawn && spawn->IsEntity()) {
  2387. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2388. if (spawn->IsPlayer())
  2389. ((Player*)spawn)->SetCharSheetChanged(true);
  2390. }
  2391. return 0;
  2392. }
  2393. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2394. if (!lua_interface)
  2395. return 0;
  2396. Spawn* spawn = lua_interface->GetSpawn(state);
  2397. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2398. float value = lua_interface->GetFloatValue(state, 3);
  2399. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2400. if (value != 0) {
  2401. int32 spell_id = 0;
  2402. if (luaspell && luaspell->spell && luaspell->caster) {
  2403. if(luaspell->resisted) {
  2404. lua_interface->ResetFunctionStack(state);
  2405. return 0;
  2406. }
  2407. spell_id = luaspell->spell->GetSpellID();
  2408. ZoneServer* zone = luaspell->caster->GetZone();
  2409. Spawn* target = 0;
  2410. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2411. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2412. target = zone->GetSpawnByID(luaspell->targets[i]);
  2413. if (target && target->Alive()) {
  2414. if (target->IsPlayer()) {
  2415. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2416. Client* client = ((Player*)target)->GetClient();
  2417. if (client) {
  2418. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2419. if (packet)
  2420. client->QueuePacket(packet);
  2421. }
  2422. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2423. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2424. }
  2425. else if (target->IsNPC()) {
  2426. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2427. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2428. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2429. }
  2430. else
  2431. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2432. }
  2433. }
  2434. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2435. }
  2436. else if (spawn) {
  2437. if (spawn->IsPlayer()) {
  2438. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2439. Client* client = ((Player*)spawn)->GetClient();
  2440. if (client) {
  2441. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2442. if (packet)
  2443. client->QueuePacket(packet);
  2444. }
  2445. }
  2446. else if (spawn->IsNPC())
  2447. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2448. else
  2449. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2450. }
  2451. }
  2452. else
  2453. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2454. return 0;
  2455. }
  2456. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2457. if (!lua_interface)
  2458. return 0;
  2459. Spawn* spawn = lua_interface->GetSpawn(state);
  2460. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2461. if (spawn && spawn->IsPlayer()) {
  2462. int32 spell_id = 0;
  2463. if (luaspell && luaspell->spell && luaspell->caster) {
  2464. if(luaspell->resisted) {
  2465. lua_interface->ResetFunctionStack(state);
  2466. return 0;
  2467. }
  2468. spell_id = luaspell->spell->GetSpellID();
  2469. ZoneServer* zone = luaspell->caster->GetZone();
  2470. Spawn* target = 0;
  2471. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2472. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2473. target = zone->GetSpawnByID(luaspell->targets[i]);
  2474. if (target) {
  2475. if (target->IsPlayer()) {
  2476. ((Player*)target)->RemoveSkillBonus(spell_id);
  2477. Client* client = ((Player*)target)->GetClient();
  2478. if (client) {
  2479. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2480. if (packet)
  2481. client->QueuePacket(packet);
  2482. }
  2483. }
  2484. else if (target->IsNPC())
  2485. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2486. else
  2487. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2488. }
  2489. }
  2490. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2491. }
  2492. else if (spawn) {
  2493. if (spawn->IsPlayer()) {
  2494. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2495. Client* client = ((Player*)spawn)->GetClient();
  2496. if (client) {
  2497. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2498. if (packet)
  2499. client->QueuePacket(packet);
  2500. }
  2501. }
  2502. else if (spawn->IsNPC())
  2503. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2504. else
  2505. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2506. }
  2507. }
  2508. return 0;
  2509. }
  2510. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2511. if (!lua_interface)
  2512. return 0;
  2513. Spawn* spawn = lua_interface->GetSpawn(state);
  2514. int8 type = lua_interface->GetInt32Value(state, 2);
  2515. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2516. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2517. if(luaspell && luaspell->resisted) {
  2518. lua_interface->ResetFunctionStack(state);
  2519. return 0;
  2520. }
  2521. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2522. ZoneServer* zone = luaspell->caster->GetZone();
  2523. Spawn* target = 0;
  2524. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2525. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2526. target = zone->GetSpawnByID(luaspell->targets[i]);
  2527. if (target && target->IsEntity()) {
  2528. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2529. ((Entity*)target)->AddMezSpell(luaspell);
  2530. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2531. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2532. if (target->IsNPC())
  2533. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2534. }
  2535. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2536. ((Entity*)target)->AddStifleSpell(luaspell);
  2537. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2538. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2539. if (target->IsNPC())
  2540. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2541. }
  2542. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2543. ((Entity*)target)->AddDazeSpell(luaspell);
  2544. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2545. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2546. if (target->IsNPC())
  2547. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2548. }
  2549. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2550. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2551. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2552. ((Entity*)target)->AddStunSpell(luaspell);
  2553. if (target->IsNPC())
  2554. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2555. }
  2556. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2557. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2558. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2559. ((Entity*)target)->AddRootSpell(luaspell);
  2560. if (target->IsNPC())
  2561. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2562. }
  2563. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2564. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2565. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2566. ((Entity*)target)->AddFearSpell(luaspell);
  2567. if (target->IsNPC())
  2568. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2569. }
  2570. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2571. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2572. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2573. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2574. }
  2575. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2576. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2577. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2578. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2579. }
  2580. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2581. ((Entity*)target)->AddSnareSpell(luaspell);
  2582. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2583. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2584. if (target->IsNPC())
  2585. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2586. }
  2587. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2588. ((Entity*)target)->AddFlightSpell(luaspell);
  2589. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2590. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2591. }
  2592. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2593. ((Entity*)target)->AddGlideSpell(luaspell);
  2594. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2595. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2596. }
  2597. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2598. ((Entity*)target)->AddSafefallSpell(luaspell);
  2599. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2600. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2601. }
  2602. else
  2603. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2604. }
  2605. else
  2606. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2607. }
  2608. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2609. }
  2610. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2611. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2612. ((Entity*)spawn)->AddMezSpell(luaspell);
  2613. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2614. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2615. }
  2616. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2617. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2618. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2619. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2620. }
  2621. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2622. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2623. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2624. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2625. }
  2626. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2627. ((Entity*)spawn)->AddStunSpell(luaspell);
  2628. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2629. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2630. }
  2631. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2632. ((Entity*)spawn)->AddRootSpell(luaspell);
  2633. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2634. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2635. }
  2636. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2637. ((Entity*)spawn)->AddFearSpell(luaspell);
  2638. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2639. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2640. }
  2641. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2642. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2643. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2644. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2645. }
  2646. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2647. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2648. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2649. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2650. }
  2651. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2652. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2653. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2654. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2655. }
  2656. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2657. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2658. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2659. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2660. }
  2661. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2662. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2663. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2664. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2665. }
  2666. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2667. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2668. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2669. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2670. }
  2671. else
  2672. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2673. }
  2674. else
  2675. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2676. return 0;
  2677. }
  2678. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2679. if (!lua_interface)
  2680. return 0;
  2681. Spawn* spawn = lua_interface->GetSpawn(state);
  2682. int8 type = lua_interface->GetInt8Value(state, 2);
  2683. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2684. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2685. if (spawn && spawn->IsEntity()) {
  2686. if (!only_remove_spawn && luaspell && luaspell->spell && luaspell->caster) {
  2687. ZoneServer* zone = luaspell->caster->GetZone();
  2688. Spawn* target = 0;
  2689. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2690. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2691. target = zone->GetSpawnByID(luaspell->targets[i]);
  2692. if (target) {
  2693. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2694. ((Entity*)target)->RemoveMezSpell(luaspell);
  2695. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2696. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2697. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2698. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2699. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2700. ((Entity*)target)->RemoveStunSpell(luaspell);
  2701. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2702. ((Entity*)target)->RemoveRootSpell(luaspell);
  2703. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2704. ((Entity*)target)->RemoveFearSpell(luaspell);
  2705. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2706. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2707. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2708. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2709. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2710. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2711. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2712. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2713. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2714. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2715. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2716. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2717. else
  2718. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2719. }
  2720. }
  2721. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2722. }
  2723. else if (only_remove_spawn) {
  2724. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2725. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2726. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2727. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2728. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2729. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2730. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2731. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2732. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2733. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2734. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2735. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2736. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2737. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2738. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2739. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2740. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2741. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2742. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2743. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2744. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2745. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2746. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2747. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2748. else
  2749. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2750. }
  2751. }
  2752. return 0;
  2753. }
  2754. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2755. if (!lua_interface)
  2756. return 0;
  2757. Spawn* spawn = lua_interface->GetSpawn(state);
  2758. int8 type = lua_interface->GetInt8Value(state, 2);
  2759. bool hasEffect = false;
  2760. if (!spawn)
  2761. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2762. else if (!spawn->IsEntity())
  2763. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2764. else if (type < CONTROL_MAX_EFFECTS)
  2765. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2766. else
  2767. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2768. lua_interface->SetBooleanValue(state, hasEffect);
  2769. return 1;
  2770. }
  2771. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2772. if (!lua_interface)
  2773. return 0;
  2774. Spawn* spawn = lua_interface->GetSpawn(state);
  2775. float distance = 0.0f;
  2776. if (!spawn)
  2777. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2778. else if (!spawn->IsNPC())
  2779. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2780. else
  2781. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2782. lua_interface->SetFloatValue(state, distance);
  2783. return 1;
  2784. }
  2785. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2786. if (!lua_interface)
  2787. return 0;
  2788. Spawn* spawn = lua_interface->GetSpawn(state);
  2789. float distance = 0.0f;
  2790. if (!spawn)
  2791. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2792. else if (!spawn->IsNPC())
  2793. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2794. else
  2795. distance = ((NPC*)spawn)->GetAggroRadius();
  2796. lua_interface->SetFloatValue(state, distance);
  2797. return 1;
  2798. }
  2799. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2800. if (!lua_interface)
  2801. return 0;
  2802. Spawn* spawn = lua_interface->GetSpawn(state);
  2803. float distance = lua_interface->GetFloatValue(state, 2);
  2804. bool override = lua_interface->GetBooleanValue(state, 3);
  2805. bool result = false;
  2806. lua_interface->ResetFunctionStack(state);
  2807. if (!spawn)
  2808. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2809. else if (!spawn->IsNPC())
  2810. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2811. else
  2812. {
  2813. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2814. result = true;
  2815. }
  2816. lua_interface->SetBooleanValue(state, result);
  2817. return 1;
  2818. }
  2819. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2820. if (!lua_interface)
  2821. return 0;
  2822. Spawn* spawn = lua_interface->GetSpawn(state);
  2823. int16 value = lua_interface->GetInt16Value(state, 2);
  2824. if (spawn && spawn->IsEntity()) {
  2825. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2826. if (spawn->IsPlayer())
  2827. ((Player*)spawn)->SetCharSheetChanged(true);
  2828. }
  2829. return 0;
  2830. }
  2831. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2832. if (!lua_interface)
  2833. return 0;
  2834. Spawn* spawn = lua_interface->GetSpawn(state);
  2835. int16 value = lua_interface->GetInt16Value(state, 2);
  2836. if (spawn && spawn->IsEntity()) {
  2837. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2838. if (spawn->IsPlayer())
  2839. ((Player*)spawn)->SetCharSheetChanged(true);
  2840. }
  2841. return 0;
  2842. }
  2843. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2844. if (!lua_interface)
  2845. return 0;
  2846. Spawn* spawn = lua_interface->GetSpawn(state);
  2847. int16 value = lua_interface->GetInt16Value(state, 2);
  2848. if (spawn && spawn->IsEntity()) {
  2849. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2850. if (spawn->IsPlayer())
  2851. ((Player*)spawn)->SetCharSheetChanged(true);
  2852. }
  2853. return 0;
  2854. }
  2855. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2856. if (!lua_interface)
  2857. return 0;
  2858. Spawn* spawn = lua_interface->GetSpawn(state);
  2859. int16 value = lua_interface->GetInt16Value(state, 2);
  2860. if (spawn && spawn->IsEntity()) {
  2861. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2862. if (spawn->IsPlayer())
  2863. ((Player*)spawn)->SetCharSheetChanged(true);
  2864. }
  2865. return 0;
  2866. }
  2867. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2868. if (!lua_interface)
  2869. return 0;
  2870. Spawn* spawn = lua_interface->GetSpawn(state);
  2871. int16 value = lua_interface->GetInt16Value(state, 2);
  2872. if (spawn && spawn->IsEntity()) {
  2873. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2874. if (spawn->IsPlayer())
  2875. ((Player*)spawn)->SetCharSheetChanged(true);
  2876. }
  2877. return 0;
  2878. }
  2879. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2880. if (!lua_interface)
  2881. return 0;
  2882. Spawn* spawn = lua_interface->GetSpawn(state);
  2883. int8 value = lua_interface->GetInt8Value(state, 2);
  2884. if (spawn && spawn->IsEntity()) {
  2885. ((Entity*)spawn)->SetDeity(value);
  2886. if (spawn->IsPlayer())
  2887. ((Player*)spawn)->SetCharSheetChanged(true);
  2888. }
  2889. lua_interface->ResetFunctionStack(state);
  2890. return 0;
  2891. }
  2892. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2893. if (!lua_interface)
  2894. return 0;
  2895. Spawn* spawn = lua_interface->GetSpawn(state);
  2896. if (spawn && spawn->IsEntity()) {
  2897. int8 deity = ((Entity*)spawn)->GetDeity();
  2898. lua_interface->SetInt32Value(state, deity);
  2899. return 1;
  2900. }
  2901. return 0;
  2902. }
  2903. int EQ2Emu_lua_SetInt(lua_State* state) {
  2904. if (!lua_interface)
  2905. return 0;
  2906. Spawn* spawn = lua_interface->GetSpawn(state);
  2907. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2908. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2909. if (spawn && spawn->IsEntity()) {
  2910. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_INT, value);
  2911. if (spawn->IsPlayer())
  2912. ((Player*)spawn)->SetCharSheetChanged(true);
  2913. }
  2914. return 0;
  2915. }
  2916. int EQ2Emu_lua_SetWis(lua_State* state) {
  2917. if (!lua_interface)
  2918. return 0;
  2919. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2920. Spawn* spawn = lua_interface->GetSpawn(state);
  2921. float value = lua_interface->GetFloatValue(state, 2);
  2922. if (spawn && spawn->IsEntity()) {
  2923. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_WIS, value);
  2924. if (spawn->IsPlayer())
  2925. ((Player*)spawn)->SetCharSheetChanged(true);
  2926. }
  2927. return 0;
  2928. }
  2929. int EQ2Emu_lua_SetSta(lua_State* state) {
  2930. if (!lua_interface)
  2931. return 0;
  2932. Spawn* spawn = lua_interface->GetSpawn(state);
  2933. float value = lua_interface->GetFloatValue(state, 2);
  2934. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2935. if (spawn && spawn->IsEntity()) {
  2936. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STA, value);
  2937. if (spawn->IsPlayer())
  2938. ((Player*)spawn)->SetCharSheetChanged(true);
  2939. }
  2940. return 0;
  2941. }
  2942. int EQ2Emu_lua_SetStr(lua_State* state) {
  2943. if (!lua_interface)
  2944. return 0;
  2945. Spawn* spawn = lua_interface->GetSpawn(state);
  2946. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2947. float value = lua_interface->GetFloatValue(state, 2);
  2948. if (spawn && spawn->IsEntity()) {
  2949. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STR, value);
  2950. if (spawn->IsPlayer())
  2951. ((Player*)spawn)->SetCharSheetChanged(true);
  2952. }
  2953. return 0;
  2954. }
  2955. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2956. if (!lua_interface)
  2957. return 0;
  2958. Spawn* spawn = lua_interface->GetSpawn(state);
  2959. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2960. float value = lua_interface->GetFloatValue(state, 2);
  2961. if (spawn && spawn->IsEntity()) {
  2962. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_AGI, value);
  2963. if (spawn->IsPlayer())
  2964. ((Player*)spawn)->SetCharSheetChanged(true);
  2965. }
  2966. return 0;
  2967. }
  2968. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2969. if (!lua_interface)
  2970. return 0;
  2971. Spawn* spawn = lua_interface->GetSpawn(state);
  2972. if (spawn) {
  2973. lua_interface->SetInt32Value(state, spawn->GetHP());
  2974. return 1;
  2975. }
  2976. return 0;
  2977. }
  2978. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2979. if (!lua_interface)
  2980. return 0;
  2981. Spawn* spawn = lua_interface->GetSpawn(state);
  2982. if (spawn) {
  2983. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2984. return 1;
  2985. }
  2986. return 0;
  2987. }
  2988. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2989. if (!lua_interface)
  2990. return 0;
  2991. Spawn* spawn = lua_interface->GetSpawn(state);
  2992. if (spawn) {
  2993. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2994. return 1;
  2995. }
  2996. return 0;
  2997. }
  2998. int EQ2Emu_lua_GetName(lua_State* state) {
  2999. if (!lua_interface)
  3000. return 0;
  3001. Spawn* spawn = lua_interface->GetSpawn(state);
  3002. if (spawn) {
  3003. lua_interface->SetStringValue(state, spawn->GetName());
  3004. return 1;
  3005. }
  3006. return 0;
  3007. }
  3008. int EQ2Emu_lua_GetLevel(lua_State* state) {
  3009. Spawn* spawn = lua_interface->GetSpawn(state);
  3010. if (spawn) {
  3011. lua_interface->SetInt32Value(state, spawn->GetLevel());
  3012. return 1;
  3013. }
  3014. return 0;
  3015. }
  3016. int EQ2Emu_lua_GetDifficulty(lua_State* state) {
  3017. Spawn* spawn = lua_interface->GetSpawn(state);
  3018. if (spawn) {
  3019. lua_interface->SetInt32Value(state, spawn->GetDifficulty());
  3020. return 1;
  3021. }
  3022. return 0;
  3023. }
  3024. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  3025. if (!lua_interface)
  3026. return 0;
  3027. Spawn* spawn = lua_interface->GetSpawn(state);
  3028. if (spawn) {
  3029. lua_interface->SetInt32Value(state, spawn->GetPower());
  3030. return 1;
  3031. }
  3032. return 0;
  3033. }
  3034. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  3035. if (!lua_interface)
  3036. return 0;
  3037. Spawn* spawn = lua_interface->GetSpawn(state);
  3038. if (spawn) {
  3039. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  3040. return 1;
  3041. }
  3042. return 0;
  3043. }
  3044. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  3045. if (!lua_interface)
  3046. return 0;
  3047. Spawn* spawn = lua_interface->GetSpawn(state);
  3048. if (spawn) {
  3049. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  3050. return 1;
  3051. }
  3052. return 0;
  3053. }
  3054. int EQ2Emu_lua_GetDistance(lua_State* state) {
  3055. if (!lua_interface)
  3056. return 0;
  3057. Spawn* spawn = lua_interface->GetSpawn(state);
  3058. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  3059. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  3060. if (spawn && spawn2) {
  3061. float distance = spawn->GetDistance(spawn2, false, include_radius);
  3062. lua_interface->SetFloatValue(state, distance);
  3063. return 1;
  3064. }
  3065. return 0;
  3066. }
  3067. int EQ2Emu_lua_GetX(lua_State* state) {
  3068. if (!lua_interface)
  3069. return 0;
  3070. Spawn* spawn = lua_interface->GetSpawn(state);
  3071. if (spawn) {
  3072. lua_interface->SetFloatValue(state, spawn->GetX());
  3073. return 1;
  3074. }
  3075. return 0;
  3076. }
  3077. int EQ2Emu_lua_GetY(lua_State* state) {
  3078. if (!lua_interface)
  3079. return 0;
  3080. Spawn* spawn = lua_interface->GetSpawn(state);
  3081. if (spawn) {
  3082. lua_interface->SetFloatValue(state, spawn->GetY());
  3083. return 1;
  3084. }
  3085. return 0;
  3086. }
  3087. int EQ2Emu_lua_GetZ(lua_State* state) {
  3088. if (!lua_interface)
  3089. return 0;
  3090. Spawn* spawn = lua_interface->GetSpawn(state);
  3091. if (spawn) {
  3092. lua_interface->SetFloatValue(state, spawn->GetZ());
  3093. return 1;
  3094. }
  3095. return 0;
  3096. }
  3097. int EQ2Emu_lua_GetHeading(lua_State* state) {
  3098. if (!lua_interface)
  3099. return 0;
  3100. Spawn* spawn = lua_interface->GetSpawn(state);
  3101. if (spawn) {
  3102. lua_interface->SetFloatValue(state, spawn->GetHeading());
  3103. return 1;
  3104. }
  3105. return 0;
  3106. }
  3107. int EQ2Emu_lua_GetModelType(lua_State* state) {
  3108. if (!lua_interface)
  3109. return 0;
  3110. Spawn* spawn = lua_interface->GetSpawn(state);
  3111. if (spawn) {
  3112. lua_interface->SetInt32Value(state, spawn->GetModelType());
  3113. return 1;
  3114. }
  3115. return 0;
  3116. }
  3117. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  3118. if (!lua_interface)
  3119. return 0;
  3120. Spawn* spawn = lua_interface->GetSpawn(state);
  3121. if (spawn) {
  3122. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  3123. return 1;
  3124. }
  3125. return 0;
  3126. }
  3127. int EQ2Emu_lua_HasMoved(lua_State* state) {
  3128. if (!lua_interface)
  3129. return 0;
  3130. Spawn* spawn = lua_interface->GetSpawn(state);
  3131. if (spawn && spawn->IsEntity()) {
  3132. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  3133. return 1;
  3134. }
  3135. return 0;
  3136. }
  3137. int EQ2Emu_lua_GetInt(lua_State* state) {
  3138. if (!lua_interface)
  3139. return 0;
  3140. Spawn* spawn = lua_interface->GetSpawn(state);
  3141. if (spawn && spawn->IsEntity()) {
  3142. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  3143. return 1;
  3144. }
  3145. return 0;
  3146. }
  3147. int EQ2Emu_lua_GetWis(lua_State* state) {
  3148. if (!lua_interface)
  3149. return 0;
  3150. Spawn* spawn = lua_interface->GetSpawn(state);
  3151. if (spawn && spawn->IsEntity()) {
  3152. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  3153. return 1;
  3154. }
  3155. return 0;
  3156. }
  3157. int EQ2Emu_lua_GetSta(lua_State* state) {
  3158. if (!lua_interface)
  3159. return 0;
  3160. Spawn* spawn = lua_interface->GetSpawn(state);
  3161. if (spawn && spawn->IsEntity()) {
  3162. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  3163. return 1;
  3164. }
  3165. return 0;
  3166. }
  3167. int EQ2Emu_lua_GetStr(lua_State* state) {
  3168. if (!lua_interface)
  3169. return 0;
  3170. Spawn* spawn = lua_interface->GetSpawn(state);
  3171. if (spawn && spawn->IsEntity()) {
  3172. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3173. return 1;
  3174. }
  3175. return 0;
  3176. }
  3177. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3178. if (!lua_interface)
  3179. return 0;
  3180. Spawn* spawn = lua_interface->GetSpawn(state);
  3181. if (spawn && spawn->IsEntity()) {
  3182. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3183. return 1;
  3184. }
  3185. return 0;
  3186. }
  3187. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3188. if (!lua_interface)
  3189. return 0;
  3190. Spawn* spawn = lua_interface->GetSpawn(state);
  3191. if (spawn && spawn->IsEntity()) {
  3192. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3193. return 1;
  3194. }
  3195. return 0;
  3196. }
  3197. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3198. if (!lua_interface)
  3199. return 0;
  3200. Spawn* spawn = lua_interface->GetSpawn(state);
  3201. if (spawn && spawn->IsEntity()) {
  3202. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3203. return 1;
  3204. }
  3205. return 0;
  3206. }
  3207. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3208. if (!lua_interface)
  3209. return 0;
  3210. Spawn* spawn = lua_interface->GetSpawn(state);
  3211. if (spawn && spawn->IsEntity()) {
  3212. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3213. return 1;
  3214. }
  3215. return 0;
  3216. }
  3217. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3218. if (!lua_interface)
  3219. return 0;
  3220. Spawn* spawn = lua_interface->GetSpawn(state);
  3221. if (spawn && spawn->IsEntity()) {
  3222. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3223. return 1;
  3224. }
  3225. return 0;
  3226. }
  3227. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3228. if (!lua_interface)
  3229. return 0;
  3230. Spawn* spawn = lua_interface->GetSpawn(state);
  3231. if (spawn && spawn->IsEntity()) {
  3232. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3233. return 1;
  3234. }
  3235. return 0;
  3236. }
  3237. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3238. if (!lua_interface)
  3239. return 0;
  3240. Spawn* player = lua_interface->GetSpawn(state);
  3241. if (!player || !player->IsPlayer()) {
  3242. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3243. return 0;
  3244. }
  3245. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3246. if (quest_id <= 0) {
  3247. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3248. return 0;
  3249. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3250. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3251. return 0;
  3252. }
  3253. int32 step = lua_interface->GetInt32Value(state, 3);
  3254. if (step > 0) {
  3255. Client* client = ((Player*)player)->GetClient();
  3256. if (client)
  3257. client->AddPendingQuestUpdate(quest_id, step);
  3258. } else {
  3259. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3260. }
  3261. return 0;
  3262. }
  3263. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3264. Spawn* player = lua_interface->GetSpawn(state);
  3265. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3266. int32 step = lua_interface->GetInt32Value(state, 3);
  3267. int32 progress = lua_interface->GetInt32Value(state, 4);
  3268. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3269. Client* client = ((Player*)player)->GetClient();
  3270. if (client)
  3271. client->AddPendingQuestUpdate(quest_id, step, progress);
  3272. }
  3273. return 0;
  3274. }
  3275. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3276. if (!lua_interface)
  3277. return 0;
  3278. Spawn* player = lua_interface->GetSpawn(state);
  3279. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3280. if (player && player->IsPlayer() && quest_id > 0) {
  3281. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3282. return 1;
  3283. }
  3284. return 0;
  3285. }
  3286. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3287. if (!lua_interface)
  3288. return 0;
  3289. Spawn* player = lua_interface->GetSpawn(state);
  3290. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3291. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3292. if (player && player->IsPlayer() && quest_id > 0) {
  3293. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3294. return 1;
  3295. }
  3296. return 0;
  3297. }
  3298. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3299. if (!lua_interface)
  3300. return 0;
  3301. Spawn* player = lua_interface->GetSpawn(state);
  3302. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3303. if (player && player->IsPlayer() && quest_id > 0) {
  3304. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3305. return 1;
  3306. }
  3307. return 0;
  3308. }
  3309. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3310. if (!lua_interface)
  3311. return 0;
  3312. Quest* quest = lua_interface->GetQuest(state);
  3313. string name = lua_interface->GetStringValue(state, 2);
  3314. string type = lua_interface->GetStringValue(state, 3);
  3315. string zone = lua_interface->GetStringValue(state, 4);
  3316. int16 level = lua_interface->GetInt16Value(state, 5);
  3317. string description = lua_interface->GetStringValue(state, 6);
  3318. bool load = true;
  3319. if (!quest) {
  3320. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3321. load = false;
  3322. }
  3323. if (load && name.length() == 0) {
  3324. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3325. load = false;
  3326. }
  3327. if (load && type.length() == 0) {
  3328. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3329. load = false;
  3330. }
  3331. if (load && zone.length() == 0) {
  3332. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3333. load = false;
  3334. }
  3335. if (load && description.length() == 0) {
  3336. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3337. load = false;
  3338. }
  3339. if (load && level == 0) {
  3340. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3341. load = false;
  3342. }
  3343. if (load)
  3344. quest->RegisterQuest(name, type, zone, level, description);
  3345. return 0;
  3346. }
  3347. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3348. if (!lua_interface)
  3349. return 0;
  3350. Quest* quest = lua_interface->GetQuest(state);
  3351. if (quest) {
  3352. int8 level = lua_interface->GetInt16Value(state, 2);
  3353. quest->SetPrereqLevel(level);
  3354. }
  3355. return 0;
  3356. }
  3357. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3358. if (!lua_interface)
  3359. return 0;
  3360. Quest* quest = lua_interface->GetQuest(state);
  3361. if (quest) {
  3362. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3363. quest->AddPrereqQuest(quest_id);
  3364. }
  3365. return 0;
  3366. }
  3367. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3368. if (!lua_interface)
  3369. return 0;
  3370. Quest* quest = lua_interface->GetQuest(state);
  3371. if (quest) {
  3372. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3373. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3374. if (quantity == 0)
  3375. quantity = 1;
  3376. Item* master_item = master_item_list.GetItem(item_id);
  3377. if (master_item) {
  3378. Item* item = new Item(master_item);
  3379. item->details.count = quantity;
  3380. quest->AddPrereqItem(item);
  3381. }
  3382. }
  3383. return 0;
  3384. }
  3385. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3386. if (!lua_interface)
  3387. return 0;
  3388. Spawn* player = lua_interface->GetSpawn(state);
  3389. if(!player || !player->IsPlayer()) {
  3390. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3391. return 0;
  3392. }
  3393. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3394. if (quest_id > 0) {
  3395. lua_interface->SetBooleanValue(state, (((Player*)player)->HasActiveQuest(quest_id) == TRUE));
  3396. return 1;
  3397. } else {
  3398. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3399. }
  3400. return 0;
  3401. }
  3402. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3403. if (!lua_interface)
  3404. return 0;
  3405. Quest* quest = lua_interface->GetQuest(state);
  3406. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3407. lua_interface->ResetFunctionStack(state);
  3408. if (quest && spawn_id > 0)
  3409. quest->SetQuestReturnNPC(spawn_id);
  3410. return 0;
  3411. }
  3412. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3413. if (!lua_interface)
  3414. return 0;
  3415. Spawn* spawn = lua_interface->GetSpawn(state);
  3416. int32 time = lua_interface->GetInt32Value(state, 2);
  3417. string function = lua_interface->GetStringValue(state, 3);
  3418. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3419. Spawn* player = lua_interface->GetSpawn(state, 5);
  3420. lua_interface->ResetFunctionStack(state);
  3421. if (!spawn) {
  3422. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3423. return 0;
  3424. }
  3425. if (time <= 0) {
  3426. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3427. return 0;
  3428. }
  3429. if (function.length() == 0) {
  3430. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3431. return 0;
  3432. }
  3433. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3434. if ( time < 10)
  3435. time = 10;
  3436. timer->timer = Timer::GetCurrentTime2() + time;
  3437. timer->function = function;
  3438. timer->spawn = spawn->GetID();
  3439. timer->player = player ? player->GetID() : 0;
  3440. if (max_count == 0)
  3441. max_count = 1;
  3442. timer->max_count = max_count;
  3443. timer->current_count = 0;
  3444. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3445. return 0;
  3446. }
  3447. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3448. if (!lua_interface)
  3449. return 0;
  3450. Spawn* spawn = lua_interface->GetSpawn(state);
  3451. string function = lua_interface->GetStringValue(state, 2);
  3452. lua_interface->ResetFunctionStack(state);
  3453. if (!spawn) {
  3454. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3455. return 0;
  3456. }
  3457. if(!spawn->GetZone()) {
  3458. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3459. return 0;
  3460. }
  3461. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3462. return 0;
  3463. }
  3464. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3465. if (!lua_interface)
  3466. return 0;
  3467. Spawn* player = lua_interface->GetSpawn(state);
  3468. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3469. lua_interface->ResetFunctionStack(state);
  3470. if (player && player->IsPlayer() && quest_id > 0) {
  3471. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3472. return 1;
  3473. }
  3474. return 0;
  3475. }
  3476. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3477. if (!lua_interface)
  3478. return 0;
  3479. Spawn* player = lua_interface->GetSpawn(state);
  3480. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3481. lua_interface->ResetFunctionStack(state);
  3482. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3483. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3484. if (quest)
  3485. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3486. return 1;
  3487. }
  3488. return 0;
  3489. }
  3490. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3491. if (!lua_interface)
  3492. return 0;
  3493. Spawn* player = lua_interface->GetSpawn(state);
  3494. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3495. lua_interface->ResetFunctionStack(state);
  3496. if (player && player->IsPlayer() && quest_id > 0) {
  3497. lua_interface->SetBooleanValue(state, (((Player*)player)->HasQuestBeenCompleted(quest_id) != 0));
  3498. return 1;
  3499. }
  3500. return 0;
  3501. }
  3502. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3503. if (!lua_interface)
  3504. return 0;
  3505. Spawn* npc = lua_interface->GetSpawn(state);
  3506. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3507. lua_interface->ResetFunctionStack(state);
  3508. if (npc && !npc->IsPlayer() && quest_id > 0)
  3509. npc->AddProvidedQuest(quest_id);
  3510. return 0;
  3511. }
  3512. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3513. if (!lua_interface)
  3514. return 0;
  3515. Spawn* npc = lua_interface->GetSpawn(state);
  3516. Spawn* player = lua_interface->GetSpawn(state, 2);
  3517. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3518. bool forced = lua_interface->GetBooleanValue(state, 4);
  3519. lua_interface->ResetFunctionStack(state);
  3520. /* NPC is allowed to be null */
  3521. if (player && player->IsPlayer() && quest_id > 0) {
  3522. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3523. if (master_quest) {
  3524. Client* client = ((Player*)player)->GetClient();
  3525. if (!client) {
  3526. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3527. }
  3528. Quest* quest = new Quest(master_quest);
  3529. if (!quest) {
  3530. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3531. }
  3532. if (client && quest) {
  3533. if (npc)
  3534. quest->SetQuestGiver(npc->GetDatabaseID());
  3535. else
  3536. quest->SetQuestGiver(0);
  3537. client->AddPendingQuest(quest, forced);
  3538. }
  3539. }
  3540. else {
  3541. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3542. }
  3543. }
  3544. else {
  3545. 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);
  3546. }
  3547. return 0;
  3548. }
  3549. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3550. if (!lua_interface)
  3551. return 0;
  3552. Quest* quest = lua_interface->GetQuest(state);
  3553. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3554. lua_interface->ResetFunctionStack(state);
  3555. if (quest) {
  3556. quest->AddPrereqClass(class_id);
  3557. }
  3558. return 0;
  3559. }
  3560. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3561. if (!lua_interface)
  3562. return 0;
  3563. Quest* quest = lua_interface->GetQuest(state);
  3564. int8 race = lua_interface->GetInt8Value(state, 2);
  3565. lua_interface->ResetFunctionStack(state);
  3566. if (quest) {
  3567. quest->AddPrereqRace(race);
  3568. }
  3569. return 0;
  3570. }
  3571. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3572. if (!lua_interface)
  3573. return 0;
  3574. Quest* quest = lua_interface->GetQuest(state);
  3575. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3576. lua_interface->ResetFunctionStack(state);
  3577. if (quest) {
  3578. quest->AddPrereqModelType(model_type);
  3579. }
  3580. return 0;
  3581. }
  3582. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3583. if (!lua_interface)
  3584. return 0;
  3585. Quest* quest = lua_interface->GetQuest(state);
  3586. int8 level = lua_interface->GetInt8Value(state, 2);
  3587. lua_interface->ResetFunctionStack(state);
  3588. if (!quest) {
  3589. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3590. return 0;
  3591. }
  3592. quest->SetPrereqTSLevel(level);
  3593. return 0;
  3594. }
  3595. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3596. if (!lua_interface)
  3597. return 0;
  3598. Quest* quest = lua_interface->GetQuest(state);
  3599. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3600. lua_interface->ResetFunctionStack(state);
  3601. if (!quest) {
  3602. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3603. return 0;
  3604. }
  3605. quest->AddPrereqTradeskillClass(class_id);
  3606. return 0;
  3607. }
  3608. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3609. if (!lua_interface)
  3610. return 0;
  3611. Quest* quest = lua_interface->GetQuest(state);
  3612. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3613. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3614. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3615. lua_interface->ResetFunctionStack(state);
  3616. if (quest) {
  3617. quest->AddPrereqFaction(faction_id, min, max);
  3618. }
  3619. return 0;
  3620. }
  3621. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3622. if (!lua_interface)
  3623. return 0;
  3624. Quest* quest = lua_interface->GetQuest(state);
  3625. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3626. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3627. lua_interface->ResetFunctionStack(state);
  3628. if (quest) {
  3629. if (quantity == 0)
  3630. quantity = 1;
  3631. Item* master_item = master_item_list.GetItem(item_id);
  3632. if (master_item) {
  3633. Item* item = new Item(master_item);
  3634. item->details.count = quantity;
  3635. quest->AddSelectableRewardItem(item);
  3636. }
  3637. }
  3638. return 0;
  3639. }
  3640. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3641. if (!lua_interface)
  3642. return 0;
  3643. Quest* quest = lua_interface->GetQuest(state);
  3644. if (quest) {
  3645. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3646. vector<Item*>* items = quest->GetRewardItems();
  3647. if (items) {
  3648. vector<Item*>::iterator itr;
  3649. for (itr = items->begin(); itr != items->end(); itr++) {
  3650. if (*itr && (*itr)->details.item_id == item_id) {
  3651. lua_interface->SetBooleanValue(state, true);
  3652. return 1;
  3653. }
  3654. }
  3655. }
  3656. }
  3657. lua_interface->SetBooleanValue(state, false);
  3658. return 1;
  3659. }
  3660. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3661. if (!lua_interface)
  3662. return 0;
  3663. Quest* quest = lua_interface->GetQuest(state);
  3664. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3665. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3666. lua_interface->ResetFunctionStack(state);
  3667. if (quest) {
  3668. if (quantity == 0)
  3669. quantity = 1;
  3670. Item* master_item = master_item_list.GetItem(item_id);
  3671. if (master_item) {
  3672. Item* item = new Item(master_item);
  3673. item->details.count = quantity;
  3674. quest->AddRewardItem(item);
  3675. }
  3676. }
  3677. return 0;
  3678. }
  3679. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3680. if (!lua_interface)
  3681. return 0;
  3682. Quest* quest = lua_interface->GetQuest(state);
  3683. int32 copper = lua_interface->GetInt32Value(state, 2);
  3684. int32 silver = lua_interface->GetInt32Value(state, 3);
  3685. int32 gold = lua_interface->GetInt32Value(state, 4);
  3686. int32 plat = lua_interface->GetInt32Value(state, 5);
  3687. lua_interface->ResetFunctionStack(state);
  3688. if (quest) {
  3689. quest->AddRewardCoins(copper, silver, gold, plat);
  3690. }
  3691. return 0;
  3692. }
  3693. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3694. if (!lua_interface)
  3695. return 0;
  3696. Quest* quest = lua_interface->GetQuest(state);
  3697. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3698. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3699. lua_interface->ResetFunctionStack(state);
  3700. if (quest && faction_id > 0 && amount != 0)
  3701. quest->AddRewardFaction(faction_id, amount);
  3702. return 0;
  3703. }
  3704. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3705. if (!lua_interface)
  3706. return 0;
  3707. Quest* quest = lua_interface->GetQuest(state);
  3708. int32 status = lua_interface->GetInt32Value(state, 2);
  3709. lua_interface->ResetFunctionStack(state);
  3710. if (quest) {
  3711. quest->SetRewardStatus(status);
  3712. }
  3713. return 0;
  3714. }
  3715. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3716. if (!lua_interface)
  3717. return 0;
  3718. Quest* quest = lua_interface->GetQuest(state);
  3719. int32 status = lua_interface->GetInt32Value(state, 2);
  3720. lua_interface->ResetFunctionStack(state);
  3721. if (quest) {
  3722. quest->SetStatusTmpReward(status);
  3723. }
  3724. return 0;
  3725. }
  3726. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3727. if (!lua_interface)
  3728. return 0;
  3729. Quest* quest = lua_interface->GetQuest(state);
  3730. int64 coins = lua_interface->GetInt64Value(state, 2);
  3731. lua_interface->ResetFunctionStack(state);
  3732. if (quest) {
  3733. quest->SetCoinTmpReward(coins);
  3734. }
  3735. return 0;
  3736. }
  3737. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3738. if (!lua_interface)
  3739. return 0;
  3740. Quest* quest = lua_interface->GetQuest(state);
  3741. string comment = lua_interface->GetStringValue(state, 2);
  3742. lua_interface->ResetFunctionStack(state);
  3743. if (quest) {
  3744. quest->SetRewardComment(comment);
  3745. }
  3746. return 0;
  3747. }
  3748. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3749. if (!lua_interface)
  3750. return 0;
  3751. Quest* quest = lua_interface->GetQuest(state);
  3752. int32 exp = lua_interface->GetInt32Value(state, 2);
  3753. lua_interface->ResetFunctionStack(state);
  3754. if (quest) {
  3755. quest->SetRewardXP(exp);
  3756. }
  3757. return 0;
  3758. }
  3759. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3760. Quest* quest = lua_interface->GetQuest(state);
  3761. int32 step = lua_interface->GetInt32Value(state, 2);
  3762. string description = lua_interface->GetStringValue(state, 3);
  3763. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3764. float percentage = lua_interface->GetFloatValue(state, 5);
  3765. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3766. int16 icon = lua_interface->GetInt16Value(state, 7);
  3767. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3768. if (quest) {
  3769. const char* taskgroup = 0;
  3770. if (str_taskgroup.length() > 0)
  3771. taskgroup = str_taskgroup.c_str();
  3772. int32 id = 0;
  3773. vector<int32>* ids = 0;
  3774. int i = 0;
  3775. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3776. if (ids == 0)
  3777. ids = new vector<int32>;
  3778. ids->push_back(id);
  3779. i++;
  3780. }
  3781. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3782. if (quest_step && icon && quantity > 0)
  3783. quest_step->SetIcon(icon);
  3784. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3785. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3786. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3787. }
  3788. }
  3789. lua_interface->ResetFunctionStack(state);
  3790. return 0;
  3791. }
  3792. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3793. {
  3794. if (!lua_interface)
  3795. return 0;
  3796. Quest* quest = lua_interface->GetQuest(state);
  3797. int32 step = lua_interface->GetInt32Value(state, 2);
  3798. string description = lua_interface->GetStringValue(state, 3);
  3799. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3800. float percentage = lua_interface->GetFloatValue(state, 5);
  3801. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3802. int16 icon = lua_interface->GetInt16Value(state, 7);
  3803. if (quest) {
  3804. const char* taskgroup = 0;
  3805. if (str_taskgroup.length() > 0)
  3806. taskgroup = str_taskgroup.c_str();
  3807. int32 id = 0;
  3808. vector<int32>* ids = 0;
  3809. int i = 0;
  3810. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3811. if (ids == 0)
  3812. ids = new vector<int32>;
  3813. ids->push_back(id);
  3814. i++;
  3815. }
  3816. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3817. if (quest_step && icon > 0 && quantity > 0)
  3818. quest_step->SetIcon(icon);
  3819. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3820. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3821. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3822. }
  3823. safe_delete(ids);
  3824. }
  3825. lua_interface->ResetFunctionStack(state);
  3826. return 0;
  3827. }
  3828. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3829. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3830. }
  3831. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3832. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3833. }
  3834. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3835. if (!lua_interface)
  3836. return 0;
  3837. Quest* quest = lua_interface->GetQuest(state);
  3838. int32 step = lua_interface->GetInt32Value(state, 2);
  3839. string description = lua_interface->GetStringValue(state, 3);
  3840. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3841. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3842. int16 icon = lua_interface->GetInt16Value(state, 6);
  3843. if (quest) {
  3844. const char* taskgroup = 0;
  3845. if (str_taskgroup.length() > 0)
  3846. taskgroup = str_taskgroup.c_str();
  3847. int32 npc_id = 0;
  3848. vector<int32>* ids = 0;
  3849. int i = 0;
  3850. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3851. if (ids == 0)
  3852. ids = new vector<int32>;
  3853. ids->push_back(npc_id);
  3854. i++;
  3855. }
  3856. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3857. if (quest_step && icon > 0)
  3858. quest_step->SetIcon(icon);
  3859. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3860. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3861. if(client)
  3862. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3863. }
  3864. safe_delete(ids);
  3865. }
  3866. lua_interface->ResetFunctionStack(state);
  3867. return 0;
  3868. }
  3869. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3870. if (!lua_interface)
  3871. return 0;
  3872. Quest* quest = lua_interface->GetQuest(state);
  3873. int32 step = lua_interface->GetInt32Value(state, 2);
  3874. string description = lua_interface->GetStringValue(state, 3);
  3875. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3876. float percentage = lua_interface->GetFloatValue(state, 5);
  3877. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3878. int16 icon = lua_interface->GetInt16Value(state, 7);
  3879. if (quest) {
  3880. const char* taskgroup = 0;
  3881. if (str_taskgroup.length() > 0)
  3882. taskgroup = str_taskgroup.c_str();
  3883. int32 item_id = 0;
  3884. vector<int32>* ids = 0;
  3885. int i = 0;
  3886. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3887. if (ids == 0)
  3888. ids = new vector<int32>;
  3889. ids->push_back(item_id);
  3890. i++;
  3891. }
  3892. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3893. if (quest_step && icon > 0 && quantity > 0)
  3894. quest_step->SetIcon(icon);
  3895. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3896. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3897. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3898. }
  3899. safe_delete(ids);
  3900. }
  3901. lua_interface->ResetFunctionStack(state);
  3902. return 0;
  3903. }
  3904. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3905. if (!lua_interface)
  3906. return 0;
  3907. Quest* quest = lua_interface->GetQuest(state);
  3908. int32 step = lua_interface->GetInt32Value(state, 2);
  3909. string description = lua_interface->GetStringValue(state, 3);
  3910. float max_variation = lua_interface->GetFloatValue(state, 4);
  3911. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3912. int16 icon = lua_interface->GetInt16Value(state, 6);
  3913. if (quest) {
  3914. const char* taskgroup = 0;
  3915. if (str_taskgroup.length() > 0)
  3916. taskgroup = str_taskgroup.c_str();
  3917. vector<Location>* locations = 0;
  3918. int8 i = 7;
  3919. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3920. while (true) {
  3921. Location loc;
  3922. loc.x = lua_interface->GetFloatValue(state, i);
  3923. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3924. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3925. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3926. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3927. break;
  3928. if (locations == 0)
  3929. locations = new vector<Location>;
  3930. locations->push_back(loc);
  3931. i += 4;
  3932. }
  3933. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3934. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3935. if (quest_step && icon > 0)
  3936. quest_step->SetIcon(icon);
  3937. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3938. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3939. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3940. }
  3941. }
  3942. lua_interface->ResetFunctionStack(state);
  3943. return 0;
  3944. }
  3945. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3946. if (!lua_interface)
  3947. return 0;
  3948. Quest* quest = lua_interface->GetQuest(state);
  3949. int32 step = lua_interface->GetInt32Value(state, 2);
  3950. string description = lua_interface->GetStringValue(state, 3);
  3951. float max_variation = lua_interface->GetFloatValue(state, 4);
  3952. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3953. int16 icon = lua_interface->GetInt16Value(state, 6);
  3954. if (quest) {
  3955. const char* taskgroup = 0;
  3956. if (str_taskgroup.length() > 0)
  3957. taskgroup = str_taskgroup.c_str();
  3958. vector<Location>* locations = 0;
  3959. int8 i = 7;
  3960. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3961. while (true) {
  3962. Location loc;
  3963. loc.x = lua_interface->GetFloatValue(state, i);
  3964. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3965. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3966. loc.zone_id = 0;
  3967. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3968. break;
  3969. if (locations == 0)
  3970. locations = new vector<Location>;
  3971. locations->push_back(loc);
  3972. i += 3;
  3973. }
  3974. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3975. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3976. if (quest_step && icon > 0)
  3977. quest_step->SetIcon(icon);
  3978. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3979. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3980. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3981. }
  3982. }
  3983. lua_interface->ResetFunctionStack(state);
  3984. return 0;
  3985. }
  3986. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3987. if (!lua_interface)
  3988. return 0;
  3989. Quest* quest = lua_interface->GetQuest(state);
  3990. int32 step = lua_interface->GetInt32Value(state, 2);
  3991. string description = lua_interface->GetStringValue(state, 3);
  3992. float max_variation = lua_interface->GetFloatValue(state, 4);
  3993. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3994. int16 icon = lua_interface->GetInt16Value(state, 6);
  3995. if (quest) {
  3996. const char* taskgroup = 0;
  3997. if (str_taskgroup.length() > 0)
  3998. taskgroup = str_taskgroup.c_str();
  3999. vector<Location>* locations = 0;
  4000. int i = 7;
  4001. while (true) {
  4002. Location loc;
  4003. loc.x = lua_interface->GetFloatValue(state, i);
  4004. loc.y = lua_interface->GetFloatValue(state, i + 1);
  4005. loc.z = lua_interface->GetFloatValue(state, i + 2);
  4006. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  4007. break;
  4008. if (locations == 0)
  4009. locations = new vector<Location>;
  4010. locations->push_back(loc);
  4011. i += 3;
  4012. }
  4013. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  4014. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  4015. if (quest_step && icon > 0)
  4016. quest_step->SetIcon(icon);
  4017. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4018. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4019. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4020. }
  4021. }
  4022. lua_interface->ResetFunctionStack(state);
  4023. return 0;
  4024. }
  4025. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  4026. Quest* quest = lua_interface->GetQuest(state);
  4027. int32 step = lua_interface->GetInt32Value(state, 2);
  4028. string description = lua_interface->GetStringValue(state, 3);
  4029. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4030. float percentage = lua_interface->GetFloatValue(state, 5);
  4031. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4032. int16 icon = lua_interface->GetInt16Value(state, 7);
  4033. if (quest) {
  4034. const char* taskgroup = 0;
  4035. if (str_taskgroup.length() > 0)
  4036. taskgroup = str_taskgroup.c_str();
  4037. int32 spell_id = 0;
  4038. vector<int32>* ids = 0;
  4039. int i = 0;
  4040. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4041. if (ids == 0)
  4042. ids = new vector<int32>;
  4043. ids->push_back(spell_id);
  4044. i++;
  4045. }
  4046. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4047. if (quest_step && icon > 0 && quantity > 0)
  4048. quest_step->SetIcon(icon);
  4049. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4050. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4051. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4052. }
  4053. safe_delete(ids);
  4054. }
  4055. lua_interface->ResetFunctionStack(state);
  4056. return 0;
  4057. }
  4058. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  4059. if (!lua_interface)
  4060. return 0;
  4061. Quest* quest = lua_interface->GetQuest(state);
  4062. int32 step = lua_interface->GetInt32Value(state, 2);
  4063. string description = lua_interface->GetStringValue(state, 3);
  4064. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4065. float percentage = lua_interface->GetFloatValue(state, 5);
  4066. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4067. int16 icon = lua_interface->GetInt16Value(state, 7);
  4068. if (quest) {
  4069. const char* taskgroup = 0;
  4070. if (str_taskgroup.length() > 0)
  4071. taskgroup = str_taskgroup.c_str();
  4072. int32 item_id = 0;
  4073. vector<int32>* ids = 0;
  4074. int i = 0;
  4075. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4076. if (ids == 0)
  4077. ids = new vector<int32>;
  4078. ids->push_back(item_id);
  4079. i++;
  4080. }
  4081. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4082. if (quest_step && icon > 0 && quantity > 0)
  4083. quest_step->SetIcon(icon);
  4084. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4085. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4086. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4087. }
  4088. safe_delete(ids);
  4089. }
  4090. lua_interface->ResetFunctionStack(state);
  4091. return 0;
  4092. }
  4093. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  4094. if (!lua_interface)
  4095. return 0;
  4096. Quest* quest = lua_interface->GetQuest(state);
  4097. int32 step = lua_interface->GetInt32Value(state, 2);
  4098. string description = lua_interface->GetStringValue(state, 3);
  4099. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4100. float percentage = lua_interface->GetFloatValue(state, 5);
  4101. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4102. int16 icon = lua_interface->GetInt16Value(state, 7);
  4103. if (quest) {
  4104. const char* taskgroup = 0;
  4105. if (str_taskgroup.length() > 0)
  4106. taskgroup = str_taskgroup.c_str();
  4107. int32 item_id = 0;
  4108. vector<int32>* ids = 0;
  4109. int i = 0;
  4110. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4111. if (ids == 0)
  4112. ids = new vector<int32>;
  4113. ids->push_back(item_id);
  4114. i++;
  4115. }
  4116. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4117. if (quest_step && icon > 0 && quantity > 0)
  4118. quest_step->SetIcon(icon);
  4119. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4120. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4121. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4122. }
  4123. safe_delete(ids);
  4124. }
  4125. lua_interface->ResetFunctionStack(state);
  4126. return 0;
  4127. }
  4128. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  4129. if (!lua_interface)
  4130. return 0;
  4131. Quest* quest = lua_interface->GetQuest(state);
  4132. string action = lua_interface->GetStringValue(state, 2);
  4133. lua_interface->ResetFunctionStack(state);
  4134. if (quest) {
  4135. if (action.length() > 0)
  4136. quest->SetCompleteAction(action);
  4137. }
  4138. return 0;
  4139. }
  4140. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  4141. if (!lua_interface)
  4142. return 0;
  4143. Quest* quest = lua_interface->GetQuest(state);
  4144. int32 step = lua_interface->GetInt32Value(state, 2);
  4145. string action = lua_interface->GetStringValue(state, 3);
  4146. lua_interface->ResetFunctionStack(state);
  4147. if (quest) {
  4148. if (step > 0 && action.length() > 0)
  4149. quest->AddCompleteAction(step, action);
  4150. }
  4151. return 0;
  4152. }
  4153. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  4154. if (!lua_interface)
  4155. return 0;
  4156. Quest* quest = lua_interface->GetQuest(state);
  4157. int32 step = lua_interface->GetInt32Value(state, 2);
  4158. string action = lua_interface->GetStringValue(state, 3);
  4159. lua_interface->ResetFunctionStack(state);
  4160. if (quest) {
  4161. if (step > 0 && action.length() > 0)
  4162. quest->AddProgressAction(step, action);
  4163. }
  4164. return 0;
  4165. }
  4166. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  4167. if (!lua_interface)
  4168. return 0;
  4169. Quest* quest = lua_interface->GetQuest(state);
  4170. string description = lua_interface->GetStringValue(state, 2);
  4171. lua_interface->ResetFunctionStack(state);
  4172. if (quest && description.length() > 0)
  4173. quest->SetDescription(description);
  4174. return 0;
  4175. }
  4176. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4177. if (!lua_interface)
  4178. return 0;
  4179. Quest* quest = lua_interface->GetQuest(state);
  4180. string description = lua_interface->GetStringValue(state, 2);
  4181. lua_interface->ResetFunctionStack(state);
  4182. if (quest && description.length() > 0)
  4183. quest->SetCompletedDescription(description);
  4184. return 0;
  4185. }
  4186. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4187. if (!lua_interface)
  4188. return 0;
  4189. Quest* quest = lua_interface->GetQuest(state);
  4190. int32 step = lua_interface->GetInt32Value(state, 2);
  4191. string description = lua_interface->GetStringValue(state, 3);
  4192. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4193. lua_interface->ResetFunctionStack(state);
  4194. if (quest && step > 0 && description.length() > 0) {
  4195. quest->SetTaskGroupDescription(step, description, display_bullets);
  4196. }
  4197. return 0;
  4198. }
  4199. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4200. if (!lua_interface)
  4201. return 0;
  4202. Quest* quest = lua_interface->GetQuest(state);
  4203. int32 step = lua_interface->GetInt32Value(state, 2);
  4204. string description = lua_interface->GetStringValue(state, 3);
  4205. lua_interface->ResetFunctionStack(state);
  4206. if (quest && step > 0 && description.length() > 0) {
  4207. quest->SetStepDescription(step, description);
  4208. }
  4209. return 0;
  4210. }
  4211. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4212. Quest* quest = lua_interface->GetQuest(state);
  4213. string zone = lua_interface->GetStringValue(state, 2);
  4214. lua_interface->ResetFunctionStack(state);
  4215. if (quest && zone.length() > 0)
  4216. quest->SetZone(zone);
  4217. return 0;
  4218. }
  4219. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4220. if (!lua_interface)
  4221. return 0;
  4222. Quest* quest = lua_interface->GetQuest(state);
  4223. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4224. lua_interface->ResetFunctionStack(state);
  4225. if (quest && spawn) {
  4226. if (spawn->IsPlayer()) {
  4227. Client* client = ((Player*)spawn)->GetClient();
  4228. if (client) {
  4229. client->AddPendingQuestReward(quest);
  4230. }
  4231. }
  4232. }
  4233. return 0;
  4234. }
  4235. int EQ2Emu_lua_Harvest(lua_State* state) {
  4236. if (!lua_interface)
  4237. return 0;
  4238. Spawn* player = lua_interface->GetSpawn(state);
  4239. Spawn* node = lua_interface->GetSpawn(state, 2);
  4240. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4241. Client* client = ((Player*)player)->GetClient();
  4242. if (client) {
  4243. ((GroundSpawn*)node)->ProcessHarvest(client);
  4244. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4245. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4246. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4247. }
  4248. }
  4249. }
  4250. else if (player && player->IsPlayer()) {
  4251. Client* client = ((Player*)player)->GetClient();
  4252. if (client)
  4253. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4254. }
  4255. lua_interface->ResetFunctionStack(state);
  4256. return 0;
  4257. }
  4258. int EQ2Emu_lua_Bind(lua_State* state) {
  4259. if (!lua_interface)
  4260. return 0;
  4261. Spawn* spawn = lua_interface->GetSpawn(state);
  4262. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4263. float x = lua_interface->GetFloatValue(state, 3);
  4264. float y = lua_interface->GetFloatValue(state, 4);
  4265. float z = lua_interface->GetFloatValue(state, 5);
  4266. float h = lua_interface->GetFloatValue(state, 6);
  4267. lua_interface->ResetFunctionStack(state);
  4268. if (!spawn) {
  4269. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4270. return 0;
  4271. }
  4272. if (!spawn->IsPlayer()) {
  4273. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4274. return 0;
  4275. }
  4276. if (zone_id == 0) {
  4277. Client* client = ((Player*)spawn)->GetClient();
  4278. if (!client) {
  4279. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4280. return 0;
  4281. }
  4282. if (!client->Bind())
  4283. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4284. }
  4285. else {
  4286. Player* player = (Player*)spawn;
  4287. player->GetPlayerInfo()->SetBindZone(zone_id);
  4288. player->GetPlayerInfo()->SetBindX(x);
  4289. player->GetPlayerInfo()->SetBindY(y);
  4290. player->GetPlayerInfo()->SetBindZ(z);
  4291. player->GetPlayerInfo()->SetBindHeading(h);
  4292. }
  4293. return 0;
  4294. }
  4295. int EQ2Emu_lua_Gate(lua_State* state) {
  4296. if (!lua_interface)
  4297. return 0;
  4298. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4299. Spawn* spawn = lua_interface->GetSpawn(state);
  4300. lua_interface->ResetFunctionStack(state);
  4301. if (spawn) {
  4302. if (spawn->IsPlayer()) {
  4303. Client* client = ((Player*)spawn)->GetClient();
  4304. if (client) {
  4305. if (!client->Gate((spell != nullptr) ? true : false))
  4306. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4307. }
  4308. }
  4309. }
  4310. return 0;
  4311. }
  4312. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4313. if (!lua_interface)
  4314. return 0;
  4315. bool ret = false;
  4316. Spawn* spawn = lua_interface->GetSpawn(state);
  4317. lua_interface->ResetFunctionStack(state);
  4318. if (spawn) {
  4319. if (spawn->IsPlayer()) {
  4320. Client* client = ((Player*)spawn)->GetClient();
  4321. if (client)
  4322. ret = client->BindAllowed();
  4323. }
  4324. }
  4325. lua_interface->SetBooleanValue(state, ret);
  4326. return 1;
  4327. }
  4328. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4329. if (!lua_interface)
  4330. return 0;
  4331. bool ret = false;
  4332. Spawn* spawn = lua_interface->GetSpawn(state);
  4333. lua_interface->ResetFunctionStack(state);
  4334. if (spawn) {
  4335. if (spawn->IsPlayer()) {
  4336. Client* client = ((Player*)spawn)->GetClient();
  4337. ZoneServer* zone = lua_interface->GetZone(state);
  4338. if (client && zone){
  4339. ret = zone->GetCanGate();
  4340. }
  4341. }
  4342. }
  4343. lua_interface->SetBooleanValue(state, ret);
  4344. return 1;
  4345. }
  4346. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4347. Spawn* spawn = lua_interface->GetSpawn(state);
  4348. lua_interface->ResetFunctionStack(state);
  4349. if (spawn) {
  4350. lua_interface->SetBooleanValue(state, spawn->Alive());
  4351. return 1;
  4352. }
  4353. return 0;
  4354. }
  4355. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4356. if (!lua_interface)
  4357. return 0;
  4358. Spawn* spawn = lua_interface->GetSpawn(state);
  4359. lua_interface->ResetFunctionStack(state);
  4360. if (spawn && spawn->IsEntity()) {
  4361. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4362. return 1;
  4363. }
  4364. return 0;
  4365. }
  4366. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4367. Spawn* spawn = lua_interface->GetSpawn(state);
  4368. string message = lua_interface->GetStringValue(state, 2);
  4369. string color_str = lua_interface->GetStringValue(state, 3);
  4370. lua_interface->ResetFunctionStack(state);
  4371. int8 color = CHANNEL_NARRATIVE;
  4372. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4373. Client* client = ((Player*)spawn)->GetClient();
  4374. if (client) {
  4375. if (color_str.length() > 0) {
  4376. // leave for backwards compat, but all future should just use the number
  4377. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4378. color = CHANNEL_COLOR_RED;
  4379. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4380. color = CHANNEL_COLOR_YELLOW;
  4381. else
  4382. {
  4383. // use a number to specify the channel as per Commands/Commands.h defines
  4384. color = (int8)atoul(color_str.c_str());
  4385. }
  4386. }
  4387. client->SimpleMessage(color, message.c_str());
  4388. }
  4389. }
  4390. return 0;
  4391. }
  4392. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4393. Spawn* spawn = lua_interface->GetSpawn(state);
  4394. string message = lua_interface->GetStringValue(state, 2);
  4395. int8 red = lua_interface->GetInt8Value(state, 3);
  4396. int8 green = lua_interface->GetInt8Value(state, 4);
  4397. int8 blue = lua_interface->GetInt8Value(state, 5);
  4398. lua_interface->ResetFunctionStack(state);
  4399. if (!spawn) {
  4400. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4401. return 0;
  4402. }
  4403. if (!spawn->IsPlayer()) {
  4404. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not a player.", lua_interface->GetScriptName(state));
  4405. return 0;
  4406. }
  4407. int32 words = ::CountWordsInString(message.c_str());
  4408. if (words < 5)
  4409. words = 5;
  4410. Client* client = ((Player*)spawn)->GetClient();
  4411. if (client)
  4412. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4413. return 0;
  4414. }
  4415. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4416. Spawn* spawn = lua_interface->GetSpawn(state);
  4417. int8 param = lua_interface->GetInt8Value(state, 2);
  4418. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4419. int8 value = lua_interface->GetInt8Value(state, 4);
  4420. lua_interface->ResetFunctionStack(state);
  4421. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4422. Client* client = ((Player*)spawn)->GetClient();
  4423. if (client) {
  4424. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4425. switch (param) {
  4426. case 1: {
  4427. packet->setDataByName("parameter1", param_value);
  4428. break;
  4429. }
  4430. case 2: {
  4431. packet->setDataByName("parameter2", param_value);
  4432. break;
  4433. }
  4434. case 3: {
  4435. packet->setDataByName("parameter3", param_value);
  4436. break;
  4437. }
  4438. case 4: {
  4439. packet->setDataByName("parameter4", param_value);
  4440. break;
  4441. }
  4442. case 5: {
  4443. packet->setDataByName("parameter5", param_value);
  4444. break;
  4445. }
  4446. }
  4447. packet->setDataByName("value", value);
  4448. client->QueuePacket(packet->serialize());
  4449. safe_delete(packet);
  4450. }
  4451. }
  4452. return 0;
  4453. }
  4454. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4455. Spawn* spawn = lua_interface->GetSpawn(state);
  4456. lua_interface->ResetFunctionStack(state);
  4457. if (spawn && spawn->IsPlayer()) {
  4458. if (((Player*)spawn)->GetIsTracking())
  4459. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4460. else
  4461. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4462. }
  4463. return 0;
  4464. }
  4465. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4466. Spawn* player = lua_interface->GetSpawn(state);
  4467. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4468. string name = lua_interface->GetStringValue(state, 3);
  4469. float distance = lua_interface->GetFloatValue(state, 4);
  4470. string command = lua_interface->GetStringValue(state, 5);
  4471. string error_text = lua_interface->GetStringValue(state, 6);
  4472. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4473. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4474. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4475. lua_interface->ResetFunctionStack(state);
  4476. if (spawn) {
  4477. if (distance == 0)
  4478. distance = 10.0f;
  4479. if (command.length() == 0)
  4480. command = name;
  4481. if (command.length() < 1 && name.length() < 1)
  4482. {
  4483. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4484. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4485. spawn->RemovePrimaryCommands();
  4486. }
  4487. else
  4488. {
  4489. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4490. }
  4491. }
  4492. return 0;
  4493. }
  4494. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4495. if (!lua_interface)
  4496. return 0;
  4497. Spawn* player = lua_interface->GetSpawn(state);
  4498. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4499. int16 tier = lua_interface->GetInt16Value(state, 3);
  4500. lua_interface->ResetFunctionStack(state);
  4501. if (player && player->IsPlayer()) {
  4502. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4503. return 1;
  4504. }
  4505. return 0;
  4506. }
  4507. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4508. if (!lua_interface)
  4509. return 0;
  4510. Spawn* player = lua_interface->GetSpawn(state);
  4511. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4512. int16 tier = lua_interface->GetInt16Value(state, 3);
  4513. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4514. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4515. bool add_to_hotbar = true;
  4516. if (num_args > 4) {
  4517. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4518. }
  4519. lua_interface->ResetFunctionStack(state);
  4520. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4521. if (player && spell && player->IsPlayer()) {
  4522. Client* client = player->GetClient();
  4523. if (client) {
  4524. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4525. {
  4526. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4527. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4528. client->GetPlayer()->UnlockSpell(spell);
  4529. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4530. }
  4531. else
  4532. {
  4533. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4534. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4535. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4536. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4537. client->GetPlayer()->UnlockSpell(spell);
  4538. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4539. }
  4540. //if (client ) {
  4541. // ((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);
  4542. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4543. if (outapp)
  4544. client->QueuePacket(outapp);
  4545. }
  4546. }
  4547. return 0;
  4548. }
  4549. int EQ2Emu_lua_DeleteSpellBook(lua_State* state) {
  4550. if (!lua_interface)
  4551. return 0;
  4552. Spawn* player = lua_interface->GetSpawn(state);
  4553. int8 type_selection = lua_interface->GetInt8Value(state, 2);
  4554. lua_interface->ResetFunctionStack(state);
  4555. if (player && player->IsPlayer()) {
  4556. Client* client = player->GetClient();
  4557. if (client) {
  4558. ((Player*)player)->DeleteSpellBook(type_selection);
  4559. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4560. if (outapp)
  4561. client->QueuePacket(outapp);
  4562. }
  4563. }
  4564. return 0;
  4565. }
  4566. int EQ2Emu_lua_SendNewAdventureSpells(lua_State* state) {
  4567. if (!lua_interface)
  4568. return 0;
  4569. Spawn* player = lua_interface->GetSpawn(state);
  4570. lua_interface->ResetFunctionStack(state);
  4571. if (player && player->IsPlayer()) {
  4572. Client* client = player->GetClient();
  4573. if (client) {
  4574. client->SendNewAdventureSpells();
  4575. }
  4576. }
  4577. return 0;
  4578. }
  4579. int EQ2Emu_lua_SendNewTradeskillSpells(lua_State* state) {
  4580. if (!lua_interface)
  4581. return 0;
  4582. Spawn* player = lua_interface->GetSpawn(state);
  4583. lua_interface->ResetFunctionStack(state);
  4584. if (player && player->IsPlayer()) {
  4585. Client* client = player->GetClient();
  4586. if (client) {
  4587. client->SendNewTradeskillSpells();
  4588. }
  4589. }
  4590. return 0;
  4591. }
  4592. int EQ2Emu_lua_RemoveSpellBookEntry(lua_State* state) {
  4593. if (!lua_interface)
  4594. return 0;
  4595. Spawn* player = lua_interface->GetSpawn(state);
  4596. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4597. lua_interface->ResetFunctionStack(state);
  4598. if (player && player->IsPlayer()) {
  4599. SpellBookEntry* sbe = ((Player*)player)->GetSpellBookSpell(spellid);
  4600. Client* client = player->GetClient();
  4601. if (sbe && client) {
  4602. ((Player*)player)->RemoveSpellBookEntry(spellid);
  4603. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4604. if (outapp)
  4605. client->QueuePacket(outapp);
  4606. }
  4607. }
  4608. return 0;
  4609. }
  4610. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4611. if (!lua_interface)
  4612. return 0;
  4613. Spawn* player = lua_interface->GetSpawn(state);
  4614. lua_interface->ResetFunctionStack(state);
  4615. if (player && player->IsPlayer()) {
  4616. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4617. return 1;
  4618. }
  4619. return 0;
  4620. }
  4621. int EQ2Emu_lua_Attack(lua_State* state) {
  4622. if (lua_interface) {
  4623. Spawn* npc = lua_interface->GetSpawn(state);
  4624. Spawn* player = lua_interface->GetSpawn(state, 2);
  4625. lua_interface->ResetFunctionStack(state);
  4626. if (npc && player && npc->IsNPC() && player->IsEntity())
  4627. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4628. }
  4629. return 0;
  4630. }
  4631. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4632. if (lua_interface) {
  4633. Spawn* target = lua_interface->GetSpawn(state);
  4634. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4635. lua_interface->ResetFunctionStack(state);
  4636. if (target && target->GetZone())
  4637. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4638. }
  4639. return 0;
  4640. }
  4641. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4642. Spawn* player;
  4643. if (lua_interface) {
  4644. player = lua_interface->GetSpawn(state);
  4645. lua_interface->ResetFunctionStack(state);
  4646. if (player && player->IsPlayer()) {
  4647. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4648. return 1;
  4649. }
  4650. }
  4651. return 0;
  4652. }
  4653. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4654. Spawn* player;
  4655. Client* client;
  4656. if (lua_interface) {
  4657. player = lua_interface->GetSpawn(state);
  4658. lua_interface->ResetFunctionStack(state);
  4659. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4660. if ((client = ((Player*)player)->GetClient()))
  4661. client->HandInCollections();
  4662. }
  4663. return 0;
  4664. }
  4665. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4666. Spawn* widget;
  4667. if (lua_interface) {
  4668. widget = lua_interface->GetSpawn(state);
  4669. lua_interface->ResetFunctionStack(state);
  4670. if (widget && widget->IsWidget())
  4671. ((Widget*)widget)->HandleUse(nullptr, "");
  4672. }
  4673. return 0;
  4674. }
  4675. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4676. Spawn* spawn = 0;
  4677. int32 primary_list = 0;
  4678. int32 secondary_list = 0;
  4679. if (lua_interface) {
  4680. spawn = lua_interface->GetSpawn(state);
  4681. primary_list = lua_interface->GetInt32Value(state, 2);
  4682. secondary_list = lua_interface->GetInt32Value(state, 3);
  4683. lua_interface->ResetFunctionStack(state);
  4684. if (!spawn->IsNPC()) {
  4685. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4686. return 0;
  4687. }
  4688. NPC* npc = (NPC*)spawn;
  4689. npc->SetPrimarySpellList(primary_list);
  4690. npc->SetSecondarySpellList(secondary_list);
  4691. npc->SetSpells(world.GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4692. }
  4693. return 0;
  4694. }
  4695. int EQ2Emu_lua_GetPet(lua_State* state) {
  4696. if (!lua_interface)
  4697. return 0;
  4698. Spawn* spawn = lua_interface->GetSpawn(state);
  4699. lua_interface->ResetFunctionStack(state);
  4700. if (spawn) {
  4701. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4702. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4703. return 1;
  4704. }
  4705. }
  4706. return 0;
  4707. }
  4708. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4709. if (!lua_interface)
  4710. return 0;
  4711. Spawn* spawn = lua_interface->GetSpawn(state);
  4712. lua_interface->ResetFunctionStack(state);
  4713. if (spawn) {
  4714. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4715. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4716. return 1;
  4717. }
  4718. }
  4719. return 0;
  4720. }
  4721. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4722. if (!lua_interface)
  4723. return 0;
  4724. Spawn* spawn = lua_interface->GetSpawn(state);
  4725. lua_interface->ResetFunctionStack(state);
  4726. if (spawn) {
  4727. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4728. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4729. return 1;
  4730. }
  4731. }
  4732. return 0;
  4733. }
  4734. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4735. if (!lua_interface)
  4736. return 0;
  4737. Spawn* spawn = lua_interface->GetSpawn(state);
  4738. lua_interface->ResetFunctionStack(state);
  4739. if (spawn) {
  4740. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4741. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4742. return 1;
  4743. }
  4744. }
  4745. return 0;
  4746. }
  4747. int EQ2Emu_lua_Charm(lua_State* state) {
  4748. if (!lua_interface)
  4749. return 0;
  4750. Spawn* owner = lua_interface->GetSpawn(state);
  4751. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4752. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4753. lua_interface->ResetFunctionStack(state);
  4754. if (!luaspell) {
  4755. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4756. return 0;
  4757. }
  4758. if(luaspell->resisted) {
  4759. return 0;
  4760. }
  4761. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4762. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4763. pet->SetPet(true);
  4764. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4765. ((NPC*)pet)->SetOwner((Entity*)owner);
  4766. // If owner is player and player does not have a summoned pet set the players charsheet
  4767. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4768. Player* player = (Player*)owner;
  4769. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4770. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4771. player->GetInfoStruct()->set_pet_movement(2);
  4772. player->GetInfoStruct()->set_pet_behavior(3);
  4773. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4774. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4775. // Make sure the values get sent to the client
  4776. player->SetCharSheetChanged(true);
  4777. }
  4778. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4779. pet->SetSpawnScript("");
  4780. // Set faction to the same as the owner
  4781. pet->SetFactionID(owner->GetFactionID());
  4782. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4783. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4784. // Clear hate list
  4785. ((NPC*)pet)->Brain()->ClearHate();
  4786. // Set the brain to a pet brain
  4787. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4788. }
  4789. return 0;
  4790. }
  4791. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4792. if (!lua_interface)
  4793. return 0;
  4794. Spawn* spawn = lua_interface->GetSpawn(state);
  4795. lua_interface->ResetFunctionStack(state);
  4796. if (!spawn) {
  4797. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4798. return 0;
  4799. }
  4800. vector<Spawn*> groupMembers;
  4801. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4802. groupMembers = *spawn->GetSpawnGroup();
  4803. }
  4804. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4805. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4806. deque<GroupMemberInfo*>::iterator itr;
  4807. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4808. if (group)
  4809. {
  4810. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4811. deque<GroupMemberInfo*>* members = group->GetMembers();
  4812. GroupMemberInfo* info = 0;
  4813. for (itr = members->begin(); itr != members->end(); itr++) {
  4814. info = *itr;
  4815. if (info->client)
  4816. groupMembers.push_back(info->client->GetPlayer());
  4817. }
  4818. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4819. }
  4820. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4821. }
  4822. else
  4823. return 0;
  4824. lua_createtable(state, groupMembers.size(), 0);
  4825. int newTable = lua_gettop(state);
  4826. for (int32 i = 0; i < groupMembers.size(); i++) {
  4827. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4828. lua_rawseti(state, newTable, i + 1);
  4829. }
  4830. return 1;
  4831. }
  4832. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4833. if (!lua_interface)
  4834. return 0;
  4835. lua_interface->ResetFunctionStack(state);
  4836. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4837. lua_interface->SetOptionWindowValue(state, option_window);
  4838. return 1;
  4839. }
  4840. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4841. if (!lua_interface)
  4842. return 0;
  4843. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4844. if (option_window) {
  4845. OptionWindowOption option_window_option;
  4846. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4847. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4848. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4849. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4850. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4851. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4852. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4853. option_window->push_back(option_window_option);
  4854. }
  4855. lua_interface->ResetFunctionStack(state);
  4856. return 0;
  4857. }
  4858. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4859. if (!lua_interface)
  4860. return 0;
  4861. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4862. Spawn* player = lua_interface->GetSpawn(state, 2);
  4863. string window_title = lua_interface->GetStringValue(state, 3);
  4864. string cancel_command = lua_interface->GetStringValue(state, 4);
  4865. lua_interface->ResetFunctionStack(state);
  4866. if (!player->IsPlayer()) {
  4867. lua_interface->LogError("%s: LUA SendOptionWindow command error: spawn is not a player", lua_interface->GetScriptName(state));
  4868. return 0;
  4869. }
  4870. Client* client = ((Player*)player)->GetClient();
  4871. if (option_window && window_title.length() > 0 && client) {
  4872. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4873. if (!packet)
  4874. return 0;
  4875. packet->setDataByName("title_text", window_title.c_str());
  4876. if (cancel_command.length() > 0)
  4877. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4878. packet->setArrayLengthByName("num_selections", option_window->size());
  4879. vector<OptionWindowOption>::iterator itr;
  4880. int8 i = 0;
  4881. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4882. OptionWindowOption opt = *itr;
  4883. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4884. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4885. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4886. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4887. if (opt.optionCommand.length() > 0)
  4888. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4889. if (opt.optionConfirmTitle.length() > 0)
  4890. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4891. i++;
  4892. }
  4893. client->QueuePacket(packet->serialize());
  4894. lua_interface->SetLuaUserDataStale(option_window);
  4895. safe_delete(option_window);
  4896. safe_delete(packet);
  4897. }
  4898. return 0;
  4899. }
  4900. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4901. if (!lua_interface)
  4902. return 0;
  4903. Spawn* spawn = lua_interface->GetSpawn(state);
  4904. lua_interface->ResetFunctionStack(state);
  4905. if (spawn) {
  4906. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4907. return 1;
  4908. }
  4909. else
  4910. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4911. return 0;
  4912. }
  4913. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4914. if (!lua_interface)
  4915. return 0;
  4916. Spawn* spawn = lua_interface->GetSpawn(state);
  4917. lua_interface->ResetFunctionStack(state);
  4918. if (spawn) {
  4919. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4920. return 1;
  4921. }
  4922. else
  4923. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4924. return 0;
  4925. }
  4926. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4927. if (!lua_interface)
  4928. return 0;
  4929. Spawn* spawn = lua_interface->GetSpawn(state);
  4930. lua_interface->ResetFunctionStack(state);
  4931. if (spawn) {
  4932. int8 class_id = spawn->GetTradeskillClass();
  4933. // Need to add 42 for the offset in the array
  4934. class_id += 44;
  4935. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4936. return 1;
  4937. }
  4938. else
  4939. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4940. return 0;
  4941. }
  4942. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4943. if (!lua_interface)
  4944. return 0;
  4945. Spawn* spawn = lua_interface->GetSpawn(state);
  4946. int16 level = lua_interface->GetInt8Value(state, 2);
  4947. lua_interface->ResetFunctionStack(state);
  4948. if (spawn) {
  4949. if (spawn->IsPlayer() && ((Player*)spawn)->GetClient())
  4950. ((Player*)spawn)->GetClient()->ChangeTSLevel(spawn->GetTSLevel(), level);
  4951. else
  4952. spawn->SetTSLevel(level);
  4953. }
  4954. else
  4955. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4956. return 0;
  4957. }
  4958. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4959. if (!lua_interface)
  4960. return 0;
  4961. Spawn* spawn = lua_interface->GetSpawn(state);
  4962. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4963. lua_interface->ResetFunctionStack(state);
  4964. if (spawn) {
  4965. spawn->SetAttackable(attackable);
  4966. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4967. }
  4968. return 0;
  4969. }
  4970. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4971. // Check to see if we have a valid lua_interface
  4972. if (!lua_interface)
  4973. return 0;
  4974. // Get the spawn that is getting the pet
  4975. Spawn* spawn = lua_interface->GetSpawn(state);
  4976. // Get the DB ID of the pet
  4977. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4978. // The max level the pet can gain
  4979. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4980. // Get the spell that this command was called from
  4981. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4982. lua_interface->ResetFunctionStack(state);
  4983. // Check to make sure the spawn pointer is valid
  4984. if (!spawn) {
  4985. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4986. return 0;
  4987. }
  4988. // Check to make sure the spawn is an entity
  4989. if (!spawn->IsEntity()) {
  4990. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4991. return 0;
  4992. }
  4993. // Check to make sure the spawn doesn't already have a pet of this type
  4994. if (((Entity*)spawn)->GetPet()) {
  4995. if (spawn->IsPlayer()) {
  4996. Client* client = ((Player*)spawn)->GetClient();
  4997. if (client)
  4998. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4999. }
  5000. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5001. return 0;
  5002. }
  5003. // Check to see if the DB ID for the pet is set
  5004. if (pet_id == 0) {
  5005. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5006. return 0;
  5007. }
  5008. // Check to see if the pointer to the spell is valid
  5009. if (!luaspell) {
  5010. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5011. return 0;
  5012. }
  5013. if(luaspell->resisted) {
  5014. return 0;
  5015. }
  5016. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  5017. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5018. if (!pet) {
  5019. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5020. return 0;
  5021. }
  5022. // Check to make sure the pet is an npc
  5023. if (!pet->IsNPC()) {
  5024. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  5025. return 0;
  5026. }
  5027. // Spawn the pet at the same location as the owner
  5028. pet->SetX(spawn->GetX());
  5029. pet->SetY(spawn->GetY());
  5030. pet->SetZ(spawn->GetZ());
  5031. pet->SetLocation(spawn->GetLocation());
  5032. pet->SetHeading(spawn->GetHeading());
  5033. std::string petName = std::string("");
  5034. if(spawn->IsEntity()) {
  5035. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  5036. }
  5037. if(petName.size() < 1) {
  5038. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5039. petName = spawn->GetZone()->pet_names.at(rand_index);
  5040. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  5041. }
  5042. // If player set various values for the char sheet (pet window)
  5043. if (spawn->IsPlayer()) {
  5044. Player* player = (Player*)spawn;
  5045. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  5046. player->GetInfoStruct()->set_pet_name(petName);
  5047. player->GetInfoStruct()->set_pet_movement(2);
  5048. player->GetInfoStruct()->set_pet_behavior(3);
  5049. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  5050. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  5051. // Make sure the values get sent to the client
  5052. player->SetCharSheetChanged(true);
  5053. }
  5054. // Set the pets name
  5055. pet->SetName(petName.c_str());
  5056. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  5057. if (max_level > 0)
  5058. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  5059. else
  5060. pet->SetLevel(spawn->GetLevel());
  5061. // Set the max level this pet can reach
  5062. ((NPC*)pet)->SetMaxPetLevel(max_level);
  5063. ((NPC*)pet)->UpdateWeapons();
  5064. // Set the faction of the pet to the same faction as the owner
  5065. pet->SetFactionID(spawn->GetFactionID());
  5066. // Set the spawn as a pet
  5067. pet->SetPet(true);
  5068. // Give a pointer of the owner to the pet
  5069. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5070. // Give a pointer of the pet to the owner
  5071. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  5072. // Set the pet type
  5073. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  5074. // Set the spell id used to create this pet
  5075. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5076. // Set the spell tier used to create this pet
  5077. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5078. // Set the pets spawn type to 6
  5079. pet->SetSpawnType(6);
  5080. // Set the pets brain
  5081. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  5082. // Check to see if the pet has a subtitle
  5083. if (strlen(pet->GetSubTitle()) > 0) {
  5084. // Add the players name to the front of the sub title
  5085. string pet_subtitle;
  5086. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5087. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5088. // Set the pets subtitle to the new one
  5089. pet->SetSubTitle(pet_subtitle.c_str());
  5090. }
  5091. // Add the "Pet Options" entity command to the pet
  5092. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5093. const char* spawn_script = world.GetSpawnScript(pet_id);
  5094. bool runScript = false;
  5095. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  5096. runScript = true;
  5097. pet->SetSpawnScript(string(spawn_script));
  5098. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_PRESPAWN);
  5099. }
  5100. spawn->GetZone()->AddSpawn(pet);
  5101. if(runScript){
  5102. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_SPAWN);
  5103. }
  5104. // Set the pet as the return value for this function
  5105. lua_interface->SetSpawnValue(state, pet);
  5106. return 1;
  5107. }
  5108. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  5109. if (!lua_interface)
  5110. return 0;
  5111. Spawn* spawn = lua_interface->GetSpawn(state);
  5112. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5113. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5114. lua_interface->ResetFunctionStack(state);
  5115. if (!spawn) {
  5116. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5117. return 0;
  5118. }
  5119. if (!spawn->IsEntity()) {
  5120. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5121. return 0;
  5122. }
  5123. if (((Entity*)spawn)->GetDeityPet()) {
  5124. if (spawn->IsPlayer()) {
  5125. Client* client = ((Player*)spawn)->GetClient();
  5126. if (client)
  5127. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  5128. }
  5129. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5130. return 0;
  5131. }
  5132. if (pet_id == 0) {
  5133. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5134. return 0;
  5135. }
  5136. if (!luaspell) {
  5137. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5138. return 0;
  5139. }
  5140. if(luaspell->resisted) {
  5141. return 0;
  5142. }
  5143. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5144. if (!pet) {
  5145. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5146. return 0;
  5147. }
  5148. if (!pet->IsNPC()) {
  5149. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5150. return 0;
  5151. }
  5152. pet->SetX(spawn->GetX());
  5153. pet->SetY(spawn->GetY());
  5154. pet->SetZ(spawn->GetZ());
  5155. pet->SetLocation(spawn->GetLocation());
  5156. pet->SetHeading(spawn->GetHeading());
  5157. spawn->GetZone()->AddSpawn(pet);
  5158. string random_pet_name;
  5159. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5160. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5161. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5162. pet->SetName(random_pet_name.c_str());
  5163. pet->SetLevel(spawn->GetLevel());
  5164. pet->SetFactionID(spawn->GetFactionID());
  5165. pet->SetPet(true);
  5166. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  5167. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5168. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  5169. pet->SetSpawnType(6);
  5170. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5171. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5172. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5173. if (strlen(pet->GetSubTitle()) > 0) {
  5174. string pet_subtitle;
  5175. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5176. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5177. pet->SetSubTitle(pet_subtitle.c_str());
  5178. }
  5179. // deity and cosmetic pets are not attackable
  5180. pet->SetAttackable(false);
  5181. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5182. lua_interface->SetSpawnValue(state, pet);
  5183. return 1;
  5184. }
  5185. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  5186. if (!lua_interface)
  5187. return 0;
  5188. Spawn* spawn = lua_interface->GetSpawn(state);
  5189. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5190. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5191. lua_interface->ResetFunctionStack(state);
  5192. if (!spawn) {
  5193. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5194. return 0;
  5195. }
  5196. if (!spawn->IsEntity()) {
  5197. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5198. return 0;
  5199. }
  5200. if (((Entity*)spawn)->GetCosmeticPet()) {
  5201. if (spawn->IsPlayer()) {
  5202. Client* client = ((Player*)spawn)->GetClient();
  5203. if (client)
  5204. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  5205. }
  5206. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5207. return 0;
  5208. }
  5209. if (pet_id == 0) {
  5210. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5211. return 0;
  5212. }
  5213. if (!luaspell) {
  5214. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5215. return 0;
  5216. }
  5217. if(luaspell->resisted) {
  5218. return 0;
  5219. }
  5220. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5221. if (!pet) {
  5222. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5223. return 0;
  5224. }
  5225. if (!pet->IsNPC()) {
  5226. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5227. return 0;
  5228. }
  5229. pet->SetX(spawn->GetX());
  5230. pet->SetY(spawn->GetY());
  5231. pet->SetZ(spawn->GetZ());
  5232. pet->SetLocation(spawn->GetLocation());
  5233. pet->SetHeading(spawn->GetHeading());
  5234. spawn->GetZone()->AddSpawn(pet);
  5235. string random_pet_name;
  5236. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5237. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5238. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5239. pet->SetName(random_pet_name.c_str());
  5240. pet->SetLevel(spawn->GetLevel());
  5241. pet->SetFactionID(spawn->GetFactionID());
  5242. pet->SetPet(true);
  5243. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  5244. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5245. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5246. pet->SetSpawnType(6);
  5247. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5248. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5249. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5250. if (strlen(pet->GetSubTitle()) > 0) {
  5251. string pet_subtitle;
  5252. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5253. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5254. pet->SetSubTitle(pet_subtitle.c_str());
  5255. }
  5256. pet->SetAttackable(false);
  5257. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5258. lua_interface->SetSpawnValue(state, pet);
  5259. return 1;
  5260. }
  5261. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5262. if (!lua_interface)
  5263. return 0;
  5264. Spawn* spawn = lua_interface->GetSpawn(state);
  5265. lua_interface->ResetFunctionStack(state);
  5266. if (!spawn) {
  5267. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5268. return 0;
  5269. }
  5270. if (!spawn->IsPet()) {
  5271. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5272. return 0;
  5273. }
  5274. if (!((NPC*)spawn)->IsDismissing() && ((NPC*)spawn)->GetOwner())
  5275. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5276. return 0;
  5277. }
  5278. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5279. if (!lua_interface)
  5280. return 0;
  5281. Quest* quest = lua_interface->GetQuest(state);
  5282. if (!quest) {
  5283. 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));
  5284. lua_interface->ResetFunctionStack(state);
  5285. return 0;
  5286. }
  5287. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5288. lua_interface->ResetFunctionStack(state);
  5289. if (feather_color > 0)
  5290. quest->SetFeatherColor(feather_color);
  5291. return 0;
  5292. }
  5293. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5294. if (!lua_interface)
  5295. return 0;
  5296. Spawn* spawn = lua_interface->GetSpawn(state);
  5297. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5298. lua_interface->ResetFunctionStack(state);
  5299. if (!spawn) {
  5300. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5301. return 0;
  5302. }
  5303. if (!spawn2) {
  5304. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5305. return 0;
  5306. }
  5307. spawn->RemoveSpawnAccess(spawn2);
  5308. return 0;
  5309. }
  5310. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5311. if (!lua_interface)
  5312. return 0;
  5313. ZoneServer* zone = lua_interface->GetZone(state);
  5314. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5315. lua_interface->ResetFunctionStack(state);
  5316. if (!zone) {
  5317. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5318. return 0;
  5319. }
  5320. if (location_id == 0) {
  5321. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5322. return 0;
  5323. }
  5324. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5325. if (!location) {
  5326. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5327. return 0;
  5328. }
  5329. Spawn* spawn = 0;
  5330. if (location->entities[0]) {
  5331. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5332. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5333. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5334. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5335. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5336. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5337. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5338. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5339. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5340. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5341. if(spawn && spawn->IsOmittedByDBFlag())
  5342. {
  5343. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5344. safe_delete(spawn);
  5345. spawn = 0;
  5346. return 0;
  5347. }
  5348. if (spawn) {
  5349. const char* script = 0;
  5350. for (int x = 0; x < 3; x++) {
  5351. switch (x) {
  5352. case 0:
  5353. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5354. break;
  5355. case 1:
  5356. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5357. break;
  5358. case 2:
  5359. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5360. break;
  5361. }
  5362. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5363. spawn->SetSpawnScript(string(script));
  5364. break;
  5365. }
  5366. }
  5367. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5368. lua_interface->SetSpawnValue(state, spawn);
  5369. return 1;
  5370. }
  5371. else {
  5372. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5373. safe_delete(spawn);
  5374. }
  5375. }
  5376. return 0;
  5377. }
  5378. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5379. if (!lua_interface)
  5380. return 0;
  5381. Spawn* caster = lua_interface->GetSpawn(state);
  5382. Spawn* target = lua_interface->GetSpawn(state, 2);
  5383. int32 id = lua_interface->GetInt32Value(state, 3);
  5384. string command = lua_interface->GetStringValue(state, 4);
  5385. lua_interface->ResetFunctionStack(state);
  5386. if (!caster) {
  5387. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5388. return 0;
  5389. }
  5390. if (!target) {
  5391. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5392. return 0;
  5393. }
  5394. if (!caster->IsPlayer()) {
  5395. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5396. return 0;
  5397. }
  5398. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5399. if (!entity_command) {
  5400. 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());
  5401. return 0;
  5402. }
  5403. Client* client = ((Player*)caster)->GetClient();
  5404. if (!client) {
  5405. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5406. return 0;
  5407. }
  5408. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5409. return 0;
  5410. }
  5411. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5412. if (!lua_interface)
  5413. return 0;
  5414. Spawn* spawn = lua_interface->GetSpawn(state);
  5415. lua_interface->ResetFunctionStack(state);
  5416. if (!spawn) {
  5417. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5418. return 0;
  5419. }
  5420. if (!spawn->IsNPC()) {
  5421. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5422. return 0;
  5423. }
  5424. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5425. return 0;
  5426. }
  5427. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5428. if (!lua_interface)
  5429. return 0;
  5430. Spawn* spawn = lua_interface->GetSpawn(state);
  5431. int16 tick = lua_interface->GetInt16Value(state, 2);
  5432. lua_interface->ResetFunctionStack(state);
  5433. if (!spawn) {
  5434. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5435. return 0;
  5436. }
  5437. if (!spawn->IsNPC()) {
  5438. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5439. return 0;
  5440. }
  5441. if (tick < 20) {
  5442. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5443. return 0;
  5444. }
  5445. ((NPC*)spawn)->Brain()->SetTick(tick);
  5446. return 0;
  5447. }
  5448. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5449. if (!lua_interface)
  5450. return 0;
  5451. Spawn* spawn = lua_interface->GetSpawn(state);
  5452. Spawn* target = lua_interface->GetSpawn(state, 2);
  5453. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5454. lua_interface->ResetFunctionStack(state);
  5455. if (!spawn) {
  5456. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5457. return 0;
  5458. }
  5459. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5460. spawn->SetFollowTarget(target, follow_distance);
  5461. return 0;
  5462. }
  5463. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5464. if (!lua_interface)
  5465. return 0;
  5466. Spawn* spawn = lua_interface->GetSpawn(state);
  5467. lua_interface->ResetFunctionStack(state);
  5468. if (!spawn) {
  5469. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5470. return 0;
  5471. }
  5472. Spawn* target = spawn->GetFollowTarget();
  5473. if (target) {
  5474. lua_interface->SetSpawnValue(state, target);
  5475. return 1;
  5476. }
  5477. return 0;
  5478. }
  5479. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5480. if (!lua_interface)
  5481. return 0;
  5482. Spawn* spawn = lua_interface->GetSpawn(state);
  5483. lua_interface->ResetFunctionStack(state);
  5484. if (!spawn) {
  5485. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5486. return 0;
  5487. }
  5488. if (spawn->following)
  5489. spawn->following = false;
  5490. else
  5491. spawn->following = true;
  5492. return 0;
  5493. }
  5494. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5495. if (!lua_interface)
  5496. return 0;
  5497. Spawn* spawn = lua_interface->GetSpawn(state);
  5498. lua_interface->ResetFunctionStack(state);
  5499. if (!spawn) {
  5500. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5501. return 0;
  5502. }
  5503. lua_interface->SetBooleanValue(state, spawn->following);
  5504. return 1;
  5505. }
  5506. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5507. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5508. // I will attempt to explain how this function works for future refrence
  5509. // Fist lets make sure lua_interface is valid, if not return out
  5510. if (!lua_interface)
  5511. return 0;
  5512. // Next we grab the first 2 params same as we usually would
  5513. Spawn* spawn = lua_interface->GetSpawn(state);
  5514. string var = lua_interface->GetStringValue(state, 2);
  5515. // 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
  5516. // 1 = Spawn
  5517. // 2 = Zone
  5518. // 3 = Item
  5519. // 4 = Quest
  5520. // 5 = String
  5521. // 6 = nil (null)
  5522. int8 dataType = 0;
  5523. // Define pointers for each potential type
  5524. Spawn* spawnVal = 0;
  5525. ZoneServer* zone = 0;
  5526. Item* item = 0;
  5527. Quest* quest = 0;
  5528. string val;
  5529. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5530. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5531. // options window are also light user data be we do not handle those.
  5532. // We check with lua_islightuserdata(lua_State*, index)
  5533. if (lua_islightuserdata(state, 3)) {
  5534. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5535. // and convert it to LUAUserData*
  5536. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5537. // Check to make sure the data we got is valid, if not give an error
  5538. if (!data || !data->IsCorrectlyInitialized()) {
  5539. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5540. }
  5541. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5542. else if (data->IsSpawn()) {
  5543. spawnVal = data->spawn;
  5544. dataType = 1;
  5545. }
  5546. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5547. else if (data->IsZone()) {
  5548. zone = data->zone;
  5549. dataType = 2;
  5550. }
  5551. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5552. else if (data->IsItem()) {
  5553. item = data->item;
  5554. dataType = 3;
  5555. }
  5556. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5557. else if (data->IsQuest()) {
  5558. quest = data->quest;
  5559. dataType = 4;
  5560. }
  5561. }
  5562. // Wasn't light user data, check if it is nil(null)
  5563. else if (lua_isnil(state, 3)) {
  5564. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5565. dataType = 6;
  5566. }
  5567. // Wasn't light user data or nil (null), must be a string
  5568. else {
  5569. // Set the string and dataType variable
  5570. val = lua_interface->GetStringValue(state, 3);
  5571. dataType = 5;
  5572. }
  5573. lua_interface->ResetFunctionStack(state);
  5574. // We now have all the params, lets check to make sure they are valid
  5575. if (!spawn) {
  5576. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5577. return 0;
  5578. }
  5579. if (var.length() == 0) {
  5580. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5581. return 0;
  5582. }
  5583. if (dataType == 0) {
  5584. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5585. return 0;
  5586. }
  5587. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5588. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5589. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5590. switch (dataType) {
  5591. case 1:
  5592. // 1 = Spawn
  5593. spawn->AddTempVariable(var, spawnVal);
  5594. break;
  5595. case 2:
  5596. // 2 = Zone
  5597. spawn->AddTempVariable(var, zone);
  5598. break;
  5599. case 3:
  5600. // 3 = Item
  5601. spawn->AddTempVariable(var, item);
  5602. break;
  5603. case 4:
  5604. // 4 = Quest
  5605. spawn->AddTempVariable(var, quest);
  5606. break;
  5607. case 5:
  5608. // 5 = String
  5609. spawn->AddTempVariable(var, val);
  5610. break;
  5611. case 6:
  5612. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5613. spawn->DeleteTempVariable(var);
  5614. break;
  5615. }
  5616. // And we are done so return out
  5617. return 0;
  5618. }
  5619. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5620. if (!lua_interface)
  5621. return 0;
  5622. Spawn* spawn = lua_interface->GetSpawn(state);
  5623. string var = lua_interface->GetStringValue(state, 2);
  5624. lua_interface->ResetFunctionStack(state);
  5625. if (!spawn) {
  5626. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5627. return 0;
  5628. }
  5629. if (var.length() == 0) {
  5630. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5631. return 0;
  5632. }
  5633. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5634. int8 type = spawn->GetTempVariableType(var);
  5635. Spawn* spawn2 = 0;
  5636. ZoneServer* zone = 0;
  5637. Item* item = 0;
  5638. Quest* quest = 0;
  5639. // Set the lua function return value based on the type of data the variable contains
  5640. switch (type) {
  5641. case 1:
  5642. spawn2 = spawn->GetTempVariableSpawn(var);
  5643. if (!spawn2)
  5644. return 0;
  5645. lua_interface->SetSpawnValue(state, spawn2);
  5646. break;
  5647. case 2:
  5648. zone = spawn->GetTempVariableZone(var);
  5649. if (!zone)
  5650. return 0;
  5651. lua_interface->SetZoneValue(state, zone);
  5652. break;
  5653. case 3:
  5654. item = spawn->GetTempVariableItem(var);
  5655. if (!item)
  5656. return 0;
  5657. lua_interface->SetItemValue(state, item);
  5658. break;
  5659. case 4:
  5660. quest = spawn->GetTempVariableQuest(var);
  5661. if (!quest)
  5662. return 0;
  5663. lua_interface->SetQuestValue(state, quest);
  5664. break;
  5665. case 5:
  5666. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5667. break;
  5668. default:
  5669. // Not a valid type then the variable was not set so return out
  5670. return 0;
  5671. }
  5672. // Return value was set so return out
  5673. return 1;
  5674. }
  5675. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5676. {
  5677. if (!lua_interface)
  5678. return 0;
  5679. Quest* quest = lua_interface->GetQuest(state);
  5680. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5681. string description = lua_interface->GetStringValue(state, 3);
  5682. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5683. if (!quest) {
  5684. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5685. lua_interface->ResetFunctionStack(state);
  5686. lua_interface->SetBooleanValue(state, false);
  5687. return 1;
  5688. }
  5689. if (!spawn) {
  5690. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5691. lua_interface->ResetFunctionStack(state);
  5692. lua_interface->SetBooleanValue(state, false);
  5693. return 1;
  5694. }
  5695. if (!spawn->IsPlayer()) {
  5696. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5697. lua_interface->ResetFunctionStack(state);
  5698. lua_interface->SetBooleanValue(state, false);
  5699. return 1;
  5700. }
  5701. if (item_id == 0) {
  5702. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5703. lua_interface->ResetFunctionStack(state);
  5704. lua_interface->SetBooleanValue(state, false);
  5705. return 1;
  5706. }
  5707. Client* client = ((Player*)spawn)->GetClient();
  5708. if (!client) {
  5709. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given player spawn", lua_interface->GetScriptName(state));
  5710. lua_interface->ResetFunctionStack(state);
  5711. lua_interface->SetBooleanValue(state, false);
  5712. return 1;
  5713. }
  5714. Item* item = master_item_list.GetItem(item_id);
  5715. if (!item) {
  5716. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5717. lua_interface->ResetFunctionStack(state);
  5718. lua_interface->SetBooleanValue(state, false);
  5719. return 1;
  5720. }
  5721. Item* firstItem = new Item(item);
  5722. quest->AddTmpRewardItem(firstItem);
  5723. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5724. bool itemsAddedSuccessfully = true;
  5725. if(num_args > 4)
  5726. {
  5727. for(int8 n=5;n<num_args+1;n++)
  5728. {
  5729. int32 new_item = lua_interface->GetInt32Value(state, n);
  5730. Item* tmpItem = master_item_list.GetItem(new_item);
  5731. if(tmpItem)
  5732. {
  5733. Item* newTmpItem = new Item(tmpItem);
  5734. quest->AddTmpRewardItem(newTmpItem);
  5735. }
  5736. else
  5737. itemsAddedSuccessfully = false;
  5738. }
  5739. }
  5740. client->AddPendingQuestReward(quest, true, true, description); // queue for display
  5741. lua_interface->ResetFunctionStack(state);
  5742. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5743. return 1;
  5744. }
  5745. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5746. if (!lua_interface)
  5747. return 0;
  5748. Quest* quest = lua_interface->GetQuest(state);
  5749. lua_interface->ResetFunctionStack(state);
  5750. if (!quest) {
  5751. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5752. return 0;
  5753. }
  5754. quest->SetRepeatable(true);
  5755. return 0;
  5756. }
  5757. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5758. if (!lua_interface)
  5759. return 0;
  5760. Spawn* spawn = lua_interface->GetSpawn(state);
  5761. lua_interface->ResetFunctionStack(state);
  5762. if (!spawn) {
  5763. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5764. return 0;
  5765. }
  5766. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5767. string ret = classes.GetClassNameCase(base_class);
  5768. if (ret.length() > 0) {
  5769. lua_interface->SetStringValue(state, ret.c_str());
  5770. return 1;
  5771. }
  5772. return 0;
  5773. }
  5774. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5775. if (!lua_interface)
  5776. return 0;
  5777. Spawn* player = lua_interface->GetSpawn(state);
  5778. lua_interface->ResetFunctionStack(state);
  5779. if (player && player->IsPlayer()) {
  5780. Client* client = player->GetClient();
  5781. if (client)
  5782. client->SendWaypoints();
  5783. }
  5784. return 0;
  5785. }
  5786. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5787. if (!lua_interface)
  5788. return 0;
  5789. Spawn* player = lua_interface->GetSpawn(state);
  5790. string name = lua_interface->GetStringValue(state, 2);
  5791. int32 type = lua_interface->GetInt32Value(state, 3);
  5792. lua_interface->ResetFunctionStack(state);
  5793. if (type == 0)
  5794. type = 2;
  5795. if (name.length() > 0) {
  5796. if (player && player->IsPlayer()) {
  5797. Client* client = player->GetClient();
  5798. if (client)
  5799. client->AddWaypoint(name, type);
  5800. }
  5801. }
  5802. return 0;
  5803. }
  5804. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5805. if (!lua_interface)
  5806. return 0;
  5807. Spawn* player = lua_interface->GetSpawn(state);
  5808. string name = lua_interface->GetStringValue(state, 2);
  5809. lua_interface->ResetFunctionStack(state);
  5810. if (name.length() > 0) {
  5811. if (player && player->IsPlayer()) {
  5812. Client* client = player->GetClient();
  5813. if (client)
  5814. client->RemoveWaypoint(name);
  5815. }
  5816. }
  5817. return 0;
  5818. }
  5819. int EQ2Emu_lua_AddWard(lua_State* state) {
  5820. if (!lua_interface)
  5821. return 0;
  5822. int32 damage = lua_interface->GetInt32Value(state);
  5823. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5824. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5825. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5826. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5827. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5828. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5829. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5830. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5831. lua_interface->ResetFunctionStack(state);
  5832. if(!spell || spell->resisted) {
  5833. return 0;
  5834. }
  5835. bool ward_was_added = false;
  5836. ZoneServer* zone = spell->caster->GetZone();
  5837. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5838. for (int32 i = 0; i < spell->targets.size(); i++) {
  5839. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5840. if (!target)
  5841. continue;
  5842. if (target->IsEntity()) {
  5843. // If the ward is already active remove it
  5844. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5845. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5846. // Create new ward info
  5847. WardInfo* ward = new WardInfo;
  5848. ward->Spell = spell;
  5849. ward->BaseDamage = damage;
  5850. ward->DamageLeft = damage;
  5851. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5852. ward->keepWard = keepWard;
  5853. ward->WardType = wardType;
  5854. if (damageAbsorptionPercent > 100)
  5855. damageAbsorptionPercent = 100;
  5856. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5857. if (damageAbsorptionMaxHealthPercent > 100)
  5858. damageAbsorptionMaxHealthPercent = 100;
  5859. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5860. ward->RedirectDamagePercent = redirectDamagePercent;
  5861. ward->LastRedirectDamage = 0;
  5862. ward->LastAbsorbedDamage = 0;
  5863. ward->HitCount = 0;
  5864. spell->num_triggers = maxHitCount;
  5865. spell->had_triggers = true;
  5866. spell->cancel_after_all_triggers = false;
  5867. ward->MaxHitCount = maxHitCount;
  5868. ward->RoundTriggered = false;
  5869. if (wardType == WARD_TYPE_MAGICAL)
  5870. ward->DamageType = damageTypes;
  5871. // Add the ward to the entity
  5872. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5873. ward_was_added = true;
  5874. }
  5875. }
  5876. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5877. if (ward_was_added && spell->caster->IsPlayer()) {
  5878. spell->had_dmg_remaining = true;
  5879. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, damage, 1);
  5880. }
  5881. return 0;
  5882. }
  5883. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5884. if (!lua_interface)
  5885. return 0;
  5886. int32 amount = lua_interface->GetInt32Value(state);
  5887. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5888. lua_interface->ResetFunctionStack(state);
  5889. WardInfo* ward = 0;
  5890. if(!spell || spell->resisted) {
  5891. return 0;
  5892. }
  5893. ZoneServer* zone = spell->caster->GetZone();
  5894. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5895. if (spell->targets.size() > 0 && zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5896. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5897. ward = target->GetWard(spell->spell->GetSpellID());
  5898. if (target && ward) {
  5899. ward->DamageLeft += amount;
  5900. if (ward->DamageLeft > ward->BaseDamage)
  5901. ward->DamageLeft = ward->BaseDamage;
  5902. for (int32 i = 0; i < spell->targets.size(); i++) {
  5903. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5904. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5905. }
  5906. }
  5907. }
  5908. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5909. if (ward && spell->caster->IsPlayer())
  5910. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
  5911. return 0;
  5912. }
  5913. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5914. if (!lua_interface)
  5915. return 0;
  5916. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5917. lua_interface->ResetFunctionStack(state);
  5918. if (!spell) {
  5919. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5920. return 0;
  5921. }
  5922. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5923. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5924. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5925. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5926. if (ward) {
  5927. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5928. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5929. return 1;
  5930. }
  5931. }
  5932. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5933. return 0;
  5934. }
  5935. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5936. if (!lua_interface)
  5937. return 0;
  5938. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5939. if (!spell) {
  5940. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5941. lua_interface->ResetFunctionStack(state);
  5942. return 0;
  5943. }
  5944. string type = lua_interface->GetStringValue(state, 2);
  5945. lua_interface->ResetFunctionStack(state);
  5946. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5947. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5948. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5949. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5950. if (ward) {
  5951. if (boost::iequals(type, "damageleft"))
  5952. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5953. else if (boost::iequals(type, "basedamage"))
  5954. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5955. else if (boost::iequals(type, "keepward"))
  5956. lua_interface->SetBooleanValue(state, ward->keepWard);
  5957. else if (boost::iequals(type, "wardtype"))
  5958. lua_interface->SetInt32Value(state, ward->WardType);
  5959. else if (boost::iequals(type, "dmgabsorptionpct"))
  5960. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5961. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5962. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5963. else if (boost::iequals(type, "redirectdamagepercent"))
  5964. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5965. else if (boost::iequals(type, "lastredirectdamage"))
  5966. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5967. else if (boost::iequals(type, "lastabsorbeddamage"))
  5968. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5969. else if (boost::iequals(type, "hitcount"))
  5970. lua_interface->SetInt32Value(state, ward->HitCount);
  5971. else if (boost::iequals(type, "maxhitcount"))
  5972. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5973. else
  5974. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5975. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5976. return 1;
  5977. }
  5978. }
  5979. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5980. return 0;
  5981. }
  5982. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5983. if (!lua_interface)
  5984. return 0;
  5985. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5986. lua_interface->ResetFunctionStack(state);
  5987. if(!spell) {
  5988. return 0;
  5989. }
  5990. ZoneServer* zone = spell->caster->GetZone();
  5991. Spawn* target = 0;
  5992. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5993. for (int32 i = 0; i < spell->targets.size(); i++) {
  5994. target = zone->GetSpawnByID(spell->targets.at(i));
  5995. if (target && target->IsEntity()) {
  5996. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5997. }
  5998. }
  5999. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6000. return 0;
  6001. }
  6002. int EQ2Emu_lua_Interrupt(lua_State* state)
  6003. {
  6004. if (!lua_interface)
  6005. return 0;
  6006. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  6007. Spawn* target = lua_interface->GetSpawn(state, 2);
  6008. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6009. lua_interface->ResetFunctionStack(state);
  6010. if (!caster)
  6011. {
  6012. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6013. return 0;
  6014. }
  6015. if (!target)
  6016. {
  6017. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6018. return 0;
  6019. }
  6020. if (!spell) {
  6021. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  6022. return 0;
  6023. }
  6024. if (!target->IsEntity() && !spell)
  6025. {
  6026. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  6027. return 0;
  6028. }
  6029. if (!target && spell) {
  6030. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6031. for (int8 i = 0; i < spell->targets.size(); i++) {
  6032. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6033. if (!target || !target->IsEntity())
  6034. continue;
  6035. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  6036. }
  6037. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6038. }
  6039. else
  6040. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  6041. return 0;
  6042. }
  6043. int EQ2Emu_lua_Stealth(lua_State* state) {
  6044. if (!lua_interface)
  6045. return 0;
  6046. int8 type = lua_interface->GetInt8Value(state);
  6047. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6048. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6049. lua_interface->ResetFunctionStack(state);
  6050. if (!spell) {
  6051. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  6052. return 0;
  6053. }
  6054. ZoneServer* zone = spell->caster->GetZone();
  6055. if (spawn) {
  6056. if (spawn->IsEntity()) {
  6057. if (type == 1) {
  6058. ((Entity*)spawn)->AddStealthSpell(spell);
  6059. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  6060. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  6061. }
  6062. else if (type == 2) {
  6063. ((Entity*)spawn)->AddInvisSpell(spell);
  6064. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  6065. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  6066. }
  6067. return 0;
  6068. }
  6069. else {
  6070. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  6071. return 0;
  6072. }
  6073. }
  6074. else {
  6075. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6076. for (int32 i = 0; i < spell->targets.size(); i++) {
  6077. spawn = zone->GetSpawnByID(spell->targets.at(i));
  6078. if (!spawn || !spawn->IsEntity())
  6079. continue;
  6080. if (type == 1) {
  6081. ((Entity*)spawn)->AddStealthSpell(spell);
  6082. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  6083. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  6084. }
  6085. else if (type == 2) {
  6086. ((Entity*)spawn)->AddInvisSpell(spell);
  6087. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  6088. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  6089. }
  6090. else {
  6091. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  6092. break;
  6093. }
  6094. }
  6095. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6096. }
  6097. return 0;
  6098. }
  6099. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  6100. if (!lua_interface)
  6101. return 0;
  6102. Spawn* spawn = lua_interface->GetSpawn(state);
  6103. lua_interface->ResetFunctionStack(state);
  6104. if (!spawn) {
  6105. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6106. return 0;
  6107. }
  6108. if (spawn->IsEntity()) {
  6109. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  6110. return 1;
  6111. }
  6112. else
  6113. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  6114. return 0;
  6115. }
  6116. int EQ2Emu_lua_IsInvis(lua_State* state) {
  6117. if (!lua_interface)
  6118. return 0;
  6119. Spawn* spawn = lua_interface->GetSpawn(state);
  6120. lua_interface->ResetFunctionStack(state);
  6121. if (!spawn) {
  6122. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  6123. return 0;
  6124. }
  6125. if (spawn->IsEntity()) {
  6126. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  6127. return 1;
  6128. }
  6129. else
  6130. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  6131. return 0;
  6132. }
  6133. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  6134. if (!lua_interface)
  6135. return 0;
  6136. Spawn* player = lua_interface->GetSpawn(state);
  6137. int32 item_id = lua_interface->GetInt32Value(state, 2);
  6138. lua_interface->ResetFunctionStack(state);
  6139. if (!player->IsPlayer()) {
  6140. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  6141. return 0;
  6142. }
  6143. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  6144. return 1;
  6145. }
  6146. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  6147. if (!lua_interface)
  6148. return 0;
  6149. Spawn* spawn = lua_interface->GetSpawn(state);
  6150. int8 slot = lua_interface->GetInt8Value(state, 2);
  6151. lua_interface->ResetFunctionStack(state);
  6152. if (!spawn) {
  6153. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6154. return 0;
  6155. }
  6156. if (!spawn->IsEntity()) {
  6157. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6158. return 0;
  6159. }
  6160. Item* item = ((Entity*)spawn)->GetEquipmentList()->GetItem(slot);
  6161. if (!item) {
  6162. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  6163. return 0;
  6164. }
  6165. lua_interface->SetItemValue(state, item);
  6166. return 1;
  6167. }
  6168. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  6169. if (!lua_interface)
  6170. return 0;
  6171. Spawn* player = lua_interface->GetSpawn(state);
  6172. int32 id = lua_interface->GetInt32Value(state, 2);
  6173. lua_interface->ResetFunctionStack(state);
  6174. if (!player) {
  6175. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6176. return 0;
  6177. }
  6178. if (!player->IsPlayer()) {
  6179. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6180. return 0;
  6181. }
  6182. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  6183. if (!item) {
  6184. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  6185. return 0;
  6186. }
  6187. lua_interface->SetItemValue(state, item);
  6188. return 1;
  6189. }
  6190. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  6191. if (!lua_interface)
  6192. return 0;
  6193. Spawn* spawn = lua_interface->GetSpawn(state);
  6194. int8 slot = lua_interface->GetInt8Value(state, 2);
  6195. int32 item_id = lua_interface->GetInt32Value(state, 3);
  6196. lua_interface->ResetFunctionStack(state);
  6197. if (!spawn) {
  6198. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6199. return 0;
  6200. }
  6201. if (!spawn->IsEntity()) {
  6202. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6203. return 0;
  6204. }
  6205. Item* item = master_item_list.GetItem(item_id);
  6206. if (!item) {
  6207. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  6208. return 0;
  6209. }
  6210. Item* copy = new Item(item);
  6211. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  6212. if(result)
  6213. {
  6214. ((Entity*)spawn)->SetEquipment(copy, slot);
  6215. spawn->vis_changed = true;
  6216. if(spawn->IsPlayer())
  6217. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6218. }
  6219. else
  6220. {
  6221. safe_delete(copy);
  6222. }
  6223. lua_interface->SetBooleanValue(state, result);
  6224. return 1;
  6225. }
  6226. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  6227. if (!lua_interface)
  6228. return 0;
  6229. Spawn* spawn = lua_interface->GetSpawn(state);
  6230. int8 slot = lua_interface->GetInt8Value(state, 2);
  6231. Item* item = lua_interface->GetItem(state, 3);
  6232. lua_interface->ResetFunctionStack(state);
  6233. if (!spawn) {
  6234. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  6235. return 0;
  6236. }
  6237. if (!spawn->IsEntity()) {
  6238. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6239. return 0;
  6240. }
  6241. if (!item) {
  6242. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  6243. return 0;
  6244. }
  6245. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  6246. if(result)
  6247. {
  6248. ((Entity*)spawn)->SetEquipment(item, slot);
  6249. spawn->vis_changed = true;
  6250. if(spawn->IsPlayer())
  6251. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6252. }
  6253. lua_interface->SetBooleanValue(state, result);
  6254. return 1;
  6255. }
  6256. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  6257. if (!lua_interface)
  6258. return 0;
  6259. Spawn* spawn = lua_interface->GetSpawn(state);
  6260. int8 slot = lua_interface->GetInt8Value(state, 2);
  6261. 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
  6262. lua_interface->ResetFunctionStack(state);
  6263. if (!spawn) {
  6264. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6265. return 0;
  6266. }
  6267. if (!spawn->IsEntity()) {
  6268. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6269. return 0;
  6270. }
  6271. if(slot >= NUM_SLOTS) {
  6272. lua_interface->LogError("%s: LUA UnequipSlot command error: wrong slot id given %u, max %u", lua_interface->GetScriptName(state), slot, NUM_SLOTS);
  6273. return 0;
  6274. }
  6275. if(spawn->IsPlayer() && ((Player*)spawn)->GetClient()) {
  6276. Item* item = ((Player*)spawn)->GetEquipmentList()->GetItem(slot);
  6277. if(item) {
  6278. item->save_needed = true;
  6279. if(no_delete_item) {
  6280. database.DeleteItem(((Player*)spawn)->GetClient()->GetCharacterID(), item, 0);
  6281. ((Player*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6282. }
  6283. else{
  6284. Client* client = ((Player*)spawn)->GetClient();
  6285. client->UnequipItem(item->details.index);
  6286. }
  6287. }
  6288. }
  6289. else
  6290. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6291. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  6292. spawn->vis_changed = true;
  6293. if(spawn->IsPlayer())
  6294. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6295. lua_interface->SetBooleanValue(state, true);
  6296. return 1;
  6297. }
  6298. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  6299. if (!lua_interface)
  6300. return 0;
  6301. Spawn* spawn = lua_interface->GetSpawn(state);
  6302. int8 slot = lua_interface->GetInt8Value(state, 2);
  6303. int16 type = lua_interface->GetInt16Value(state, 3);
  6304. int8 r = lua_interface->GetInt8Value(state, 4);
  6305. int8 g = lua_interface->GetInt8Value(state, 5);
  6306. int8 b = lua_interface->GetInt8Value(state, 6);
  6307. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6308. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6309. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6310. lua_interface->ResetFunctionStack(state);
  6311. if (!spawn) {
  6312. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6313. return 0;
  6314. }
  6315. if (!spawn->IsEntity()) {
  6316. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6317. return 0;
  6318. }
  6319. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6320. spawn->vis_changed = true;
  6321. lua_interface->SetBooleanValue(state, true);
  6322. return 1;
  6323. }
  6324. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6325. if (!lua_interface)
  6326. return 0;
  6327. Spawn* player = lua_interface->GetSpawn(state);
  6328. int32 id = lua_interface->GetInt32Value(state, 2);
  6329. int8 count = lua_interface->GetInt8Value(state, 3);
  6330. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6331. lua_interface->ResetFunctionStack(state);
  6332. if (!player) {
  6333. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6334. return 0;
  6335. }
  6336. if (!player->IsPlayer()) {
  6337. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6338. return 0;
  6339. }
  6340. if (!count)
  6341. count = 1;
  6342. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6343. if (!item) {
  6344. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6345. return 0;
  6346. }
  6347. lua_interface->SetItemValue(state, item);
  6348. return 1;
  6349. }
  6350. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6351. if (!lua_interface)
  6352. return 0;
  6353. Spawn* spawn = lua_interface->GetSpawn(state);
  6354. int32 anim = lua_interface->GetInt32Value(state, 2);
  6355. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6356. int8 type = lua_interface->GetInt8Value(state, 4);
  6357. lua_interface->ResetFunctionStack(state);
  6358. if (!spawn) {
  6359. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6360. return 0;
  6361. }
  6362. if (spawn2) {
  6363. if (spawn2->IsPlayer()) {
  6364. if (type != 1 && type != 2)
  6365. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6366. else
  6367. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6368. return 0;
  6369. }
  6370. else {
  6371. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6372. return 0;
  6373. }
  6374. }
  6375. else
  6376. spawn->GetZone()->PlayAnimation(spawn, anim);
  6377. return 0;
  6378. }
  6379. int EQ2Emu_lua_IsPet(lua_State* state) {
  6380. if (!lua_interface)
  6381. return 0;
  6382. Spawn* spawn = lua_interface->GetSpawn(state);
  6383. lua_interface->ResetFunctionStack(state);
  6384. if (!spawn) {
  6385. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6386. return 0;
  6387. }
  6388. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6389. return 1;
  6390. }
  6391. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6392. if (!lua_interface)
  6393. return 0;
  6394. Spawn* spawn = lua_interface->GetSpawn(state);
  6395. lua_interface->ResetFunctionStack(state);
  6396. if (!spawn) {
  6397. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6398. return 0;
  6399. }
  6400. if (!spawn->IsNPC()) {
  6401. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6402. return 0;
  6403. }
  6404. if (((NPC*)spawn)->GetOwner()) {
  6405. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6406. return 1;
  6407. }
  6408. return 0;
  6409. }
  6410. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6411. if (!lua_interface)
  6412. return 0;
  6413. Spawn* spawn = lua_interface->GetSpawn(state);
  6414. Spawn* target = lua_interface->GetSpawn(state, 2);
  6415. lua_interface->ResetFunctionStack(state);
  6416. if (!spawn) {
  6417. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6418. return 0;
  6419. }
  6420. if (!spawn) {
  6421. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6422. return 0;
  6423. }
  6424. spawn->SetTarget(target);
  6425. return 0;
  6426. }
  6427. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6428. if (!lua_interface)
  6429. return 0;
  6430. Spawn* spawn = lua_interface->GetSpawn(state);
  6431. bool val = lua_interface->GetBooleanValue(state, 2);
  6432. lua_interface->ResetFunctionStack(state);
  6433. if (!spawn) {
  6434. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6435. return 0;
  6436. }
  6437. if (!spawn->IsEntity()) {
  6438. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6439. return 0;
  6440. }
  6441. ((Entity*)spawn)->InCombat(val);
  6442. if (val) {
  6443. spawn->ClearRunningLocations();
  6444. spawn->CalculateRunningLocation(true);
  6445. }
  6446. return 0;
  6447. }
  6448. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6449. if (!lua_interface)
  6450. return 0;
  6451. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6452. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6453. lua_interface->ResetFunctionStack(state);
  6454. if (!spawn1) {
  6455. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6456. return 0;
  6457. }
  6458. if (!spawn2) {
  6459. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6460. return 0;
  6461. }
  6462. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6463. return 1;
  6464. }
  6465. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6466. if (!lua_interface)
  6467. return 0;
  6468. Spawn* spawn = lua_interface->GetSpawn(state);
  6469. lua_interface->ResetFunctionStack(state);
  6470. if (!spawn) {
  6471. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6472. return 0;
  6473. }
  6474. if (!spawn->IsNPC()) {
  6475. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6476. return 0;
  6477. }
  6478. ((NPC*)spawn)->ClearRunback();
  6479. return 0;
  6480. }
  6481. int EQ2Emu_lua_Runback(lua_State* state) {
  6482. if (!lua_interface)
  6483. return 0;
  6484. Spawn* spawn = lua_interface->GetSpawn(state);
  6485. lua_interface->ResetFunctionStack(state);
  6486. if (!spawn) {
  6487. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6488. return 0;
  6489. }
  6490. if (!spawn->IsNPC()) {
  6491. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6492. return 0;
  6493. }
  6494. ((NPC*)spawn)->Runback();
  6495. return 0;
  6496. }
  6497. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6498. if (!lua_interface)
  6499. return 0;
  6500. Spawn* spawn = lua_interface->GetSpawn(state);
  6501. lua_interface->ResetFunctionStack(state);
  6502. if (!spawn) {
  6503. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6504. return 0;
  6505. }
  6506. if (!spawn->IsNPC()) {
  6507. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6508. return 0;
  6509. }
  6510. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6511. return 1;
  6512. }
  6513. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6514. if (!lua_interface)
  6515. return 0;
  6516. Spawn* spawn = lua_interface->GetSpawn(state);
  6517. lua_interface->ResetFunctionStack(state);
  6518. if (!spawn) {
  6519. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6520. return 0;
  6521. }
  6522. if (!spawn->IsEntity()) {
  6523. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6524. return 0;
  6525. }
  6526. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6527. return 1;
  6528. }
  6529. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6530. if (!lua_interface)
  6531. return 0;
  6532. Spawn* spawn = lua_interface->GetSpawn(state);
  6533. lua_interface->ResetFunctionStack(state);
  6534. if (!spawn) {
  6535. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6536. return 0;
  6537. }
  6538. if (!spawn->IsEntity()) {
  6539. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6540. return 0;
  6541. }
  6542. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6543. return 1;
  6544. }
  6545. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6546. if (!lua_interface)
  6547. return 0;
  6548. Spawn* spawn = lua_interface->GetSpawn(state);
  6549. lua_interface->ResetFunctionStack(state);
  6550. if (!spawn) {
  6551. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6552. return 0;
  6553. }
  6554. if (!spawn->IsEntity()) {
  6555. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6556. return 0;
  6557. }
  6558. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6559. return 1;
  6560. }
  6561. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6562. if (!lua_interface)
  6563. return 0;
  6564. Spawn* spawn = lua_interface->GetSpawn(state);
  6565. lua_interface->ResetFunctionStack(state);
  6566. if (!spawn) {
  6567. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6568. return 0;
  6569. }
  6570. if (!spawn->IsEntity()) {
  6571. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6572. return 0;
  6573. }
  6574. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6575. return 1;
  6576. }
  6577. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6578. if (!lua_interface)
  6579. return 0;
  6580. Spawn* spawn = lua_interface->GetSpawn(state);
  6581. Spawn* target = lua_interface->GetSpawn(state, 2);
  6582. float distance = lua_interface->GetFloatValue(state, 3);
  6583. lua_interface->ResetFunctionStack(state);
  6584. if (!spawn) {
  6585. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6586. return 0;
  6587. }
  6588. if (!target) {
  6589. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6590. return 0;
  6591. }
  6592. if (!spawn->IsNPC()) {
  6593. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6594. return 0;
  6595. }
  6596. if (!target->IsEntity()) {
  6597. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6598. return 0;
  6599. }
  6600. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6601. return 1;
  6602. }
  6603. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6604. if (!lua_interface)
  6605. return 0;
  6606. Spawn* spawn = lua_interface->GetSpawn(state);
  6607. Spawn* target = lua_interface->GetSpawn(state, 2);
  6608. float distance = lua_interface->GetFloatValue(state, 3);
  6609. lua_interface->ResetFunctionStack(state);
  6610. if (!spawn) {
  6611. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6612. return 0;
  6613. }
  6614. if (!target) {
  6615. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6616. return 0;
  6617. }
  6618. if (!spawn->IsNPC()) {
  6619. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6620. return 0;
  6621. }
  6622. if (!target->IsEntity()) {
  6623. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6624. return 0;
  6625. }
  6626. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6627. return 0;
  6628. }
  6629. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6630. if (!lua_interface)
  6631. return 0;
  6632. Spawn* spawn = lua_interface->GetSpawn(state);
  6633. lua_interface->ResetFunctionStack(state);
  6634. if (!spawn) {
  6635. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6636. return 0;
  6637. }
  6638. if (!spawn->IsNPC()) {
  6639. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6640. return 0;
  6641. }
  6642. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6643. return 1;
  6644. }
  6645. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6646. if (!lua_interface)
  6647. return 0;
  6648. Spawn* spawn = lua_interface->GetSpawn(state);
  6649. lua_interface->ResetFunctionStack(state);
  6650. if (!spawn) {
  6651. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6652. return 0;
  6653. }
  6654. if (!spawn->IsNPC()) {
  6655. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6656. return 0;
  6657. }
  6658. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6659. return 1;
  6660. }
  6661. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6662. if (!lua_interface)
  6663. return 0;
  6664. Spawn* spawn = lua_interface->GetSpawn(state);
  6665. lua_interface->ResetFunctionStack(state);
  6666. if (!spawn) {
  6667. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6668. return 0;
  6669. }
  6670. if (!spawn->IsNPC()) {
  6671. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6672. return 0;
  6673. }
  6674. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6675. if (hated) {
  6676. lua_interface->SetSpawnValue(state, hated);
  6677. return 1;
  6678. }
  6679. return 0;
  6680. }
  6681. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6682. if (!lua_interface)
  6683. return 0;
  6684. Spawn* spawn = lua_interface->GetSpawn(state);
  6685. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6686. lua_interface->ResetFunctionStack(state);
  6687. if (!spawn) {
  6688. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6689. return 0;
  6690. }
  6691. if (!spawn->IsNPC()) {
  6692. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6693. return 0;
  6694. }
  6695. if (!hated) {
  6696. ((NPC*)spawn)->Brain()->ClearHate();
  6697. return 0;
  6698. }
  6699. else
  6700. {
  6701. if (!hated->IsEntity()) {
  6702. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6703. return 0;
  6704. }
  6705. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6706. return 0;
  6707. }
  6708. return 0;
  6709. }
  6710. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6711. if (!lua_interface)
  6712. return 0;
  6713. Spawn* spawn = lua_interface->GetSpawn(state);
  6714. lua_interface->ResetFunctionStack(state);
  6715. if (!spawn) {
  6716. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6717. return 0;
  6718. }
  6719. if (!spawn->IsNPC()) {
  6720. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6721. return 0;
  6722. }
  6723. ((NPC*)spawn)->Brain()->ClearEncounter();
  6724. return 0;
  6725. }
  6726. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6727. if (!lua_interface)
  6728. return 0;
  6729. Spawn* spawn = lua_interface->GetSpawn(state);
  6730. lua_interface->ResetFunctionStack(state);
  6731. if (!spawn) {
  6732. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6733. return 0;
  6734. }
  6735. if (!spawn->IsNPC()) {
  6736. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6737. return 0;
  6738. }
  6739. // Temp list to store hate list
  6740. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6741. if (encounterList->size() == 0) {
  6742. safe_delete(encounterList);
  6743. return 0;
  6744. }
  6745. lua_createtable(state, encounterList->size(), 0);
  6746. int newTable = lua_gettop(state);
  6747. for (int32 i = 0; i < encounterList->size(); i++) {
  6748. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6749. if (temp)
  6750. lua_interface->SetSpawnValue(state, temp);
  6751. lua_rawseti(state, newTable, i + 1);
  6752. }
  6753. safe_delete(encounterList);
  6754. return 1;
  6755. }
  6756. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6757. if (!lua_interface)
  6758. return 0;
  6759. Spawn* spawn = lua_interface->GetSpawn(state);
  6760. lua_interface->ResetFunctionStack(state);
  6761. if (!spawn) {
  6762. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6763. return 0;
  6764. }
  6765. if (!spawn->IsNPC()) {
  6766. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6767. return 0;
  6768. }
  6769. // Temp list to store hate list
  6770. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6771. if (hateList->size() == 0) {
  6772. safe_delete(hateList);
  6773. return 0;
  6774. }
  6775. lua_createtable(state, hateList->size(), 0);
  6776. int newTable = lua_gettop(state);
  6777. for (int32 i = 0; i < hateList->size(); i++) {
  6778. lua_interface->SetSpawnValue(state, hateList->at(i));
  6779. lua_rawseti(state, newTable, i + 1);
  6780. }
  6781. safe_delete(hateList);
  6782. return 1;
  6783. }
  6784. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6785. if (!lua_interface)
  6786. return 0;
  6787. Spawn* spawn = lua_interface->GetSpawn(state);
  6788. lua_interface->ResetFunctionStack(state);
  6789. if (!spawn) {
  6790. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6791. return 0;
  6792. }
  6793. if (spawn->IsPlayer()) {
  6794. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6795. lua_interface->SetBooleanValue(state, true);
  6796. else
  6797. lua_interface->SetBooleanValue(state, false);
  6798. return 1;
  6799. }
  6800. else {
  6801. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6802. return 1;
  6803. }
  6804. }
  6805. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6806. if (!lua_interface)
  6807. return 0;
  6808. Quest* quest = lua_interface->GetQuest(state);
  6809. lua_interface->ResetFunctionStack(state);
  6810. if (!quest) {
  6811. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6812. return 0;
  6813. }
  6814. quest->SetCompletedFlag(true);
  6815. return 0;
  6816. }
  6817. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6818. if (!lua_interface)
  6819. return 0;
  6820. Spawn* spawn = lua_interface->GetSpawn(state);
  6821. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6822. int8 tier = lua_interface->GetInt8Value(state, 3);
  6823. lua_interface->ResetFunctionStack(state);
  6824. if (!spawn) {
  6825. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6826. return 0;
  6827. }
  6828. if (!spawn->IsEntity()) {
  6829. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6830. return 0;
  6831. }
  6832. if (spellID == 0) {
  6833. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6834. return 0;
  6835. }
  6836. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6837. if (effect) {
  6838. if (tier > 0) {
  6839. // If a tier was passed chec to see if it is the same as the effect
  6840. if (tier == effect->tier)
  6841. lua_interface->SetBooleanValue(state, true);
  6842. else
  6843. lua_interface->SetBooleanValue(state, false);
  6844. return 1;
  6845. }
  6846. else {
  6847. // Have an effect but no tier was passed so return true
  6848. lua_interface->SetBooleanValue(state, true);
  6849. }
  6850. return 1;
  6851. }
  6852. // no effect so return false
  6853. lua_interface->SetBooleanValue(state, false);
  6854. return 1;
  6855. }
  6856. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6857. if (!lua_interface)
  6858. return 0;
  6859. Spawn* spawn = lua_interface->GetSpawn(state);
  6860. int32 id = lua_interface->GetInt32Value(state, 2);
  6861. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6862. lua_interface->ResetFunctionStack(state);
  6863. Spawn* spawn2 = 0;
  6864. vector<Spawn*> list;
  6865. if (!spawn) {
  6866. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6867. return 0;
  6868. }
  6869. //If zone not provided, use spawn's zone
  6870. if (!zone)
  6871. zone = spawn->GetZone();
  6872. list = zone->GetSpawnsByID(id);
  6873. if (list.size() == 0) {
  6874. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6875. return 0;
  6876. }
  6877. vector<Spawn*>::iterator itr = list.begin();
  6878. for (int8 i = 0; i < list.size(); i++) {
  6879. spawn2 = itr[i];
  6880. if (spawn2)
  6881. spawn2->AddAllowAccessSpawn(spawn);
  6882. }
  6883. return 0;
  6884. }
  6885. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6886. if (!lua_interface)
  6887. return 0;
  6888. Spawn* spawn = lua_interface->GetSpawn(state);
  6889. int32 id = lua_interface->GetInt32Value(state, 2);
  6890. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6891. lua_interface->ResetFunctionStack(state);
  6892. Spawn* spawn2 = 0;
  6893. if (!spawn) {
  6894. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6895. return 0;
  6896. }
  6897. //If zone not provided, use spawn's zone
  6898. if (!zone)
  6899. zone = spawn->GetZone();
  6900. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6901. vector<Spawn*>::iterator itr = list.begin();
  6902. if (list.size() == 0) {
  6903. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6904. return 0;
  6905. }
  6906. for (int8 i = 0; i < list.size(); i++) {
  6907. spawn2 = itr[i];
  6908. if (spawn2)
  6909. spawn2->RemoveSpawnAccess(spawn);
  6910. }
  6911. return 0;
  6912. }
  6913. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6914. if (!lua_interface)
  6915. return 0;
  6916. Quest* quest = lua_interface->GetQuest(state);
  6917. lua_interface->ResetFunctionStack(state);
  6918. if (!quest) {
  6919. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6920. return 0;
  6921. }
  6922. quest->SetYellowName(true);
  6923. return 0;
  6924. }
  6925. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6926. if (!lua_interface)
  6927. return 0;
  6928. Spawn* spawn = lua_interface->GetSpawn(state);
  6929. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6930. lua_interface->ResetFunctionStack(state);
  6931. if (!spawn) {
  6932. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6933. return 0;
  6934. }
  6935. if (!spawn->IsPlayer()) {
  6936. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6937. return 0;
  6938. }
  6939. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6940. return 1;
  6941. }
  6942. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6943. if (!lua_interface)
  6944. return 0;
  6945. Spawn* spawn = lua_interface->GetSpawn(state);
  6946. lua_interface->ResetFunctionStack(state);
  6947. if (!spawn) {
  6948. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6949. return 0;
  6950. }
  6951. if (!spawn->IsPlayer()) {
  6952. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6953. return 0;
  6954. }
  6955. ZoneServer* zone = spawn->GetZone();
  6956. if (!zone) {
  6957. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6958. return 0;
  6959. }
  6960. Instance_Type iType = zone->GetInstanceType();
  6961. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6962. iType == GROUP_LOCKOUT_INSTANCE ||
  6963. iType == RAID_LOCKOUT_INSTANCE ||
  6964. iType == SOLO_PERSIST_INSTANCE ||
  6965. iType == GROUP_PERSIST_INSTANCE ||
  6966. iType == RAID_PERSIST_INSTANCE) {
  6967. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6968. if (data) {
  6969. // Check to see if the timer has already been set, if it has return out.
  6970. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6971. return 0;
  6972. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6973. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6974. if(spawn->IsPlayer()) {
  6975. Client* client = ((Player*)spawn)->GetClient();
  6976. if (client) {
  6977. string time_msg = "";
  6978. int32 time = data->success_lockout_time;
  6979. int16 hour;
  6980. int8 min;
  6981. int8 sec;
  6982. hour = time / 3600;
  6983. time = time % 3600;
  6984. min = time / 60;
  6985. time = time % 60;
  6986. sec = time;
  6987. if (hour > 0) {
  6988. char temp[10];
  6989. sprintf(temp, " %i", hour);
  6990. time_msg.append(temp);
  6991. time_msg.append(" hour");
  6992. time_msg.append((hour > 1) ? "s" : "");
  6993. }
  6994. if (min > 0) {
  6995. char temp[5];
  6996. sprintf(temp, " %i", min);
  6997. time_msg.append(temp);
  6998. time_msg.append(" minute");
  6999. time_msg.append((min > 1) ? "s" : "");
  7000. }
  7001. // Only add seconds if minutes and hours are 0
  7002. if (hour == 0 && min == 0 && sec > 0) {
  7003. char temp[5];
  7004. sprintf(temp, " %i", sec);
  7005. time_msg.append(temp);
  7006. time_msg.append(" second");
  7007. time_msg.append((sec > 1) ? "s" : "");
  7008. }
  7009. 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());
  7010. }
  7011. else {
  7012. lua_interface->LogError("LUA SetSuccessTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7013. }
  7014. }
  7015. }
  7016. else
  7017. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7018. }
  7019. else
  7020. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  7021. return 0;
  7022. }
  7023. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  7024. if (!lua_interface)
  7025. return 0;
  7026. Spawn* spawn = lua_interface->GetSpawn(state);
  7027. lua_interface->ResetFunctionStack(state);
  7028. if (!spawn) {
  7029. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7030. return 0;
  7031. }
  7032. if (!spawn->IsPlayer()) {
  7033. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  7034. return 0;
  7035. }
  7036. ZoneServer* zone = spawn->GetZone();
  7037. if (!zone) {
  7038. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  7039. return 0;
  7040. }
  7041. Instance_Type iType = zone->GetInstanceType();
  7042. if (iType == SOLO_LOCKOUT_INSTANCE ||
  7043. iType == GROUP_LOCKOUT_INSTANCE ||
  7044. iType == RAID_LOCKOUT_INSTANCE ||
  7045. iType == SOLO_PERSIST_INSTANCE ||
  7046. iType == GROUP_PERSIST_INSTANCE ||
  7047. iType == RAID_PERSIST_INSTANCE) {
  7048. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  7049. if (data) {
  7050. // Check to see if the timer has already been set, if it has return out.
  7051. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  7052. return 0;
  7053. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  7054. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  7055. if(spawn->IsPlayer()) {
  7056. Client* client = ((Player*)spawn)->GetClient();
  7057. if (client) {
  7058. string time_msg = "";
  7059. int32 time = data->failure_lockout_time;
  7060. int16 hour;
  7061. int8 min;
  7062. int8 sec;
  7063. hour = time / 3600;
  7064. time = time % 3600;
  7065. min = time / 60;
  7066. time = time % 60;
  7067. sec = time;
  7068. if (hour > 0) {
  7069. char temp[10];
  7070. sprintf(temp, " %i", hour);
  7071. time_msg.append(temp);
  7072. time_msg.append(" hour");
  7073. time_msg.append((hour > 1) ? "s" : "");
  7074. }
  7075. if (min > 0) {
  7076. char temp[5];
  7077. sprintf(temp, " %i", min);
  7078. time_msg.append(temp);
  7079. time_msg.append(" minute");
  7080. time_msg.append((min > 1) ? "s" : "");
  7081. }
  7082. // Only add seconds if minutes and hours are 0
  7083. if (hour == 0 && min == 0 && sec > 0) {
  7084. char temp[5];
  7085. sprintf(temp, " %i", sec);
  7086. time_msg.append(temp);
  7087. time_msg.append(" second");
  7088. time_msg.append((sec > 1) ? "s" : "");
  7089. }
  7090. 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());
  7091. }
  7092. }
  7093. else {
  7094. lua_interface->LogError("LUA SetFailureTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7095. }
  7096. }
  7097. else
  7098. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7099. }
  7100. else
  7101. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  7102. return 0;
  7103. }
  7104. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  7105. if (!lua_interface)
  7106. return 0;
  7107. Spawn* spawn = lua_interface->GetSpawn(state);
  7108. lua_interface->ResetFunctionStack(state);
  7109. if (!spawn) {
  7110. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  7111. return 0;
  7112. }
  7113. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  7114. return 1;
  7115. }
  7116. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  7117. if (!lua_interface)
  7118. return 0;
  7119. Spawn* player = lua_interface->GetSpawn(state);
  7120. Spawn* ground = lua_interface->GetSpawn(state, 2);
  7121. if (!player) {
  7122. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7123. lua_interface->ResetFunctionStack(state);
  7124. return 0;
  7125. }
  7126. if (!player->IsPlayer()) {
  7127. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  7128. lua_interface->ResetFunctionStack(state);
  7129. return 0;
  7130. }
  7131. if (!ground) {
  7132. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7133. lua_interface->ResetFunctionStack(state);
  7134. return 0;
  7135. }
  7136. if (!ground->IsGroundSpawn()) {
  7137. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  7138. lua_interface->ResetFunctionStack(state);
  7139. return 0;
  7140. }
  7141. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7142. if (!groundspawn_entries) {
  7143. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7144. lua_interface->ResetFunctionStack(state);
  7145. return 0;
  7146. }
  7147. Skill* skill = 0;
  7148. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  7149. if (collection_skill == "Collecting")
  7150. skill = ((Player*)player)->GetSkillByName("Gathering");
  7151. else
  7152. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  7153. if (!skill) {
  7154. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  7155. lua_interface->ResetFunctionStack(state);
  7156. return 0;
  7157. }
  7158. vector<GroundSpawnEntry*>::iterator itr;
  7159. GroundSpawnEntry* entry = 0;
  7160. bool can_harvest = false;
  7161. sint32 min_skill = -1;
  7162. int16 totalSkill = skill->current_val;
  7163. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  7164. if(skillID != 0xFFFFFFFF)
  7165. {
  7166. ((Entity*)player)->MStats.lock();
  7167. totalSkill += ((Entity*)player)->stats[skillID];
  7168. ((Entity*)player)->MStats.unlock();
  7169. }
  7170. // first, iterate through groundspawn_entries, discard tables player cannot use
  7171. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  7172. {
  7173. entry = *itr;
  7174. if (min_skill == -1 || entry->min_skill_level < min_skill)
  7175. min_skill = entry->min_skill_level;
  7176. // if player lacks skill, skip table
  7177. if (entry->min_skill_level > totalSkill)
  7178. continue;
  7179. // if bonus, but player lacks level, skip table
  7180. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  7181. continue;
  7182. can_harvest = true;
  7183. break;
  7184. }
  7185. lua_interface->SetBooleanValue(state, can_harvest);
  7186. // If false, send the message to the client
  7187. if (!can_harvest) {
  7188. Client* client = ((Player*)player)->GetClient();
  7189. if (client) {
  7190. string msg = "You do not have enough skill to ";
  7191. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  7192. msg.append("gather");
  7193. else if (collection_skill == "Mining")
  7194. msg.append("mine");
  7195. else if (collection_skill == "Trapping")
  7196. msg.append("trap");
  7197. else if (collection_skill == "Foresting")
  7198. msg.append("forest");
  7199. else if (collection_skill == "Fishing")
  7200. msg.append("catch");
  7201. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  7202. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  7203. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  7204. }
  7205. }
  7206. lua_interface->ResetFunctionStack(state);
  7207. return 1;
  7208. }
  7209. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  7210. if (!lua_interface)
  7211. return 0;
  7212. Spawn* player = lua_interface->GetSpawn(state);
  7213. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  7214. lua_interface->ResetFunctionStack(state);
  7215. if (!player) {
  7216. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  7217. return 0;
  7218. }
  7219. if (!player->IsPlayer()) {
  7220. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  7221. return 0;
  7222. }
  7223. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  7224. lua_interface->SetBooleanValue(state, ret);
  7225. return 1;
  7226. }
  7227. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  7228. // Check to see if we have a valid lua_interface
  7229. if (!lua_interface)
  7230. return 0;
  7231. // Get the spawn that is getting the pet
  7232. Spawn* spawn = lua_interface->GetSpawn(state);
  7233. Spawn* target = lua_interface->GetSpawn(state, 2);
  7234. // Get the DB ID of the pet
  7235. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  7236. float x = lua_interface->GetFloatValue(state, 4);
  7237. float y = lua_interface->GetFloatValue(state, 5);
  7238. float z = lua_interface->GetFloatValue(state, 6);
  7239. // Get the spell that this command was called from
  7240. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7241. lua_interface->ResetFunctionStack(state);
  7242. // Check to make sure the spawn pointer is valid
  7243. if (!spawn) {
  7244. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  7245. return 0;
  7246. }
  7247. // Check to make sure the spawn is an entity
  7248. if (!spawn->IsEntity()) {
  7249. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  7250. return 0;
  7251. }
  7252. if (!target) {
  7253. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  7254. return 0;
  7255. }
  7256. if (!target->IsEntity()) {
  7257. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  7258. return 0;
  7259. }
  7260. // Check to see if the DB ID for the pet is set
  7261. if (pet_id == 0) {
  7262. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  7263. return 0;
  7264. }
  7265. // Check to see if the pointer to the spell is valid
  7266. if (!luaspell) {
  7267. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  7268. return 0;
  7269. }
  7270. if(luaspell->resisted) {
  7271. return 0;
  7272. }
  7273. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  7274. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  7275. if (!pet) {
  7276. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  7277. return 0;
  7278. }
  7279. // Check to make sure the pet is an npc
  7280. if (!pet->IsNPC()) {
  7281. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  7282. return 0;
  7283. }
  7284. if (x == 0)
  7285. x = spawn->GetX();
  7286. if (y == 0)
  7287. y = spawn->GetY();
  7288. if (z == 0)
  7289. z = spawn->GetZ();
  7290. // Spawn the pet at the same location as the owner
  7291. pet->SetX(x);
  7292. pet->SetY(y);
  7293. pet->SetZ(z);
  7294. pet->SetLocation(spawn->GetLocation());
  7295. pet->SetHeading(spawn->GetHeading());
  7296. spawn->GetZone()->AddSpawn(pet);
  7297. const char* spawn_script = world.GetSpawnScript(pet_id);
  7298. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  7299. spawn->SetSpawnScript(string(spawn_script));
  7300. spawn->GetZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7301. }
  7302. std::string petName = std::string("");
  7303. if(spawn->IsEntity()) {
  7304. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  7305. }
  7306. if(petName.size() < 1) {
  7307. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  7308. petName = spawn->GetZone()->pet_names.at(rand_index);
  7309. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  7310. }
  7311. // Set the pets name
  7312. pet->SetName(petName.c_str());
  7313. // Set the level of the pet to the owners level
  7314. pet->SetLevel(spawn->GetLevel());
  7315. // Set the faction of the pet to the same faction as the owner
  7316. pet->SetFactionID(spawn->GetFactionID());
  7317. // Set the spawn as a pet
  7318. pet->SetPet(true);
  7319. // Give a pointer of the owner to the pet
  7320. ((NPC*)pet)->SetOwner((Entity*)spawn);
  7321. // Set the pet type
  7322. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  7323. // Set the spell id used to create this pet
  7324. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  7325. // Set the spell tier used to create this pet
  7326. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  7327. // Set the pets spawn type to 6
  7328. pet->SetSpawnType(6);
  7329. // Set the pets brain
  7330. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  7331. // Check to see if the pet has a subtitle
  7332. if (strlen(pet->GetSubTitle()) > 0) {
  7333. // Add the players name to the front of the sub title
  7334. string pet_subtitle;
  7335. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  7336. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  7337. // Set the pets subtitle to the new one
  7338. pet->SetSubTitle(pet_subtitle.c_str());
  7339. }
  7340. // Set the pet as the return value for this function
  7341. lua_interface->SetSpawnValue(state, pet);
  7342. return 1;
  7343. }
  7344. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  7345. if (!lua_interface)
  7346. return 0;
  7347. Spawn* spawn = lua_interface->GetSpawn(state);
  7348. Spawn* player = lua_interface->GetSpawn(state, 2);
  7349. float max_distance = lua_interface->GetFloatValue(state, 3);
  7350. string type = lua_interface->GetStringValue(state, 4);
  7351. lua_interface->ResetFunctionStack(state);
  7352. if (!spawn || (spawn && spawn->IsPlayer())) {
  7353. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  7354. return 0;
  7355. }
  7356. if (!player || !player->IsPlayer()) {
  7357. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  7358. return 0;
  7359. }
  7360. Client* client = ((Player*)player)->GetClient();
  7361. if (!client) {
  7362. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7363. return 0;
  7364. }
  7365. //Set max_distance to default if not set or not proper value
  7366. if (max_distance <= 0)
  7367. max_distance = 500;
  7368. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7369. if (packet) {
  7370. float unknown2_3 = 0;
  7371. int8 placement_mode = 0;
  7372. if (type == "wall") {
  7373. placement_mode = 2;
  7374. unknown2_3 = 150;
  7375. }
  7376. else if (type == "ceiling")
  7377. placement_mode = 1;
  7378. packet->setDataByName("placement_mode", placement_mode);
  7379. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7380. packet->setDataByName("model_type", spawn->GetModelType());
  7381. packet->setDataByName("unknown", 1); //size
  7382. packet->setDataByName("unknown2", 1); //size 2
  7383. packet->setDataByName("unknown2", .5, 1); //size 3
  7384. packet->setDataByName("unknown2", 3, 2);
  7385. packet->setDataByName("unknown2", unknown2_3, 3);
  7386. packet->setDataByName("max_distance", max_distance);
  7387. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7388. client->QueuePacket(packet->serialize());
  7389. safe_delete(packet);
  7390. }
  7391. return 0;
  7392. }
  7393. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7394. if (!lua_interface)
  7395. return 0;
  7396. Item* item = lua_interface->GetItem(state);
  7397. lua_interface->ResetFunctionStack(state);
  7398. if (!item) {
  7399. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7400. return 0;
  7401. }
  7402. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7403. return 1;
  7404. }
  7405. int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
  7406. if (!lua_interface)
  7407. return 0;
  7408. Item* item = lua_interface->GetItem(state);
  7409. lua_interface->ResetFunctionStack(state);
  7410. if (!item) {
  7411. lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7412. return 0;
  7413. }
  7414. lua_interface->SetInt32Value(state, item->effect_type);
  7415. return 1;
  7416. }
  7417. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7418. if (!lua_interface)
  7419. return 0;
  7420. Spawn* spawn = lua_interface->GetSpawn(state);
  7421. lua_interface->ResetFunctionStack(state);
  7422. if (!spawn) {
  7423. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7424. return 0;
  7425. }
  7426. if (spawn->GetZone())
  7427. spawn->GetZone()->AddTransportSpawn(spawn);
  7428. return 0;
  7429. }
  7430. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7431. if (!lua_interface)
  7432. return 0;
  7433. Spawn* spawn = lua_interface->GetSpawn(state);
  7434. lua_interface->ResetFunctionStack(state);
  7435. if (!spawn) {
  7436. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7437. return 0;
  7438. }
  7439. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7440. return 1;
  7441. }
  7442. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7443. if (!lua_interface)
  7444. return 0;
  7445. Skill* skill = lua_interface->GetSkill(state);
  7446. lua_interface->ResetFunctionStack(state);
  7447. if (!skill) {
  7448. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7449. return 0;
  7450. }
  7451. lua_interface->SetInt32Value(state, skill->current_val);
  7452. return 1;
  7453. }
  7454. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7455. if (!lua_interface)
  7456. return 0;
  7457. Skill* skill = lua_interface->GetSkill(state);
  7458. lua_interface->ResetFunctionStack(state);
  7459. if (!skill) {
  7460. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7461. return 0;
  7462. }
  7463. lua_interface->SetInt32Value(state, skill->max_val);
  7464. return 1;
  7465. }
  7466. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7467. if (!lua_interface)
  7468. return 0;
  7469. Skill* skill = lua_interface->GetSkill(state);
  7470. lua_interface->ResetFunctionStack(state);
  7471. if (!skill) {
  7472. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7473. return 0;
  7474. }
  7475. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7476. return 1;
  7477. }
  7478. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7479. if (!lua_interface)
  7480. return 0;
  7481. Skill* skill = lua_interface->GetSkill(state);
  7482. int16 value = lua_interface->GetInt16Value(state, 2);
  7483. lua_interface->ResetFunctionStack(state);
  7484. if (!skill) {
  7485. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7486. return 0;
  7487. }
  7488. skill->max_val = value;
  7489. if (skill->max_val < skill->current_val)
  7490. skill->current_val = skill->max_val;
  7491. return 0;
  7492. }
  7493. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7494. if (!lua_interface)
  7495. return 0;
  7496. Skill* skill = lua_interface->GetSkill(state);
  7497. int16 value = lua_interface->GetInt16Value(state, 2);
  7498. lua_interface->ResetFunctionStack(state);
  7499. if (!skill) {
  7500. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7501. return 0;
  7502. }
  7503. if (value > skill->max_val)
  7504. skill->current_val = skill->max_val;
  7505. else
  7506. skill->current_val = value;
  7507. return 0;
  7508. }
  7509. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7510. if (!lua_interface)
  7511. return 0;
  7512. Spawn* player = lua_interface->GetSpawn(state);
  7513. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7514. lua_interface->ResetFunctionStack(state);
  7515. if (skill_id > 0 && player && player->IsPlayer()) {
  7516. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7517. return 1;
  7518. }
  7519. return 0;
  7520. }
  7521. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7522. if (!lua_interface)
  7523. return 0;
  7524. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7525. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7526. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7527. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7528. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7529. lua_interface->ResetFunctionStack(state);
  7530. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7531. if (player_spawn && player_spawn->IsPlayer()) {
  7532. Player* player = (Player*)player_spawn;
  7533. bool added = false;
  7534. if (!player->skill_list.HasSkill(skill_id)) {
  7535. player->AddSkill(skill_id, current_val, max_val, true);
  7536. added = true;
  7537. }
  7538. 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
  7539. Client* client = player->GetClient();
  7540. if (client) {
  7541. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7542. if (packet)
  7543. client->QueuePacket(packet);
  7544. }
  7545. }
  7546. if (added) {
  7547. lua_interface->SetBooleanValue(state, true);
  7548. return 1;
  7549. }
  7550. }
  7551. else {
  7552. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7553. }
  7554. }
  7555. else {
  7556. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7557. }
  7558. lua_interface->SetBooleanValue(state, false);
  7559. return 1;
  7560. }
  7561. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7562. if (!lua_interface)
  7563. return 0;
  7564. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7565. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7566. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7567. lua_interface->ResetFunctionStack(state);
  7568. if (skill_id > 0) {
  7569. if (player_spawn && player_spawn->IsPlayer()) {
  7570. Player* player = (Player*)player_spawn;
  7571. if (player->skill_list.HasSkill(skill_id)) {
  7572. player->RemovePlayerSkill(skill_id, true);
  7573. if (!more_to_remove) {
  7574. Client* client = player->GetClient();
  7575. if (client) {
  7576. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7577. if (packet)
  7578. client->QueuePacket(packet);
  7579. }
  7580. }
  7581. }
  7582. }
  7583. else {
  7584. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7585. }
  7586. }
  7587. else {
  7588. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7589. }
  7590. return 0;
  7591. }
  7592. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7593. if (!lua_interface)
  7594. return 0;
  7595. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7596. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7597. int16 amount = lua_interface->GetInt8Value(state, 3);
  7598. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7599. lua_interface->ResetFunctionStack(state);
  7600. if (amount > 0 && skill_type < 100) {
  7601. if (player_spawn && player_spawn->IsPlayer()) {
  7602. Player* player = (Player*)player_spawn;
  7603. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7604. if (!more_to_increase) {
  7605. Client* client = player->GetClient();
  7606. if (client) {
  7607. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7608. if (packet)
  7609. client->QueuePacket(packet);
  7610. }
  7611. }
  7612. }
  7613. else {
  7614. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7615. }
  7616. }
  7617. else {
  7618. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7619. }
  7620. return 0;
  7621. }
  7622. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7623. if (!lua_interface)
  7624. return 0;
  7625. Spawn* spawn = lua_interface->GetSpawn(state);
  7626. string name = lua_interface->GetStringValue(state, 2);
  7627. lua_interface->ResetFunctionStack(state);
  7628. if (!spawn) {
  7629. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7630. return 0;
  7631. }
  7632. if (!spawn->IsEntity()) {
  7633. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7634. return 0;
  7635. }
  7636. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7637. if (skill) {
  7638. lua_interface->SetSkillValue(state, skill);
  7639. return 1;
  7640. }
  7641. return 0;
  7642. }
  7643. int EQ2Emu_lua_AddProc(lua_State* state) {
  7644. if (!lua_interface)
  7645. return 0;
  7646. Spawn* spawn = lua_interface->GetSpawn(state);
  7647. int8 type = lua_interface->GetInt8Value(state, 2);
  7648. float chance = lua_interface->GetFloatValue(state, 3);
  7649. Item* item = lua_interface->GetItem(state, 4);
  7650. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7651. LuaSpell* spell = 0;
  7652. if (!spawn && (!spell || !use_all_spelltargets)) {
  7653. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7654. return 0;
  7655. }
  7656. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7657. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7658. return 0;
  7659. }
  7660. if (!item)
  7661. spell = lua_interface->GetCurrentSpell(state);
  7662. if (!item && !spell) {
  7663. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7664. return 0;
  7665. }
  7666. if(spell && spell->resisted) {
  7667. return 0;
  7668. }
  7669. if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
  7670. Spawn* target;
  7671. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7672. for (int8 i = 0; i < spell->targets.size(); i++) {
  7673. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7674. if (!target || !target->IsEntity())
  7675. continue;
  7676. ((Entity*)target)->AddProc(type, chance, item, spell);
  7677. }
  7678. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7679. }
  7680. else
  7681. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7682. return 0;
  7683. }
  7684. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7685. if (!lua_interface)
  7686. return 0;
  7687. Spawn* spawn = lua_interface->GetSpawn(state);
  7688. Item* item = lua_interface->GetItem(state, 2);
  7689. LuaSpell* spell = 0;
  7690. if (!spawn) {
  7691. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7692. lua_interface->ResetFunctionStack(state);
  7693. return 0;
  7694. }
  7695. if (!spawn->IsEntity()) {
  7696. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7697. lua_interface->ResetFunctionStack(state);
  7698. return 0;
  7699. }
  7700. if (!item)
  7701. spell = lua_interface->GetCurrentSpell(state);
  7702. lua_interface->ResetFunctionStack(state);
  7703. if (!item && !spell) {
  7704. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7705. return 0;
  7706. }
  7707. if (spell && spell->caster && spell->caster->GetZone()) {
  7708. Spawn* target;
  7709. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7710. for (int8 i = 0; i < spell->targets.size(); i++) {
  7711. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7712. if (!target || !target->IsEntity())
  7713. continue;
  7714. ((Entity*)target)->RemoveProc(item, spell);
  7715. }
  7716. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7717. spell->caster->RemoveProc(item, spell);
  7718. }
  7719. else
  7720. ((Entity*)spawn)->RemoveProc(item, spell);
  7721. return 0;
  7722. }
  7723. int EQ2Emu_lua_Knockback(lua_State* state) {
  7724. if (!lua_interface)
  7725. return 0;
  7726. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7727. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7728. int32 duration = lua_interface->GetInt32Value(state, 3);
  7729. float vertical = lua_interface->GetFloatValue(state, 4);
  7730. float horizontal = lua_interface->GetFloatValue(state, 5);
  7731. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7732. lua_interface->ResetFunctionStack(state);
  7733. if (!target_spawn) {
  7734. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7735. return 0;
  7736. }
  7737. if (!spawn) {
  7738. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7739. return 0;
  7740. }
  7741. if ((vertical != 0 || horizontal != 0)) {
  7742. if(spawn->IsPlayer()) {
  7743. Client* client = ((Player*)spawn)->GetClient();
  7744. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7745. if (packet) {
  7746. packet->setDataByName("target_x", target_spawn->GetX());
  7747. packet->setDataByName("target_y", target_spawn->GetY());
  7748. packet->setDataByName("target_z", target_spawn->GetZ());
  7749. packet->setDataByName("vertical_movement", vertical);
  7750. packet->setDataByName("horizontal_movement", horizontal);
  7751. if (use_heading)
  7752. packet->setDataByName("use_player_heading", 1);
  7753. client->QueuePacket(packet->serialize());
  7754. }
  7755. safe_delete(packet);
  7756. }
  7757. else {
  7758. spawn->SetKnockback(target_spawn, duration, vertical, horizontal);
  7759. }
  7760. }
  7761. return 0;
  7762. }
  7763. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7764. if (!lua_interface)
  7765. return 0;
  7766. Spawn* spawn = lua_interface->GetSpawn(state);
  7767. lua_interface->ResetFunctionStack(state);
  7768. if (!spawn) {
  7769. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7770. return 0;
  7771. }
  7772. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7773. return 1;
  7774. }
  7775. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7776. if (!lua_interface)
  7777. return 0;
  7778. Spawn* caster = lua_interface->GetSpawn(state);
  7779. Spawn* target = lua_interface->GetSpawn(state, 2);
  7780. string name = lua_interface->GetStringValue(state, 3);
  7781. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7782. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7783. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7784. string success_msg = lua_interface->GetStringValue(state, 7);
  7785. string effect_msg = lua_interface->GetStringValue(state, 8);
  7786. lua_interface->ResetFunctionStack(state);
  7787. if (!caster) {
  7788. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7789. return 0;
  7790. }
  7791. if (!caster->IsEntity()) {
  7792. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7793. return 0;
  7794. }
  7795. if (!target) {
  7796. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7797. return 0;
  7798. }
  7799. if (!target->IsEntity()) {
  7800. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7801. return 0;
  7802. }
  7803. if (name.length() == 0) {
  7804. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7805. return 0;
  7806. }
  7807. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7808. return 0;
  7809. }
  7810. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7811. if (!lua_interface)
  7812. return 0;
  7813. string name = lua_interface->GetStringValue(state);
  7814. lua_interface->ResetFunctionStack(state);
  7815. if (name.length() == 0) {
  7816. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7817. return 0;
  7818. }
  7819. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7820. if (!skill) {
  7821. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7822. return 0;
  7823. }
  7824. lua_interface->SetInt32Value(state, skill->skill_id);
  7825. return 1;
  7826. }
  7827. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7828. if (!lua_interface)
  7829. return 0;
  7830. Spawn* spawn = lua_interface->GetSpawn(state);
  7831. lua_interface->ResetFunctionStack(state);
  7832. if (!spawn) {
  7833. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7834. return 0;
  7835. }
  7836. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7837. return 1;
  7838. }
  7839. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7840. if (!lua_interface)
  7841. return 0;
  7842. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7843. lua_interface->ResetFunctionStack(state);
  7844. if (!luaspell) {
  7845. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7846. return 0;
  7847. }
  7848. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7849. return 1;
  7850. }
  7851. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7852. if (!lua_interface)
  7853. return 0;
  7854. Spawn* spawn = lua_interface->GetSpawn(state);
  7855. Spawn* target = lua_interface->GetSpawn(state, 2);
  7856. lua_interface->ResetFunctionStack(state);
  7857. if (!spawn) {
  7858. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7859. return 0;
  7860. }
  7861. if (!spawn->IsEntity()) {
  7862. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7863. return 0;
  7864. }
  7865. if (!target) {
  7866. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7867. return 0;
  7868. }
  7869. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7870. return 1;
  7871. }
  7872. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7873. if (!lua_interface)
  7874. return 0;
  7875. Spawn* spawn = lua_interface->GetSpawn(state);
  7876. Spawn* target = lua_interface->GetSpawn(state, 2);
  7877. lua_interface->ResetFunctionStack(state);
  7878. if (!spawn) {
  7879. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7880. return 0;
  7881. }
  7882. if (!spawn->IsEntity()) {
  7883. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7884. return 0;
  7885. }
  7886. if (!target) {
  7887. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7888. return 0;
  7889. }
  7890. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7891. return 1;
  7892. }
  7893. int EQ2Emu_lua_InFront(lua_State* state) {
  7894. if (!lua_interface)
  7895. return 0;
  7896. Spawn* spawn = lua_interface->GetSpawn(state);
  7897. Spawn* target = lua_interface->GetSpawn(state, 2);
  7898. lua_interface->ResetFunctionStack(state);
  7899. if (!spawn) {
  7900. lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7901. return 0;
  7902. }
  7903. if (!spawn->IsEntity()) {
  7904. lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7905. return 0;
  7906. }
  7907. if (!target) {
  7908. lua_interface->LogError("%s: LUA InFrontSpawn command error: target is not valid", lua_interface->GetScriptName(state));
  7909. return 0;
  7910. }
  7911. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->InFrontSpawn(target, spawn->GetX(), spawn->GetZ()));
  7912. return 1;
  7913. }
  7914. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7915. if (!lua_interface)
  7916. return 0;
  7917. Item* item = lua_interface->GetItem(state);
  7918. lua_interface->ResetFunctionStack(state);
  7919. if (!item) {
  7920. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7921. return 0;
  7922. }
  7923. lua_interface->SetInt32Value(state, item->details.count);
  7924. return 1;
  7925. }
  7926. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7927. if (!lua_interface)
  7928. return 0;
  7929. Item* item = lua_interface->GetItem(state);
  7930. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7931. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7932. lua_interface->ResetFunctionStack(state);
  7933. if (!item) {
  7934. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7935. return 0;
  7936. }
  7937. if (!owner) {
  7938. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7939. return 0;
  7940. }
  7941. if (!owner->IsPlayer()) {
  7942. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7943. return 0;
  7944. }
  7945. if (item->stack_count < new_count) {
  7946. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7947. return 0;
  7948. }
  7949. if (new_count > 0) {
  7950. item->details.count = new_count;
  7951. item->save_needed = true;
  7952. }
  7953. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7954. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7955. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7956. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7957. else
  7958. {
  7959. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7960. return 0;
  7961. }
  7962. Client* client = ((Player*)owner)->GetClient();
  7963. if (!client)
  7964. return 0;
  7965. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7966. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7967. if (app)
  7968. client->QueuePacket(app);
  7969. return 0;
  7970. }
  7971. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7972. if (!lua_interface)
  7973. return 0;
  7974. int32 time = lua_interface->GetInt32Value(state);
  7975. string function = lua_interface->GetStringValue(state, 2);
  7976. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7977. Spawn* target = lua_interface->GetSpawn(state, 4);
  7978. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7979. lua_interface->ResetFunctionStack(state);
  7980. if (time == 0) {
  7981. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7982. return 0;
  7983. }
  7984. if (function.length() == 0) {
  7985. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7986. return 0;
  7987. }
  7988. if (!spell || (!spell->caster || !spell->caster->GetZone())) {
  7989. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7990. return 0;
  7991. }
  7992. SpellScriptTimer* timer = new SpellScriptTimer;
  7993. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7994. #ifdef WIN32
  7995. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7996. #else
  7997. bzero(timer, sizeof(SpellScriptTimer));
  7998. #endif*/
  7999. timer->caster = 0;
  8000. timer->deleteWhenDone = false;
  8001. timer->target = 0;
  8002. timer->time = Timer::GetCurrentTime2() + time;
  8003. timer->customFunction = function;
  8004. timer->spell = spell;
  8005. if (caster)
  8006. timer->caster = caster->GetID();
  8007. if (target)
  8008. timer->target = target->GetID();
  8009. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  8010. return 0;
  8011. }
  8012. int EQ2Emu_lua_Resurrect(lua_State* state) {
  8013. if (!lua_interface)
  8014. return 0;
  8015. float hp_perc = lua_interface->GetFloatValue(state);
  8016. float power_perc = lua_interface->GetFloatValue(state, 2);
  8017. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  8018. Spawn* target = lua_interface->GetSpawn(state, 4);
  8019. string heal_name = lua_interface->GetStringValue(state, 5);
  8020. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  8021. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  8022. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8023. lua_interface->ResetFunctionStack(state);
  8024. if (!spell) {
  8025. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  8026. return 0;
  8027. }
  8028. Entity* caster = spell->caster;
  8029. if (!caster) {
  8030. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  8031. return 0;
  8032. }
  8033. Client* client = 0;
  8034. PendingResurrection* rez = 0;
  8035. ZoneServer* zone = spell->caster->GetZone();
  8036. if (!target) {
  8037. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8038. if (spell->targets.size() > 0) {
  8039. vector<int32> spell_targets = spell->targets;
  8040. for (int8 i = 0; i < spell_targets.size(); i++) {
  8041. target = zone->GetSpawnByID(spell_targets.at(i));
  8042. if (!target)
  8043. continue;
  8044. if (!target->IsPlayer())
  8045. continue;
  8046. client = ((Player*)target)->GetClient();
  8047. if (!client)
  8048. continue;
  8049. rez = client->GetCurrentRez();
  8050. if (rez->active)
  8051. continue;
  8052. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  8053. rez->active = true;
  8054. rez->caster = caster;
  8055. rez->expire_timer = new Timer;
  8056. int32 duration = spell->spell->GetSpellDuration();
  8057. rez->expire_timer->Start(duration * 100);
  8058. rez->hp_perc = hp_perc;
  8059. rez->mp_perc = power_perc;
  8060. rez->range = spell->spell->GetSpellData()->range;
  8061. rez->spell_name = spell->spell->GetName();
  8062. if (heal_name.length() > 0)
  8063. rez->heal_name = heal_name;
  8064. else
  8065. rez->heal_name = rez->spell_name;
  8066. rez->no_calcs = no_calcs;
  8067. rez->crit_mod = crit_mod;
  8068. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  8069. if (send_window)
  8070. client->SendResurrectionWindow();
  8071. else {
  8072. target->GetZone()->ResurrectSpawn(target, client);
  8073. rez->should_delete = true;
  8074. }
  8075. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  8076. }
  8077. }
  8078. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8079. }
  8080. else {
  8081. if(!target->IsPlayer())
  8082. return 0;
  8083. client = ((Player*)target)->GetClient();
  8084. if (!client)
  8085. return 0;
  8086. rez = client->GetCurrentRez();
  8087. if (rez->active)
  8088. return 0;
  8089. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  8090. rez->active = true;
  8091. rez->caster = caster;
  8092. rez->expire_timer = new Timer;
  8093. int32 duration = spell->spell->GetSpellDuration();
  8094. rez->expire_timer->Start(duration * 100);
  8095. rez->hp_perc = hp_perc;
  8096. rez->mp_perc = power_perc;
  8097. rez->range = spell->spell->GetSpellData()->range;
  8098. rez->spell_name = spell->spell->GetName();
  8099. if (heal_name.length() > 0)
  8100. rez->heal_name = heal_name;
  8101. else
  8102. rez->heal_name = rez->spell_name;
  8103. rez->no_calcs = no_calcs;
  8104. rez->crit_mod = crit_mod;
  8105. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  8106. if (send_window)
  8107. client->SendResurrectionWindow();
  8108. else {
  8109. target->GetZone()->ResurrectSpawn(target, client);
  8110. rez->should_delete = true;
  8111. }
  8112. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  8113. }
  8114. return 0;
  8115. }
  8116. int EQ2Emu_lua_SetVision(lua_State* state) {
  8117. if (!lua_interface)
  8118. return 0;
  8119. Spawn* spawn = lua_interface->GetSpawn(state);
  8120. int32 vision = lua_interface->GetInt32Value(state, 2);
  8121. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8122. lua_interface->ResetFunctionStack(state);
  8123. if (!spawn) {
  8124. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8125. return 0;
  8126. }
  8127. if (!spawn->IsEntity()) {
  8128. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8129. return 0;
  8130. }
  8131. if (spell && spell->targets.size() > 0) {
  8132. ZoneServer* zone = spell->caster->GetZone();
  8133. for (int8 i = 0; i < spell->targets.size(); i++) {
  8134. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8135. if (target && target->IsEntity()) {
  8136. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  8137. if (target->IsPlayer())
  8138. ((Player*)target)->SetCharSheetChanged(true);
  8139. }
  8140. }
  8141. }
  8142. else {
  8143. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  8144. if (spawn->IsPlayer())
  8145. ((Player*)spawn)->SetCharSheetChanged(true);
  8146. }
  8147. return 0;
  8148. }
  8149. int EQ2Emu_lua_BlurVision(lua_State* state) {
  8150. if (!lua_interface)
  8151. return 0;
  8152. Spawn* spawn = lua_interface->GetSpawn(state);
  8153. float intensity = lua_interface->GetFloatValue(state, 2);
  8154. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8155. lua_interface->ResetFunctionStack(state);
  8156. if (!spawn) {
  8157. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8158. return 0;
  8159. }
  8160. if (!spawn->IsEntity()) {
  8161. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8162. return 0;
  8163. }
  8164. if (spell && spell->targets.size() > 0) {
  8165. ZoneServer* zone = spell->caster->GetZone();
  8166. for (int8 i = 0; i < spell->targets.size(); i++) {
  8167. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8168. if (target && target->IsEntity()) {
  8169. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  8170. if (target->IsPlayer())
  8171. ((Player*)target)->SetCharSheetChanged(true);
  8172. }
  8173. }
  8174. }
  8175. else {
  8176. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  8177. if (spawn->IsPlayer())
  8178. ((Player*)spawn)->SetCharSheetChanged(true);
  8179. }
  8180. return 0;
  8181. }
  8182. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  8183. if (!lua_interface)
  8184. return 0;
  8185. Spawn* spawn = lua_interface->GetSpawn(state);
  8186. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  8187. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8188. lua_interface->ResetFunctionStack(state);
  8189. if (!spawn) {
  8190. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  8191. return 0;
  8192. }
  8193. if (!spawn->IsEntity()) {
  8194. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  8195. return 0;
  8196. }
  8197. if (spell && spell->targets.size() > 0) {
  8198. ZoneServer* zone = spell->caster->GetZone();
  8199. for (int8 i = 0; i < spell->targets.size(); i++) {
  8200. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8201. if (target && target->IsEntity()) {
  8202. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8203. if (target->IsPlayer())
  8204. ((Player*)target)->SetCharSheetChanged(true);
  8205. }
  8206. }
  8207. }
  8208. else {
  8209. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8210. if (spawn->IsPlayer())
  8211. ((Player*)spawn)->SetCharSheetChanged(true);
  8212. }
  8213. return 0;
  8214. }
  8215. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  8216. if (!lua_interface)
  8217. return 0;
  8218. Item* item = lua_interface->GetItem(state);
  8219. int8 type = lua_interface->GetInt32Value(state, 2);
  8220. lua_interface->ResetFunctionStack(state);
  8221. if (!item) {
  8222. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  8223. return 0;
  8224. }
  8225. if (type == 1)
  8226. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  8227. else if (type == 2)
  8228. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  8229. return 1;
  8230. }
  8231. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  8232. if (!lua_interface)
  8233. return 0;
  8234. Spawn* target = lua_interface->GetSpawn(state);
  8235. float val = lua_interface->GetFloatValue(state, 2);
  8236. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8237. lua_interface->ResetFunctionStack(state);
  8238. // Added from Gangrenous post
  8239. if (spell && spell->resisted)
  8240. return 0;
  8241. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  8242. if (val > 1.0f)
  8243. val = 1.0f - (val / 100.0f);
  8244. if (spell && spell->spell && spell->targets.size() > 0) {
  8245. ZoneServer* zone = spell->caster->GetZone();
  8246. for (int32 i = 0; i != spell->targets.size(); i++) {
  8247. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  8248. if (spawn && spawn->IsEntity()) {
  8249. ((Entity*)spawn)->SetSpeedMultiplier(val);
  8250. if (spawn->IsPlayer())
  8251. ((Player*)spawn)->SetCharSheetChanged(true);
  8252. }
  8253. }
  8254. }
  8255. else {
  8256. if (target && target->IsEntity()) {
  8257. ((Entity*)target)->SetSpeedMultiplier(val);
  8258. if (target->IsPlayer())
  8259. ((Player*)target)->SetCharSheetChanged(true);
  8260. }
  8261. }
  8262. return 0;
  8263. }
  8264. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  8265. if (!lua_interface)
  8266. return 0;
  8267. Spawn* spawn = lua_interface->GetSpawn(state);
  8268. int16 model = lua_interface->GetInt16Value(state, 2);
  8269. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8270. lua_interface->ResetFunctionStack(state);
  8271. if (spell && spell->spell && spell->targets.size() > 0) {
  8272. ZoneServer* zone = spell->caster->GetZone();
  8273. for (int32 i = 0; i < spell->targets.size(); i++) {
  8274. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8275. if (target)
  8276. target->SetIllusionModel(model);
  8277. }
  8278. }
  8279. else {
  8280. if (!spawn) {
  8281. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8282. return 0;
  8283. }
  8284. spawn->SetIllusionModel(model);
  8285. }
  8286. return 0;
  8287. }
  8288. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  8289. if (!lua_interface)
  8290. return 0;
  8291. Spawn* spawn = lua_interface->GetSpawn(state);
  8292. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8293. lua_interface->ResetFunctionStack(state);
  8294. if (spell && spell->spell && spell->targets.size() > 0) {
  8295. ZoneServer* zone = spell->caster->GetZone();
  8296. for (int32 i = 0; i < spell->targets.size(); i++) {
  8297. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8298. if (target)
  8299. target->SetIllusionModel(0);
  8300. }
  8301. }
  8302. else {
  8303. if (!spawn) {
  8304. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8305. return 0;
  8306. }
  8307. spawn->SetIllusionModel(0);
  8308. }
  8309. return 0;
  8310. }
  8311. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  8312. if (!lua_interface)
  8313. return 0;
  8314. Spawn* caster = lua_interface->GetSpawn(state);
  8315. Spawn* target = lua_interface->GetSpawn(state, 2);
  8316. float chance = lua_interface->GetFloatValue(state, 3);
  8317. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8318. lua_interface->ResetFunctionStack(state);
  8319. if (!caster) {
  8320. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8321. return 0;
  8322. }
  8323. if (!caster->IsEntity()) {
  8324. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  8325. return 0;
  8326. }
  8327. if (!target) {
  8328. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8329. return 0;
  8330. }
  8331. if (!target->IsEntity()) {
  8332. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  8333. return 0;
  8334. }
  8335. if (chance <= 0) {
  8336. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  8337. return 0;
  8338. }
  8339. if (!spell) {
  8340. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8341. return 0;
  8342. }
  8343. if(spell->resisted) {
  8344. return 0;
  8345. }
  8346. if (((Entity*)caster)->GetThreatTransfer()) {
  8347. return 0;
  8348. }
  8349. ThreatTransfer* transfer = new ThreatTransfer;
  8350. transfer->Target = target->GetID();
  8351. transfer->Amount = chance;
  8352. transfer->Spell = spell;
  8353. ((Entity*)caster)->SetThreatTransfer(transfer);
  8354. return 0;
  8355. }
  8356. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  8357. if (!lua_interface)
  8358. return 0;
  8359. Spawn* spawn = lua_interface->GetSpawn(state);
  8360. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8361. lua_interface->ResetFunctionStack(state);
  8362. if (!spawn) {
  8363. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  8364. return 0;
  8365. }
  8366. if (!spell) {
  8367. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8368. return 0;
  8369. }
  8370. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  8371. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  8372. if(transfer && transfer->Spell != spell) {
  8373. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  8374. return 0;
  8375. }
  8376. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  8377. }
  8378. return 0;
  8379. }
  8380. int EQ2Emu_lua_CureByType(lua_State* state) {
  8381. if (!lua_interface)
  8382. return 0;
  8383. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8384. int8 cure_count = lua_interface->GetInt8Value(state);
  8385. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8386. string cure_name = lua_interface->GetStringValue(state, 3);
  8387. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8388. Spawn* target = lua_interface->GetSpawn(state, 5);
  8389. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  8390. lua_interface->ResetFunctionStack(state);
  8391. if(spell && spell->resisted) {
  8392. return 0;
  8393. }
  8394. if (target) {
  8395. if (!target->IsEntity()) {
  8396. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8397. return 0;
  8398. }
  8399. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8400. std::string alternate_name = "item";
  8401. if(spell)
  8402. alternate_name = std::string(spell->spell->GetName());
  8403. if(!caster && spell)
  8404. caster = (Spawn*)spell->caster;
  8405. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  8406. }
  8407. }
  8408. else {
  8409. ZoneServer* zone = spell->caster->GetZone();
  8410. vector<int32> targets = spell->targets;
  8411. vector<Entity*> targets_to_cure;
  8412. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8413. for (int8 i = 0; i < targets.size(); i++) {
  8414. target = zone->GetSpawnByID(targets.at(i));
  8415. if (!target || !target->IsEntity())
  8416. continue;
  8417. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8418. targets_to_cure.push_back((Entity*)target);
  8419. }
  8420. }
  8421. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8422. vector<Entity*>::iterator itr;
  8423. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  8424. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8425. }
  8426. }
  8427. return 0;
  8428. }
  8429. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  8430. if (!lua_interface)
  8431. return 0;
  8432. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8433. if (!spell) {
  8434. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8435. lua_interface->ResetFunctionStack(state);
  8436. return 0;
  8437. }
  8438. if(spell->resisted) {
  8439. lua_interface->ResetFunctionStack(state);
  8440. return 0;
  8441. }
  8442. int8 cure_count = lua_interface->GetInt8Value(state);
  8443. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8444. string cure_name = lua_interface->GetStringValue(state, 3);
  8445. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8446. Spawn* target = lua_interface->GetSpawn(state, 5);
  8447. lua_interface->ResetFunctionStack(state);
  8448. if (target) {
  8449. if (!target->IsEntity()) {
  8450. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8451. return 0;
  8452. }
  8453. if (((Entity*)target)->GetDetCount() > 0)
  8454. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8455. }
  8456. else {
  8457. ZoneServer* zone = spell->caster->GetZone();
  8458. vector<int32> targets = spell->targets;
  8459. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8460. for (int8 i = 0; i < targets.size(); i++) {
  8461. target = zone->GetSpawnByID(targets.at(i));
  8462. if (!target || !target->IsEntity())
  8463. continue;
  8464. if (((Entity*)target)->GetDetCount() > 0)
  8465. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8466. }
  8467. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8468. }
  8469. return 0;
  8470. }
  8471. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8472. if (!lua_interface)
  8473. return 0;
  8474. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8475. lua_interface->ResetFunctionStack(state);
  8476. if (!spell) {
  8477. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8478. return 0;
  8479. }
  8480. if (!spell->caster) {
  8481. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8482. return 0;
  8483. }
  8484. if (!spell->caster->GetZone()) {
  8485. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8486. return 0;
  8487. }
  8488. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8489. return 0;
  8490. }
  8491. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8492. if (!lua_interface)
  8493. return 0;
  8494. Spawn* spawn = lua_interface->GetSpawn(state);
  8495. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8496. lua_interface->ResetFunctionStack(state);
  8497. if (!spell) {
  8498. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8499. return 0;
  8500. }
  8501. if (spawn && spawn->IsEntity())
  8502. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8503. else {
  8504. ZoneServer* zone = spell->caster->GetZone();
  8505. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8506. for (int32 i = 0; i < spell->targets.size(); i++) {
  8507. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8508. if (!spawn || !spawn->IsEntity())
  8509. continue;
  8510. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8511. }
  8512. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8513. }
  8514. return 0;
  8515. }
  8516. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8517. if (!lua_interface)
  8518. return 0;
  8519. Spawn* spawn = lua_interface->GetSpawn(state);
  8520. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8521. lua_interface->ResetFunctionStack(state);
  8522. if (!spell) {
  8523. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8524. return 0;
  8525. }
  8526. if (spawn && spawn->IsEntity())
  8527. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8528. else {
  8529. ZoneServer* zone = spell->caster->GetZone();
  8530. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8531. for (int32 i = 0; i < spell->targets.size(); i++) {
  8532. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8533. if (!spawn || !spawn->IsEntity())
  8534. continue;
  8535. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8536. }
  8537. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8538. }
  8539. return 0;
  8540. }
  8541. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8542. if (!lua_interface)
  8543. return 0;
  8544. Spawn* caster = lua_interface->GetSpawn(state);
  8545. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8546. lua_interface->ResetFunctionStack(state);
  8547. if (!caster) {
  8548. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8549. return 0;
  8550. }
  8551. if (!caster->IsPlayer()) {
  8552. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8553. return 0;
  8554. }
  8555. Spawn* target = caster->GetTarget();
  8556. if (!target) {
  8557. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8558. return 0;
  8559. }
  8560. Client* client = ((Player*)caster)->GetClient();
  8561. if (!client) {
  8562. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8563. return 0;
  8564. }
  8565. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8566. if (ho) {
  8567. ho->SetTarget(target->GetID());
  8568. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8569. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8570. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8571. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8572. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8573. deque<GroupMemberInfo*>::iterator itr;
  8574. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8575. if (group)
  8576. {
  8577. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8578. deque<GroupMemberInfo*>* members = group->GetMembers();
  8579. for (itr = members->begin(); itr != members->end(); itr++) {
  8580. if ((*itr)->client)
  8581. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8582. }
  8583. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8584. }
  8585. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8586. }
  8587. else
  8588. safe_delete(ho);
  8589. }
  8590. else {
  8591. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8592. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8593. }
  8594. else
  8595. safe_delete(ho);
  8596. }
  8597. }
  8598. return 0;
  8599. }
  8600. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8601. if (!lua_interface)
  8602. return 0;
  8603. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8604. if (!spell) {
  8605. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8606. return 0;
  8607. }
  8608. int16 triggerCount = lua_interface->GetInt16Value(state);
  8609. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8610. if (!triggerCount) {
  8611. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8612. return 0;
  8613. }
  8614. spell->num_triggers = triggerCount;
  8615. spell->had_triggers = true;
  8616. spell->cancel_after_all_triggers = cancel_after_triggers;
  8617. return 0;
  8618. }
  8619. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8620. if (!lua_interface)
  8621. return 0;
  8622. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8623. lua_interface->ResetFunctionStack(state);
  8624. if (!spell) {
  8625. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8626. return 0;
  8627. }
  8628. lua_interface->SetInt32Value(state, spell->num_triggers);
  8629. return 1;
  8630. }
  8631. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8632. if (!lua_interface)
  8633. return 0;
  8634. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8635. if (!spell) {
  8636. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8637. lua_interface->ResetFunctionStack(state);
  8638. return 0;
  8639. }
  8640. if (!spell->caster || !spell->caster->GetZone()) {
  8641. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: caster / caster zone must be set!", lua_interface->GetScriptName(state));
  8642. lua_interface->ResetFunctionStack(state);
  8643. return 0;
  8644. }
  8645. int16 remove_count = lua_interface->GetInt16Value(state);
  8646. lua_interface->ResetFunctionStack(state);
  8647. if (!remove_count)
  8648. remove_count = 1;
  8649. if (remove_count >= spell->num_triggers) {
  8650. spell->num_triggers = 0;
  8651. if (spell->cancel_after_all_triggers)
  8652. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8653. }
  8654. else {
  8655. spell->num_triggers -= remove_count;
  8656. Client* client = spell->caster->IsPlayer() ? ((Player*)spell->caster)->GetClient() : nullptr;
  8657. ClientPacketFunctions::SendMaintainedExamineUpdate(client, spell->slot_pos, spell->num_triggers, 0);
  8658. }
  8659. return 0;
  8660. }
  8661. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8662. if (!lua_interface)
  8663. return 0;
  8664. Spawn* spawn = lua_interface->GetSpawn(state);
  8665. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8666. lua_interface->ResetFunctionStack(state);
  8667. if (!spawn) {
  8668. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8669. return 0;
  8670. }
  8671. if (!copy_spawn) {
  8672. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8673. return 0;
  8674. }
  8675. spawn->CopySpawnAppearance(copy_spawn);
  8676. return 0;
  8677. }
  8678. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8679. Spawn* spawn = lua_interface->GetSpawn(state);
  8680. int8 type = lua_interface->GetInt8Value(state, 2);
  8681. lua_interface->ResetFunctionStack(state);
  8682. if (!spawn) {
  8683. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8684. return 0;
  8685. }
  8686. else if (!spawn->IsEntity()) {
  8687. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8688. return 0;
  8689. }
  8690. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8691. return 1;
  8692. }
  8693. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8694. if (!lua_interface)
  8695. return 0;
  8696. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8697. int8 type = lua_interface->GetInt8Value(state);
  8698. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8699. lua_interface->ResetFunctionStack(state);
  8700. if (!spell) {
  8701. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8702. return 0;
  8703. }
  8704. if(spell->resisted) {
  8705. return 0;
  8706. }
  8707. if (spawn) {
  8708. if (!spawn->IsEntity()) {
  8709. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8710. return 0;
  8711. }
  8712. Entity* entity = ((Entity*)spawn);
  8713. entity->AddImmunity(spell, type);
  8714. }
  8715. else if(spell->caster && spell->caster->GetZone()) {
  8716. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8717. for (int8 i = 0; i < spell->targets.size(); i++) {
  8718. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8719. if (!spawn || !spawn->IsEntity())
  8720. continue;
  8721. Entity* entity = ((Entity*)spawn);
  8722. entity->AddImmunity(spell, type);
  8723. }
  8724. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8725. }
  8726. return 0;
  8727. }
  8728. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8729. if (!lua_interface)
  8730. return 0;
  8731. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8732. int8 type = lua_interface->GetInt8Value(state);
  8733. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8734. lua_interface->ResetFunctionStack(state);
  8735. if (!spell) {
  8736. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8737. return 0;
  8738. }
  8739. if (spawn) {
  8740. if (!spawn->IsEntity()) {
  8741. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8742. return 0;
  8743. }
  8744. Entity* entity = ((Entity*)spawn);
  8745. entity->RemoveImmunity(spell, type);
  8746. }
  8747. else if(spell->caster && spell->caster->GetZone()) {
  8748. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8749. for (int8 i = 0; i < spell->targets.size(); i++) {
  8750. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8751. if (!spawn || !spawn->IsEntity())
  8752. continue;
  8753. Entity* entity = ((Entity*)spawn);
  8754. entity->RemoveImmunity(spell, type);
  8755. }
  8756. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8757. }
  8758. return 0;
  8759. }
  8760. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8761. if (!lua_interface)
  8762. return 0;
  8763. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8764. if (!spell) {
  8765. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8766. lua_interface->ResetFunctionStack(state);
  8767. return 0;
  8768. }
  8769. if(spell->resisted) {
  8770. lua_interface->ResetFunctionStack(state);
  8771. return 0;
  8772. }
  8773. float snare = lua_interface->GetFloatValue(state);
  8774. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8775. lua_interface->ResetFunctionStack(state);
  8776. // convert the val to the speed multipler value (100 - val)
  8777. float val = 100.0 - snare;
  8778. val /= 100.0;
  8779. if (spawn) {
  8780. if (!spawn->IsEntity()) {
  8781. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8782. return 0;
  8783. }
  8784. ((Entity*)spawn)->SetSnareValue(spell, val);
  8785. }
  8786. else if(spell->caster && spell->caster->GetZone()) {
  8787. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8788. for (int8 i = 0; i < spell->targets.size(); i++) {
  8789. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8790. if (!spawn || !spawn->IsEntity())
  8791. continue;
  8792. ((Entity*)spawn)->SetSnareValue(spell, val);
  8793. }
  8794. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8795. }
  8796. return 0;
  8797. }
  8798. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8799. if (!lua_interface)
  8800. return 0;
  8801. Spawn* spawn = lua_interface->GetSpawn(state);
  8802. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8803. lua_interface->ResetFunctionStack(state);
  8804. if (!spawn) {
  8805. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8806. return 0;
  8807. }
  8808. if (race_id == 0) {
  8809. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8810. return 0;
  8811. }
  8812. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8813. return 1;
  8814. }
  8815. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8816. if (!lua_interface)
  8817. return 0;
  8818. Spawn* spawn = lua_interface->GetSpawn(state);
  8819. lua_interface->ResetFunctionStack(state);
  8820. if (!spawn) {
  8821. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8822. return 0;
  8823. }
  8824. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8825. return 1;
  8826. }
  8827. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8828. if (!lua_interface)
  8829. return 0;
  8830. Spawn* spawn = lua_interface->GetSpawn(state);
  8831. lua_interface->ResetFunctionStack(state);
  8832. if (!spawn) {
  8833. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8834. return 0;
  8835. }
  8836. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8837. return 1;
  8838. }
  8839. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8840. if (!lua_interface)
  8841. return 0;
  8842. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8843. lua_interface->ResetFunctionStack(state);
  8844. if (!spell) {
  8845. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8846. return 0;
  8847. }
  8848. lua_interface->SetStringValue(state, spell->spell->GetName());
  8849. return 1;
  8850. }
  8851. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8852. if (!lua_interface)
  8853. return 0;
  8854. Quest* quest = lua_interface->GetQuest(state);
  8855. lua_interface->ResetFunctionStack(state);
  8856. if (!quest) {
  8857. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8858. return 0;
  8859. }
  8860. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8861. return 1;
  8862. }
  8863. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8864. if (!lua_interface)
  8865. return 0;
  8866. Quest* quest = lua_interface->GetQuest(state);
  8867. int32 flags = lua_interface->GetInt32Value(state, 2);
  8868. lua_interface->ResetFunctionStack(state);
  8869. if (!quest) {
  8870. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8871. return 0;
  8872. }
  8873. quest->SetQuestFlags(flags);
  8874. return 0;
  8875. }
  8876. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8877. if (!lua_interface)
  8878. return 0;
  8879. Quest* quest = lua_interface->GetQuest(state);
  8880. Spawn* player = lua_interface->GetSpawn(state, 2);
  8881. int32 step = lua_interface->GetInt32Value(state, 3);
  8882. int32 duration = lua_interface->GetInt32Value(state, 4);
  8883. string action = lua_interface->GetStringValue(state, 5);
  8884. lua_interface->ResetFunctionStack(state);
  8885. if (!quest) {
  8886. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8887. return 0;
  8888. }
  8889. if (!player) {
  8890. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8891. return 0;
  8892. }
  8893. if (!player->IsPlayer()) {
  8894. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8895. return 0;
  8896. }
  8897. if (step == 0) {
  8898. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8899. return 0;
  8900. }
  8901. if (duration == 0) {
  8902. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8903. return 0;
  8904. }
  8905. if (action.length() == 0) {
  8906. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8907. return 0;
  8908. }
  8909. Client* client = ((Player*)player)->GetClient();
  8910. if (!client) {
  8911. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8912. return 0;
  8913. }
  8914. quest->SetTimerStep(step);
  8915. quest->AddFailedAction(step, action);
  8916. quest->SetStepTimer(duration);
  8917. client->AddQuestTimer(quest->GetQuestID());
  8918. return 0;
  8919. }
  8920. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8921. if (!lua_interface)
  8922. return 0;
  8923. Quest* quest = lua_interface->GetQuest(state);
  8924. Spawn* player = lua_interface->GetSpawn(state, 2);
  8925. lua_interface->ResetFunctionStack(state);
  8926. if (!quest) {
  8927. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8928. return 0;
  8929. }
  8930. if (!player) {
  8931. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8932. return 0;
  8933. }
  8934. if (!player->IsPlayer()) {
  8935. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8936. return 0;
  8937. }
  8938. Client* client = ((Player*)player)->GetClient();
  8939. if (!client) {
  8940. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8941. return 0;
  8942. }
  8943. quest->SetTimerStep(0);
  8944. quest->SetStepTimer(0);
  8945. client->RemoveQuestTimer(quest->GetQuestID());
  8946. return 0;
  8947. }
  8948. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8949. if (!lua_interface)
  8950. return 0;
  8951. Spawn* player = lua_interface->GetSpawn(state);
  8952. Quest* quest = lua_interface->GetQuest(state, 2);
  8953. int32 step = lua_interface->GetInt32Value(state, 3);
  8954. lua_interface->ResetFunctionStack(state);
  8955. if (!player) {
  8956. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8957. return 0;
  8958. }
  8959. if (!player->IsPlayer()) {
  8960. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8961. return 0;
  8962. }
  8963. if (!quest) {
  8964. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8965. return 0;
  8966. }
  8967. if (step == 0) {
  8968. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8969. return 0;
  8970. }
  8971. Client* client = ((Player*)player)->GetClient();
  8972. if (!client) {
  8973. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8974. return 0;
  8975. }
  8976. if (quest->RemoveQuestStep(step, client)) {
  8977. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8978. client->GetCurrentZone()->SendQuestUpdates(client);
  8979. }
  8980. else
  8981. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8982. return 0;
  8983. }
  8984. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8985. if (!lua_interface)
  8986. return 0;
  8987. Quest* quest = lua_interface->GetQuest(state, 1);
  8988. int32 step = lua_interface->GetInt32Value(state, 2);
  8989. string desc = lua_interface->GetStringValue(state, 3);
  8990. string task_group = lua_interface->GetStringValue(state, 4);
  8991. lua_interface->ResetFunctionStack(state);
  8992. if (!quest) {
  8993. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8994. return 0;
  8995. }
  8996. if (step == 0) {
  8997. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8998. return 0;
  8999. }
  9000. QuestStep* quest_step = quest->GetQuestStep(step);
  9001. if (!quest_step) {
  9002. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  9003. return 0;
  9004. }
  9005. quest_step->SetStepProgress(0);
  9006. quest_step->SetTaskGroup(task_group);
  9007. quest_step->SetDescription(desc);
  9008. return 0;
  9009. }
  9010. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  9011. if (!lua_interface)
  9012. return 0;
  9013. Quest* quest = lua_interface->GetQuest(state);
  9014. int32 step = lua_interface->GetInt32Value(state, 2);
  9015. string action = lua_interface->GetStringValue(state, 3);
  9016. lua_interface->ResetFunctionStack(state);
  9017. if (!quest) {
  9018. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  9019. return 0;
  9020. }
  9021. if (step == 0) {
  9022. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  9023. return 0;
  9024. }
  9025. if (action.length() == 0) {
  9026. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  9027. return 0;
  9028. }
  9029. quest->AddFailedAction(step, action);
  9030. return 0;
  9031. }
  9032. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  9033. if (!lua_interface)
  9034. return 0;
  9035. Spawn* player = lua_interface->GetSpawn(state);
  9036. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9037. int32 step = lua_interface->GetInt32Value(state, 3);
  9038. lua_interface->ResetFunctionStack(state);
  9039. if (!player) {
  9040. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  9041. return 0;
  9042. }
  9043. if (!player->IsPlayer()) {
  9044. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9045. return 0;
  9046. }
  9047. if (quest_id == 0) {
  9048. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  9049. return 0;
  9050. }
  9051. if (step == 0) {
  9052. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  9053. return 0;
  9054. }
  9055. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  9056. if (!quest) {
  9057. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  9058. return 0;
  9059. }
  9060. quest->StepFailed(step);
  9061. return 0;
  9062. }
  9063. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  9064. if (!lua_interface)
  9065. return 0;
  9066. Spawn* player = lua_interface->GetSpawn(state);
  9067. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9068. lua_interface->ResetFunctionStack(state);
  9069. if (!player) {
  9070. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  9071. return 0;
  9072. }
  9073. if (!player->IsPlayer()) {
  9074. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  9075. return 0;
  9076. }
  9077. if (quest_id == 0) {
  9078. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  9079. return 0;
  9080. }
  9081. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestCompletedCount(quest_id));
  9082. return 1;
  9083. }
  9084. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  9085. if (!lua_interface)
  9086. return 0;
  9087. string name = lua_interface->GetStringValue(state);
  9088. string value = lua_interface->GetStringValue(state, 2);
  9089. string comment = lua_interface->GetStringValue(state, 3);
  9090. lua_interface->ResetFunctionStack(state);
  9091. if (name.length() == 0) {
  9092. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  9093. return 0;
  9094. }
  9095. if (value.length() == 0) {
  9096. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  9097. return 0;
  9098. }
  9099. string varname = string("lua_").append(name);
  9100. Variable* var = variables.FindVariable(varname);
  9101. if (var)
  9102. var->SetValue(value.c_str());
  9103. else {
  9104. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  9105. variables.AddVariable(var);
  9106. }
  9107. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  9108. return 0;
  9109. }
  9110. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  9111. if (!lua_interface)
  9112. return 0;
  9113. string name = lua_interface->GetStringValue(state);
  9114. lua_interface->ResetFunctionStack(state);
  9115. if (name.length() == 0) {
  9116. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  9117. return 0;
  9118. }
  9119. string varname = string("lua_").append(name);
  9120. Variable* var = variables.FindVariable(varname);
  9121. if (var)
  9122. lua_interface->SetStringValue(state, var->GetValue());
  9123. else
  9124. lua_interface->SetStringValue(state, "NULL");
  9125. return 1;
  9126. }
  9127. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  9128. if (!lua_interface)
  9129. return 0;
  9130. Spawn* player = lua_interface->GetSpawn(state);
  9131. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9132. lua_interface->ResetFunctionStack(state);
  9133. if (!player) {
  9134. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9135. return 0;
  9136. }
  9137. if (!player->IsPlayer()) {
  9138. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9139. return 0;
  9140. }
  9141. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  9142. return 1;
  9143. }
  9144. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  9145. if (!lua_interface)
  9146. return 0;
  9147. Spawn* player = lua_interface->GetSpawn(state);
  9148. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9149. lua_interface->ResetFunctionStack(state);
  9150. if (!player) {
  9151. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9152. return 0;
  9153. }
  9154. if (!player->IsPlayer()) {
  9155. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9156. return 0;
  9157. }
  9158. Language* language = master_languages_list.GetLanguage(language_id);
  9159. if (language)
  9160. {
  9161. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  9162. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID(), 0);
  9163. }
  9164. return 0;
  9165. }
  9166. int EQ2Emu_lua_IsNight(lua_State* state) {
  9167. if (!lua_interface)
  9168. return 0;
  9169. ZoneServer* zone = lua_interface->GetZone(state);
  9170. lua_interface->ResetFunctionStack(state);
  9171. if (!zone) {
  9172. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  9173. return 0;
  9174. }
  9175. lua_interface->SetBooleanValue(state, zone->IsDusk());
  9176. return 1;
  9177. }
  9178. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  9179. if (!lua_interface)
  9180. return 0;
  9181. Spawn* spawn = lua_interface->GetSpawn(state);
  9182. lua_interface->ResetFunctionStack(state);
  9183. if (!spawn) {
  9184. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  9185. return 0;
  9186. }
  9187. if (!spawn->IsWidget()) {
  9188. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  9189. return 0;
  9190. }
  9191. ((Widget*)spawn)->SetMultiFloorLift(true);
  9192. if (spawn->GetZone())
  9193. spawn->GetZone()->AddTransportSpawn(spawn);
  9194. return 0;
  9195. }
  9196. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  9197. if (!lua_interface)
  9198. return 0;
  9199. Spawn* player = lua_interface->GetSpawn(state);
  9200. int32 path = lua_interface->GetInt32Value(state, 2);
  9201. lua_interface->ResetFunctionStack(state);
  9202. if (!player) {
  9203. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9204. return 0;
  9205. }
  9206. if (!player->IsPlayer()) {
  9207. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9208. return 0;
  9209. }
  9210. if (path == 0) {
  9211. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  9212. return 0;
  9213. }
  9214. Client* client = ((Player*)player)->GetClient();
  9215. if (!client) {
  9216. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9217. return 0;
  9218. }
  9219. client->SendFlightAutoMount(path);
  9220. return 0;
  9221. }
  9222. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  9223. if (!lua_interface)
  9224. return 0;
  9225. Spawn* player = lua_interface->GetSpawn(state);
  9226. if (!player) {
  9227. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9228. return 0;
  9229. }
  9230. if (!player->IsPlayer()) {
  9231. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9232. return 0;
  9233. }
  9234. Client* client = ((Player*)player)->GetClient();
  9235. if (!client) {
  9236. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9237. return 0;
  9238. }
  9239. client->EndAutoMount();
  9240. return 0;
  9241. }
  9242. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  9243. if (!lua_interface)
  9244. return 0;
  9245. Spawn* player = lua_interface->GetSpawn(state);
  9246. lua_interface->ResetFunctionStack(state);
  9247. if (!player) {
  9248. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  9249. return 0;
  9250. }
  9251. if (!player->IsPlayer()) {
  9252. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9253. return 0;
  9254. }
  9255. Client* client = ((Player*)player)->GetClient();
  9256. if (!client) {
  9257. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9258. return 0;
  9259. }
  9260. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  9261. return 1;
  9262. }
  9263. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  9264. if (!lua_interface)
  9265. return 0;
  9266. Spawn* player = lua_interface->GetSpawn(state);
  9267. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9268. int32 value = lua_interface->GetInt32Value(state, 3);
  9269. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9270. lua_interface->ResetFunctionStack(state);
  9271. if (!player) {
  9272. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9273. return 0;
  9274. }
  9275. if (!player->IsPlayer()) {
  9276. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9277. return 0;
  9278. }
  9279. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  9280. return 0;
  9281. }
  9282. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  9283. if (!lua_interface)
  9284. return 0;
  9285. Spawn* player = lua_interface->GetSpawn(state);
  9286. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9287. lua_interface->ResetFunctionStack(state);
  9288. if (!player) {
  9289. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9290. return 0;
  9291. }
  9292. if (!player->IsPlayer()) {
  9293. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9294. return 0;
  9295. }
  9296. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  9297. if (!hd)
  9298. return 0;
  9299. lua_interface->SetInt32Value(state, hd->Value);
  9300. lua_interface->SetInt32Value(state, hd->Value2);
  9301. return 2;
  9302. }
  9303. int EQ2Emu_lua_SetGridID(lua_State* state) {
  9304. if (!lua_interface)
  9305. return 0;
  9306. Spawn* spawn = lua_interface->GetSpawn(state);
  9307. int32 grid = lua_interface->GetInt32Value(state, 2);
  9308. lua_interface->ResetFunctionStack(state);
  9309. if (!spawn) {
  9310. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9311. return 0;
  9312. }
  9313. if (grid == 0) {
  9314. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  9315. return 0;
  9316. }
  9317. spawn->SetLocation(grid);
  9318. return 0;
  9319. }
  9320. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  9321. if (!lua_interface)
  9322. return 0;
  9323. Spawn* spawn = lua_interface->GetSpawn(state);
  9324. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9325. int32 value1 = lua_interface->GetInt32Value(state, 3);
  9326. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9327. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  9328. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  9329. lua_interface->ResetFunctionStack(state);
  9330. if (!spawn) {
  9331. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9332. return 0;
  9333. }
  9334. //Add this quest to the list of required quests for this spawn
  9335. spawn->SetRequiredHistory(event_id, value1, value2);
  9336. //If private spawn value set
  9337. if (private_spawn) {
  9338. //Set the spawn to be private when not granted access via history
  9339. spawn->AddAllowAccessSpawn(spawn);
  9340. spawn->SetPrivateQuestSpawn(true);
  9341. }
  9342. //This value will override vis_flags in the vis packet
  9343. if (flag_override > 0)
  9344. spawn->SetQuestsRequiredOverride(flag_override);
  9345. return 0;
  9346. }
  9347. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  9348. if (!lua_interface)
  9349. return 0;
  9350. Spawn* player = lua_interface->GetSpawn(state);
  9351. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9352. int32 step_id = lua_interface->GetInt32Value(state, 3);
  9353. lua_interface->ResetFunctionStack(state);
  9354. if (!player) {
  9355. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  9356. return 0;
  9357. }
  9358. if (!player->IsPlayer()) {
  9359. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  9360. return 0;
  9361. }
  9362. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  9363. return 1;
  9364. }
  9365. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  9366. if (!lua_interface)
  9367. return 0;
  9368. Spawn* player = lua_interface->GetSpawn(state);
  9369. int8 level = lua_interface->GetInt8Value(state, 2);
  9370. lua_interface->ResetFunctionStack(state);
  9371. if (!player) {
  9372. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  9373. return 0;
  9374. }
  9375. if (!player->IsPlayer()) {
  9376. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  9377. return 0;
  9378. }
  9379. if (level == 0) {
  9380. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  9381. return 0;
  9382. }
  9383. Client* client = ((Player*)player)->GetClient();
  9384. if (!client) {
  9385. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  9386. return 0;
  9387. }
  9388. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  9389. return 0;
  9390. }
  9391. int EQ2Emu_lua_AddCoin(lua_State* state) {
  9392. if (!lua_interface)
  9393. return 0;
  9394. Spawn* player = lua_interface->GetSpawn(state);
  9395. int32 amount = lua_interface->GetInt32Value(state, 2);
  9396. lua_interface->ResetFunctionStack(state);
  9397. if (!player) {
  9398. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9399. return 0;
  9400. }
  9401. if (!player->IsPlayer()) {
  9402. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9403. return 0;
  9404. }
  9405. if (amount == 0) {
  9406. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9407. return 0;
  9408. }
  9409. ((Player*)player)->AddCoins(amount);
  9410. return 0;
  9411. }
  9412. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  9413. if (!lua_interface)
  9414. return 0;
  9415. Spawn* player = lua_interface->GetSpawn(state);
  9416. int32 amount = lua_interface->GetInt32Value(state, 2);
  9417. lua_interface->ResetFunctionStack(state);
  9418. if (!player) {
  9419. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9420. return 0;
  9421. }
  9422. if (!player->IsPlayer()) {
  9423. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9424. return 0;
  9425. }
  9426. if (amount == 0) {
  9427. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9428. return 0;
  9429. }
  9430. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  9431. return 1;
  9432. }
  9433. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  9434. if (!lua_interface)
  9435. return 0;
  9436. ZoneServer* zone = lua_interface->GetZone(state);
  9437. lua_interface->ResetFunctionStack(state);
  9438. if (!zone) {
  9439. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9440. return 0;
  9441. }
  9442. vector<Entity*> players = zone->GetPlayers();
  9443. if (players.size() == 0)
  9444. return 0;
  9445. lua_createtable(state, players.size(), 0);
  9446. int newTable = lua_gettop(state);
  9447. for (int32 i = 0; i < players.size(); i++) {
  9448. lua_interface->SetSpawnValue(state, players.at(i));
  9449. lua_rawseti(state, newTable, i + 1);
  9450. }
  9451. return 1;
  9452. }
  9453. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  9454. if (!lua_interface)
  9455. return 0;
  9456. ZoneServer* zone = lua_interface->GetZone(state, 1);
  9457. if (!zone) {
  9458. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9459. return 0;
  9460. }
  9461. int32 group_id = lua_interface->GetInt32Value(state, 2);
  9462. lua_interface->ResetFunctionStack(state);
  9463. //Map of <placement_id, location_id>
  9464. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  9465. map<int32, int32>::iterator itr;
  9466. vector<Spawn*> group;
  9467. for (itr = locs->begin(); itr != locs->end(); itr++) {
  9468. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  9469. if (!location) {
  9470. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  9471. return 0;
  9472. }
  9473. Spawn* spawn = 0;
  9474. if (location->entities[0]) {
  9475. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  9476. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  9477. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  9478. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  9479. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  9480. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  9481. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  9482. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  9483. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9484. spawn = zone->AddSignSpawn(location, location->entities[0]);
  9485. if(spawn && spawn->IsOmittedByDBFlag())
  9486. {
  9487. 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);
  9488. safe_delete(spawn);
  9489. continue;
  9490. }
  9491. if (spawn) {
  9492. const char* script = 0;
  9493. for (int x = 0; x < 3; x++) {
  9494. switch (x) {
  9495. case 0:
  9496. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  9497. break;
  9498. case 1:
  9499. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  9500. break;
  9501. case 2:
  9502. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  9503. break;
  9504. }
  9505. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9506. spawn->SetSpawnScript(string(script));
  9507. break;
  9508. }
  9509. }
  9510. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9511. lua_interface->SetSpawnValue(state, spawn);
  9512. group.push_back(spawn);
  9513. }
  9514. else {
  9515. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  9516. safe_delete(spawn);
  9517. }
  9518. }
  9519. }
  9520. if (!group.empty()) {
  9521. lua_createtable(state, group.size(), 0);
  9522. int newTable = lua_gettop(state);
  9523. for (int32 i = 0; i < group.size(); i++) {
  9524. lua_interface->SetSpawnValue(state, group[i]);
  9525. lua_rawseti(state, newTable, i + 1);
  9526. }
  9527. }
  9528. else
  9529. lua_pushnil(state);
  9530. return 1;
  9531. }
  9532. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9533. if (!lua_interface)
  9534. return 0;
  9535. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9536. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9537. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9538. lua_interface->ResetFunctionStack(state);
  9539. if (!spawn) {
  9540. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9541. return 0;
  9542. }
  9543. if (anim_id == 0) {
  9544. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9545. return 0;
  9546. }
  9547. if (leeway == 0)
  9548. leeway = 5000;
  9549. spawn->SetSpawnAnim(anim_id);
  9550. spawn->SetSpawnAnimLeeway(leeway);
  9551. return 0;
  9552. }
  9553. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9554. if (!lua_interface)
  9555. return 0;
  9556. Spawn* player = lua_interface->GetSpawn(state);
  9557. lua_interface->ResetFunctionStack(state);
  9558. if (!player || !player->IsPlayer()) {
  9559. return 0;
  9560. }
  9561. Client* client = ((Player*)player)->GetClient();
  9562. if (!client) {
  9563. return 0;
  9564. }
  9565. lua_interface->SetInt32Value(state, client->GetVersion());
  9566. return 1;
  9567. }
  9568. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9569. if (!lua_interface)
  9570. return 0;
  9571. Item* item = lua_interface->GetItem(state);
  9572. lua_interface->ResetFunctionStack(state);
  9573. if (!item) {
  9574. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9575. return 0;
  9576. }
  9577. lua_interface->SetInt32Value(state, item->details.item_id);
  9578. return 1;
  9579. }
  9580. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9581. if (!lua_interface)
  9582. return 0;
  9583. Spawn* spawn = lua_interface->GetSpawn(state);
  9584. lua_interface->ResetFunctionStack(state);
  9585. if (!spawn) {
  9586. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9587. return 0;
  9588. }
  9589. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9590. return 1;
  9591. }
  9592. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9593. if (!lua_interface)
  9594. return 0;
  9595. Spawn* spawn = lua_interface->GetSpawn(state);
  9596. lua_interface->ResetFunctionStack(state);
  9597. if (!spawn) {
  9598. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9599. return 0;
  9600. }
  9601. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9602. return 1;
  9603. }
  9604. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9605. if (!lua_interface)
  9606. return 0;
  9607. Spawn* spawn = lua_interface->GetSpawn(state);
  9608. lua_interface->ResetFunctionStack(state);
  9609. if (!spawn) {
  9610. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9611. return 0;
  9612. }
  9613. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9614. return 1;
  9615. }
  9616. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9617. if (!lua_interface)
  9618. return 0;
  9619. Spawn* spawn = lua_interface->GetSpawn(state);
  9620. lua_interface->ResetFunctionStack(state);
  9621. if (!spawn) {
  9622. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9623. return 0;
  9624. }
  9625. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9626. return 1;
  9627. }
  9628. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9629. if (!lua_interface)
  9630. return 0;
  9631. Spawn* spawn = lua_interface->GetSpawn(state);
  9632. float pct = lua_interface->GetFloatValue(state, 2);
  9633. lua_interface->ResetFunctionStack(state);
  9634. if (!spawn) {
  9635. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9636. return 0;
  9637. }
  9638. if (pct == 0) {
  9639. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9640. return 0;
  9641. }
  9642. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9643. lua_interface->SetInt32Value(state, amount);
  9644. return 1;
  9645. }
  9646. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9647. if (!lua_interface)
  9648. return 0;
  9649. Spawn* spawn = lua_interface->GetSpawn(state);
  9650. float pct = lua_interface->GetFloatValue(state, 2);
  9651. lua_interface->ResetFunctionStack(state);
  9652. if (!spawn) {
  9653. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9654. return 0;
  9655. }
  9656. if (pct == 0) {
  9657. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9658. return 0;
  9659. }
  9660. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9661. lua_interface->SetInt32Value(state, amount);
  9662. return 1;
  9663. }
  9664. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9665. if (!lua_interface)
  9666. return 0;
  9667. Spawn* spawn = lua_interface->GetSpawn(state);
  9668. lua_interface->ResetFunctionStack(state);
  9669. if (!spawn) {
  9670. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9671. return 0;
  9672. }
  9673. if (!spawn->IsPlayer()) {
  9674. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9675. return 0;
  9676. }
  9677. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9678. return 1;
  9679. }
  9680. int EQ2Emu_lua_Evac(lua_State* state) {
  9681. if (!lua_interface)
  9682. return 0;
  9683. Spawn* target = lua_interface->GetSpawn(state);
  9684. if (target) {
  9685. float x = target->GetZone()->GetSafeX();
  9686. float y = target->GetZone()->GetSafeY();
  9687. float z = target->GetZone()->GetSafeZ();
  9688. float h = target->GetZone()->GetSafeHeading();
  9689. target->SetX(x);
  9690. target->SetY(y);
  9691. target->SetZ(z);
  9692. target->SetHeading(h);
  9693. target->SetSpawnOrigX(x);
  9694. target->SetSpawnOrigY(y);
  9695. target->SetSpawnOrigZ(z);
  9696. target->SetSpawnOrigHeading(h);
  9697. if (target->IsPlayer()) {
  9698. Client* client = ((Player*)target)->GetClient();
  9699. if (client) {
  9700. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9701. int numargs = lua_interface->GetNumberOfArgs(state);
  9702. if(numargs == 4) {
  9703. x = lua_interface->GetFloatValue(state,1);
  9704. y = lua_interface->GetFloatValue(state,2);
  9705. z = lua_interface->GetFloatValue(state,3);
  9706. h = lua_interface->GetFloatValue(state,4);
  9707. }
  9708. client->SetReloadingZone(true);
  9709. target->SetX(x);
  9710. target->SetY(y);
  9711. target->SetZ(z);
  9712. target->SetHeading(h);
  9713. target->SetSpawnOrigX(x);
  9714. target->SetSpawnOrigY(y);
  9715. target->SetSpawnOrigZ(z);
  9716. target->SetSpawnOrigHeading(h);
  9717. target->SetAppearancePosition(x,y,z);
  9718. client->SetZoningCoords(x,y,z,h);
  9719. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9720. if (packet)
  9721. {
  9722. packet->setDataByName("x", x);
  9723. packet->setDataByName("y", y);
  9724. packet->setDataByName("z", z);
  9725. client->QueuePacket(packet->serialize());
  9726. safe_delete(packet);
  9727. }
  9728. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9729. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9730. }
  9731. }
  9732. lua_interface->ResetFunctionStack(state);
  9733. }
  9734. else {
  9735. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9736. if(!spell || !spell->caster || !spell->caster->GetZone()) {
  9737. lua_interface->ResetFunctionStack(state);
  9738. return 0;
  9739. }
  9740. ZoneServer* zone = spell->caster->GetZone();
  9741. float x = spell->caster->GetZone()->GetSafeX();
  9742. float y = spell->caster->GetZone()->GetSafeY();
  9743. float z = spell->caster->GetZone()->GetSafeZ();
  9744. float h = spell->caster->GetZone()->GetSafeHeading();
  9745. int numargs = lua_interface->GetNumberOfArgs(state);
  9746. if(numargs == 4) {
  9747. x = lua_interface->GetFloatValue(state,1);
  9748. y = lua_interface->GetFloatValue(state,2);
  9749. z = lua_interface->GetFloatValue(state,3);
  9750. h = lua_interface->GetFloatValue(state,4);
  9751. }
  9752. lua_interface->ResetFunctionStack(state);
  9753. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9754. for (int32 i = 0; i < spell->targets.size(); i++) {
  9755. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9756. if (!target2)
  9757. continue;
  9758. if (target2->IsPlayer()) {
  9759. Client* client = ((Player*)target2)->GetClient();
  9760. if (client) {
  9761. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9762. client->SetReloadingZone(true);
  9763. target2->SetX(x);
  9764. target2->SetY(y);
  9765. target2->SetZ(z);
  9766. target2->SetHeading(h);
  9767. target2->SetSpawnOrigX(x);
  9768. target2->SetSpawnOrigY(y);
  9769. target2->SetSpawnOrigZ(z);
  9770. target2->SetSpawnOrigHeading(h);
  9771. target2->SetAppearancePosition(x,y,z);
  9772. client->SetZoningCoords(x,y,z,h);
  9773. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9774. if (packet)
  9775. {
  9776. packet->setDataByName("x", x);
  9777. packet->setDataByName("y", y);
  9778. packet->setDataByName("z", z);
  9779. client->QueuePacket(packet->serialize());
  9780. safe_delete(packet);
  9781. }
  9782. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9783. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9784. }
  9785. }
  9786. }
  9787. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9788. }
  9789. return 0;
  9790. }
  9791. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9792. if (!lua_interface)
  9793. return 0;
  9794. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9795. lua_interface->ResetFunctionStack(state);
  9796. if (!luaspell || !luaspell->spell) {
  9797. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9798. return 0;
  9799. }
  9800. int8 tier = luaspell->spell->GetSpellTier();
  9801. lua_interface->SetInt32Value(state, tier);
  9802. return 1;
  9803. }
  9804. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9805. if (!lua_interface)
  9806. return 0;
  9807. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9808. lua_interface->ResetFunctionStack(state);
  9809. if (!luaspell || !luaspell->spell) {
  9810. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9811. return 0;
  9812. }
  9813. int32 spell_id = luaspell->spell->GetSpellID();
  9814. lua_interface->SetInt32Value(state, spell_id);
  9815. return 1;
  9816. }
  9817. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9818. if (!lua_interface)
  9819. return 0;
  9820. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9821. lua_interface->ResetFunctionStack(state);
  9822. if (!spawn) {
  9823. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9824. return 0;
  9825. }
  9826. if (!spawn->IsPlayer()) {
  9827. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9828. return 0;
  9829. }
  9830. ZoneServer* zone = spawn->GetZone();
  9831. if (!zone) {
  9832. return 0;
  9833. }
  9834. Client* client = ((Player*)spawn)->GetClient();
  9835. if (!client) {
  9836. return 0;
  9837. }
  9838. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9839. return 0;
  9840. }
  9841. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9842. if (!lua_interface)
  9843. return 0;
  9844. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9845. lua_interface->ResetFunctionStack(state);
  9846. if (!spawn) {
  9847. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9848. return 0;
  9849. }
  9850. if (!spawn->IsPlayer()) {
  9851. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9852. return 0;
  9853. }
  9854. ZoneServer* zone = spawn->GetZone();
  9855. if (!zone) {
  9856. return 0;
  9857. }
  9858. Client* client = ((Player*)spawn)->GetClient();
  9859. if (!client) {
  9860. return 0;
  9861. }
  9862. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9863. return 0;
  9864. }
  9865. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9866. if (!lua_interface)
  9867. return 0;
  9868. Spawn* caster = lua_interface->GetSpawn(state);
  9869. Spawn* target = lua_interface->GetSpawn(state, 2);
  9870. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9871. string spell_name = lua_interface->GetStringValue(state, 4);
  9872. lua_interface->ResetFunctionStack(state);
  9873. if (!caster) {
  9874. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9875. return 0;
  9876. }
  9877. if (!caster->IsEntity()) {
  9878. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9879. return 0;
  9880. }
  9881. if (!target) {
  9882. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9883. return 0;
  9884. }
  9885. if (!target->IsEntity()) {
  9886. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9887. return 0;
  9888. }
  9889. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9890. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9891. return 0;
  9892. }
  9893. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9894. if (!lua_interface)
  9895. return 0;
  9896. Spawn* player = lua_interface->GetSpawn(state);
  9897. int32 amount = lua_interface->GetInt32Value(state, 2);
  9898. lua_interface->ResetFunctionStack(state);
  9899. if (player && player->IsPlayer() && amount > 0) {
  9900. ((Player*)player)->AddXP(amount);
  9901. }
  9902. return 0;
  9903. }
  9904. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9905. if (!lua_interface)
  9906. return 0;
  9907. Spawn* player = lua_interface->GetSpawn(state);
  9908. int8 type = lua_interface->GetInt8Value(state, 2);
  9909. string text = lua_interface->GetStringValue(state, 3);
  9910. lua_interface->ResetFunctionStack(state);
  9911. Client* client = 0;
  9912. if (player && player->IsPlayer())
  9913. client = ((Player*)player)->GetClient();
  9914. if (!client || text.length() == 0) {
  9915. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9916. return 0;
  9917. }
  9918. client->SimpleMessage(type, text.c_str());
  9919. return 0;
  9920. }
  9921. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9922. if (!lua_interface)
  9923. return 0;
  9924. Spawn* player = lua_interface->GetSpawn(state);
  9925. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9926. lua_interface->ResetFunctionStack(state);
  9927. Client* client = 0;
  9928. if (player && player->IsPlayer())
  9929. client = ((Player*)player)->GetClient();
  9930. if (!client || !spawn) {
  9931. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9932. return 0;
  9933. }
  9934. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9935. if (!items) {
  9936. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9937. return 0;
  9938. }
  9939. client->SendLootResponsePacket(spawn->GetLootCoins(), items, spawn, true);
  9940. return 0;
  9941. }
  9942. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9943. if (!lua_interface)
  9944. return 0;
  9945. Spawn* spawnref = lua_interface->GetSpawn(state);
  9946. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9947. lua_interface->ResetFunctionStack(state);
  9948. if (spawn_id > 0 && spawnref) {
  9949. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9950. if (spawns.size() == 0) {
  9951. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9952. return 0;
  9953. }
  9954. Spawn* spawn = 0;
  9955. int16 index = MakeRandomInt(0, spawns.size());
  9956. if (index >= spawns.size() || index < 0)
  9957. index = 0;
  9958. spawn = spawns[index];
  9959. lua_interface->SetSpawnValue(state, spawn);
  9960. return 1;
  9961. }
  9962. else {
  9963. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9964. }
  9965. return 0;
  9966. }
  9967. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9968. Spawn* player = lua_interface->GetSpawn(state);
  9969. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9970. string name = lua_interface->GetStringValue(state, 3);
  9971. float distance = lua_interface->GetFloatValue(state, 4);
  9972. string command = lua_interface->GetStringValue(state, 5);
  9973. string error_text = lua_interface->GetStringValue(state, 6);
  9974. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9975. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9976. lua_interface->ResetFunctionStack(state);
  9977. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9978. if (distance == 0)
  9979. distance = 10.0f;
  9980. if (command.length() == 0)
  9981. command = name;
  9982. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9983. if (spawns.size() == 0) {
  9984. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9985. return 0;
  9986. }
  9987. Spawn* spawn = 0;
  9988. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9989. spawn = *itr;
  9990. if (spawn) {
  9991. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9992. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9993. }
  9994. }
  9995. }
  9996. return 0;
  9997. }
  9998. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9999. if (!lua_interface)
  10000. return 0;
  10001. Client* client = 0;
  10002. Spawn* player = lua_interface->GetSpawn(state);
  10003. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  10004. lua_interface->ResetFunctionStack(state);
  10005. if (player && player->IsPlayer() && player->GetZone())
  10006. client = ((Player*)player)->GetClient();
  10007. else{
  10008. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  10009. return 0;
  10010. }
  10011. if (client) {
  10012. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  10013. if (packet) {
  10014. packet->setDataByName("goal_num", goal_num);
  10015. client->QueuePacket(packet->serialize());
  10016. safe_delete(packet);
  10017. }
  10018. }
  10019. return 0;
  10020. }
  10021. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  10022. if (!lua_interface)
  10023. return 0;
  10024. Client* client = 0;
  10025. Spawn* player = lua_interface->GetSpawn(state);
  10026. lua_interface->ResetFunctionStack(state);
  10027. if (player && player->IsPlayer() && player->GetZone())
  10028. client = ((Player*)player)->GetClient();
  10029. else {
  10030. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  10031. return 0;
  10032. }
  10033. if (client) {
  10034. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  10035. }
  10036. return 0;
  10037. }
  10038. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  10039. if (!lua_interface)
  10040. return 0;
  10041. Client* client = 0;
  10042. Spawn* player = lua_interface->GetSpawn(state);
  10043. float duration = lua_interface->GetFloatValue(state, 2);
  10044. string text = lua_interface->GetStringValue(state, 3);
  10045. string voice = lua_interface->GetStringValue(state, 4);
  10046. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  10047. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  10048. string signal = lua_interface->GetStringValue(state, 7);
  10049. string goal1 = lua_interface->GetStringValue(state, 8);
  10050. string task1 = lua_interface->GetStringValue(state, 9);
  10051. string goal2 = lua_interface->GetStringValue(state, 10);
  10052. string task2 = lua_interface->GetStringValue(state, 11);
  10053. string goal3 = lua_interface->GetStringValue(state, 12);
  10054. string task3 = lua_interface->GetStringValue(state, 13);
  10055. string goal4 = lua_interface->GetStringValue(state, 14);
  10056. string task4 = lua_interface->GetStringValue(state, 15);
  10057. lua_interface->ResetFunctionStack(state);
  10058. if (!player) {
  10059. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  10060. return 0;
  10061. }
  10062. if (!player->IsPlayer()) {
  10063. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  10064. return 0;
  10065. }
  10066. else
  10067. client = ((Player*)player)->GetClient();
  10068. if (!client) {
  10069. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  10070. return 0;
  10071. }
  10072. if (text.length() == 0) {
  10073. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  10074. return 0;
  10075. }
  10076. if (duration >= 0 && duration < 2)
  10077. duration = 2;
  10078. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  10079. if (packet) {
  10080. packet->setDataByName("open_seconds_max", duration);
  10081. packet->setDataByName("text", text.c_str());
  10082. packet->setDataByName("voice", voice.c_str());
  10083. int8 num_goals = 1;
  10084. if (task2.length() > 0)
  10085. num_goals++;
  10086. if (task3.length() > 0)
  10087. num_goals++;
  10088. if (task4.length() > 0)
  10089. num_goals++;
  10090. packet->setArrayLengthByName("num_goals", num_goals);
  10091. for (int8 i = 0; i < num_goals; i++) {
  10092. packet->setSubArrayLengthByName("num_tasks", 1, i);
  10093. }
  10094. if (goal1.length() > 0)
  10095. packet->setArrayDataByName("goal_text", goal1.c_str());
  10096. if (goal2.length() > 0)
  10097. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  10098. if (goal3.length() > 0)
  10099. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  10100. if (goal4.length() > 0)
  10101. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  10102. packet->setSubArrayDataByName("task_text", task1.c_str());
  10103. if (task2.length() > 0)
  10104. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  10105. if (task3.length() > 0)
  10106. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  10107. if (task4.length() > 0)
  10108. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  10109. packet->setDataByName("complete_sound", "click");
  10110. packet->setDataByName("signal", signal.c_str());
  10111. packet->setDataByName("voice_key1", voice_key1);
  10112. packet->setDataByName("voice_key2", voice_key2);
  10113. client->QueuePacket(packet->serialize());
  10114. safe_delete(packet);
  10115. }
  10116. return 0;
  10117. }
  10118. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  10119. if (!lua_interface)
  10120. return 0;
  10121. Client* client = 0;
  10122. Spawn* player = lua_interface->GetSpawn(state);
  10123. string window = lua_interface->GetStringValue(state, 2);
  10124. int8 show = lua_interface->GetInt8Value(state, 3);
  10125. lua_interface->ResetFunctionStack(state);
  10126. if (!player) {
  10127. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  10128. return 0;
  10129. }
  10130. if (!player->IsPlayer()) {
  10131. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  10132. return 0;
  10133. }
  10134. else
  10135. client = ((Player*)player)->GetClient();
  10136. if (!client) {
  10137. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  10138. return 0;
  10139. }
  10140. if (window.length() == 0) {
  10141. lua_interface->LogError("LUA ShowWindow required parameters not given");
  10142. return 0;
  10143. }
  10144. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  10145. if (packet) {
  10146. packet->setDataByName("window", window.c_str());
  10147. packet->setDataByName("show", show);
  10148. client->QueuePacket(packet->serialize());
  10149. safe_delete(packet);
  10150. }
  10151. return 0;
  10152. }
  10153. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  10154. //See GameEvents.txt for options that can be used for this function
  10155. if (!lua_interface)
  10156. return 0;
  10157. Client* client = 0;
  10158. Spawn* player = lua_interface->GetSpawn(state);
  10159. string event_name = lua_interface->GetStringValue(state, 2);
  10160. int8 enabled = lua_interface->GetInt8Value(state, 3);
  10161. lua_interface->ResetFunctionStack(state);
  10162. if (!player || !player->IsPlayer()) {
  10163. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  10164. return 0;
  10165. }
  10166. client = ((Player*)player)->GetClient();
  10167. if (!client) {
  10168. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  10169. return 0;
  10170. }
  10171. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  10172. if (packet) {
  10173. packet->setDataByName("event_name", event_name.c_str());
  10174. packet->setDataByName("enabled", enabled);
  10175. client->QueuePacket(packet->serialize());
  10176. safe_delete(packet);
  10177. }
  10178. return 0;
  10179. }
  10180. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  10181. if (!lua_interface)
  10182. return 0;
  10183. Spawn* player = lua_interface->GetSpawn(state);
  10184. lua_interface->ResetFunctionStack(state);
  10185. if (player && player->IsPlayer()) {
  10186. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  10187. return 1;
  10188. }
  10189. return 0;
  10190. }
  10191. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  10192. if (!lua_interface)
  10193. return 0;
  10194. Spawn* player = lua_interface->GetSpawn(state);
  10195. int8 step = lua_interface->GetInt8Value(state, 2);
  10196. lua_interface->ResetFunctionStack(state);
  10197. if (player && player->IsPlayer() && step > 0) {
  10198. ((Player*)player)->SetTutorialStep(step);
  10199. }
  10200. return 0;
  10201. }
  10202. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  10203. if (!lua_interface)
  10204. return 0;
  10205. Client* client = 0;
  10206. Spawn* player = lua_interface->GetSpawn(state);
  10207. string window = lua_interface->GetStringValue(state, 2);
  10208. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  10209. lua_interface->ResetFunctionStack(state);
  10210. if (!player) {
  10211. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  10212. return 0;
  10213. }
  10214. if (!player->IsPlayer()) {
  10215. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  10216. return 0;
  10217. }
  10218. else
  10219. client = ((Player*)player)->GetClient();
  10220. if (!client) {
  10221. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  10222. return 0;
  10223. }
  10224. if (window.length() == 0) {
  10225. lua_interface->LogError("LUA FlashWindow required parameters not given");
  10226. return 0;
  10227. }
  10228. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  10229. if (packet) {
  10230. packet->setDataByName("window", window.c_str());
  10231. packet->setDataByName("flash_seconds", flash_seconds);
  10232. client->QueuePacket(packet->serialize());
  10233. safe_delete(packet);
  10234. }
  10235. return 0;
  10236. }
  10237. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  10238. if (!lua_interface)
  10239. return 0;
  10240. Spawn* spawn = lua_interface->GetSpawn(state);
  10241. Spawn* target = lua_interface->GetSpawn(state, 2);
  10242. lua_interface->ResetFunctionStack(state);
  10243. if (spawn && target)
  10244. return spawn->CheckLoS(target);
  10245. return 0;
  10246. }
  10247. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  10248. if (!lua_interface)
  10249. return 0;
  10250. Spawn* spawn = lua_interface->GetSpawn(state);
  10251. float x = lua_interface->GetFloatValue(state, 2);
  10252. float y = lua_interface->GetFloatValue(state, 3);
  10253. float z = lua_interface->GetFloatValue(state, 4);
  10254. lua_interface->ResetFunctionStack(state);
  10255. if (spawn)
  10256. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  10257. return 0;
  10258. }
  10259. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  10260. if (!lua_interface)
  10261. return 0;
  10262. ZoneServer* zone = lua_interface->GetZone(state);
  10263. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  10264. lua_interface->ResetFunctionStack(state);
  10265. if (zone)
  10266. zone->SetExpansionFlag(xpackFlag);
  10267. return 0;
  10268. }
  10269. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  10270. if (!lua_interface)
  10271. return 0;
  10272. ZoneServer* zone = lua_interface->GetZone(state);
  10273. lua_interface->ResetFunctionStack(state);
  10274. if (zone) {
  10275. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  10276. return 1;
  10277. }
  10278. return 0;
  10279. }
  10280. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  10281. if (!lua_interface)
  10282. return 0;
  10283. ZoneServer* zone = lua_interface->GetZone(state);
  10284. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  10285. lua_interface->ResetFunctionStack(state);
  10286. if (zone)
  10287. zone->SetHolidayFlag(holidayFlag);
  10288. return 0;
  10289. }
  10290. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  10291. if (!lua_interface)
  10292. return 0;
  10293. ZoneServer* zone = lua_interface->GetZone(state);
  10294. lua_interface->ResetFunctionStack(state);
  10295. if (zone) {
  10296. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  10297. return 1;
  10298. }
  10299. return 0;
  10300. }
  10301. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  10302. if (!lua_interface)
  10303. return 0;
  10304. Spawn* spawn = lua_interface->GetSpawn(state);
  10305. bool canbind = lua_interface->GetInt32Value(state, 2);
  10306. lua_interface->ResetFunctionStack(state);
  10307. if(!spawn) {
  10308. lua_interface->LogError("%s: LUA SetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10309. return 0;
  10310. }
  10311. ZoneServer* zone = spawn->GetZone();
  10312. if (zone)
  10313. zone->SetCanBind(canbind);
  10314. return 0;
  10315. }
  10316. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  10317. if (!lua_interface)
  10318. return 0;
  10319. Spawn* spawn = lua_interface->GetSpawn(state);
  10320. lua_interface->ResetFunctionStack(state);
  10321. if(!spawn) {
  10322. lua_interface->LogError("%s: LUA GetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10323. return 0;
  10324. }
  10325. ZoneServer* zone = spawn->GetZone();
  10326. if (zone) {
  10327. lua_interface->SetInt32Value(state, zone->GetCanBind());
  10328. return 1;
  10329. }
  10330. return 0;
  10331. }
  10332. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  10333. if (!lua_interface)
  10334. return 0;
  10335. Spawn* spawn = lua_interface->GetSpawn(state);
  10336. bool cangate = lua_interface->GetInt32Value(state, 2);
  10337. lua_interface->ResetFunctionStack(state);
  10338. if(!spawn) {
  10339. lua_interface->LogError("%s: LUA SetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10340. return 0;
  10341. }
  10342. ZoneServer* zone = spawn->GetZone();
  10343. if (zone)
  10344. zone->SetCanGate(cangate);
  10345. return 0;
  10346. }
  10347. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  10348. if (!lua_interface)
  10349. return 0;
  10350. Spawn* spawn = lua_interface->GetSpawn(state);
  10351. lua_interface->ResetFunctionStack(state);
  10352. if(!spawn) {
  10353. lua_interface->LogError("%s: LUA GetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10354. return 0;
  10355. }
  10356. ZoneServer* zone = spawn->GetZone();
  10357. if (zone) {
  10358. lua_interface->SetInt32Value(state, zone->GetCanGate());
  10359. return 1;
  10360. }
  10361. return 0;
  10362. }
  10363. int EQ2Emu_lua_SetCanEvac(lua_State* state) {
  10364. if (!lua_interface)
  10365. return 0;
  10366. Spawn* spawn = lua_interface->GetSpawn(state);
  10367. bool canevac = lua_interface->GetInt32Value(state, 2);
  10368. lua_interface->ResetFunctionStack(state);
  10369. if(!spawn) {
  10370. lua_interface->LogError("%s: LUA SetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10371. return 0;
  10372. }
  10373. ZoneServer* zone = spawn->GetZone();
  10374. if (zone)
  10375. zone->SetCanEvac(canevac);
  10376. return 0;
  10377. }
  10378. int EQ2Emu_lua_GetCanEvac(lua_State* state) {
  10379. if (!lua_interface)
  10380. return 0;
  10381. Spawn* spawn = lua_interface->GetSpawn(state);
  10382. lua_interface->ResetFunctionStack(state);
  10383. if(!spawn) {
  10384. lua_interface->LogError("%s: LUA GetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10385. return 0;
  10386. }
  10387. ZoneServer* zone = spawn->GetZone();
  10388. if (zone) {
  10389. lua_interface->SetInt32Value(state, zone->GetCanEvac());
  10390. return 1;
  10391. }
  10392. return 0;
  10393. }
  10394. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  10395. if (!lua_interface)
  10396. return 0;
  10397. Spawn* spawn = lua_interface->GetSpawn(state);
  10398. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  10399. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  10400. float distance = lua_interface->GetFloatValue(state, 4);
  10401. string in_range_function = lua_interface->GetStringValue(state, 5);
  10402. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  10403. lua_interface->ResetFunctionStack(state);
  10404. if (spawn && distance > 0 && in_range_function.length() > 0)
  10405. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  10406. return 0;
  10407. }
  10408. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  10409. if (!lua_interface)
  10410. return 0;
  10411. Spawn* spawn = lua_interface->GetSpawn(state);
  10412. Spawn* target = lua_interface->GetSpawn(state, 2);
  10413. lua_interface->ResetFunctionStack(state);
  10414. if (spawn && target)
  10415. {
  10416. if (spawn->IsPlayer() && target->IsEntity())
  10417. {
  10418. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  10419. return 1;
  10420. }
  10421. else if (spawn->IsEntity() && target->IsEntity())
  10422. {
  10423. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  10424. return 1;
  10425. }
  10426. }
  10427. return 0;
  10428. }
  10429. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  10430. if (!lua_interface)
  10431. return 0;
  10432. Spawn* spawn = lua_interface->GetSpawn(state);
  10433. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10434. lua_interface->ResetFunctionStack(state);
  10435. if (spawn && spawn->IsEntity())
  10436. {
  10437. ((Entity*)spawn)->SetSeeInvisSpell(val);
  10438. if (spawn->IsPlayer())
  10439. {
  10440. Client* client = ((Player*)spawn)->GetClient();
  10441. if (client)
  10442. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  10443. }
  10444. }
  10445. return 0;
  10446. }
  10447. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  10448. if (!lua_interface)
  10449. return 0;
  10450. Spawn* spawn = lua_interface->GetSpawn(state);
  10451. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10452. lua_interface->ResetFunctionStack(state);
  10453. if (spawn && spawn->IsEntity())
  10454. {
  10455. ((Entity*)spawn)->SetSeeHideSpell(val);
  10456. if (spawn->IsPlayer())
  10457. {
  10458. Client* client = ((Player*)spawn)->GetClient();
  10459. if (client)
  10460. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  10461. }
  10462. }
  10463. return 0;
  10464. }
  10465. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  10466. {
  10467. if (!lua_interface)
  10468. return 0;
  10469. Spawn* player = lua_interface->GetSpawn(state);
  10470. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10471. string command = lua_interface->GetStringValue(state, 3);
  10472. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10473. lua_interface->ResetFunctionStack(state);
  10474. if (spawn && player && player->IsPlayer())
  10475. {
  10476. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10477. bool res = false;
  10478. if (cmd)
  10479. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  10480. lua_interface->SetBooleanValue(state, res);
  10481. return 1;
  10482. }
  10483. return 0;
  10484. }
  10485. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  10486. {
  10487. if (!lua_interface)
  10488. return 0;
  10489. Spawn* spawn = lua_interface->GetSpawn(state);
  10490. int32 charID = lua_interface->GetInt32Value(state, 2);
  10491. string command = lua_interface->GetStringValue(state, 3);
  10492. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10493. lua_interface->ResetFunctionStack(state);
  10494. if (spawn && charID)
  10495. {
  10496. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10497. bool res = false;
  10498. if (cmd)
  10499. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  10500. lua_interface->SetBooleanValue(state, res);
  10501. return 1;
  10502. }
  10503. return 0;
  10504. }
  10505. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  10506. {
  10507. if (!lua_interface)
  10508. return 0;
  10509. Spawn* spawn = lua_interface->GetSpawn(state);
  10510. string command = lua_interface->GetStringValue(state, 2);
  10511. lua_interface->ResetFunctionStack(state);
  10512. if (spawn && command.length() > 0)
  10513. spawn->RemovePrimaryEntityCommand(command.c_str());
  10514. return 0;
  10515. }
  10516. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  10517. if (!lua_interface)
  10518. return 0;
  10519. Spawn* spawn = lua_interface->GetSpawn(state);
  10520. float distance = lua_interface->GetFloatValue(state, 2);
  10521. string command = lua_interface->GetStringValue(state, 3);
  10522. Spawn* player = lua_interface->GetSpawn(state, 4);
  10523. lua_interface->ResetFunctionStack(state);
  10524. if (spawn) {
  10525. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  10526. }
  10527. return 0;
  10528. }
  10529. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  10530. if (!lua_interface)
  10531. return 0;
  10532. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10533. Spawn* spawn = lua_interface->GetSpawn(state);
  10534. Spawn* player = lua_interface->GetSpawn(state, 2);
  10535. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  10536. lua_interface->ResetFunctionStack(state);
  10537. if (spawn && player && transport_id && player->IsPlayer()) {
  10538. Client* client = 0;
  10539. if (player && player->IsPlayer())
  10540. client = ((Player*)player)->GetClient();
  10541. if (!client)
  10542. return 0;
  10543. vector<TransportDestination*> destinations;
  10544. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  10545. if (destinations.size())
  10546. {
  10547. client->SetTemporaryTransportID(transport_id);
  10548. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  10549. }
  10550. else
  10551. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  10552. }
  10553. return 0;
  10554. }
  10555. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  10556. if (!lua_interface)
  10557. return 0;
  10558. Spawn* player = lua_interface->GetSpawn(state);
  10559. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  10560. lua_interface->ResetFunctionStack(state);
  10561. if (player && player->IsPlayer()) {
  10562. Client* client = 0;
  10563. if (player && player->IsPlayer())
  10564. client = ((Player*)player)->GetClient();
  10565. if (!client)
  10566. return 0;
  10567. client->SetTemporaryTransportID(transport_id);
  10568. }
  10569. return 0;
  10570. }
  10571. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10572. if (!lua_interface)
  10573. return 0;
  10574. Spawn* player = lua_interface->GetSpawn(state);
  10575. lua_interface->ResetFunctionStack(state);
  10576. if (player && player->IsPlayer()) {
  10577. Client* client = 0;
  10578. if (player && player->IsPlayer())
  10579. client = ((Player*)player)->GetClient();
  10580. if (!client)
  10581. return 0;
  10582. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10583. return 1;
  10584. }
  10585. return 0;
  10586. }
  10587. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10588. if (!lua_interface)
  10589. return 0;
  10590. Spawn* spawn = lua_interface->GetSpawn(state);
  10591. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10592. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10593. if (!spawn) {
  10594. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10595. return 0;
  10596. }
  10597. if (!spawn->IsEntity()) {
  10598. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10599. return 0;
  10600. }
  10601. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10602. {
  10603. 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);
  10604. return 0;
  10605. }
  10606. lua_interface->ResetFunctionStack(state);
  10607. if (spell && spell->targets.size() > 0) {
  10608. ZoneServer* zone = spell->caster->GetZone();
  10609. for (int8 i = 0; i < spell->targets.size(); i++) {
  10610. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10611. if (target && target->IsEntity()) {
  10612. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10613. if (target->IsPlayer())
  10614. ((Player*)target)->SetCharSheetChanged(true);
  10615. }
  10616. }
  10617. }
  10618. else {
  10619. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10620. if (spawn->IsPlayer())
  10621. ((Player*)spawn)->SetCharSheetChanged(true);
  10622. }
  10623. return 0;
  10624. }
  10625. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10626. if (!lua_interface)
  10627. return 0;
  10628. Spawn* spawn = lua_interface->GetSpawn(state);
  10629. lua_interface->ResetFunctionStack(state);
  10630. if (!spawn) {
  10631. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10632. return 0;
  10633. }
  10634. if (!spawn->IsEntity()) {
  10635. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10636. return 0;
  10637. }
  10638. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10639. return 1;
  10640. }
  10641. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10642. if (!lua_interface)
  10643. return 0;
  10644. int32 spell_id = lua_interface->GetInt32Value(state);
  10645. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10646. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10647. if (spell_id > 0) {
  10648. if (spell_tier == 0)
  10649. spell_tier = 1;
  10650. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10651. if(!spell) {
  10652. lua_interface->LogError("%s: GetSpell: Failed, spell id %u spell tier %u does not exist.", lua_interface->GetScriptName(state), spell_id, spell_tier);
  10653. lua_interface->ResetFunctionStack(state);
  10654. return 0;
  10655. }
  10656. LuaSpell* lua_spell = 0;
  10657. if(custom_lua_script.size() > 0)
  10658. {
  10659. // attempt to load the custom script since it isn't already loaded
  10660. // we will re-obtain the lua_spell further below
  10661. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10662. {
  10663. 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());
  10664. lua_interface->LoadLuaSpell(custom_lua_script);
  10665. }
  10666. }
  10667. else
  10668. custom_lua_script = spell->GetSpellData()->lua_script;
  10669. if (!lua_spell && lua_interface)
  10670. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10671. lua_interface->ResetFunctionStack(state);
  10672. if (!lua_spell)
  10673. {
  10674. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10675. return 0;
  10676. }
  10677. lua_spell->spell = new Spell(spell);
  10678. lua_interface->AddCustomSpell(lua_spell);
  10679. lua_interface->SetSpellValue(state, lua_spell);
  10680. return 1;
  10681. }
  10682. return 0;
  10683. }
  10684. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10685. if (!lua_interface)
  10686. return 0;
  10687. LuaSpell* spell = lua_interface->GetSpell(state);
  10688. string field = lua_interface->GetStringValue(state, 2);
  10689. lua_interface->ResetFunctionStack(state);
  10690. if (!spell) {
  10691. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10692. return 0;
  10693. }
  10694. if (!spell->spell || !spell->spell->GetSpellData()) {
  10695. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10696. return 0;
  10697. }
  10698. boost::to_lower(field);
  10699. return spell->spell->GetSpellData(state, field);
  10700. }
  10701. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10702. if (!lua_interface)
  10703. return 0;
  10704. LuaSpell* spell = lua_interface->GetSpell(state);
  10705. string field = lua_interface->GetStringValue(state, 2);
  10706. int8 fieldArg = 3; // field value after the initial set
  10707. if (!spell) {
  10708. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10709. lua_interface->ResetFunctionStack(state);
  10710. return 0;
  10711. }
  10712. if (!spell->spell || !spell->spell->GetSpellData()) {
  10713. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10714. lua_interface->ResetFunctionStack(state);
  10715. return 0;
  10716. }
  10717. boost::to_lower(field);
  10718. bool valSet = false;
  10719. spell->spell->SetSpellData(state, field, fieldArg);
  10720. lua_interface->ResetFunctionStack(state);
  10721. return valSet;
  10722. }
  10723. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10724. if (!lua_interface)
  10725. return 0;
  10726. LuaSpell* spell = lua_interface->GetSpell(state);
  10727. int8 idx = lua_interface->GetInt32Value(state, 2);
  10728. if (!spell) {
  10729. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10730. lua_interface->ResetFunctionStack(state);
  10731. return 0;
  10732. }
  10733. if (!spell->spell || !spell->spell->GetSpellData()) {
  10734. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10735. lua_interface->ResetFunctionStack(state);
  10736. return 0;
  10737. }
  10738. if (spell->spell->lua_data.size() <= idx)
  10739. {
  10740. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10741. lua_interface->ResetFunctionStack(state);
  10742. return 0;
  10743. }
  10744. bool setVal = true;
  10745. LUAData* data = spell->spell->lua_data[idx];
  10746. switch (data->type)
  10747. {
  10748. case 0:
  10749. {
  10750. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10751. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10752. data->int_value = value;
  10753. data->int_value2 = value2;
  10754. break;
  10755. }
  10756. case 1:
  10757. {
  10758. float value = lua_interface->GetFloatValue(state, 3);
  10759. float value2 = lua_interface->GetFloatValue(state, 4);
  10760. data->float_value = value;
  10761. data->float_value2 = value2;
  10762. break;
  10763. }
  10764. case 2:
  10765. {
  10766. bool value = lua_interface->GetBooleanValue(state, 3);
  10767. data->bool_value = value;
  10768. break;
  10769. }
  10770. case 3:
  10771. {
  10772. string value = lua_interface->GetStringValue(state, 3);
  10773. string value2 = lua_interface->GetStringValue(state, 4);
  10774. data->string_value = value;
  10775. data->string_value2 = value2;
  10776. break;
  10777. }
  10778. default:
  10779. setVal = false;
  10780. }
  10781. lua_interface->ResetFunctionStack(state);
  10782. return setVal;
  10783. }
  10784. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10785. if (!lua_interface)
  10786. return 0;
  10787. LuaSpell* spell = lua_interface->GetSpell(state);
  10788. int8 idx = lua_interface->GetInt32Value(state, 2);
  10789. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10790. lua_interface->ResetFunctionStack(state);
  10791. if (!spell) {
  10792. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10793. return 0;
  10794. }
  10795. if (!spell->spell || !spell->spell->GetSpellData()) {
  10796. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10797. return 0;
  10798. }
  10799. if (spell->spell->lua_data.size() <= idx)
  10800. {
  10801. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10802. return 0;
  10803. }
  10804. bool setVal = true;
  10805. LUAData* data = spell->spell->lua_data[idx];
  10806. switch (data->type)
  10807. {
  10808. case 0:
  10809. {
  10810. if(!secondfield)
  10811. lua_interface->SetSInt32Value(state, data->int_value);
  10812. else
  10813. lua_interface->SetSInt32Value(state, data->int_value2);
  10814. break;
  10815. }
  10816. case 1:
  10817. {
  10818. if (!secondfield)
  10819. lua_interface->SetFloatValue(state, data->float_value);
  10820. else
  10821. lua_interface->SetFloatValue(state, data->float_value2);
  10822. break;
  10823. }
  10824. case 2:
  10825. {
  10826. lua_interface->SetBooleanValue(state, data->bool_value);
  10827. break;
  10828. }
  10829. case 3:
  10830. {
  10831. if (!secondfield)
  10832. lua_interface->SetStringValue(state, data->string_value.c_str());
  10833. else
  10834. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10835. break;
  10836. }
  10837. default:
  10838. setVal = false;
  10839. }
  10840. return setVal;
  10841. }
  10842. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10843. if (!lua_interface)
  10844. return 0;
  10845. LuaSpell* spell = lua_interface->GetSpell(state);
  10846. int8 idx = lua_interface->GetInt32Value(state, 2);
  10847. string field = lua_interface->GetStringValue(state, 3);
  10848. boost::to_lower(field);
  10849. if (!spell) {
  10850. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10851. lua_interface->ResetFunctionStack(state);
  10852. return 0;
  10853. }
  10854. if (!spell->spell || !spell->spell->GetSpellData()) {
  10855. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10856. lua_interface->ResetFunctionStack(state);
  10857. return 0;
  10858. }
  10859. if (spell->spell->effects.size() <= idx)
  10860. {
  10861. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10862. lua_interface->ResetFunctionStack(state);
  10863. return 0;
  10864. }
  10865. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10866. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10867. if (field == "description")
  10868. effect->description = string(lua_interface->GetStringValue(state, 4));
  10869. else if (field == "bullet")
  10870. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10871. else if (field == "percentage")
  10872. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10873. else { // no match
  10874. lua_interface->ResetFunctionStack(state);
  10875. return 0;
  10876. }
  10877. lua_interface->ResetFunctionStack(state);
  10878. return 1;
  10879. }
  10880. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10881. if (!lua_interface)
  10882. return 0;
  10883. LuaSpell* spell = lua_interface->GetSpell(state);
  10884. int8 idx = lua_interface->GetInt32Value(state, 2);
  10885. string field = lua_interface->GetStringValue(state, 3);
  10886. lua_interface->ResetFunctionStack(state);
  10887. boost::to_lower(field);
  10888. if (!spell) {
  10889. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10890. return 0;
  10891. }
  10892. if (!spell->spell || !spell->spell->GetSpellData()) {
  10893. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10894. return 0;
  10895. }
  10896. if (spell->spell->effects.size() <= idx)
  10897. {
  10898. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10899. return 0;
  10900. }
  10901. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10902. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10903. if (field == "description")
  10904. lua_interface->SetStringValue(state, effect->description.c_str());
  10905. else if (field == "bullet")
  10906. lua_interface->SetInt32Value(state, effect->subbullet);
  10907. else if (field == "percentage")
  10908. lua_interface->SetInt32Value(state, effect->percentage);
  10909. else // no match
  10910. return 0;
  10911. return 1;
  10912. }
  10913. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10914. if (!lua_interface)
  10915. return 0;
  10916. LuaSpell* spell = lua_interface->GetSpell(state);
  10917. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10918. Spawn* target = lua_interface->GetSpawn(state, 3);
  10919. lua_interface->ResetFunctionStack(state);
  10920. if (!target) {
  10921. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10922. return 0;
  10923. }
  10924. if (!target->IsEntity()) {
  10925. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10926. return 0;
  10927. }
  10928. if (!spell) {
  10929. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10930. return 0;
  10931. }
  10932. if (caster && !caster->IsEntity()) {
  10933. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10934. return 0;
  10935. }
  10936. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10937. return 0;
  10938. }
  10939. int EQ2Emu_lua_InWater(lua_State* state) {
  10940. if (!lua_interface)
  10941. return 0;
  10942. Spawn* spawn = lua_interface->GetSpawn(state);
  10943. lua_interface->ResetFunctionStack(state);
  10944. if (spawn) {
  10945. lua_interface->SetBooleanValue(state, spawn->InWater());
  10946. return 1;
  10947. }
  10948. return 0;
  10949. }
  10950. int EQ2Emu_lua_InLava(lua_State* state) {
  10951. if (!lua_interface)
  10952. return 0;
  10953. Spawn* spawn = lua_interface->GetSpawn(state);
  10954. lua_interface->ResetFunctionStack(state);
  10955. if (spawn) {
  10956. lua_interface->SetBooleanValue(state, spawn->InLava());
  10957. return 1;
  10958. }
  10959. return 0;
  10960. }
  10961. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10962. if (!lua_interface)
  10963. return 0;
  10964. Spawn* attacker = lua_interface->GetSpawn(state);
  10965. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10966. int8 type = lua_interface->GetInt8Value(state, 3);
  10967. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10968. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10969. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10970. string spell_name = lua_interface->GetStringValue(state, 7);
  10971. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10972. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10973. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10974. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10975. bool take_power = (lua_interface->GetInt8Value(state, 12) == 1);
  10976. lua_interface->ResetFunctionStack(state);
  10977. if (!attacker) {
  10978. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10979. lua_interface->SetBooleanValue(state, false);
  10980. return 1;
  10981. }
  10982. if (!attacker->IsEntity()) {
  10983. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10984. lua_interface->SetBooleanValue(state, false);
  10985. return 1;
  10986. }
  10987. if (!victim) {
  10988. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10989. lua_interface->SetBooleanValue(state, false);
  10990. return 1;
  10991. }
  10992. if (!victim->IsEntity()) {
  10993. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10994. lua_interface->SetBooleanValue(state, false);
  10995. return 1;
  10996. }
  10997. 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);
  10998. lua_interface->SetBooleanValue(state, has_damaged);
  10999. return 1;
  11000. }
  11001. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  11002. if (!lua_interface)
  11003. return 0;
  11004. Spawn* spawn = lua_interface->GetSpawn(state);
  11005. lua_interface->ResetFunctionStack(state);
  11006. if (spawn) {
  11007. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  11008. return 1;
  11009. }
  11010. return 0;
  11011. }
  11012. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  11013. if (!lua_interface)
  11014. return 0;
  11015. Spawn* spawn = lua_interface->GetSpawn(state);
  11016. bool invul = lua_interface->GetBooleanValue(state, 2);
  11017. lua_interface->ResetFunctionStack(state);
  11018. if (spawn) {
  11019. spawn->SetInvulnerable(invul);
  11020. }
  11021. return 0;
  11022. }
  11023. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  11024. if (!lua_interface)
  11025. return 0;
  11026. string category = lua_interface->GetStringValue(state);
  11027. string name = lua_interface->GetStringValue(state, 2);
  11028. lua_interface->ResetFunctionStack(state);
  11029. Rule *ret = 0;
  11030. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11031. lua_interface->SetBooleanValue(state, ret->GetBool());
  11032. return 1;
  11033. }
  11034. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11035. return 0;
  11036. }
  11037. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  11038. if (!lua_interface)
  11039. return 0;
  11040. string category = lua_interface->GetStringValue(state);
  11041. string name = lua_interface->GetStringValue(state, 2);
  11042. lua_interface->ResetFunctionStack(state);
  11043. Rule *ret = 0;
  11044. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11045. lua_interface->SetInt32Value(state, ret->GetInt32());
  11046. return 1;
  11047. }
  11048. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11049. return 0;
  11050. }
  11051. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  11052. if (!lua_interface)
  11053. return 0;
  11054. string category = lua_interface->GetStringValue(state);
  11055. string name = lua_interface->GetStringValue(state, 2);
  11056. lua_interface->ResetFunctionStack(state);
  11057. Rule *ret = 0;
  11058. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11059. lua_interface->SetFloatValue(state, ret->GetFloat());
  11060. return 1;
  11061. }
  11062. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11063. return 0;
  11064. }
  11065. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  11066. if (!lua_interface)
  11067. return 0;
  11068. Spawn* spawn = lua_interface->GetSpawn(state);
  11069. string type = lua_interface->GetStringValue(state, 2);
  11070. lua_interface->ResetFunctionStack(state);
  11071. if (spawn) {
  11072. int res = 1;
  11073. boost::to_lower(type);
  11074. if(type == "assigned_aa")
  11075. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  11076. else if ( type == "unassigned_aa")
  11077. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  11078. else if ( type == "assigned_tradeskill_aa")
  11079. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  11080. else if ( type == "unassigned_tradeskill_aa")
  11081. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  11082. else if ( type == "assigned_prestige_aa")
  11083. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  11084. else if ( type == "unassigned_prestige_aa")
  11085. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  11086. else if ( type == "assigned_tradeskill_prestige_aa")
  11087. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  11088. else if ( type == "unassigned_tradeskill_prestige_aa")
  11089. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  11090. else
  11091. res = 0;
  11092. return res;
  11093. }
  11094. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  11095. return 0;
  11096. }
  11097. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  11098. if (!lua_interface)
  11099. return 0;
  11100. Spawn* spawn = lua_interface->GetSpawn(state);
  11101. string type = lua_interface->GetStringValue(state, 2);
  11102. sint32 value = lua_interface->GetSInt32Value(state, 3);
  11103. lua_interface->ResetFunctionStack(state);
  11104. if (spawn) {
  11105. boost::to_lower(type);
  11106. if(type == "assigned_aa")
  11107. spawn->SetAssignedAA((sint16)value);
  11108. else if ( type == "unassigned_aa")
  11109. spawn->SetUnassignedAA((sint16)value);
  11110. else if ( type == "assigned_tradeskill_aa")
  11111. spawn->SetTradeskillAA((sint16)value);
  11112. else if ( type == "unassigned_tradeskill_aa")
  11113. spawn->SetUnassignedTradeskillAA((sint16)value);
  11114. else if ( type == "assigned_prestige_aa")
  11115. spawn->SetPrestigeAA((sint16)value);
  11116. else if ( type == "unassigned_prestige_aa")
  11117. spawn->SetUnassignedPrestigeAA((sint16)value);
  11118. else if ( type == "assigned_tradeskill_prestige_aa")
  11119. spawn->SetTradeskillPrestigeAA((sint16)value);
  11120. else if ( type == "unassigned_tradeskill_prestige_aa")
  11121. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  11122. if(spawn->IsPlayer())
  11123. ((Player*)spawn)->SetCharSheetChanged(true);
  11124. }
  11125. return 0;
  11126. }
  11127. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  11128. if (!lua_interface)
  11129. return 0;
  11130. string titleName = lua_interface->GetStringValue(state);
  11131. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  11132. lua_interface->ResetFunctionStack(state);
  11133. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  11134. lua_interface->SetSInt32Value(state, index);
  11135. return 1;
  11136. }
  11137. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  11138. if (!lua_interface)
  11139. return 0;
  11140. Spawn* spawn = lua_interface->GetSpawn(state);
  11141. string titleName = lua_interface->GetStringValue(state, 2);
  11142. lua_interface->ResetFunctionStack(state);
  11143. if(!spawn->IsPlayer())
  11144. {
  11145. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  11146. lua_interface->SetSInt32Value(state, -1);
  11147. return 1;
  11148. }
  11149. Player* player = (Player*)spawn;
  11150. // check if player already has the title, don't need to add twice
  11151. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11152. if ( playerHasTitle)
  11153. {
  11154. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  11155. return 1;
  11156. }
  11157. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  11158. if(!title)
  11159. {
  11160. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11161. lua_interface->SetSInt32Value(state, -1);
  11162. return 1;
  11163. }
  11164. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  11165. if(returnIdx < 0)
  11166. {
  11167. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11168. }
  11169. lua_interface->SetSInt32Value(state, returnIdx);
  11170. player->GetClient()->SendTitleUpdate();
  11171. return 1;
  11172. }
  11173. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  11174. if (!lua_interface)
  11175. return 0;
  11176. Spawn* spawn = lua_interface->GetSpawn(state);
  11177. string titleName = lua_interface->GetStringValue(state, 2);
  11178. lua_interface->ResetFunctionStack(state);
  11179. if(!spawn->IsPlayer())
  11180. {
  11181. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11182. return 0;
  11183. }
  11184. Player* player = (Player*)spawn;
  11185. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11186. if(!title)
  11187. {
  11188. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11189. return 0;
  11190. }
  11191. if(title->GetPrefix())
  11192. {
  11193. 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());
  11194. return 0;
  11195. }
  11196. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  11197. player->GetClient()->SendTitleUpdate();
  11198. return 1;
  11199. }
  11200. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  11201. if (!lua_interface)
  11202. return 0;
  11203. Spawn* spawn = lua_interface->GetSpawn(state);
  11204. string titleName = lua_interface->GetStringValue(state, 2);
  11205. lua_interface->ResetFunctionStack(state);
  11206. if(!spawn->IsPlayer())
  11207. {
  11208. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11209. return 0;
  11210. }
  11211. Player* player = (Player*)spawn;
  11212. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11213. if(!title)
  11214. {
  11215. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11216. return 0;
  11217. }
  11218. if(!title->GetPrefix())
  11219. {
  11220. 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());
  11221. return 0;
  11222. }
  11223. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  11224. player->GetClient()->SendTitleUpdate();
  11225. return 1;
  11226. }
  11227. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  11228. if (!lua_interface)
  11229. return 0;
  11230. Spawn* spawn = lua_interface->GetSpawn(state);
  11231. lua_interface->ResetFunctionStack(state);
  11232. if(!spawn->IsPlayer())
  11233. {
  11234. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11235. return 0;
  11236. }
  11237. Player* player = (Player*)spawn;
  11238. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  11239. player->GetClient()->SendTitleUpdate();
  11240. return 1;
  11241. }
  11242. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  11243. if (!lua_interface)
  11244. return 0;
  11245. Spawn* spawn = lua_interface->GetSpawn(state);
  11246. lua_interface->ResetFunctionStack(state);
  11247. if(!spawn->IsPlayer())
  11248. {
  11249. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11250. return 0;
  11251. }
  11252. Player* player = (Player*)spawn;
  11253. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  11254. player->GetClient()->SendTitleUpdate();
  11255. return 1;
  11256. }
  11257. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  11258. if (!lua_interface)
  11259. return 0;
  11260. Spawn* spawn = lua_interface->GetSpawn(state);
  11261. string field = lua_interface->GetStringValue(state, 2);
  11262. lua_interface->ResetFunctionStack(state);
  11263. if(!spawn || !spawn->IsEntity())
  11264. {
  11265. 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));
  11266. return 0;
  11267. }
  11268. Entity* ent = (Entity*)spawn;
  11269. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  11270. return 1;
  11271. }
  11272. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  11273. if (!lua_interface)
  11274. return 0;
  11275. Spawn* spawn = lua_interface->GetSpawn(state);
  11276. string field = lua_interface->GetStringValue(state, 2);
  11277. lua_interface->ResetFunctionStack(state);
  11278. if(!spawn || !spawn->IsEntity())
  11279. {
  11280. 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));
  11281. return 0;
  11282. }
  11283. Entity* ent = (Entity*)spawn;
  11284. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  11285. return 1;
  11286. }
  11287. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  11288. if (!lua_interface)
  11289. return 0;
  11290. Spawn* spawn = lua_interface->GetSpawn(state);
  11291. string field = lua_interface->GetStringValue(state, 2);
  11292. lua_interface->ResetFunctionStack(state);
  11293. if(!spawn || !spawn->IsEntity())
  11294. {
  11295. 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));
  11296. return 0;
  11297. }
  11298. Entity* ent = (Entity*)spawn;
  11299. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  11300. return 1;
  11301. }
  11302. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  11303. if (!lua_interface)
  11304. return 0;
  11305. Spawn* spawn = lua_interface->GetSpawn(state);
  11306. string field = lua_interface->GetStringValue(state, 2);
  11307. lua_interface->ResetFunctionStack(state);
  11308. if(!spawn || !spawn->IsEntity())
  11309. {
  11310. 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));
  11311. return 0;
  11312. }
  11313. Entity* ent = (Entity*)spawn;
  11314. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  11315. return 1;
  11316. }
  11317. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  11318. if (!lua_interface)
  11319. return 0;
  11320. Spawn* spawn = lua_interface->GetSpawn(state);
  11321. string field = lua_interface->GetStringValue(state, 2);
  11322. string value = lua_interface->GetStringValue(state, 3);
  11323. lua_interface->ResetFunctionStack(state);
  11324. if(!spawn || !spawn->IsEntity())
  11325. {
  11326. 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));
  11327. return 0;
  11328. }
  11329. Entity* ent = (Entity*)spawn;
  11330. bool set_ = ent->SetInfoStructString(field, value);
  11331. lua_interface->SetBooleanValue(state, set_);
  11332. return 1;
  11333. }
  11334. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  11335. if (!lua_interface)
  11336. return 0;
  11337. Spawn* spawn = lua_interface->GetSpawn(state);
  11338. string field = lua_interface->GetStringValue(state, 2);
  11339. int64 value = lua_interface->GetInt64Value(state, 3);
  11340. lua_interface->ResetFunctionStack(state);
  11341. if(!spawn || !spawn->IsEntity())
  11342. {
  11343. 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));
  11344. return 0;
  11345. }
  11346. Entity* ent = (Entity*)spawn;
  11347. bool set_ = ent->SetInfoStructUInt(field, value);
  11348. lua_interface->SetBooleanValue(state, set_);
  11349. return 1;
  11350. }
  11351. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  11352. if (!lua_interface)
  11353. return 0;
  11354. Spawn* spawn = lua_interface->GetSpawn(state);
  11355. string field = lua_interface->GetStringValue(state, 2);
  11356. sint64 value = lua_interface->GetSInt64Value(state, 3);
  11357. lua_interface->ResetFunctionStack(state);
  11358. if(!spawn || !spawn->IsEntity())
  11359. {
  11360. 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));
  11361. return 0;
  11362. }
  11363. Entity* ent = (Entity*)spawn;
  11364. bool set_ = ent->SetInfoStructSInt(field, value);
  11365. lua_interface->SetBooleanValue(state, set_);
  11366. return 1;
  11367. }
  11368. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  11369. if (!lua_interface)
  11370. return 0;
  11371. Spawn* spawn = lua_interface->GetSpawn(state);
  11372. string field = lua_interface->GetStringValue(state, 2);
  11373. float value = lua_interface->GetFloatValue(state, 3);
  11374. lua_interface->ResetFunctionStack(state);
  11375. if(!spawn || !spawn->IsEntity())
  11376. {
  11377. 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));
  11378. return 0;
  11379. }
  11380. Entity* ent = (Entity*)spawn;
  11381. bool set_ = ent->SetInfoStructFloat(field, value);
  11382. lua_interface->SetBooleanValue(state, set_);
  11383. return 1;
  11384. }
  11385. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  11386. if (!lua_interface)
  11387. return 0;
  11388. Spawn* spawn = lua_interface->GetSpawn(state);
  11389. bool value = lua_interface->GetBooleanValue(state, 2);
  11390. lua_interface->ResetFunctionStack(state);
  11391. if(!spawn || !spawn->IsPlayer())
  11392. {
  11393. 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));
  11394. return 0;
  11395. }
  11396. ((Player*)spawn)->SetCharSheetChanged(value);
  11397. return 0;
  11398. }
  11399. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  11400. if (!lua_interface)
  11401. return 0;
  11402. Spawn* spawn = lua_interface->GetSpawn(state);
  11403. std::string fromName = lua_interface->GetStringValue(state, 2);
  11404. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11405. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11406. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11407. int32 copper = lua_interface->GetInt32Value(state, 6);
  11408. int32 silver = lua_interface->GetInt32Value(state, 7);
  11409. int32 gold = lua_interface->GetInt32Value(state, 8);
  11410. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11411. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11412. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11413. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11414. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11415. lua_interface->ResetFunctionStack(state);
  11416. if(!spawn || !spawn->IsPlayer())
  11417. {
  11418. 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));
  11419. lua_interface->SetBooleanValue(state, false);
  11420. return 1;
  11421. }
  11422. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11423. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11424. lua_interface->SetBooleanValue(state, true);
  11425. return 1;
  11426. }
  11427. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  11428. if (!lua_interface)
  11429. return 0;
  11430. int32 char_id = lua_interface->GetInt32Value(state);
  11431. std::string fromName = lua_interface->GetStringValue(state, 2);
  11432. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11433. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11434. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11435. int32 copper = lua_interface->GetInt32Value(state, 6);
  11436. int32 silver = lua_interface->GetInt32Value(state, 7);
  11437. int32 gold = lua_interface->GetInt32Value(state, 8);
  11438. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11439. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11440. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11441. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11442. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11443. lua_interface->ResetFunctionStack(state);
  11444. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11445. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11446. lua_interface->SetBooleanValue(state, true);
  11447. return 1;
  11448. }
  11449. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  11450. Spawn* widget;
  11451. if (lua_interface) {
  11452. widget = lua_interface->GetSpawn(state);
  11453. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  11454. lua_interface->ResetFunctionStack(state);
  11455. if (widget && widget->IsWidget())
  11456. {
  11457. ((Widget*)widget)->OpenDoor();
  11458. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  11459. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11460. }
  11461. else
  11462. 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));
  11463. }
  11464. return 0;
  11465. }
  11466. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  11467. Spawn* widget;
  11468. if (lua_interface) {
  11469. widget = lua_interface->GetSpawn(state);
  11470. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  11471. lua_interface->ResetFunctionStack(state);
  11472. if (widget && widget->IsWidget())
  11473. {
  11474. ((Widget*)widget)->CloseDoor();
  11475. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  11476. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11477. }
  11478. else
  11479. 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));
  11480. }
  11481. return 0;
  11482. }
  11483. int EQ2Emu_lua_IsOpen(lua_State* state) {
  11484. if (!lua_interface)
  11485. return 0;
  11486. Spawn* widget = lua_interface->GetSpawn(state);
  11487. lua_interface->ResetFunctionStack(state);
  11488. if (widget && widget->IsWidget())
  11489. {
  11490. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  11491. return 1;
  11492. }
  11493. return 0;
  11494. }
  11495. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  11496. if (!lua_interface)
  11497. return 0;
  11498. sint32 min = lua_interface->GetSInt32Value(state);
  11499. sint32 max = lua_interface->GetSInt32Value(state, 2);
  11500. lua_interface->ResetFunctionStack(state);
  11501. sint32 result = MakeRandomInt(min, max);
  11502. lua_interface->SetSInt32Value(state, result);
  11503. return 1;
  11504. }
  11505. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  11506. if (!lua_interface)
  11507. return 0;
  11508. float min = lua_interface->GetFloatValue(state);
  11509. float max = lua_interface->GetFloatValue(state, 2);
  11510. lua_interface->ResetFunctionStack(state);
  11511. float result = MakeRandomFloat(min, max);
  11512. lua_interface->SetFloatValue(state, result);
  11513. return 1;
  11514. }
  11515. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  11516. if (!lua_interface)
  11517. return 0;
  11518. Spawn* spawn = lua_interface->GetSpawn(state);
  11519. int32 value = lua_interface->GetInt32Value(state, 2);
  11520. lua_interface->ResetFunctionStack(state);
  11521. if(!spawn)
  11522. {
  11523. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11524. lua_interface->SetBooleanValue(state, false);
  11525. return 1;
  11526. }
  11527. spawn->AddIconValue(value);
  11528. lua_interface->SetBooleanValue(state, true);
  11529. return 1;
  11530. }
  11531. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  11532. if (!lua_interface)
  11533. return 0;
  11534. Spawn* spawn = lua_interface->GetSpawn(state);
  11535. int32 value = lua_interface->GetInt32Value(state, 2);
  11536. lua_interface->ResetFunctionStack(state);
  11537. if(!spawn)
  11538. {
  11539. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11540. lua_interface->SetBooleanValue(state, false);
  11541. return 1;
  11542. }
  11543. spawn->RemoveIconValue(value);
  11544. lua_interface->SetBooleanValue(state, true);
  11545. return 1;
  11546. }
  11547. int EQ2Emu_lua_GetShardID(lua_State* state) {
  11548. Spawn* npc = lua_interface->GetSpawn(state);
  11549. lua_interface->ResetFunctionStack(state);
  11550. if (npc && npc->IsNPC()) {
  11551. NPC* shard = (NPC*)npc;
  11552. int32 shardid = shard->GetShardID();
  11553. lua_interface->SetInt32Value(state, shardid);
  11554. return 1;
  11555. }
  11556. lua_interface->SetInt32Value(state, 0);
  11557. return 1;
  11558. }
  11559. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  11560. Spawn* npc = lua_interface->GetSpawn(state);
  11561. lua_interface->ResetFunctionStack(state);
  11562. if (npc && npc->IsNPC()) {
  11563. NPC* shard = (NPC*)npc;
  11564. int32 charid = shard->GetShardCharID();
  11565. lua_interface->SetInt32Value(state, charid);
  11566. return 1;
  11567. }
  11568. lua_interface->SetInt32Value(state, 0);
  11569. return 1;
  11570. }
  11571. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  11572. Spawn* npc = lua_interface->GetSpawn(state);
  11573. lua_interface->ResetFunctionStack(state);
  11574. if (npc && npc->IsNPC()) {
  11575. NPC* shard = (NPC*)npc;
  11576. int64 timestamp = shard->GetShardCreatedTimestamp();
  11577. lua_interface->SetSInt64Value(state, timestamp);
  11578. return 1;
  11579. }
  11580. lua_interface->SetSInt64Value(state, 0);
  11581. return 1;
  11582. }
  11583. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  11584. if (!lua_interface)
  11585. return 0;
  11586. int32 shardid = lua_interface->GetInt32Value(state);
  11587. lua_interface->ResetFunctionStack(state);
  11588. if(shardid < 1)
  11589. lua_interface->SetBooleanValue(state, false);
  11590. else
  11591. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  11592. return 1;
  11593. }
  11594. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  11595. if (!lua_interface)
  11596. return 0;
  11597. Spawn* spawn = lua_interface->GetSpawn(state);
  11598. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11599. if (spawn) {
  11600. spawn->PauseMovement(delay_in_ms);
  11601. }
  11602. lua_interface->ResetFunctionStack(state);
  11603. return 0;
  11604. }
  11605. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11606. if (!lua_interface)
  11607. return 0;
  11608. Spawn* spawn = lua_interface->GetSpawn(state);
  11609. if (spawn) {
  11610. spawn->ResetMovement();
  11611. }
  11612. lua_interface->ResetFunctionStack(state);
  11613. return 0;
  11614. }
  11615. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11616. Player* player = (Player*)lua_interface->GetSpawn(state);
  11617. int8 level = lua_interface->GetInt8Value(state, 2);
  11618. lua_interface->ResetFunctionStack(state);
  11619. if (player && player->IsPlayer() && level > 0) {
  11620. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11621. return 1;
  11622. }
  11623. return 0;
  11624. }
  11625. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11626. Player* player = (Player*)lua_interface->GetSpawn(state);
  11627. int8 level = lua_interface->GetInt8Value(state, 2);
  11628. lua_interface->ResetFunctionStack(state);
  11629. if (player && player->IsPlayer() && level > 0) {
  11630. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11631. return 1;
  11632. }
  11633. return 0;
  11634. }
  11635. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11636. ZoneServer* zone = lua_interface->GetZone(state);
  11637. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11638. lua_interface->ResetFunctionStack(state);
  11639. if (zone) {
  11640. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11641. if (spawn) {
  11642. lua_interface->SetSpawnValue(state, spawn);
  11643. return 1;
  11644. }
  11645. }
  11646. return 0;
  11647. }
  11648. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11649. if (!lua_interface)
  11650. return 0;
  11651. Spawn* spawn = lua_interface->GetSpawn(state);
  11652. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11653. lua_interface->ResetFunctionStack(state);
  11654. bool res = false;
  11655. if(spawn && spawn->IsTransportSpawn())
  11656. {
  11657. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11658. spawn->SetRailID(rail_id);
  11659. res = true;
  11660. }
  11661. else if (!spawn) {
  11662. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11663. }
  11664. else if(!spawn->IsTransportSpawn()) {
  11665. 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());
  11666. }
  11667. lua_interface->SetBooleanValue(state, res);
  11668. return 1;
  11669. }
  11670. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11671. if (!lua_interface)
  11672. return 0;
  11673. ZoneServer* zone = lua_interface->GetZone(state);
  11674. lua_interface->ResetFunctionStack(state);
  11675. if (zone) {
  11676. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11677. return 1;
  11678. }
  11679. return 0;
  11680. }
  11681. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11682. if (!lua_interface)
  11683. return 0;
  11684. Spawn* spawn = lua_interface->GetSpawn(state);
  11685. lua_interface->ResetFunctionStack(state);
  11686. if (spawn) {
  11687. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11688. return 1;
  11689. }
  11690. return 0;
  11691. }
  11692. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11693. if (!lua_interface)
  11694. return 0;
  11695. Spawn* player = lua_interface->GetSpawn(state);
  11696. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11697. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11698. lua_interface->ResetFunctionStack(state);
  11699. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11700. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11701. }
  11702. else if(!zoneID) {
  11703. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11704. }
  11705. else
  11706. {
  11707. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11708. return 1;
  11709. }
  11710. return 0;
  11711. }
  11712. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11713. if (!lua_interface)
  11714. return 0;
  11715. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11716. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11717. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11718. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11719. lua_interface->ResetFunctionStack(state);
  11720. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11721. world.GetWorldTimeStruct()->year = newYear;
  11722. world.GetWorldTimeStruct()->month = newMonth;
  11723. world.GetWorldTimeStruct()->hour = newHour;
  11724. world.GetWorldTimeStruct()->minute = newMinute;
  11725. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11726. return 0;
  11727. }
  11728. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11729. if (!lua_interface)
  11730. return 0;
  11731. lua_interface->ResetFunctionStack(state);
  11732. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11733. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11734. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11735. return 1;
  11736. }
  11737. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11738. if (!lua_interface)
  11739. return 0;
  11740. lua_interface->ResetFunctionStack(state);
  11741. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11742. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11743. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11744. return 1;
  11745. }
  11746. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11747. if (!lua_interface)
  11748. return 0;
  11749. lua_interface->ResetFunctionStack(state);
  11750. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11751. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11752. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11753. return 1;
  11754. }
  11755. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11756. if (!lua_interface)
  11757. return 0;
  11758. lua_interface->ResetFunctionStack(state);
  11759. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11760. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11761. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11762. return 1;
  11763. }
  11764. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11765. if (!lua_interface)
  11766. return 0;
  11767. lua_interface->ResetFunctionStack(state);
  11768. world.SendTimeUpdate();
  11769. return 0;
  11770. }
  11771. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11772. bool update_result = false;
  11773. Faction* faction = 0;
  11774. Spawn* spawn = lua_interface->GetSpawn(state);
  11775. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11776. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11777. lua_interface->ResetFunctionStack(state);
  11778. if(!spawn || !spawn->IsPlayer()) {
  11779. lua_interface->LogError("LUA ChangeFaction command error: player is not valid");
  11780. return 0;
  11781. }
  11782. Player* player = (Player*)spawn;
  11783. Client* client = player->GetClient();
  11784. if (faction_id > 0) {
  11785. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11786. if(hasfaction == 0) {
  11787. //they do not have the faction. Lets get the default value and feed it in.
  11788. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11789. //add the default faction for the player.
  11790. player->SetFactionValue(faction_id, defaultfaction);
  11791. }
  11792. if(increase >= 0) {
  11793. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11794. faction = master_faction_list.GetFaction(faction_id);
  11795. if(faction && update_result)
  11796. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11797. else if(faction)
  11798. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11799. lua_interface->SetBooleanValue(state, true);
  11800. return 1;
  11801. }
  11802. if(increase < 0){
  11803. //change the negative to a positive, since thats how decreasefaction() likes it.
  11804. increase *= -1;
  11805. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11806. faction = master_faction_list.GetFaction(faction_id);
  11807. if(faction && update_result)
  11808. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11809. else if(faction)
  11810. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11811. lua_interface->SetBooleanValue(state, true);
  11812. return 1;
  11813. }
  11814. }
  11815. lua_interface->SetBooleanValue(state, false);
  11816. return 1;
  11817. }
  11818. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11819. bool hascoin = 0;
  11820. Player* player = (Player*)lua_interface->GetSpawn(state);
  11821. int32 coins = lua_interface->GetInt32Value(state, 2);
  11822. lua_interface->ResetFunctionStack(state);
  11823. if (player && player->IsPlayer()) {
  11824. hascoin = player->HasCoins(coins);
  11825. if(hascoin == 0) {
  11826. lua_interface->SetBooleanValue(state, false);
  11827. return 1;
  11828. }
  11829. if(hascoin == 1) {
  11830. lua_interface->SetBooleanValue(state, true);
  11831. return 1;
  11832. }
  11833. }
  11834. return 0;
  11835. }
  11836. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11837. int32 loot_tier = 0;
  11838. Spawn* spawn = lua_interface->GetSpawn(state);
  11839. lua_interface->ResetFunctionStack(state);
  11840. if (spawn) {
  11841. loot_tier = spawn->GetLootTier();
  11842. lua_interface->SetInt32Value(state, loot_tier);
  11843. return 1;
  11844. }
  11845. return 0;
  11846. }
  11847. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11848. if (!lua_interface)
  11849. return 0;
  11850. Spawn* spawn = lua_interface->GetSpawn(state);
  11851. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11852. lua_interface->ResetFunctionStack(state);
  11853. if (spawn) {
  11854. spawn->SetLootTier(loot_tier);
  11855. lua_interface->SetBooleanValue(state, true);
  11856. return 1;
  11857. }
  11858. lua_interface->SetBooleanValue(state, false);
  11859. return 1;
  11860. }
  11861. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11862. int32 loot_drop_type = 0;
  11863. Spawn* spawn = lua_interface->GetSpawn(state);
  11864. lua_interface->ResetFunctionStack(state);
  11865. if (spawn) {
  11866. loot_drop_type = spawn->GetLootDropType();
  11867. lua_interface->SetInt32Value(state, loot_drop_type);
  11868. return 1;
  11869. }
  11870. return 0;
  11871. }
  11872. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11873. if (!lua_interface)
  11874. return 0;
  11875. Spawn* spawn = lua_interface->GetSpawn(state);
  11876. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11877. lua_interface->ResetFunctionStack(state);
  11878. if (spawn) {
  11879. spawn->SetLootDropType(loot_drop_type);
  11880. lua_interface->SetBooleanValue(state, true);
  11881. return 1;
  11882. }
  11883. lua_interface->SetBooleanValue(state, false);
  11884. return 1;
  11885. }
  11886. int EQ2Emu_lua_DamageEquippedItems(lua_State* state) {
  11887. if (!lua_interface)
  11888. return 0;
  11889. Spawn* spawn = lua_interface->GetSpawn(state);
  11890. int8 damage_amount = lua_interface->GetInt32Value(state, 2);
  11891. if(damage_amount > 100) {
  11892. damage_amount = 100;
  11893. }
  11894. if (!spawn) {
  11895. lua_interface->LogError("%s: LUA DamageEquippedItems command error: spawn is not valid", lua_interface->GetScriptName(state));
  11896. lua_interface->ResetFunctionStack(state);
  11897. return 0;
  11898. }
  11899. lua_interface->ResetFunctionStack(state);
  11900. if (spawn->IsPlayer()) {
  11901. if (((Player*)spawn)->GetClient() && ((Player*)spawn)->DamageEquippedItems(damage_amount, ((Player*)spawn)->GetClient()))
  11902. lua_interface->SetBooleanValue(state, true);
  11903. else
  11904. lua_interface->SetBooleanValue(state, false);
  11905. }
  11906. else {
  11907. lua_interface->SetBooleanValue(state, false);
  11908. }
  11909. return 1;
  11910. }
  11911. int EQ2Emu_lua_CreateWidgetRegion(lua_State* state) {
  11912. ZoneServer* zone = lua_interface->GetZone(state);
  11913. int32 version = lua_interface->GetInt32Value(state, 2);
  11914. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11915. if(region_map == nullptr) {
  11916. lua_interface->LogError("%s: LUA CreateWidgetRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11917. lua_interface->ResetFunctionStack(state);
  11918. return 0;
  11919. }
  11920. string region_name = lua_interface->GetStringValue(state, 3);
  11921. string env_name = lua_interface->GetStringValue(state, 4);
  11922. int32 grid_id = lua_interface->GetInt32Value(state, 5);
  11923. int32 widget_id = lua_interface->GetInt32Value(state, 6);
  11924. float dist = lua_interface->GetFloatValue(state, 7);
  11925. region_map->InsertRegionNode(zone, version, region_name, env_name, grid_id, widget_id, dist);
  11926. lua_interface->ResetFunctionStack(state);
  11927. lua_interface->SetBooleanValue(state, true);
  11928. return 1;
  11929. }
  11930. int EQ2Emu_lua_RemoveRegion(lua_State* state) {
  11931. ZoneServer* zone = lua_interface->GetZone(state);
  11932. int32 version = lua_interface->GetInt32Value(state, 2);
  11933. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11934. if(region_map == nullptr) {
  11935. lua_interface->LogError("%s: LUA RemoveRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11936. lua_interface->ResetFunctionStack(state);
  11937. return 0;
  11938. }
  11939. string region_name = lua_interface->GetStringValue(state, 3);
  11940. region_map->RemoveRegionNode(region_name);
  11941. lua_interface->ResetFunctionStack(state);
  11942. lua_interface->SetBooleanValue(state, true);
  11943. return 1;
  11944. }
  11945. int EQ2Emu_lua_SetPlayerPOVGhost(lua_State* state) {
  11946. Client* client = nullptr;
  11947. Spawn* player = lua_interface->GetSpawn(state);
  11948. if (!player) {
  11949. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not valid");
  11950. lua_interface->SetBooleanValue(state, false);
  11951. lua_interface->ResetFunctionStack(state);
  11952. return 1;
  11953. }
  11954. if (!player->IsPlayer()) {
  11955. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
  11956. lua_interface->SetBooleanValue(state, false);
  11957. lua_interface->ResetFunctionStack(state);
  11958. return 1;
  11959. }
  11960. client = player->GetClient();
  11961. if (!client) {
  11962. lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
  11963. lua_interface->SetBooleanValue(state, false);
  11964. lua_interface->ResetFunctionStack(state);
  11965. return 1;
  11966. }
  11967. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  11968. bool success_sight = client->SetPlayerPOVGhost(spawn);
  11969. lua_interface->ResetFunctionStack(state);
  11970. lua_interface->SetBooleanValue(state, success_sight);
  11971. return 1;
  11972. }
  11973. int EQ2Emu_lua_SetCastOnAggroComplete(lua_State* state) {
  11974. if (!lua_interface)
  11975. return 0;
  11976. bool result = false;
  11977. Spawn* spawn = lua_interface->GetSpawn(state);
  11978. bool cast_completed = (lua_interface->GetInt8Value(state, 2) == 1);
  11979. lua_interface->ResetFunctionStack(state);
  11980. if (!spawn)
  11981. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11982. else if (!spawn->IsNPC())
  11983. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11984. else
  11985. {
  11986. ((NPC*)spawn)->cast_on_aggro_completed = cast_completed;
  11987. result = true;
  11988. }
  11989. lua_interface->SetBooleanValue(state, result);
  11990. return 1;
  11991. }
  11992. int EQ2Emu_lua_IsCastOnAggroComplete(lua_State* state) {
  11993. if (!lua_interface)
  11994. return 0;
  11995. bool result = false;
  11996. Spawn* spawn = lua_interface->GetSpawn(state);
  11997. lua_interface->ResetFunctionStack(state);
  11998. if (!spawn)
  11999. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  12000. else if (!spawn->IsNPC())
  12001. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  12002. else
  12003. {
  12004. if(((NPC*)spawn)->cast_on_aggro_completed)
  12005. result = true;
  12006. }
  12007. lua_interface->SetBooleanValue(state, result);
  12008. return 1;
  12009. }
  12010. int EQ2Emu_lua_AddRecipeBookToPlayer(lua_State* state) {
  12011. Client* client = nullptr;
  12012. Spawn* player = lua_interface->GetSpawn(state);
  12013. int32 recipe_book_id = lua_interface->GetInt32Value(state, 2);
  12014. lua_interface->ResetFunctionStack(state);
  12015. if (!player) {
  12016. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not valid");
  12017. lua_interface->SetBooleanValue(state, false);
  12018. return 1;
  12019. }
  12020. if (!player->IsPlayer()) {
  12021. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not a player");
  12022. lua_interface->SetBooleanValue(state, false);
  12023. return 1;
  12024. }
  12025. client = player->GetClient();
  12026. if (!client) {
  12027. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: could not find client");
  12028. lua_interface->SetBooleanValue(state, false);
  12029. return 1;
  12030. }
  12031. bool result = client->AddRecipeBookToPlayer(recipe_book_id);
  12032. lua_interface->SetBooleanValue(state, result);
  12033. return 1;
  12034. }
  12035. int EQ2Emu_lua_RemoveRecipeFromPlayer(lua_State* state) {
  12036. Client* client = nullptr;
  12037. Spawn* player = lua_interface->GetSpawn(state);
  12038. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  12039. lua_interface->ResetFunctionStack(state);
  12040. if (!player) {
  12041. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not valid");
  12042. lua_interface->SetBooleanValue(state, false);
  12043. return 1;
  12044. }
  12045. if (!player->IsPlayer()) {
  12046. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not a player");
  12047. lua_interface->SetBooleanValue(state, false);
  12048. return 1;
  12049. }
  12050. client = player->GetClient();
  12051. if (!client) {
  12052. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: could not find client");
  12053. lua_interface->SetBooleanValue(state, false);
  12054. return 1;
  12055. }
  12056. bool result = client->RemoveRecipeFromPlayer(recipe_id);
  12057. lua_interface->SetBooleanValue(state, result);
  12058. return 1;
  12059. }
  12060. int EQ2Emu_lua_ReplaceWidgetFromClient(lua_State* state) {
  12061. Client* client = nullptr;
  12062. Spawn* player = lua_interface->GetSpawn(state);
  12063. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12064. bool delete_widget = (lua_interface->GetInt8Value(state, 3) == 1);
  12065. // rest are all optional fields
  12066. float x = lua_interface->GetFloatValue(state, 4);
  12067. float y = lua_interface->GetFloatValue(state, 5);
  12068. float z = lua_interface->GetFloatValue(state, 6);
  12069. int32 grid_id = lua_interface->GetInt32Value(state, 7);
  12070. lua_interface->ResetFunctionStack(state);
  12071. if (!player) {
  12072. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not valid");
  12073. lua_interface->SetBooleanValue(state, false);
  12074. return 1;
  12075. }
  12076. if (!player->IsPlayer()) {
  12077. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not a player");
  12078. lua_interface->SetBooleanValue(state, false);
  12079. return 1;
  12080. }
  12081. if(!player->GetZone()) {
  12082. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  12083. lua_interface->SetBooleanValue(state, false);
  12084. return 1;
  12085. }
  12086. client = player->GetClient();
  12087. if (!client) {
  12088. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: could not find client");
  12089. lua_interface->SetBooleanValue(state, false);
  12090. return 1;
  12091. }
  12092. if(!client->IsReadyForUpdates()) {
  12093. lua_interface->LogError("LUA ReplaceWidgetFromClient command failed: client has not signaled sys_client_avatar_ready");
  12094. lua_interface->SetBooleanValue(state, false);
  12095. return 1;
  12096. }
  12097. client->SendReplaceWidget(widget_id, delete_widget, x, y, z, grid_id);
  12098. lua_interface->SetBooleanValue(state, true);
  12099. return 1;
  12100. }
  12101. int EQ2Emu_lua_RemoveWidgetFromSpawnMap(lua_State* state) {
  12102. Client* client = nullptr;
  12103. Spawn* spawn = lua_interface->GetSpawn(state);
  12104. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12105. lua_interface->ResetFunctionStack(state);
  12106. if (!spawn) {
  12107. lua_interface->LogError("LUA RemoveWidgetFromSpawnMap command error: spawn is not valid");
  12108. lua_interface->SetBooleanValue(state, false);
  12109. return 1;
  12110. }
  12111. if(!spawn->GetZone()) {
  12112. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  12113. lua_interface->SetBooleanValue(state, false);
  12114. return 1;
  12115. }
  12116. spawn->AddIgnoredWidget(widget_id);
  12117. lua_interface->SetBooleanValue(state, true);
  12118. return 1;
  12119. }
  12120. int EQ2Emu_lua_RemoveWidgetFromZoneMap(lua_State* state) {
  12121. ZoneServer* zone = lua_interface->GetZone(state);
  12122. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12123. lua_interface->ResetFunctionStack(state);
  12124. if(!zone) {
  12125. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: zone is not valid");
  12126. lua_interface->SetBooleanValue(state, false);
  12127. return 1;
  12128. }
  12129. if(!zone->IsLoading()) {
  12130. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: can only be called during zone loading, in preinit_zone_script ZoneScript function");
  12131. lua_interface->SetBooleanValue(state, false);
  12132. return 1;
  12133. }
  12134. zone->AddIgnoredWidget(widget_id);
  12135. lua_interface->SetBooleanValue(state, true);
  12136. return 1;
  12137. }
  12138. int EQ2Emu_lua_SendHearCast(lua_State* state) {
  12139. if (!lua_interface)
  12140. return 0;
  12141. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  12142. Spawn* spawn = lua_interface->GetSpawn(state);
  12143. int32 spell_visual_id = lua_interface->GetInt32Value(state, 2);
  12144. int16 cast_time = lua_interface->GetInt16Value(state, 3);
  12145. Spawn* caster = lua_interface->GetSpawn(state, 4);
  12146. Spawn* target = lua_interface->GetSpawn(state, 5);
  12147. lua_interface->ResetFunctionStack(state);
  12148. if(spell && spawn && spawn->IsEntity()) {
  12149. ZoneServer* zone = spawn->GetZone();
  12150. if(zone) {
  12151. zone->SendCastSpellPacket(spell, caster && caster->IsEntity() ? (Entity*)caster : (Entity*)spawn, spell_visual_id, cast_time > 0 ? cast_time : 0xFFFF);
  12152. }
  12153. }
  12154. else if (spawn) {
  12155. if (spawn->IsPlayer()) {
  12156. Client* client = ((Player*)spawn)->GetClient();
  12157. if (client) {
  12158. client->SendHearCast(caster ? caster : client->GetPlayer(), target ? target : client->GetPlayer(), spell_visual_id, cast_time);
  12159. }
  12160. }
  12161. }
  12162. return 0;
  12163. }
  12164. int EQ2Emu_lua_GetCharacterFlag(lua_State* state) {
  12165. if (!lua_interface)
  12166. return 0;
  12167. Spawn* player = lua_interface->GetSpawn(state);
  12168. sint32 flag_id = lua_interface->GetSInt32Value(state, 2);
  12169. lua_interface->ResetFunctionStack(state);
  12170. if (!player) {
  12171. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  12172. return 0;
  12173. }
  12174. if (!player->IsPlayer()) {
  12175. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  12176. return 0;
  12177. }
  12178. bool ret = ((Player*)player)->get_character_flag(flag_id);
  12179. lua_interface->SetBooleanValue(state, ret);
  12180. return 1;
  12181. }
  12182. int EQ2Emu_lua_ToggleCharacterFlag(lua_State* state) {
  12183. if (!lua_interface)
  12184. return 0;
  12185. Spawn* player = lua_interface->GetSpawn(state);
  12186. sint32 flag_id = lua_interface->GetSInt32Value(state, 2);
  12187. lua_interface->ResetFunctionStack(state);
  12188. if (!player) {
  12189. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  12190. return 0;
  12191. }
  12192. if (!player->IsPlayer()) {
  12193. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  12194. return 0;
  12195. }
  12196. ((Player*)player)->toggle_character_flag(flag_id);
  12197. return 0;
  12198. }