9
3

LuaFunctions.cpp 434 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "Rules/Rules.h"
  29. #include "../common/Log.h"
  30. #include <math.h>
  31. #include "HeroicOp/HeroicOp.h"
  32. #include "RaceTypes/RaceTypes.h"
  33. #include "ClientPacketFunctions.h"
  34. #include "Transmute.h"
  35. #include "Titles.h"
  36. #include <boost/algorithm/string/predicate.hpp>
  37. #include <sstream>
  38. #include <boost/algorithm/string.hpp>
  39. extern MasterFactionList master_faction_list;
  40. extern WorldDatabase database;
  41. extern LuaInterface* lua_interface;
  42. extern ConfigReader configReader;
  43. extern MasterQuestList master_quest_list;
  44. extern MasterItemList master_item_list;
  45. extern MasterSpellList master_spell_list;
  46. extern World world;
  47. extern Commands commands;
  48. extern ZoneList zone_list;
  49. extern Races races;
  50. extern Classes classes;
  51. extern Variables variables;
  52. extern MasterSkillList master_skill_list;
  53. extern MasterHeroicOPList master_ho_list;
  54. extern MasterRaceTypeList race_types_list;
  55. extern MasterLanguagesList master_languages_list;
  56. extern MasterTitlesList master_titles_list;
  57. extern RuleManager rule_manager;
  58. vector<string> ParseString(string strVal, char delim) {
  59. stringstream ss(strVal);
  60. vector<string> ret;
  61. while (ss.good())
  62. {
  63. string substr;
  64. getline(ss, substr, delim);
  65. ret.push_back(substr);
  66. }
  67. return ret;
  68. }
  69. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  70. stringstream ss(strVal);
  71. vector<unsigned int> ret;
  72. while (ss.good())
  73. {
  74. string substr;
  75. getline(ss, substr, delim);
  76. stringstream valss(substr);
  77. unsigned int val = 0;
  78. valss >> val;
  79. ret.push_back(val);
  80. }
  81. return ret;
  82. }
  83. map<string, signed int> ParseStringMap(string strVal, char delim) {
  84. vector<string> pairs = ParseString(strVal, delim);
  85. vector<string>::iterator itr;
  86. map<string, signed int> ret;
  87. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  88. vector<string> keyvaluepair = ParseString(*itr, ':');
  89. if (keyvaluepair.size() == 2) {
  90. stringstream valss(keyvaluepair[1]);
  91. int32 val = 0;
  92. valss >> val;
  93. ret[keyvaluepair[0]] = val;
  94. }
  95. }
  96. return ret;
  97. }
  98. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  99. vector<string> pairs = ParseString(strVal, delim);
  100. vector<string>::iterator itr;
  101. map<unsigned int, unsigned short> ret;
  102. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  103. vector<string> keyvaluepair = ParseString(*itr, ':');
  104. int32 key = 0;
  105. if (keyvaluepair.size() > 0) {
  106. stringstream keyss(keyvaluepair[0]);
  107. keyss >> key;
  108. }
  109. if (keyvaluepair.size() == 1) {
  110. ret[key] = 1;
  111. }
  112. else if (keyvaluepair.size() == 2) {
  113. stringstream valss(keyvaluepair[1]);
  114. unsigned short val = 0;
  115. valss >> val;
  116. ret[key] = val;
  117. }
  118. }
  119. return ret;
  120. }
  121. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  122. vector<string> pairs = ParseString(strVal, delim);
  123. vector<string>::iterator itr;
  124. map<unsigned int, signed int> ret;
  125. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  126. vector<string> keyvaluepair = ParseString(*itr, ':');
  127. int32 key = 0;
  128. if (keyvaluepair.size() > 0) {
  129. stringstream keyss(keyvaluepair[0]);
  130. keyss >> key;
  131. }
  132. if (keyvaluepair.size() == 1) {
  133. ret[key] = 1;
  134. }
  135. else if (keyvaluepair.size() == 2) {
  136. stringstream valss(keyvaluepair[1]);
  137. signed int val = 0;
  138. valss >> val;
  139. ret[key] = val;
  140. }
  141. }
  142. return ret;
  143. }
  144. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  145. if (!lua_interface)
  146. return 0;
  147. Spawn* spawn = lua_interface->GetSpawn(state);
  148. string mp3_string = lua_interface->GetStringValue(state, 2);
  149. string text_string = lua_interface->GetStringValue(state, 3);
  150. string emote_string = lua_interface->GetStringValue(state, 4);
  151. int32 key1 = lua_interface->GetInt32Value(state, 5);
  152. int32 key2 = lua_interface->GetInt32Value(state, 6);
  153. Spawn* player = lua_interface->GetSpawn(state, 7);
  154. int8 language = lua_interface->GetInt8Value(state, 8);
  155. lua_interface->ResetFunctionStack(state);
  156. if (spawn) {
  157. const char* mp3 = 0;
  158. const char* text = 0;
  159. const char* emote = 0;
  160. if (mp3_string.length() > 0)
  161. mp3 = mp3_string.c_str();
  162. if (text_string.length() > 0)
  163. text = text_string.c_str();
  164. if (emote_string.length() > 0)
  165. emote = emote_string.c_str();
  166. Client* client = 0;
  167. if (player && player->IsPlayer())
  168. client = ((Player*)player)->GetClient();
  169. if (client) {
  170. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  171. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  172. }
  173. else
  174. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  175. }
  176. return 0;
  177. }
  178. int EQ2Emu_lua_PlayFlavorID(lua_State* state) {
  179. if (!lua_interface)
  180. return 0;
  181. Spawn* spawn = lua_interface->GetSpawn(state);
  182. int8 type = lua_interface->GetInt8Value(state, 2);
  183. int32 id = lua_interface->GetInt32Value(state, 3);
  184. int16 index = lua_interface->GetInt16Value(state, 4);
  185. Spawn* player = lua_interface->GetSpawn(state, 5);
  186. int8 language = lua_interface->GetInt8Value(state, 6);
  187. lua_interface->ResetFunctionStack(state);
  188. if (spawn) {
  189. Client* client = 0;
  190. if (player && player->IsPlayer())
  191. client = ((Player*)player)->GetClient();
  192. if (client) {
  193. VoiceOverStruct non_garble, garble;
  194. bool garble_success = false;
  195. bool success = world.FindVoiceOver(type, id, index, &non_garble, &garble_success, &garble);
  196. client->SendPlayFlavor(spawn, language, &non_garble, &garble, success, garble_success);
  197. }
  198. else
  199. spawn->GetZone()->PlayFlavorID(spawn, type, id, index, language);
  200. }
  201. return 0;
  202. }
  203. int EQ2Emu_lua_PlaySound(lua_State* state) {
  204. if (!lua_interface)
  205. return 0;
  206. Spawn* spawn = lua_interface->GetSpawn(state);
  207. string sound_string = lua_interface->GetStringValue(state, 2);
  208. float x = lua_interface->GetFloatValue(state, 3);
  209. float y = lua_interface->GetFloatValue(state, 4);
  210. float z = lua_interface->GetFloatValue(state, 5);
  211. Spawn* player = lua_interface->GetSpawn(state, 6);
  212. lua_interface->ResetFunctionStack(state);
  213. if (spawn && sound_string.length() > 0) {
  214. Client* client = 0;
  215. if (player && player->IsPlayer())
  216. client = ((Player*)player)->GetClient();
  217. if (client)
  218. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  219. else
  220. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  221. }
  222. return 0;
  223. }
  224. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  225. if (!lua_interface)
  226. return 0;
  227. Spawn* spawn = lua_interface->GetSpawn(state);
  228. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  229. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  230. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  231. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  232. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  233. lua_interface->ResetFunctionStack(state);
  234. if (!spawn) {
  235. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  236. return 0;
  237. }
  238. if (quest_id > 0) {
  239. //Add this quest to the list of required quests for this spawn
  240. spawn->SetQuestsRequired(quest_id, quest_step);
  241. //If private spawn value set
  242. if (private_spawn) {
  243. //Set the spawn to be private when not granted access through this quest
  244. spawn->AddAllowAccessSpawn(spawn);
  245. spawn->SetPrivateQuestSpawn(true);
  246. }
  247. //This value allows access after a quest step, or the whole quest has been completed
  248. if (continued_access)
  249. spawn->SetQuestsRequiredContinuedAccess(true);
  250. //This value will override vis_flags in the vis packet
  251. if (flag_override > 0)
  252. spawn->SetQuestsRequiredOverride(flag_override);
  253. }
  254. return 0;
  255. }
  256. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  257. if (!lua_interface)
  258. return 0;
  259. Spawn* spawn = lua_interface->GetSpawn(state);
  260. float max_distance = lua_interface->GetFloatValue(state, 2);
  261. string variable = lua_interface->GetStringValue(state, 3);
  262. string value = lua_interface->GetStringValue(state, 4);
  263. lua_interface->ResetFunctionStack(state);
  264. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  265. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  266. return 0;
  267. }
  268. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  269. if (!lua_interface)
  270. return 0;
  271. Client* client = 0;
  272. Spawn* player = lua_interface->GetSpawn(state);
  273. float intensity = lua_interface->GetFloatValue(state, 2);
  274. int8 direction = lua_interface->GetInt8Value(state, 3);
  275. lua_interface->ResetFunctionStack(state);
  276. if (!player) {
  277. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  278. return 0;
  279. }
  280. if (!player->IsPlayer()) {
  281. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  282. return 0;
  283. }
  284. if (player->GetZone())
  285. client = ((Player*)player)->GetClient();
  286. if (!client) {
  287. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  288. return 0;
  289. }
  290. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  291. if (packet) {
  292. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  293. v1 = *(float *)(a1 + 4);
  294. if ( v1 > 0.0 )
  295. v2 = fminf(v1, 1.0);
  296. else
  297. v2 = 0.1;
  298. */
  299. packet->setDataByName("intensity", intensity);
  300. if ( client->GetVersion() > 561 )
  301. packet->setDataByName("direction", direction);
  302. client->QueuePacket(packet->serialize());
  303. safe_delete(packet);
  304. }
  305. return 0;
  306. }
  307. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* dead = lua_interface->GetSpawn(state);
  311. Spawn* killer = lua_interface->GetSpawn(state, 2);
  312. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  313. lua_interface->ResetFunctionStack(state);
  314. if (dead && dead->Alive() && dead->GetZone())
  315. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  316. return 0;
  317. }
  318. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  319. if (!lua_interface)
  320. return 0;
  321. Spawn* spawn = lua_interface->GetSpawn(state);
  322. float max_distance = lua_interface->GetFloatValue(state, 2);
  323. bool include_players = lua_interface->GetInt8Value(state, 3);
  324. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  325. lua_interface->ResetFunctionStack(state);
  326. if (max_distance > 0 && spawn && spawn->GetZone())
  327. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  328. return 0;
  329. }
  330. int EQ2Emu_lua_Despawn(lua_State* state) {
  331. if (!lua_interface)
  332. return 0;
  333. Spawn* spawn = lua_interface->GetSpawn(state);
  334. int32 delay = lua_interface->GetInt32Value(state, 2);
  335. lua_interface->ResetFunctionStack(state);
  336. if (spawn && spawn->GetZone())
  337. spawn->GetZone()->Despawn(spawn, delay);
  338. return 0;
  339. }
  340. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  341. if (!lua_interface)
  342. return 0;
  343. Spawn* spawn = lua_interface->GetSpawn(state);
  344. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  345. lua_interface->ResetFunctionStack(state);
  346. if (spawn) {
  347. spawn->info_changed = true;
  348. spawn->SetShowHandIcon(displayHandIcon);
  349. }
  350. return 0;
  351. }
  352. //this function is used to force an update packet to be sent.
  353. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  354. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  355. if (!lua_interface)
  356. return 0;
  357. Spawn* spawn = lua_interface->GetSpawn(state);
  358. lua_interface->ResetFunctionStack(state);
  359. if (spawn) {
  360. spawn->vis_changed = true;
  361. spawn->GetZone()->AddChangedSpawn(spawn);
  362. }
  363. return 0;
  364. }
  365. //this function is used to force an update packet to be sent.
  366. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  367. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  368. if (!lua_interface)
  369. return 0;
  370. Spawn* spawn = lua_interface->GetSpawn(state);
  371. lua_interface->ResetFunctionStack(state);
  372. if (spawn) {
  373. spawn->info_changed = true;
  374. spawn->GetZone()->AddChangedSpawn(spawn);
  375. }
  376. return 0;
  377. }
  378. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  379. if (!lua_interface)
  380. return 0;
  381. Spawn* spawn = lua_interface->GetSpawn(state);
  382. int32 new_state = lua_interface->GetInt32Value(state, 2);
  383. Spawn* player = lua_interface->GetSpawn(state, 3);
  384. lua_interface->ResetFunctionStack(state);
  385. if (spawn) {
  386. if(player)
  387. {
  388. if(player->IsPlayer())
  389. {
  390. Client* client = ((Player*)player)->GetClient();
  391. if(client)
  392. {
  393. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  394. lua_interface->SetBooleanValue(state, true);
  395. return 1;
  396. }
  397. else
  398. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument does not have active client.", spawn->GetName());
  399. }
  400. else
  401. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument is NOT a player.", spawn->GetName());
  402. }
  403. else
  404. {
  405. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  406. lua_interface->SetBooleanValue(state, true);
  407. return 1;
  408. }
  409. }
  410. lua_interface->SetBooleanValue(state, false);
  411. return 1;
  412. }
  413. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  414. if (!lua_interface)
  415. return 0;
  416. Spawn* spawn = lua_interface->GetSpawn(state);
  417. string variable = lua_interface->GetStringValue(state, 2);
  418. string value = lua_interface->GetStringValue(state, 3);
  419. bool no_update = lua_interface->GetBooleanValue(state, 4); // send update is true by default in SetSpawnCommand, so allow user to specify 'true' to disable send update.
  420. bool temporary_flag = true;
  421. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  422. int8 index = 0;
  423. if(num_args >= 5)
  424. {
  425. temporary_flag = lua_interface->GetBooleanValue(state, 5); // this used to be false, but no one bothered to set it temporary, we don't need to update the DB
  426. index = lua_interface->GetInt8Value(state, 6);
  427. }
  428. lua_interface->ResetFunctionStack(state);
  429. int32 type = commands.GetSpawnSetType(variable);
  430. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  431. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  432. return 0;
  433. }
  434. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  435. if (!lua_interface)
  436. return 0;
  437. Spawn* spawn = lua_interface->GetSpawn(state);
  438. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  439. lua_interface->ResetFunctionStack(state);
  440. if (spawn && spawn_id > 0) {
  441. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  442. if (closest_spawn) {
  443. lua_interface->SetSpawnValue(state, closest_spawn);
  444. return 1;
  445. }
  446. }
  447. return 0;
  448. }
  449. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  450. if (!lua_interface)
  451. return 0;
  452. vector<Spawn*> spawns;
  453. int32 position = 0;
  454. if(lua_istable(state, 1)) {
  455. size_t len = lua_rawlen(state, 1);
  456. for(int i=1;i <= len; i++)
  457. {
  458. // get the entry to stack
  459. lua_rawgeti(state, 1, i);
  460. int Top = lua_gettop(state);
  461. if(lua_islightuserdata(state,Top)) {
  462. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  463. if(data->IsSpawn()) {
  464. spawns.push_back(data->spawn);
  465. }
  466. }
  467. // remove entry from stack
  468. lua_pop(state,1);
  469. }
  470. }
  471. position = lua_interface->GetInt32Value(state, 2);
  472. lua_interface->ResetFunctionStack(state);
  473. Spawn* spawn = 0;
  474. if(position < spawns.size()) {
  475. spawn = spawns.at(position);
  476. }
  477. if(spawn) {
  478. lua_interface->SetSpawnValue(state, spawn);
  479. return 1;
  480. }
  481. return 0;
  482. }
  483. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  484. if (!lua_interface)
  485. return 0;
  486. vector<Spawn*> spawns;
  487. if(lua_istable(state, 1)) {
  488. size_t len = lua_rawlen(state, 1);
  489. for(int i=1;i <= len; i++)
  490. {
  491. // get the entry to stack
  492. lua_rawgeti(state, 1, i);
  493. int Top = lua_gettop(state);
  494. if(lua_islightuserdata(state,Top)) {
  495. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  496. if(data->IsSpawn()) {
  497. spawns.push_back(data->spawn);
  498. }
  499. }
  500. // remove entry from stack
  501. lua_pop(state,1);
  502. }
  503. }
  504. lua_interface->ResetFunctionStack(state);
  505. lua_interface->SetInt32Value(state, spawns.size());
  506. return 1;
  507. }
  508. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  509. if (!lua_interface)
  510. return 0;
  511. Spawn* spawn = lua_interface->GetSpawn(state);
  512. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  513. lua_interface->ResetFunctionStack(state);
  514. if (spawn) {
  515. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  516. if (spawns.size() > 0) {
  517. lua_createtable(state, spawns.size(), 0);
  518. int newTable = lua_gettop(state);
  519. for (int32 i = 0; i < spawns.size(); i++) {
  520. lua_interface->SetSpawnValue(state, spawns.at(i));
  521. lua_rawseti(state, newTable, i + 1);
  522. }
  523. return 1;
  524. }
  525. }
  526. return 0;
  527. }
  528. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  529. if (!lua_interface)
  530. return 0;
  531. Spawn* spawn = lua_interface->GetSpawn(state);
  532. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  533. lua_interface->ResetFunctionStack(state);
  534. if (spawn) {
  535. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  536. if (spawns.size() > 0) {
  537. lua_createtable(state, spawns.size(), 0);
  538. int newTable = lua_gettop(state);
  539. for (int32 i = 0; i < spawns.size(); i++) {
  540. lua_interface->SetSpawnValue(state, spawns.at(i));
  541. lua_rawseti(state, newTable, i + 1);
  542. }
  543. return 1;
  544. }
  545. }
  546. return 0;
  547. }
  548. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  549. if (!lua_interface)
  550. return 0;
  551. Spawn* spawn = lua_interface->GetSpawn(state);
  552. lua_interface->ResetFunctionStack(state);
  553. if (spawn) {
  554. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  555. if (spawns.size() > 0) {
  556. lua_createtable(state, spawns.size(), 0);
  557. int newTable = lua_gettop(state);
  558. for (int32 i = 0; i < spawns.size(); i++) {
  559. lua_interface->SetSpawnValue(state, spawns.at(i));
  560. lua_rawseti(state, newTable, i + 1);
  561. }
  562. return 1;
  563. }
  564. }
  565. return 0;
  566. }
  567. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  568. if (!lua_interface)
  569. return 0;
  570. string variable_name = lua_interface->GetStringValue(state);
  571. lua_interface->ResetFunctionStack(state);
  572. Variable* var = variables.FindVariable(variable_name);
  573. if (var) {
  574. lua_interface->SetStringValue(state, var->GetValue());
  575. return 1;
  576. }
  577. return 0;
  578. }
  579. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  580. if (!lua_interface)
  581. return 0;
  582. int32 total_coins = lua_interface->GetInt32Value(state);
  583. lua_interface->ResetFunctionStack(state);
  584. if (total_coins == 0) {
  585. lua_interface->SetStringValue(state, "0 copper");
  586. return 1;
  587. }
  588. char tmp[64] = { 0 };
  589. string message = "";
  590. int32 val = 0;
  591. if (total_coins >= 1000000) {
  592. val = total_coins / 1000000;
  593. total_coins -= 1000000 * val;
  594. sprintf(tmp, " %u Platinum", val);
  595. message.append(tmp);
  596. memset(tmp, 0, 64);
  597. }
  598. if (total_coins >= 10000) {
  599. val = total_coins / 10000;
  600. total_coins -= 10000 * val;
  601. sprintf(tmp, " %u Gold", val);
  602. message.append(tmp);
  603. memset(tmp, 0, 64);
  604. }
  605. if (total_coins >= 100) {
  606. val = total_coins / 100;
  607. total_coins -= 100 * val;
  608. sprintf(tmp, " %u Silver", val);
  609. message.append(tmp);
  610. memset(tmp, 0, 64);
  611. }
  612. if (total_coins > 0) {
  613. sprintf(tmp, " %u Copper", (int32)total_coins);
  614. message.append(tmp);
  615. }
  616. lua_interface->SetStringValue(state, message.c_str());
  617. return 1;
  618. }
  619. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  620. ZoneServer* zone = lua_interface->GetZone(state);
  621. int32 group_id = lua_interface->GetInt32Value(state, 2);
  622. lua_interface->ResetFunctionStack(state);
  623. if (zone) {
  624. Spawn* spawn = zone->GetSpawnGroup(group_id);
  625. if (spawn) {
  626. lua_interface->SetSpawnValue(state, spawn);
  627. return 1;
  628. }
  629. }
  630. return 0;
  631. }
  632. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  633. ZoneServer* zone = lua_interface->GetZone(state);
  634. int32 location_id = lua_interface->GetInt32Value(state, 2);
  635. lua_interface->ResetFunctionStack(state);
  636. if (zone) {
  637. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  638. if (spawn) {
  639. lua_interface->SetSpawnValue(state, spawn);
  640. return 1;
  641. }
  642. }
  643. return 0;
  644. }
  645. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  646. Spawn* spawn = lua_interface->GetSpawn(state);
  647. lua_interface->ResetFunctionStack(state);
  648. if (spawn) {
  649. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  650. return 1;
  651. }
  652. return 0;
  653. }
  654. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  655. Spawn* spawn = lua_interface->GetSpawn(state);
  656. lua_interface->ResetFunctionStack(state);
  657. if (spawn) {
  658. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  659. return 1;
  660. }
  661. return 0;
  662. }
  663. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  664. if (!lua_interface)
  665. return 0;
  666. Spawn* spawn = lua_interface->GetSpawn(state);
  667. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  668. lua_interface->ResetFunctionStack(state);
  669. if (spawn) {
  670. spawn->SetSpawnGroupID(new_group_id);
  671. lua_interface->SetBooleanValue(state, true);
  672. return 1;
  673. }
  674. lua_interface->SetBooleanValue(state, false);
  675. return 1;
  676. }
  677. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  678. if (!lua_interface)
  679. return 0;
  680. Spawn* spawn = lua_interface->GetSpawn(state);
  681. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  682. lua_interface->ResetFunctionStack(state);
  683. if (spawn) {
  684. if(spawn->GetSpawnGroupID() == new_group_id) {
  685. lua_interface->SetBooleanValue(state, false);
  686. return 1;
  687. }
  688. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  689. lua_interface->SetBooleanValue(state, true);
  690. return 1;
  691. }
  692. lua_interface->SetBooleanValue(state, false);
  693. return 1;
  694. }
  695. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  696. Spawn* spawn = lua_interface->GetSpawn(state);
  697. lua_interface->ResetFunctionStack(state);
  698. if (spawn) {
  699. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  700. return 1;
  701. }
  702. return 0;
  703. }
  704. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  705. Spawn* spawn = lua_interface->GetSpawn(state);
  706. lua_interface->ResetFunctionStack(state);
  707. if (spawn) {
  708. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  709. return 1;
  710. }
  711. return 0;
  712. }
  713. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  714. Player* player = (Player*)lua_interface->GetSpawn(state);
  715. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  716. lua_interface->ResetFunctionStack(state);
  717. if (player && player->IsPlayer() && faction_id > 0) {
  718. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  719. return 1;
  720. }
  721. return 0;
  722. }
  723. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  724. if (!lua_interface)
  725. return 0;
  726. Spawn* spawn = lua_interface->GetSpawn(state);
  727. int32 value = lua_interface->GetInt32Value(state, 2);
  728. lua_interface->ResetFunctionStack(state);
  729. if (spawn) {
  730. spawn->SetFactionID(value);
  731. }
  732. return 0;
  733. }
  734. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  735. Spawn* spawn = lua_interface->GetSpawn(state);
  736. lua_interface->ResetFunctionStack(state);
  737. if (spawn) {
  738. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  739. return 1;
  740. }
  741. return 0;
  742. }
  743. int EQ2Emu_lua_GetGender(lua_State* state) {
  744. Spawn* spawn = lua_interface->GetSpawn(state);
  745. lua_interface->ResetFunctionStack(state);
  746. if (spawn) {
  747. lua_interface->SetInt32Value(state, spawn->GetGender());
  748. return 1;
  749. }
  750. return 0;
  751. }
  752. int EQ2Emu_lua_GetTarget(lua_State* state) {
  753. Spawn* spawn = lua_interface->GetSpawn(state);
  754. lua_interface->ResetFunctionStack(state);
  755. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  756. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  757. return 1;
  758. }
  759. return 0;
  760. }
  761. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  762. if (!lua_interface)
  763. return 0;
  764. Spawn* spawn = lua_interface->GetSpawn(state);
  765. string mp3_string = lua_interface->GetStringValue(state, 2);
  766. int32 key1 = lua_interface->GetInt32Value(state, 3);
  767. int32 key2 = lua_interface->GetInt32Value(state, 4);
  768. Spawn* player = lua_interface->GetSpawn(state, 5);
  769. lua_interface->ResetFunctionStack(state);
  770. if (spawn && mp3_string.length() > 0) {
  771. Client* client = 0;
  772. if (player && player->IsPlayer())
  773. client = ((Player*)player)->GetClient();
  774. if (client) {
  775. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  776. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  777. }
  778. else
  779. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  780. }
  781. return 0;
  782. }
  783. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  784. if (!lua_interface)
  785. return 0;
  786. Spawn* spawn = lua_interface->GetSpawn(state);
  787. lua_interface->ResetFunctionStack(state);
  788. if (spawn) {
  789. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  790. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  791. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  792. return 3;
  793. }
  794. return 0;
  795. }
  796. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  797. if (!lua_interface)
  798. return 0;
  799. Spawn* spawn = lua_interface->GetSpawn(state);
  800. if (spawn) {
  801. int32 item_id = lua_interface->GetInt32Value(state, 2);
  802. lua_interface->ResetFunctionStack(state);
  803. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  804. return 1;
  805. }
  806. lua_interface->ResetFunctionStack(state);
  807. return 0;
  808. }
  809. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  810. if (!lua_interface)
  811. return 0;
  812. Spawn* spawn = lua_interface->GetSpawn(state);
  813. if (spawn && spawn->IsEntity()) {
  814. int32 item_id = lua_interface->GetInt32Value(state, 2);
  815. int16 charges = lua_interface->GetInt16Value(state, 3);
  816. if (charges == 0)
  817. charges = 1;
  818. ((Entity*)spawn)->AddLootItem(item_id, charges);
  819. }
  820. lua_interface->ResetFunctionStack(state);
  821. return 0;
  822. }
  823. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  824. if (!lua_interface)
  825. return 0;
  826. Spawn* spawn = lua_interface->GetSpawn(state);
  827. if (spawn && spawn->IsEntity()) {
  828. int32 item_id = lua_interface->GetInt32Value(state, 2);
  829. Item* item = spawn->LootItem(item_id);
  830. lua_interface->SetLuaUserDataStale(item);
  831. safe_delete(item);
  832. }
  833. lua_interface->ResetFunctionStack(state);
  834. return 0;
  835. }
  836. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  837. if (!lua_interface)
  838. return 0;
  839. Spawn* spawn = lua_interface->GetSpawn(state);
  840. if (spawn) {
  841. int32 val = lua_interface->GetInt32Value(state, 2);
  842. spawn->AddLootCoins(val);
  843. }
  844. lua_interface->ResetFunctionStack(state);
  845. return 0;
  846. }
  847. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  848. if (!lua_interface)
  849. return 0;
  850. Spawn* entity = lua_interface->GetSpawn(state);
  851. Spawn* player = lua_interface->GetSpawn(state, 2);
  852. if (entity && player && player->IsPlayer()) {
  853. int32 coins = lua_interface->GetInt32Value(state, 3);
  854. vector<Item*>* items = 0;
  855. int i = 0;
  856. int32 item_id = 0;
  857. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  858. if (items == 0)
  859. items = new vector<Item*>;
  860. if (master_item_list.GetItem(item_id))
  861. items->push_back(master_item_list.GetItem(item_id));
  862. i++;
  863. }
  864. Client* client = 0;
  865. client = ((Player*)player)->GetClient();
  866. if (client)
  867. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  868. if(coins > 0)
  869. entity->AddLootCoins(coins);
  870. safe_delete(items);
  871. }
  872. lua_interface->ResetFunctionStack(state);
  873. return 0;
  874. }
  875. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  876. if (!lua_interface)
  877. return 0;
  878. Spawn* entity = lua_interface->GetSpawn(state);
  879. Spawn* player = lua_interface->GetSpawn(state, 2);
  880. int32 item_id = lua_interface->GetInt32Value(state, 3);
  881. lua_interface->ResetFunctionStack(state);
  882. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  883. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  884. return 1;
  885. }
  886. return 0;
  887. }
  888. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  889. if (!lua_interface)
  890. return 0;
  891. Spawn* entity = lua_interface->GetSpawn(state);
  892. Spawn* player = lua_interface->GetSpawn(state, 2);
  893. lua_interface->ResetFunctionStack(state);
  894. if (entity && player && player->IsPlayer()) {
  895. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  896. return 1;
  897. }
  898. return 0;
  899. }
  900. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  901. if (!lua_interface)
  902. return 0;
  903. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  904. lua_interface->SetLuaUserDataStale(conversation);
  905. safe_delete(conversation);
  906. lua_interface->ResetFunctionStack(state);
  907. conversation = new vector<ConversationOption>();
  908. lua_interface->SetConversationValue(state, conversation);
  909. return 1;
  910. }
  911. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  912. if (!lua_interface)
  913. return 0;
  914. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  915. if (conversation) {
  916. ConversationOption conv_option;
  917. conv_option.option = lua_interface->GetStringValue(state, 2);
  918. conv_option.function = lua_interface->GetStringValue(state, 3);
  919. if (conv_option.option.length() > 0)
  920. conversation->push_back(conv_option);
  921. }
  922. lua_interface->ResetFunctionStack(state);
  923. return 0;
  924. }
  925. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  926. if (!lua_interface)
  927. return 0;
  928. Spawn* npc = lua_interface->GetSpawn(state);
  929. Spawn* player = lua_interface->GetSpawn(state, 2);
  930. lua_interface->ResetFunctionStack(state);
  931. if (npc && player && player->IsPlayer() && player->GetZone()) {
  932. Client* client = ((Player*)player)->GetClient();
  933. if (client) {
  934. int32 conversation_id = client->GetConversationID(npc, 0);
  935. client->CloseDialog(conversation_id);
  936. }
  937. }
  938. return 0;
  939. }
  940. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  941. if (!lua_interface)
  942. return 0;
  943. Item* item = lua_interface->GetItem(state);
  944. Spawn* player = lua_interface->GetSpawn(state, 2);
  945. lua_interface->ResetFunctionStack(state);
  946. if (item && player && player->IsPlayer() && player->GetZone()) {
  947. Client* client = ((Player*)player)->GetClient();
  948. if (client) {
  949. int32 conversation_id = client->GetConversationID(0, item);
  950. client->CloseDialog(conversation_id);
  951. }
  952. }
  953. return 0;
  954. }
  955. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  956. if (!lua_interface)
  957. return 0;
  958. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  959. Spawn* spawn = 0;
  960. Item* item = 0;
  961. int8 type = lua_interface->GetInt8Value(state, 2);
  962. if (type == 1 || type == 3)
  963. spawn = lua_interface->GetSpawn(state, 3);
  964. else if (type == 2 || type == 4)
  965. item = lua_interface->GetItem(state, 3);
  966. Spawn* player = lua_interface->GetSpawn(state, 4);
  967. string text = lua_interface->GetStringValue(state, 5);
  968. string mp3 = lua_interface->GetStringValue(state, 6);
  969. int32 key1 = lua_interface->GetInt32Value(state, 7);
  970. int32 key2 = lua_interface->GetInt32Value(state, 8);
  971. int8 language = lua_interface->GetInt8Value(state, 9);
  972. int numargs = lua_interface->GetNumberOfArgs(state);
  973. int8 can_close = 1;
  974. if(numargs > 9)
  975. can_close = lua_interface->GetInt32Value(state, 10);
  976. lua_interface->ResetFunctionStack(state);
  977. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  978. Client* client = ((Player*)player)->GetClient();
  979. if (client) {
  980. if (spawn) {
  981. // Need to do this so the function works the same as it did before
  982. if (type == 1)
  983. type++;
  984. if (mp3.length() > 0)
  985. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2, language, can_close);
  986. else
  987. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), nullptr, 0, 0, language, can_close);
  988. }
  989. else {
  990. if (mp3.length() > 0)
  991. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2, language, can_close);
  992. else
  993. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, nullptr, 0, 0, language, can_close);
  994. }
  995. }
  996. }
  997. lua_interface->SetLuaUserDataStale(conversation);
  998. safe_delete(conversation);
  999. return 0;
  1000. }
  1001. int EQ2Emu_lua_StartConversation(lua_State* state) {
  1002. if (!lua_interface)
  1003. return 0;
  1004. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  1005. Spawn* source = lua_interface->GetSpawn(state, 2);
  1006. Spawn* player = lua_interface->GetSpawn(state, 3);
  1007. string text = lua_interface->GetStringValue(state, 4);
  1008. string mp3 = lua_interface->GetStringValue(state, 5);
  1009. int32 key1 = lua_interface->GetInt32Value(state, 6);
  1010. int32 key2 = lua_interface->GetInt32Value(state, 7);
  1011. int8 language = lua_interface->GetInt32Value(state, 8);
  1012. int numargs = lua_interface->GetNumberOfArgs(state);
  1013. int8 can_close = 1;
  1014. if(numargs > 8)
  1015. can_close = lua_interface->GetInt32Value(state, 9);
  1016. lua_interface->ResetFunctionStack(state);
  1017. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1018. Client* client = ((Player*)player)->GetClient();
  1019. if (mp3.length() > 0)
  1020. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2, language, can_close);
  1021. else
  1022. client->DisplayConversation(source, 1, conversation, text.c_str(), nullptr, 0, 0, language, can_close);
  1023. lua_interface->SetLuaUserDataStale(conversation);
  1024. safe_delete(conversation);
  1025. }
  1026. else
  1027. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in StartConversation, potentially AddConversationOption not yet called or the StartConversation arguments are incorrect, text: %s, conversationSize: %i.", source ? source->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  1028. return 0;
  1029. }
  1030. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1031. if (!lua_interface)
  1032. return 0;
  1033. Spawn* spawn = lua_interface->GetSpawn(state);
  1034. float distance = lua_interface->GetFloatValue(state, 2);
  1035. string in_range_function = lua_interface->GetStringValue(state, 3);
  1036. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1037. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1038. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1039. return 0;
  1040. }
  1041. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1042. ZoneServer* zone = lua_interface->GetZone(state);
  1043. float x = lua_interface->GetFloatValue(state, 2);
  1044. float y = lua_interface->GetFloatValue(state, 3);
  1045. float z = lua_interface->GetFloatValue(state, 4);
  1046. float max_variation = lua_interface->GetFloatValue(state, 5);
  1047. string in_range_function = lua_interface->GetStringValue(state, 6);
  1048. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1049. lua_interface->ResetFunctionStack(state);
  1050. if (zone && in_range_function.length() > 0)
  1051. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1052. return 0;
  1053. }
  1054. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1055. if (!lua_interface)
  1056. return 0;
  1057. Spawn* spawn = lua_interface->GetSpawn(state);
  1058. if (spawn && spawn->IsEntity()) {
  1059. int32 val = lua_interface->GetInt32Value(state, 2);
  1060. ((Entity*)spawn)->SetLootCoins(val);
  1061. }
  1062. lua_interface->ResetFunctionStack(state);
  1063. return 0;
  1064. }
  1065. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1066. if (!lua_interface)
  1067. return 0;
  1068. Spawn* spawn = lua_interface->GetSpawn(state);
  1069. lua_interface->ResetFunctionStack(state);
  1070. if (spawn && spawn->IsEntity()) {
  1071. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1072. return 1;
  1073. }
  1074. return 0;
  1075. }
  1076. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1077. if (!lua_interface)
  1078. return 0;
  1079. Spawn* spawn = lua_interface->GetSpawn(state);
  1080. float x = lua_interface->GetFloatValue(state, 2);
  1081. float y = lua_interface->GetFloatValue(state, 3);
  1082. float z = lua_interface->GetFloatValue(state, 4);
  1083. float speed = lua_interface->GetFloatValue(state, 5);
  1084. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1085. string function = lua_interface->GetStringValue(state, 7);
  1086. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1087. float heading = lua_interface->GetFloatValue(state, 8);
  1088. if (spawn) {
  1089. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1090. spawn->GetZone()->AddMovementNPC(spawn);
  1091. }
  1092. lua_interface->ResetFunctionStack(state);
  1093. return 0;
  1094. }
  1095. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1096. if (!lua_interface)
  1097. return 0;
  1098. Spawn* spawn = lua_interface->GetSpawn(state);
  1099. lua_interface->ResetFunctionStack(state);
  1100. if (spawn) {
  1101. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1102. return 1;
  1103. }
  1104. return 0;
  1105. }
  1106. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1107. if (!lua_interface)
  1108. return 0;
  1109. Spawn* spawn = lua_interface->GetSpawn(state);
  1110. lua_interface->ResetFunctionStack(state);
  1111. if (spawn && spawn->IsPlayer()) {
  1112. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1113. return 1;
  1114. }
  1115. lua_interface->SetInt32Value(state, 0);
  1116. return 1;
  1117. }
  1118. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1119. if (!lua_interface)
  1120. return 0;
  1121. Spawn* spawn = lua_interface->GetSpawn(state);
  1122. Spawn* target = lua_interface->GetSpawn(state, 2);
  1123. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1124. bool reset_action_state = true;
  1125. if(num_args > 2)
  1126. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1127. if (spawn && target) {
  1128. if (spawn->IsEntity())
  1129. // ((Entity*)spawn)->FaceTarget(target);
  1130. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1131. }
  1132. lua_interface->ResetFunctionStack(state);
  1133. return 0;
  1134. }
  1135. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1136. if (!lua_interface)
  1137. return 0;
  1138. Spawn* spawn = lua_interface->GetSpawn(state);
  1139. float x = lua_interface->GetFloatValue(state, 2);
  1140. float y = lua_interface->GetFloatValue(state, 3);
  1141. float z = lua_interface->GetFloatValue(state, 4);
  1142. float speed = lua_interface->GetFloatValue(state, 5);
  1143. string lua_function = lua_interface->GetStringValue(state, 6);
  1144. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1145. if (spawn) {
  1146. if (speed == 0)
  1147. speed = spawn->GetSpeed();
  1148. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1149. }
  1150. lua_interface->ResetFunctionStack(state);
  1151. return 0;
  1152. }
  1153. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1154. if (!lua_interface)
  1155. return 0;
  1156. Spawn* spawn = lua_interface->GetSpawn(state);
  1157. lua_interface->ResetFunctionStack(state);
  1158. if (spawn) {
  1159. spawn->ClearRunningLocations();
  1160. }
  1161. return 0;
  1162. }
  1163. int EQ2Emu_lua_Say(lua_State* state) {
  1164. if (!lua_interface)
  1165. return 0;
  1166. Spawn* spawn = lua_interface->GetSpawn(state);
  1167. string message = lua_interface->GetStringValue(state, 2);
  1168. Spawn* player = lua_interface->GetSpawn(state, 3);
  1169. float dist = lua_interface->GetFloatValue(state, 4);
  1170. int32 language = lua_interface->GetInt32Value(state, 5);
  1171. if (spawn && message.length() > 0) {
  1172. Client* client = 0;
  1173. if (player && player->IsPlayer())
  1174. client = ((Player*)player)->GetClient();
  1175. if (client)
  1176. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1177. else
  1178. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1179. }
  1180. lua_interface->ResetFunctionStack(state);
  1181. return 0;
  1182. }
  1183. int EQ2Emu_lua_Shout(lua_State* state) {
  1184. if (!lua_interface)
  1185. return 0;
  1186. Spawn* spawn = lua_interface->GetSpawn(state);
  1187. string message = lua_interface->GetStringValue(state, 2);
  1188. Spawn* player = lua_interface->GetSpawn(state, 3);
  1189. float dist = lua_interface->GetFloatValue(state, 4);
  1190. int32 language = lua_interface->GetInt32Value(state, 5);
  1191. if (spawn && message.length() > 0) {
  1192. Client* client = 0;
  1193. if (player && player->IsPlayer())
  1194. client = ((Player*)player)->GetClient();
  1195. if (client)
  1196. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1197. else
  1198. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1199. }
  1200. lua_interface->ResetFunctionStack(state);
  1201. return 0;
  1202. }
  1203. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1204. if (!lua_interface)
  1205. return 0;
  1206. Spawn* spawn = lua_interface->GetSpawn(state);
  1207. string message = lua_interface->GetStringValue(state, 2);
  1208. Spawn* player = lua_interface->GetSpawn(state, 3);
  1209. float dist = lua_interface->GetFloatValue(state, 4);
  1210. int32 language = lua_interface->GetInt32Value(state, 5);
  1211. if (spawn && message.length() > 0) {
  1212. Client* client = 0;
  1213. if (player && player->IsPlayer())
  1214. client = ((Player*)player)->GetClient();
  1215. if (client)
  1216. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1217. else
  1218. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1219. }
  1220. lua_interface->ResetFunctionStack(state);
  1221. return 0;
  1222. }
  1223. int EQ2Emu_lua_Emote(lua_State* state) {
  1224. if (!lua_interface)
  1225. return 0;
  1226. Spawn* spawn = lua_interface->GetSpawn(state);
  1227. string message = lua_interface->GetStringValue(state, 2);
  1228. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1229. Spawn* player = lua_interface->GetSpawn(state, 4);
  1230. char* to = 0;
  1231. if (spawn2)
  1232. to = spawn2->GetName();
  1233. if (spawn && message.length() > 0) {
  1234. Client* client = 0;
  1235. if (player && player->IsPlayer())
  1236. client = ((Player*)player)->GetClient();
  1237. if (client)
  1238. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1239. else
  1240. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1241. }
  1242. lua_interface->ResetFunctionStack(state);
  1243. return 0;
  1244. }
  1245. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1246. if (!lua_interface)
  1247. return 0;
  1248. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1249. if(!luaspell || luaspell->resisted) {
  1250. lua_interface->ResetFunctionStack(state);
  1251. return 0;
  1252. }
  1253. Spawn* caster = luaspell->caster;
  1254. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1255. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1256. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1257. Spawn* target = lua_interface->GetSpawn(state, 4);
  1258. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1259. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1260. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1261. lua_interface->ResetFunctionStack(state);
  1262. boost::to_lower(heal_type);
  1263. if (caster && caster->IsEntity()) {
  1264. bool success = false;
  1265. luaspell->resisted = false;
  1266. if (target) {
  1267. float distance = caster->GetDistance(target, true);
  1268. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1269. success = true;
  1270. }
  1271. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1272. Spawn* target = 0;
  1273. ZoneServer* zone = luaspell->caster->GetZone();
  1274. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1275. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1276. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1277. float distance = caster->GetDistance(target, true);
  1278. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1279. }
  1280. }
  1281. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1282. success = true;
  1283. }
  1284. if (success) {
  1285. if (caster->GetZone())
  1286. caster->GetZone()->TriggerCharSheetTimer();
  1287. }
  1288. }
  1289. return 0;
  1290. }
  1291. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1292. if (!lua_interface)
  1293. return 0;
  1294. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1295. if(!luaspell || luaspell->resisted) {
  1296. lua_interface->ResetFunctionStack(state);
  1297. return 0;
  1298. }
  1299. Spawn* caster = luaspell->caster;
  1300. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1301. float percentage = lua_interface->GetFloatValue(state, 2);
  1302. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1303. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1304. Spawn* target = lua_interface->GetSpawn(state, 5);
  1305. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1306. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1307. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1308. lua_interface->ResetFunctionStack(state);
  1309. boost::to_lower(heal_type);
  1310. int32 min_heal = 0, max_heal = 0;
  1311. if (caster && caster->IsEntity() && target) {
  1312. if(percentage <= 0.0f)
  1313. {
  1314. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1315. return 0;
  1316. }
  1317. if(heal_type == "power")
  1318. {
  1319. if(current_value)
  1320. {
  1321. if(caster_value)
  1322. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1323. else
  1324. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1325. }
  1326. else
  1327. {
  1328. if(caster_value)
  1329. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1330. else
  1331. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1332. }
  1333. }
  1334. else
  1335. {
  1336. if(current_value)
  1337. {
  1338. if(caster_value)
  1339. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1340. else
  1341. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1342. }
  1343. else
  1344. {
  1345. if(caster_value)
  1346. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1347. else
  1348. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1349. }
  1350. }
  1351. bool success = false;
  1352. luaspell->resisted = false;
  1353. if (target) {
  1354. float distance = caster->GetDistance(target, true);
  1355. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1356. success = true;
  1357. }
  1358. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1359. Spawn* target = 0;
  1360. ZoneServer* zone = luaspell->caster->GetZone();
  1361. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1362. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1363. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1364. float distance = caster->GetDistance(target, true);
  1365. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1366. }
  1367. }
  1368. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1369. success = true;
  1370. }
  1371. if (success) {
  1372. if (caster->GetZone())
  1373. caster->GetZone()->TriggerCharSheetTimer();
  1374. }
  1375. }
  1376. return 0;
  1377. }
  1378. int EQ2Emu_lua_AddItem(lua_State* state) {
  1379. if (!lua_interface)
  1380. return 0;
  1381. Spawn* spawn = lua_interface->GetSpawn(state);
  1382. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1383. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1384. lua_interface->ResetFunctionStack(state);
  1385. // default of 1 quantity to add
  1386. if (quantity == 0)
  1387. quantity = 1;
  1388. if (spawn && spawn->IsPlayer()) {
  1389. Client* client = ((Player*)spawn)->GetClient();
  1390. if (client && item_id > 0) {
  1391. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1392. return 1;
  1393. }
  1394. }
  1395. lua_interface->SetBooleanValue(state, false);
  1396. return 1;
  1397. }
  1398. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1399. if (!lua_interface)
  1400. return 0;
  1401. Spawn* spawn = lua_interface->GetSpawn(state);
  1402. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1403. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1404. string location = lua_interface->GetStringValue(state, 4);
  1405. int16 item_count = lua_interface->GetInt16Value(state,5);
  1406. //devn00b: if we dont have a count, assume 1 item.
  1407. if(!item_count) {
  1408. item_count = 1;
  1409. }
  1410. lua_interface->ResetFunctionStack(state);
  1411. if (spawn && spawn->IsPlayer()) {
  1412. Client* client = ((Player*)spawn)->GetClient();
  1413. if (client && item_id > 0) {
  1414. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1415. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1416. else
  1417. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1418. if (send_messages) {
  1419. Item* item = master_item_list.GetItem(item_id);
  1420. if (item) {
  1421. if(item_count > 1) {
  1422. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1423. string popup_text1 = "You receive "+ item_count;
  1424. string popup_text2 = " " + item->name;
  1425. string popup_text = popup_text1 + popup_text2;
  1426. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1427. // return 1;
  1428. } else {
  1429. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1430. string popup_text = "You receive " + item->name;
  1431. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1432. }
  1433. }
  1434. }
  1435. return 1;
  1436. }
  1437. }
  1438. lua_interface->SetBooleanValue(state, false);
  1439. return 1;
  1440. }
  1441. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1442. Spawn* spawn = lua_interface->GetSpawn(state);
  1443. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1444. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1445. lua_interface->ResetFunctionStack(state);
  1446. // default of 1 to remove
  1447. if (quantity == 0)
  1448. quantity = 1;
  1449. Client* client;
  1450. Item* item;
  1451. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1452. if ((client = ((Player*)spawn)->GetClient())) {
  1453. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1454. if (client->RemoveItem(item, quantity)) {
  1455. lua_interface->SetBooleanValue(state, true);
  1456. return 1;
  1457. }
  1458. }
  1459. }
  1460. }
  1461. lua_interface->SetBooleanValue(state, false);
  1462. return 1;
  1463. }
  1464. int EQ2Emu_lua_HasItem(lua_State* state) {
  1465. Spawn* player = lua_interface->GetSpawn(state);
  1466. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1467. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1468. lua_interface->ResetFunctionStack(state);
  1469. if (player && player->IsPlayer()) {
  1470. bool hasItem = false;
  1471. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1472. if (!hasItem)
  1473. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1474. lua_interface->SetBooleanValue(state, hasItem);
  1475. return 1;
  1476. }
  1477. lua_interface->SetBooleanValue(state, false);
  1478. return 1;
  1479. }
  1480. int EQ2Emu_lua_Spawn(lua_State* state) {
  1481. if (!lua_interface)
  1482. return 0;
  1483. ZoneServer* zone = lua_interface->GetZone(state);
  1484. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1485. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1486. float x = lua_interface->GetFloatValue(state, 4);
  1487. float y = lua_interface->GetFloatValue(state, 5);
  1488. float z = lua_interface->GetFloatValue(state, 6);
  1489. float heading = lua_interface->GetFloatValue(state, 7);
  1490. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1491. Spawn* spawn = zone->GetSpawn(spawn_id);
  1492. if (!spawn)
  1493. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1494. else {
  1495. spawn->SetX(x);
  1496. spawn->SetZ(z);
  1497. spawn->SetY(y,true,true);
  1498. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1499. spawn->SetHeading(heading);
  1500. if (restricted_npc)
  1501. spawn->AddAllowAccessSpawn(spawn);
  1502. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1503. bool scriptActive = false;
  1504. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1505. scriptActive = true;
  1506. spawn->SetSpawnScript(string(spawn_script));
  1507. }
  1508. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1509. zone->AddSpawn(spawn);
  1510. if (scriptActive) {
  1511. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1512. }
  1513. lua_interface->ResetFunctionStack(state);
  1514. lua_interface->SetSpawnValue(state, spawn);
  1515. return 1;
  1516. }
  1517. }
  1518. else {
  1519. string output = "Invalid paramaters to LUA Spawn command: \n";
  1520. if (!zone)
  1521. output = output.append("\t").append("Missing zone reference. \n");
  1522. if (spawn_id == 0)
  1523. output = output.append("\t").append("Missing spawn_id.");
  1524. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1525. }
  1526. lua_interface->ResetFunctionStack(state);
  1527. return 0;
  1528. }
  1529. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1530. if (!lua_interface)
  1531. return 0;
  1532. ZoneServer* zone = lua_interface->GetZone(state);
  1533. lua_interface->ResetFunctionStack(state);
  1534. if (zone) {
  1535. lua_interface->SetStringValue(state, zone->GetZoneName());
  1536. return 1;
  1537. }
  1538. return 0;
  1539. }
  1540. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1541. if (!lua_interface)
  1542. return 0;
  1543. ZoneServer* zone = lua_interface->GetZone(state);
  1544. lua_interface->ResetFunctionStack(state);
  1545. if (zone) {
  1546. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1547. return 1;
  1548. }
  1549. return 0;
  1550. }
  1551. int EQ2Emu_lua_GetZone(lua_State* state) {
  1552. if (!lua_interface)
  1553. return 0;
  1554. int32 zone_id = lua_interface->GetInt32Value(state);
  1555. ZoneServer* zone = 0;
  1556. if (zone_id > 0)
  1557. zone = zone_list.Get(zone_id, true, false, false);
  1558. else {
  1559. string zone_name = lua_interface->GetStringValue(state);
  1560. if (zone_name.length() > 0) {
  1561. zone = zone_list.Get(zone_name.c_str(), true, false, false);
  1562. }
  1563. else {
  1564. Spawn* spawn = lua_interface->GetSpawn(state);
  1565. if (spawn)
  1566. zone = spawn->GetZone();
  1567. }
  1568. }
  1569. lua_interface->ResetFunctionStack(state);
  1570. if (zone) {
  1571. lua_interface->SetZoneValue(state, zone);
  1572. return 1;
  1573. }
  1574. return 0;
  1575. }
  1576. int EQ2Emu_lua_AddHate(lua_State* state) {
  1577. Spawn* entity = lua_interface->GetSpawn(state);
  1578. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1579. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1580. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1581. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1582. if(luaspell && luaspell->resisted) {
  1583. lua_interface->ResetFunctionStack(state);
  1584. return 0;
  1585. }
  1586. if (entity && entity->IsEntity() && amount != 0) {
  1587. if (luaspell && luaspell->caster) {
  1588. ZoneServer* zone = luaspell->caster->GetZone();
  1589. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1590. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1591. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1592. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1593. entity->CheckEncounterState((Entity*)spawn);
  1594. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1595. if (send_packet)
  1596. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1597. }
  1598. }
  1599. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1600. }
  1601. else if (npc && npc->IsNPC() && npc->GetZone()) {
  1602. entity->CheckEncounterState((Entity*)npc);
  1603. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1604. }
  1605. }
  1606. lua_interface->ResetFunctionStack(state);
  1607. return 0;
  1608. }
  1609. int EQ2Emu_lua_Zone(lua_State* state) {
  1610. if (!lua_interface)
  1611. return 0;
  1612. ZoneServer* zone = lua_interface->GetZone(state);
  1613. Spawn* player = lua_interface->GetSpawn(state, 2);
  1614. Client* client = 0;
  1615. if (player && player->IsPlayer())
  1616. client = ((Player*)player)->GetClient();
  1617. float x = lua_interface->GetFloatValue(state, 3);
  1618. float y = lua_interface->GetFloatValue(state, 4);
  1619. float z = lua_interface->GetFloatValue(state, 5);
  1620. float heading = lua_interface->GetFloatValue(state, 6);
  1621. if (zone && client) {
  1622. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1623. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1624. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1625. {
  1626. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1627. return 0;
  1628. }
  1629. if (x != 0 || y != 0 || z != 0) {
  1630. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1631. player->SetX(x);
  1632. player->SetY(y);
  1633. player->SetZ(z);
  1634. player->SetHeading(heading);
  1635. client->Zone(zone->GetZoneName(), false);
  1636. }
  1637. else
  1638. client->Zone(zone->GetZoneName());
  1639. }
  1640. else
  1641. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1642. lua_interface->ResetFunctionStack(state);
  1643. return 0;
  1644. }
  1645. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1646. if (!lua_interface)
  1647. return 0;
  1648. Spawn* spawn = lua_interface->GetSpawn(state);
  1649. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1650. if (spawn && spawn2)
  1651. spawn->AddAllowAccessSpawn(spawn2);
  1652. lua_interface->ResetFunctionStack(state);
  1653. return 0;
  1654. }
  1655. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1656. if (!lua_interface)
  1657. return 0;
  1658. Spawn* target = lua_interface->GetSpawn(state);
  1659. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1660. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1661. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1662. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1663. lua_interface->ResetFunctionStack(state);
  1664. if (!target) {
  1665. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1666. return 0;
  1667. }
  1668. if (!target->IsEntity()) {
  1669. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1670. return 0;
  1671. }
  1672. if (spell_id <= 0) {
  1673. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1674. return 0;
  1675. }
  1676. if (caster && !caster->IsEntity()) {
  1677. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1678. return 0;
  1679. }
  1680. if (spell_tier == 0)
  1681. spell_tier = 1;
  1682. if (!caster)
  1683. caster = target;
  1684. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1685. return 0;
  1686. }
  1687. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1688. if (!lua_interface)
  1689. return 0;
  1690. Spawn* target = lua_interface->GetSpawn(state);
  1691. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1692. if(!luaspell || luaspell->resisted) {
  1693. lua_interface->ResetFunctionStack(state);
  1694. lua_interface->SetBooleanValue(state, false);
  1695. return 1;
  1696. }
  1697. Spawn* caster = luaspell->caster;
  1698. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1699. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1700. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1701. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1702. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1703. //lua_interface->ResetFunctionStack(state);
  1704. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1705. vector<int16> faction_req;
  1706. vector<int16> race_req;
  1707. int32 class_req = 0;
  1708. int32 i = 0;
  1709. int8 f = 0;
  1710. int8 r = 0;
  1711. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1712. if (class_id < 100) {
  1713. class_req += pow(2.0, double(class_id - 1));
  1714. }
  1715. else if (class_id > 100 && class_id < 1000) {
  1716. race_req.push_back(class_id);
  1717. r++;
  1718. }
  1719. else {
  1720. faction_req.push_back(class_id);
  1721. f++;
  1722. }
  1723. i++;
  1724. }
  1725. lua_interface->ResetFunctionStack(state);
  1726. if (caster && caster->IsEntity()) {
  1727. bool race_match = false;
  1728. bool success = false;
  1729. luaspell->resisted = false;
  1730. if (luaspell->targets.size() > 0) {
  1731. ZoneServer* zone = luaspell->caster->GetZone();
  1732. Spawn* target = 0;
  1733. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1734. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1735. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1736. if (race_req.size() > 0) {
  1737. for (int8 i = 0; i < race_req.size(); i++) {
  1738. if(race_req[i] == target->GetRace() ||
  1739. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1740. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1741. race_match = true;
  1742. }
  1743. }
  1744. }
  1745. else
  1746. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1747. if (race_match == true) {
  1748. float distance = caster->GetDistance(target, true);
  1749. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1750. }
  1751. }
  1752. }
  1753. success = true;
  1754. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1755. }
  1756. else if (target) {
  1757. //check class and race/faction here
  1758. if (race_req.size() > 0) {
  1759. for (int8 i = 0; i < race_req.size(); i++) {
  1760. if(race_req[i] == target->GetRace() ||
  1761. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1762. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1763. race_match = true;
  1764. }
  1765. }
  1766. }
  1767. else
  1768. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1769. if (race_match == true) {
  1770. float distance = caster->GetDistance(target, true);
  1771. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1772. success = true;
  1773. }
  1774. }
  1775. lua_interface->SetBooleanValue(state, luaspell->has_damaged);
  1776. if (success) {
  1777. Spell* spell = luaspell->spell;
  1778. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1779. ((Player*)caster)->InCombat(true);
  1780. if (caster->GetZone())
  1781. caster->GetZone()->TriggerCharSheetTimer();
  1782. }
  1783. }
  1784. }
  1785. else {
  1786. lua_interface->SetBooleanValue(state, false);
  1787. }
  1788. return 1;
  1789. }
  1790. int EQ2Emu_lua_SpellDamageExt(lua_State* state) {
  1791. if (!lua_interface)
  1792. return 0;
  1793. Spawn* target = lua_interface->GetSpawn(state);
  1794. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1795. if(!luaspell || luaspell->resisted) {
  1796. lua_interface->ResetFunctionStack(state);
  1797. lua_interface->SetBooleanValue(state, false);
  1798. return 1;
  1799. }
  1800. Spawn* caster = luaspell->caster;
  1801. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1802. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1803. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1804. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1805. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1806. int32 override_packet_type = lua_interface->GetInt32Value(state, 7);
  1807. bool take_power = lua_interface->GetInt32Value(state, 8) == 1;
  1808. //lua_interface->ResetFunctionStack(state);
  1809. int32 class_id = lua_interface->GetInt32Value(state, 9);
  1810. vector<int16> faction_req;
  1811. vector<int16> race_req;
  1812. int32 class_req = 0;
  1813. int32 i = 0;
  1814. int8 f = 0;
  1815. int8 r = 0;
  1816. while ((class_id = lua_interface->GetInt32Value(state, 9 + i))) {
  1817. if (class_id < 100) {
  1818. class_req += pow(2.0, double(class_id - 1));
  1819. }
  1820. else if (class_id > 100 && class_id < 1000) {
  1821. race_req.push_back(class_id);
  1822. r++;
  1823. }
  1824. else {
  1825. faction_req.push_back(class_id);
  1826. f++;
  1827. }
  1828. i++;
  1829. }
  1830. lua_interface->ResetFunctionStack(state);
  1831. if (caster && caster->IsEntity()) {
  1832. bool race_match = false;
  1833. bool success = false;
  1834. luaspell->resisted = false;
  1835. if (luaspell->targets.size() > 0) {
  1836. ZoneServer* zone = luaspell->caster->GetZone();
  1837. Spawn* target = 0;
  1838. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1839. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1840. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1841. if (race_req.size() > 0) {
  1842. for (int8 i = 0; i < race_req.size(); i++) {
  1843. if(race_req[i] == target->GetRace() ||
  1844. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1845. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1846. race_match = true;
  1847. }
  1848. }
  1849. }
  1850. else
  1851. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1852. if (race_match == true) {
  1853. float distance = caster->GetDistance(target, true);
  1854. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power);
  1855. }
  1856. }
  1857. }
  1858. success = true;
  1859. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1860. }
  1861. else if (target) {
  1862. //check class and race/faction here
  1863. if (race_req.size() > 0) {
  1864. for (int8 i = 0; i < race_req.size(); i++) {
  1865. if(race_req[i] == target->GetRace() ||
  1866. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1867. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1868. race_match = true;
  1869. }
  1870. }
  1871. }
  1872. else
  1873. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1874. if (race_match == true) {
  1875. float distance = caster->GetDistance(target, true);
  1876. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power))
  1877. success = true;
  1878. }
  1879. }
  1880. lua_interface->SetBooleanValue(state, luaspell->has_damaged);
  1881. if (success) {
  1882. Spell* spell = luaspell->spell;
  1883. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1884. ((Player*)caster)->InCombat(true);
  1885. if (caster->GetZone())
  1886. caster->GetZone()->TriggerCharSheetTimer();
  1887. }
  1888. }
  1889. }
  1890. else {
  1891. lua_interface->SetBooleanValue(state, false);
  1892. }
  1893. return 1;
  1894. }
  1895. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1896. if (!lua_interface)
  1897. return 0;
  1898. Spawn* spawn = lua_interface->GetSpawn(state);
  1899. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1900. lua_interface->ResetFunctionStack(state);
  1901. if (spawn && value != 0) {
  1902. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1903. spawn->SetPower(spawn->GetTotalPower());
  1904. else
  1905. spawn->SetPower(spawn->GetPower() + value);
  1906. }
  1907. return 0;
  1908. }
  1909. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1910. if (!lua_interface)
  1911. return 0;
  1912. Spawn* spawn = lua_interface->GetSpawn(state);
  1913. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1914. lua_interface->ResetFunctionStack(state);
  1915. if (spawn && value != 0) {
  1916. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1917. spawn->SetHP(spawn->GetTotalHP());
  1918. else
  1919. spawn->SetHP(spawn->GetHP() + value);
  1920. }
  1921. return 0;
  1922. }
  1923. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1924. if (!lua_interface)
  1925. return 0;
  1926. Spawn* spawn = lua_interface->GetSpawn(state);
  1927. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1928. lua_interface->ResetFunctionStack(state);
  1929. if (spawn && value != 0) {
  1930. spawn->SetTotalPower(value);
  1931. spawn->SetTotalPowerBaseInstance(value);
  1932. }
  1933. return 0;
  1934. }
  1935. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1936. if (!lua_interface)
  1937. return 0;
  1938. Spawn* spawn = lua_interface->GetSpawn(state);
  1939. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1940. lua_interface->ResetFunctionStack(state);
  1941. if (spawn && value != 0) {
  1942. spawn->SetTotalHP(value);
  1943. spawn->SetTotalHPBaseInstance(value);
  1944. }
  1945. return 0;
  1946. }
  1947. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1948. if (!lua_interface)
  1949. return 0;
  1950. Spawn* spawn = lua_interface->GetSpawn(state);
  1951. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1952. lua_interface->ResetFunctionStack(state);
  1953. if (spawn) {
  1954. spawn->SetHP(value);
  1955. if (value > spawn->GetTotalHPBase())
  1956. spawn->SetTotalHP(value);
  1957. }
  1958. return 0;
  1959. }
  1960. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1961. if (!lua_interface)
  1962. return 0;
  1963. Spawn* spawn = lua_interface->GetSpawn(state);
  1964. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1965. float value = lua_interface->GetFloatValue(state, 2);
  1966. lua_interface->ResetFunctionStack(state);
  1967. if (spawn && spawn->IsEntity() && value > 0)
  1968. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1969. if (spawn && spawn->IsPlayer())
  1970. ((Player*)spawn)->SetCharSheetChanged(true);
  1971. return 0;
  1972. }
  1973. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1974. if (!lua_interface)
  1975. return 0;
  1976. Spawn* spawn = lua_interface->GetSpawn(state);
  1977. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1978. lua_interface->ResetFunctionStack(state);
  1979. if (spawn && spawn->IsEntity() && value > 0)
  1980. ((Entity*)spawn)->SetTotalHPBase(value);
  1981. return 0;
  1982. }
  1983. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1984. if (!lua_interface)
  1985. return 0;
  1986. Spawn* spawn = lua_interface->GetSpawn(state);
  1987. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1988. lua_interface->ResetFunctionStack(state);
  1989. if (spawn && value > 0) {
  1990. spawn->SetPower(value);
  1991. if (value > spawn->GetTotalPowerBase())
  1992. spawn->SetTotalPower(value);
  1993. }
  1994. return 0;
  1995. }
  1996. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1997. if (!lua_interface)
  1998. return 0;
  1999. Spawn* spawn = lua_interface->GetSpawn(state);
  2000. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2001. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2002. lua_interface->ResetFunctionStack(state);
  2003. if (spawn && spawn->IsEntity() && value > 0)
  2004. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  2005. return 0;
  2006. }
  2007. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  2008. if (!lua_interface)
  2009. return 0;
  2010. Spawn* spawn = lua_interface->GetSpawn(state);
  2011. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2012. lua_interface->ResetFunctionStack(state);
  2013. if (spawn && spawn->IsEntity() && value > 0)
  2014. ((Entity*)spawn)->SetTotalPowerBase(value);
  2015. return 0;
  2016. }
  2017. int EQ2Emu_lua_SetPosition(lua_State* state) {
  2018. if (!lua_interface)
  2019. return 0;
  2020. Spawn* spawn = lua_interface->GetSpawn(state);
  2021. float x = lua_interface->GetFloatValue(state, 2);
  2022. float y = lua_interface->GetFloatValue(state, 3);
  2023. float z = lua_interface->GetFloatValue(state, 4);
  2024. float heading = lua_interface->GetFloatValue(state, 5);
  2025. lua_interface->ResetFunctionStack(state);
  2026. if (spawn) {
  2027. spawn->SetX(x);
  2028. spawn->SetY(y);
  2029. spawn->SetZ(z);
  2030. if (heading != 0)
  2031. spawn->SetHeading(heading);
  2032. spawn->SetSpawnOrigX(spawn->GetX());
  2033. spawn->SetSpawnOrigY(spawn->GetY());
  2034. spawn->SetSpawnOrigZ(spawn->GetZ());
  2035. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  2036. if (spawn->IsPlayer()) {
  2037. Client* client = ((Player*)spawn)->GetClient();
  2038. if (client) {
  2039. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  2040. client->QueuePacket(packet);
  2041. }
  2042. }
  2043. }
  2044. return 0;
  2045. }
  2046. int EQ2Emu_lua_SetHeading(lua_State* state) {
  2047. if (!lua_interface)
  2048. return 0;
  2049. Spawn* spawn = lua_interface->GetSpawn(state);
  2050. float value = lua_interface->GetFloatValue(state, 2);
  2051. lua_interface->ResetFunctionStack(state);
  2052. if (spawn) {
  2053. spawn->SetHeading(value);
  2054. if (spawn->IsPlayer()) {
  2055. Client* client = ((Player*)spawn)->GetClient();
  2056. if (client) {
  2057. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  2058. client->QueuePacket(packet);
  2059. }
  2060. }
  2061. }
  2062. return 0;
  2063. }
  2064. int EQ2Emu_lua_SetModelType(lua_State* state) {
  2065. if (!lua_interface)
  2066. return 0;
  2067. Spawn* spawn = lua_interface->GetSpawn(state);
  2068. int16 value = lua_interface->GetInt16Value(state, 2);
  2069. lua_interface->ResetFunctionStack(state);
  2070. if (spawn)
  2071. spawn->SetModelType(value);
  2072. return 0;
  2073. }
  2074. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  2075. if (!lua_interface)
  2076. return 0;
  2077. Spawn* spawn = lua_interface->GetSpawn(state);
  2078. int8 value = lua_interface->GetInt8Value(state, 2);
  2079. lua_interface->ResetFunctionStack(state);
  2080. if (spawn) {
  2081. if (spawn->IsPlayer())
  2082. ((Player*)spawn)->SetPlayerAdventureClass(value);
  2083. else
  2084. spawn->SetAdventureClass(value);
  2085. }
  2086. return 0;
  2087. }
  2088. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  2089. if (!lua_interface)
  2090. return 0;
  2091. Spawn* spawn = lua_interface->GetSpawn(state);
  2092. int8 value = lua_interface->GetInt8Value(state, 2);
  2093. lua_interface->ResetFunctionStack(state);
  2094. if (spawn) {
  2095. spawn->SetTradeskillClass(value);
  2096. if (spawn->IsEntity()) {
  2097. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  2098. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  2099. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  2100. }
  2101. if (spawn->IsPlayer())
  2102. ((Player*)spawn)->SetCharSheetChanged(true);
  2103. }
  2104. return 0;
  2105. }
  2106. int EQ2Emu_lua_SetMount(lua_State* state) {
  2107. if (!lua_interface)
  2108. return 0;
  2109. Spawn* spawn = lua_interface->GetSpawn(state);
  2110. int16 value = lua_interface->GetInt16Value(state, 2);
  2111. if (spawn && spawn->IsEntity()) {
  2112. ((Entity*)spawn)->SetMount(value);
  2113. EQ2_Color color;
  2114. color.red = 255;
  2115. color.green = 255;
  2116. color.blue = 255;
  2117. ((Entity*)spawn)->SetMountColor(&color);
  2118. ((Entity*)spawn)->SetMountSaddleColor(&color);
  2119. }
  2120. return 0;
  2121. }
  2122. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  2123. if (!lua_interface)
  2124. return 0;
  2125. Spawn* spawn = lua_interface->GetSpawn(state);
  2126. EQ2_Color mount_color;
  2127. EQ2_Color saddle_color;
  2128. mount_color.red = lua_interface->GetInt8Value(state, 2);
  2129. mount_color.green = lua_interface->GetInt8Value(state, 3);
  2130. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  2131. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  2132. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  2133. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  2134. if (spawn && spawn->IsEntity()) {
  2135. ((Entity*)spawn)->SetMountColor(&mount_color);
  2136. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  2137. }
  2138. return 0;
  2139. }
  2140. int EQ2Emu_lua_GetMount(lua_State* state) {
  2141. if (!lua_interface)
  2142. return 0;
  2143. Spawn* spawn = lua_interface->GetSpawn(state);
  2144. if (spawn && spawn->IsEntity()) {
  2145. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2146. return 1;
  2147. }
  2148. return 0;
  2149. }
  2150. int EQ2Emu_lua_GetRace(lua_State* state) {
  2151. if (!lua_interface)
  2152. return 0;
  2153. Spawn* spawn = lua_interface->GetSpawn(state);
  2154. if (spawn)
  2155. {
  2156. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2157. lua_interface->SetInt32Value(state, spawn->GetRace());
  2158. return 1;
  2159. }
  2160. return 0;
  2161. }
  2162. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2163. if (!lua_interface)
  2164. return 0;
  2165. Spawn* spawn = lua_interface->GetSpawn(state);
  2166. if (spawn) {
  2167. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2168. return 1;
  2169. }
  2170. return 0;
  2171. }
  2172. int EQ2Emu_lua_GetClass(lua_State* state) {
  2173. Spawn* spawn = lua_interface->GetSpawn(state);
  2174. if (spawn) {
  2175. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2176. return 1;
  2177. }
  2178. return 0;
  2179. }
  2180. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2181. Spawn* spawn = lua_interface->GetSpawn(state);
  2182. if (spawn) {
  2183. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2184. return 1;
  2185. }
  2186. return 0;
  2187. }
  2188. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2189. if (!lua_interface)
  2190. return 0;
  2191. Spawn* spawn = lua_interface->GetSpawn(state);
  2192. float value = lua_interface->GetFloatValue(state, 2);
  2193. lua_interface->ResetFunctionStack(state);
  2194. if (spawn) {
  2195. spawn->SetSpeed(value);
  2196. if(spawn->IsEntity())
  2197. ((Entity*)spawn)->SetSpeed(value);
  2198. if (spawn->IsPlayer()) {
  2199. Client* client = ((Player*)spawn)->GetClient();
  2200. if (client) {
  2201. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2202. if (packet) {
  2203. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2204. packet->setDataByName("speed", value);
  2205. packet->setDataByName("size", 0.51);
  2206. EQ2Packet* app = packet->serialize();
  2207. client->QueuePacket(app);
  2208. safe_delete(packet);
  2209. }
  2210. }
  2211. }
  2212. }
  2213. return 0;
  2214. }
  2215. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2216. if (!lua_interface)
  2217. return 0;
  2218. Spawn* spawn = lua_interface->GetSpawn(state);
  2219. const int16 type = lua_interface->GetInt16Value(state, 2);
  2220. const float value = lua_interface->GetFloatValue(state, 3);
  2221. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2222. if(!luaspell || luaspell->resisted) {
  2223. lua_interface->ResetFunctionStack(state);
  2224. return 0;
  2225. }
  2226. int64 class_req = 0;
  2227. int32 class_id = 0;
  2228. vector<int16> faction_req;
  2229. vector<int16> race_req;
  2230. int32 i = 0;
  2231. int8 f = 0;
  2232. int8 r = 0;
  2233. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2234. if (class_id < 100) {
  2235. class_req += pow(2.0, double(class_id - 1));
  2236. }
  2237. else if (class_id > 100 && class_id < 1000) {
  2238. race_req.push_back(class_id);
  2239. r++;
  2240. }
  2241. else {
  2242. faction_req.push_back(class_id);
  2243. f++;
  2244. }
  2245. i++;
  2246. }
  2247. if (value != 0 && type >= 0) {
  2248. if (luaspell && luaspell->spell && luaspell->caster) {
  2249. ZoneServer* zone = luaspell->caster->GetZone();
  2250. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2251. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2252. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2253. if (target) {
  2254. if (target->IsPlayer()) {
  2255. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2256. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2257. if (((Player*)target)->GetGroupMemberInfo())
  2258. ((Player*)target)->UpdateGroupMemberInfo();
  2259. ((Player*)target)->SetCharSheetChanged(true);
  2260. }
  2261. else if (target->IsNPC())
  2262. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2263. else
  2264. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2265. }
  2266. }
  2267. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2268. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2269. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2270. }
  2271. else if (spawn && spawn->IsEntity()) {
  2272. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2273. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2274. if (spawn->IsPlayer())
  2275. ((Player*)spawn)->SetCharSheetChanged(true);
  2276. }
  2277. else
  2278. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2279. }
  2280. else
  2281. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2282. return 0;
  2283. }
  2284. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2285. if (!lua_interface)
  2286. return 0;
  2287. Spawn* spawn = lua_interface->GetSpawn(state);
  2288. int16 type = lua_interface->GetInt16Value(state, 2);
  2289. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2290. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2291. if (!spawn) {
  2292. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2293. return 0;
  2294. }
  2295. if (!spawn->IsEntity()) {
  2296. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2297. return 0;
  2298. }
  2299. if (value == 0) {
  2300. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2301. return 0;
  2302. }
  2303. if (!luaspell || !luaspell->spell) {
  2304. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2305. return 0;
  2306. }
  2307. if(luaspell->resisted) {
  2308. lua_interface->ResetFunctionStack(state);
  2309. return 0;
  2310. }
  2311. int32 class_req = 0;
  2312. vector<int16> faction_req;
  2313. vector<int16> race_req;
  2314. int32 class_id = 0;
  2315. int32 i = 0;
  2316. int8 f = 0;
  2317. int8 r = 0;
  2318. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2319. if (class_id < 100) {
  2320. class_req += pow(2.0, double(class_id - 1));
  2321. }
  2322. else if (class_id > 100 && class_id < 1000) {
  2323. race_req.push_back(class_id);
  2324. r++;
  2325. }
  2326. else {
  2327. faction_req.push_back(class_id);
  2328. f++;
  2329. }
  2330. i++;
  2331. }
  2332. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2333. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2334. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2335. if (spawn->IsPlayer())
  2336. ((Player*)spawn)->SetCharSheetChanged(true);
  2337. return 0;
  2338. }
  2339. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2340. if (!lua_interface)
  2341. return 0;
  2342. Spawn* spawn = lua_interface->GetSpawn(state);
  2343. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2344. if (!spawn) {
  2345. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2346. return 0;
  2347. }
  2348. if (!spawn->IsEntity()) {
  2349. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2350. return 0;
  2351. }
  2352. if (!luaspell || !luaspell->spell) {
  2353. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2354. return 0;
  2355. }
  2356. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2357. if (spawn->IsPlayer())
  2358. ((Player*)spawn)->SetCharSheetChanged(true);
  2359. return 0;
  2360. }
  2361. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2362. if (!lua_interface)
  2363. return 0;
  2364. Spawn* spawn = lua_interface->GetSpawn(state);
  2365. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2366. if (luaspell && luaspell->spell) {
  2367. ZoneServer* zone = nullptr;
  2368. if (luaspell->caster != nullptr)
  2369. zone = luaspell->caster->GetZone();
  2370. if(!zone && spawn) {
  2371. zone = spawn->GetZone(); // workaround to try to establish a zone to find the targets and remove the spells
  2372. }
  2373. Spawn* target = 0;
  2374. if(zone) {
  2375. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2376. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2377. target = zone->GetSpawnByID(luaspell->targets[i]);
  2378. if (target && target->IsEntity()) {
  2379. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2380. if (target->IsPlayer())
  2381. ((Player*)target)->SetCharSheetChanged(true);
  2382. }
  2383. }
  2384. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2385. }
  2386. else {
  2387. LogWrite(LUA__ERROR, 0, "LUA", "Error removing spell bonus buff %s called by %s, zone is not available.", luaspell->spell ? luaspell->spell->GetName() : "NotSet", spawn->GetName());
  2388. }
  2389. }
  2390. else if (spawn && spawn->IsEntity()) {
  2391. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2392. if (spawn->IsPlayer())
  2393. ((Player*)spawn)->SetCharSheetChanged(true);
  2394. }
  2395. return 0;
  2396. }
  2397. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2398. if (!lua_interface)
  2399. return 0;
  2400. Spawn* spawn = lua_interface->GetSpawn(state);
  2401. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2402. float value = lua_interface->GetFloatValue(state, 3);
  2403. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2404. if (value != 0) {
  2405. int32 spell_id = 0;
  2406. if (luaspell && luaspell->spell && luaspell->caster) {
  2407. if(luaspell->resisted) {
  2408. lua_interface->ResetFunctionStack(state);
  2409. return 0;
  2410. }
  2411. spell_id = luaspell->spell->GetSpellID();
  2412. ZoneServer* zone = luaspell->caster->GetZone();
  2413. Spawn* target = 0;
  2414. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2415. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2416. target = zone->GetSpawnByID(luaspell->targets[i]);
  2417. if (target && target->Alive()) {
  2418. if (target->IsPlayer()) {
  2419. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2420. Client* client = ((Player*)target)->GetClient();
  2421. if (client) {
  2422. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2423. if (packet)
  2424. client->QueuePacket(packet);
  2425. }
  2426. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2427. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2428. }
  2429. else if (target->IsNPC()) {
  2430. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2431. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2432. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2433. }
  2434. else
  2435. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2436. }
  2437. }
  2438. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2439. }
  2440. else if (spawn) {
  2441. if (spawn->IsPlayer()) {
  2442. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2443. Client* client = ((Player*)spawn)->GetClient();
  2444. if (client) {
  2445. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2446. if (packet)
  2447. client->QueuePacket(packet);
  2448. }
  2449. }
  2450. else if (spawn->IsNPC())
  2451. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2452. else
  2453. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2454. }
  2455. }
  2456. else
  2457. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2458. return 0;
  2459. }
  2460. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2461. if (!lua_interface)
  2462. return 0;
  2463. Spawn* spawn = lua_interface->GetSpawn(state);
  2464. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2465. if (spawn && spawn->IsPlayer()) {
  2466. int32 spell_id = 0;
  2467. if (luaspell && luaspell->spell && luaspell->caster) {
  2468. if(luaspell->resisted) {
  2469. lua_interface->ResetFunctionStack(state);
  2470. return 0;
  2471. }
  2472. spell_id = luaspell->spell->GetSpellID();
  2473. ZoneServer* zone = luaspell->caster->GetZone();
  2474. Spawn* target = 0;
  2475. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2476. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2477. target = zone->GetSpawnByID(luaspell->targets[i]);
  2478. if (target) {
  2479. if (target->IsPlayer()) {
  2480. ((Player*)target)->RemoveSkillBonus(spell_id);
  2481. Client* client = ((Player*)target)->GetClient();
  2482. if (client) {
  2483. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2484. if (packet)
  2485. client->QueuePacket(packet);
  2486. }
  2487. }
  2488. else if (target->IsNPC())
  2489. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2490. else
  2491. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2492. }
  2493. }
  2494. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2495. }
  2496. else if (spawn) {
  2497. if (spawn->IsPlayer()) {
  2498. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2499. Client* client = ((Player*)spawn)->GetClient();
  2500. if (client) {
  2501. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2502. if (packet)
  2503. client->QueuePacket(packet);
  2504. }
  2505. }
  2506. else if (spawn->IsNPC())
  2507. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2508. else
  2509. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2510. }
  2511. }
  2512. return 0;
  2513. }
  2514. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2515. if (!lua_interface)
  2516. return 0;
  2517. Spawn* spawn = lua_interface->GetSpawn(state);
  2518. int8 type = lua_interface->GetInt32Value(state, 2);
  2519. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2520. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2521. if(luaspell && luaspell->resisted) {
  2522. lua_interface->ResetFunctionStack(state);
  2523. return 0;
  2524. }
  2525. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2526. ZoneServer* zone = luaspell->caster->GetZone();
  2527. Spawn* target = 0;
  2528. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2529. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2530. target = zone->GetSpawnByID(luaspell->targets[i]);
  2531. if (target && target->IsEntity()) {
  2532. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2533. ((Entity*)target)->AddMezSpell(luaspell);
  2534. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2535. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2536. if (target->IsNPC())
  2537. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2538. }
  2539. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2540. ((Entity*)target)->AddStifleSpell(luaspell);
  2541. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2542. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2543. if (target->IsNPC())
  2544. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2545. }
  2546. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2547. ((Entity*)target)->AddDazeSpell(luaspell);
  2548. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2549. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2550. if (target->IsNPC())
  2551. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2552. }
  2553. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2554. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2555. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2556. ((Entity*)target)->AddStunSpell(luaspell);
  2557. if (target->IsNPC())
  2558. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2559. }
  2560. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2561. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2562. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2563. ((Entity*)target)->AddRootSpell(luaspell);
  2564. if (target->IsNPC())
  2565. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2566. }
  2567. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2568. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2569. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2570. ((Entity*)target)->AddFearSpell(luaspell);
  2571. if (target->IsNPC())
  2572. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2573. }
  2574. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2575. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2576. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2577. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2578. }
  2579. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2580. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2581. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2582. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2583. }
  2584. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2585. ((Entity*)target)->AddSnareSpell(luaspell);
  2586. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2587. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2588. if (target->IsNPC())
  2589. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2590. }
  2591. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2592. ((Entity*)target)->AddFlightSpell(luaspell);
  2593. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2594. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2595. }
  2596. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2597. ((Entity*)target)->AddGlideSpell(luaspell);
  2598. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2599. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2600. }
  2601. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2602. ((Entity*)target)->AddSafefallSpell(luaspell);
  2603. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2604. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2605. }
  2606. else
  2607. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2608. }
  2609. else
  2610. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2611. }
  2612. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2613. }
  2614. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2615. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2616. ((Entity*)spawn)->AddMezSpell(luaspell);
  2617. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2618. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2619. }
  2620. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2621. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2622. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2623. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2624. }
  2625. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2626. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2627. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2628. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2629. }
  2630. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2631. ((Entity*)spawn)->AddStunSpell(luaspell);
  2632. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2633. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2634. }
  2635. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2636. ((Entity*)spawn)->AddRootSpell(luaspell);
  2637. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2638. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2639. }
  2640. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2641. ((Entity*)spawn)->AddFearSpell(luaspell);
  2642. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2643. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2644. }
  2645. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2646. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2647. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2648. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2649. }
  2650. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2651. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2652. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2653. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2654. }
  2655. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2656. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2657. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2658. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2659. }
  2660. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2661. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2662. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2663. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2664. }
  2665. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2666. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2667. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2668. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2669. }
  2670. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2671. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2672. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2673. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2674. }
  2675. else
  2676. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2677. }
  2678. else
  2679. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2680. return 0;
  2681. }
  2682. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2683. if (!lua_interface)
  2684. return 0;
  2685. Spawn* spawn = lua_interface->GetSpawn(state);
  2686. int8 type = lua_interface->GetInt8Value(state, 2);
  2687. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2688. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2689. if (spawn && spawn->IsEntity()) {
  2690. if (!only_remove_spawn && luaspell && luaspell->spell && luaspell->caster) {
  2691. ZoneServer* zone = luaspell->caster->GetZone();
  2692. Spawn* target = 0;
  2693. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2694. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2695. target = zone->GetSpawnByID(luaspell->targets[i]);
  2696. if (target) {
  2697. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2698. ((Entity*)target)->RemoveMezSpell(luaspell);
  2699. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2700. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2701. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2702. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2703. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2704. ((Entity*)target)->RemoveStunSpell(luaspell);
  2705. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2706. ((Entity*)target)->RemoveRootSpell(luaspell);
  2707. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2708. ((Entity*)target)->RemoveFearSpell(luaspell);
  2709. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2710. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2711. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2712. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2713. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2714. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2715. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2716. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2717. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2718. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2719. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2720. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2721. else
  2722. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2723. }
  2724. }
  2725. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2726. }
  2727. else if (only_remove_spawn) {
  2728. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2729. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2730. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2731. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2732. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2733. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2734. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2735. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2736. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2737. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2738. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2739. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2740. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2741. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2742. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2743. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2744. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2745. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2746. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2747. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2748. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2749. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2750. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2751. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2752. else
  2753. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2754. }
  2755. }
  2756. return 0;
  2757. }
  2758. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2759. if (!lua_interface)
  2760. return 0;
  2761. Spawn* spawn = lua_interface->GetSpawn(state);
  2762. int8 type = lua_interface->GetInt8Value(state, 2);
  2763. bool hasEffect = false;
  2764. if (!spawn)
  2765. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2766. else if (!spawn->IsEntity())
  2767. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2768. else if (type < CONTROL_MAX_EFFECTS)
  2769. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2770. else
  2771. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2772. lua_interface->SetBooleanValue(state, hasEffect);
  2773. return 1;
  2774. }
  2775. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2776. if (!lua_interface)
  2777. return 0;
  2778. Spawn* spawn = lua_interface->GetSpawn(state);
  2779. float distance = 0.0f;
  2780. if (!spawn)
  2781. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2782. else if (!spawn->IsNPC())
  2783. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2784. else
  2785. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2786. lua_interface->SetFloatValue(state, distance);
  2787. return 1;
  2788. }
  2789. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2790. if (!lua_interface)
  2791. return 0;
  2792. Spawn* spawn = lua_interface->GetSpawn(state);
  2793. float distance = 0.0f;
  2794. if (!spawn)
  2795. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2796. else if (!spawn->IsNPC())
  2797. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2798. else
  2799. distance = ((NPC*)spawn)->GetAggroRadius();
  2800. lua_interface->SetFloatValue(state, distance);
  2801. return 1;
  2802. }
  2803. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2804. if (!lua_interface)
  2805. return 0;
  2806. Spawn* spawn = lua_interface->GetSpawn(state);
  2807. float distance = lua_interface->GetFloatValue(state, 2);
  2808. bool override = lua_interface->GetBooleanValue(state, 3);
  2809. bool result = false;
  2810. lua_interface->ResetFunctionStack(state);
  2811. if (!spawn)
  2812. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2813. else if (!spawn->IsNPC())
  2814. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2815. else
  2816. {
  2817. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2818. result = true;
  2819. }
  2820. lua_interface->SetBooleanValue(state, result);
  2821. return 1;
  2822. }
  2823. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2824. if (!lua_interface)
  2825. return 0;
  2826. Spawn* spawn = lua_interface->GetSpawn(state);
  2827. int16 value = lua_interface->GetInt16Value(state, 2);
  2828. if (spawn && spawn->IsEntity()) {
  2829. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2830. if (spawn->IsPlayer())
  2831. ((Player*)spawn)->SetCharSheetChanged(true);
  2832. }
  2833. return 0;
  2834. }
  2835. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2836. if (!lua_interface)
  2837. return 0;
  2838. Spawn* spawn = lua_interface->GetSpawn(state);
  2839. int16 value = lua_interface->GetInt16Value(state, 2);
  2840. if (spawn && spawn->IsEntity()) {
  2841. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2842. if (spawn->IsPlayer())
  2843. ((Player*)spawn)->SetCharSheetChanged(true);
  2844. }
  2845. return 0;
  2846. }
  2847. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2848. if (!lua_interface)
  2849. return 0;
  2850. Spawn* spawn = lua_interface->GetSpawn(state);
  2851. int16 value = lua_interface->GetInt16Value(state, 2);
  2852. if (spawn && spawn->IsEntity()) {
  2853. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2854. if (spawn->IsPlayer())
  2855. ((Player*)spawn)->SetCharSheetChanged(true);
  2856. }
  2857. return 0;
  2858. }
  2859. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2860. if (!lua_interface)
  2861. return 0;
  2862. Spawn* spawn = lua_interface->GetSpawn(state);
  2863. int16 value = lua_interface->GetInt16Value(state, 2);
  2864. if (spawn && spawn->IsEntity()) {
  2865. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2866. if (spawn->IsPlayer())
  2867. ((Player*)spawn)->SetCharSheetChanged(true);
  2868. }
  2869. return 0;
  2870. }
  2871. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2872. if (!lua_interface)
  2873. return 0;
  2874. Spawn* spawn = lua_interface->GetSpawn(state);
  2875. int16 value = lua_interface->GetInt16Value(state, 2);
  2876. if (spawn && spawn->IsEntity()) {
  2877. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2878. if (spawn->IsPlayer())
  2879. ((Player*)spawn)->SetCharSheetChanged(true);
  2880. }
  2881. return 0;
  2882. }
  2883. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2884. if (!lua_interface)
  2885. return 0;
  2886. Spawn* spawn = lua_interface->GetSpawn(state);
  2887. int8 value = lua_interface->GetInt8Value(state, 2);
  2888. if (spawn && spawn->IsEntity()) {
  2889. ((Entity*)spawn)->SetDeity(value);
  2890. if (spawn->IsPlayer())
  2891. ((Player*)spawn)->SetCharSheetChanged(true);
  2892. }
  2893. lua_interface->ResetFunctionStack(state);
  2894. return 0;
  2895. }
  2896. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2897. if (!lua_interface)
  2898. return 0;
  2899. Spawn* spawn = lua_interface->GetSpawn(state);
  2900. if (spawn && spawn->IsEntity()) {
  2901. int8 deity = ((Entity*)spawn)->GetDeity();
  2902. lua_interface->SetInt32Value(state, deity);
  2903. return 1;
  2904. }
  2905. return 0;
  2906. }
  2907. int EQ2Emu_lua_SetInt(lua_State* state) {
  2908. if (!lua_interface)
  2909. return 0;
  2910. Spawn* spawn = lua_interface->GetSpawn(state);
  2911. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2912. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2913. if (spawn && spawn->IsEntity()) {
  2914. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_INT, value);
  2915. if (spawn->IsPlayer())
  2916. ((Player*)spawn)->SetCharSheetChanged(true);
  2917. }
  2918. return 0;
  2919. }
  2920. int EQ2Emu_lua_SetWis(lua_State* state) {
  2921. if (!lua_interface)
  2922. return 0;
  2923. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2924. Spawn* spawn = lua_interface->GetSpawn(state);
  2925. float value = lua_interface->GetFloatValue(state, 2);
  2926. if (spawn && spawn->IsEntity()) {
  2927. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_WIS, value);
  2928. if (spawn->IsPlayer())
  2929. ((Player*)spawn)->SetCharSheetChanged(true);
  2930. }
  2931. return 0;
  2932. }
  2933. int EQ2Emu_lua_SetSta(lua_State* state) {
  2934. if (!lua_interface)
  2935. return 0;
  2936. Spawn* spawn = lua_interface->GetSpawn(state);
  2937. float value = lua_interface->GetFloatValue(state, 2);
  2938. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2939. if (spawn && spawn->IsEntity()) {
  2940. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STA, value);
  2941. if (spawn->IsPlayer())
  2942. ((Player*)spawn)->SetCharSheetChanged(true);
  2943. }
  2944. return 0;
  2945. }
  2946. int EQ2Emu_lua_SetStr(lua_State* state) {
  2947. if (!lua_interface)
  2948. return 0;
  2949. Spawn* spawn = lua_interface->GetSpawn(state);
  2950. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2951. float value = lua_interface->GetFloatValue(state, 2);
  2952. if (spawn && spawn->IsEntity()) {
  2953. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STR, value);
  2954. if (spawn->IsPlayer())
  2955. ((Player*)spawn)->SetCharSheetChanged(true);
  2956. }
  2957. return 0;
  2958. }
  2959. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2960. if (!lua_interface)
  2961. return 0;
  2962. Spawn* spawn = lua_interface->GetSpawn(state);
  2963. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2964. float value = lua_interface->GetFloatValue(state, 2);
  2965. if (spawn && spawn->IsEntity()) {
  2966. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_AGI, value);
  2967. if (spawn->IsPlayer())
  2968. ((Player*)spawn)->SetCharSheetChanged(true);
  2969. }
  2970. return 0;
  2971. }
  2972. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2973. if (!lua_interface)
  2974. return 0;
  2975. Spawn* spawn = lua_interface->GetSpawn(state);
  2976. if (spawn) {
  2977. lua_interface->SetInt32Value(state, spawn->GetHP());
  2978. return 1;
  2979. }
  2980. return 0;
  2981. }
  2982. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2983. if (!lua_interface)
  2984. return 0;
  2985. Spawn* spawn = lua_interface->GetSpawn(state);
  2986. if (spawn) {
  2987. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2988. return 1;
  2989. }
  2990. return 0;
  2991. }
  2992. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2993. if (!lua_interface)
  2994. return 0;
  2995. Spawn* spawn = lua_interface->GetSpawn(state);
  2996. if (spawn) {
  2997. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2998. return 1;
  2999. }
  3000. return 0;
  3001. }
  3002. int EQ2Emu_lua_GetName(lua_State* state) {
  3003. if (!lua_interface)
  3004. return 0;
  3005. Spawn* spawn = lua_interface->GetSpawn(state);
  3006. if (spawn) {
  3007. lua_interface->SetStringValue(state, spawn->GetName());
  3008. return 1;
  3009. }
  3010. return 0;
  3011. }
  3012. int EQ2Emu_lua_GetLevel(lua_State* state) {
  3013. Spawn* spawn = lua_interface->GetSpawn(state);
  3014. if (spawn) {
  3015. lua_interface->SetInt32Value(state, spawn->GetLevel());
  3016. return 1;
  3017. }
  3018. return 0;
  3019. }
  3020. int EQ2Emu_lua_GetDifficulty(lua_State* state) {
  3021. Spawn* spawn = lua_interface->GetSpawn(state);
  3022. if (spawn) {
  3023. lua_interface->SetInt32Value(state, spawn->GetDifficulty());
  3024. return 1;
  3025. }
  3026. return 0;
  3027. }
  3028. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  3029. if (!lua_interface)
  3030. return 0;
  3031. Spawn* spawn = lua_interface->GetSpawn(state);
  3032. if (spawn) {
  3033. lua_interface->SetInt32Value(state, spawn->GetPower());
  3034. return 1;
  3035. }
  3036. return 0;
  3037. }
  3038. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  3039. if (!lua_interface)
  3040. return 0;
  3041. Spawn* spawn = lua_interface->GetSpawn(state);
  3042. if (spawn) {
  3043. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  3044. return 1;
  3045. }
  3046. return 0;
  3047. }
  3048. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  3049. if (!lua_interface)
  3050. return 0;
  3051. Spawn* spawn = lua_interface->GetSpawn(state);
  3052. if (spawn) {
  3053. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  3054. return 1;
  3055. }
  3056. return 0;
  3057. }
  3058. int EQ2Emu_lua_GetDistance(lua_State* state) {
  3059. if (!lua_interface)
  3060. return 0;
  3061. Spawn* spawn = lua_interface->GetSpawn(state);
  3062. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  3063. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  3064. if (spawn && spawn2) {
  3065. float distance = spawn->GetDistance(spawn2, false, include_radius);
  3066. lua_interface->SetFloatValue(state, distance);
  3067. return 1;
  3068. }
  3069. return 0;
  3070. }
  3071. int EQ2Emu_lua_GetX(lua_State* state) {
  3072. if (!lua_interface)
  3073. return 0;
  3074. Spawn* spawn = lua_interface->GetSpawn(state);
  3075. if (spawn) {
  3076. lua_interface->SetFloatValue(state, spawn->GetX());
  3077. return 1;
  3078. }
  3079. return 0;
  3080. }
  3081. int EQ2Emu_lua_GetY(lua_State* state) {
  3082. if (!lua_interface)
  3083. return 0;
  3084. Spawn* spawn = lua_interface->GetSpawn(state);
  3085. if (spawn) {
  3086. lua_interface->SetFloatValue(state, spawn->GetY());
  3087. return 1;
  3088. }
  3089. return 0;
  3090. }
  3091. int EQ2Emu_lua_GetZ(lua_State* state) {
  3092. if (!lua_interface)
  3093. return 0;
  3094. Spawn* spawn = lua_interface->GetSpawn(state);
  3095. if (spawn) {
  3096. lua_interface->SetFloatValue(state, spawn->GetZ());
  3097. return 1;
  3098. }
  3099. return 0;
  3100. }
  3101. int EQ2Emu_lua_GetHeading(lua_State* state) {
  3102. if (!lua_interface)
  3103. return 0;
  3104. Spawn* spawn = lua_interface->GetSpawn(state);
  3105. if (spawn) {
  3106. lua_interface->SetFloatValue(state, spawn->GetHeading());
  3107. return 1;
  3108. }
  3109. return 0;
  3110. }
  3111. int EQ2Emu_lua_GetModelType(lua_State* state) {
  3112. if (!lua_interface)
  3113. return 0;
  3114. Spawn* spawn = lua_interface->GetSpawn(state);
  3115. if (spawn) {
  3116. lua_interface->SetInt32Value(state, spawn->GetModelType());
  3117. return 1;
  3118. }
  3119. return 0;
  3120. }
  3121. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  3122. if (!lua_interface)
  3123. return 0;
  3124. Spawn* spawn = lua_interface->GetSpawn(state);
  3125. if (spawn) {
  3126. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  3127. return 1;
  3128. }
  3129. return 0;
  3130. }
  3131. int EQ2Emu_lua_HasMoved(lua_State* state) {
  3132. if (!lua_interface)
  3133. return 0;
  3134. Spawn* spawn = lua_interface->GetSpawn(state);
  3135. if (spawn && spawn->IsEntity()) {
  3136. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  3137. return 1;
  3138. }
  3139. return 0;
  3140. }
  3141. int EQ2Emu_lua_GetInt(lua_State* state) {
  3142. if (!lua_interface)
  3143. return 0;
  3144. Spawn* spawn = lua_interface->GetSpawn(state);
  3145. if (spawn && spawn->IsEntity()) {
  3146. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  3147. return 1;
  3148. }
  3149. return 0;
  3150. }
  3151. int EQ2Emu_lua_GetWis(lua_State* state) {
  3152. if (!lua_interface)
  3153. return 0;
  3154. Spawn* spawn = lua_interface->GetSpawn(state);
  3155. if (spawn && spawn->IsEntity()) {
  3156. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  3157. return 1;
  3158. }
  3159. return 0;
  3160. }
  3161. int EQ2Emu_lua_GetSta(lua_State* state) {
  3162. if (!lua_interface)
  3163. return 0;
  3164. Spawn* spawn = lua_interface->GetSpawn(state);
  3165. if (spawn && spawn->IsEntity()) {
  3166. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  3167. return 1;
  3168. }
  3169. return 0;
  3170. }
  3171. int EQ2Emu_lua_GetStr(lua_State* state) {
  3172. if (!lua_interface)
  3173. return 0;
  3174. Spawn* spawn = lua_interface->GetSpawn(state);
  3175. if (spawn && spawn->IsEntity()) {
  3176. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3177. return 1;
  3178. }
  3179. return 0;
  3180. }
  3181. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3182. if (!lua_interface)
  3183. return 0;
  3184. Spawn* spawn = lua_interface->GetSpawn(state);
  3185. if (spawn && spawn->IsEntity()) {
  3186. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3187. return 1;
  3188. }
  3189. return 0;
  3190. }
  3191. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3192. if (!lua_interface)
  3193. return 0;
  3194. Spawn* spawn = lua_interface->GetSpawn(state);
  3195. if (spawn && spawn->IsEntity()) {
  3196. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3197. return 1;
  3198. }
  3199. return 0;
  3200. }
  3201. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3202. if (!lua_interface)
  3203. return 0;
  3204. Spawn* spawn = lua_interface->GetSpawn(state);
  3205. if (spawn && spawn->IsEntity()) {
  3206. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3207. return 1;
  3208. }
  3209. return 0;
  3210. }
  3211. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3212. if (!lua_interface)
  3213. return 0;
  3214. Spawn* spawn = lua_interface->GetSpawn(state);
  3215. if (spawn && spawn->IsEntity()) {
  3216. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3217. return 1;
  3218. }
  3219. return 0;
  3220. }
  3221. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3222. if (!lua_interface)
  3223. return 0;
  3224. Spawn* spawn = lua_interface->GetSpawn(state);
  3225. if (spawn && spawn->IsEntity()) {
  3226. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3227. return 1;
  3228. }
  3229. return 0;
  3230. }
  3231. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3232. if (!lua_interface)
  3233. return 0;
  3234. Spawn* spawn = lua_interface->GetSpawn(state);
  3235. if (spawn && spawn->IsEntity()) {
  3236. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3237. return 1;
  3238. }
  3239. return 0;
  3240. }
  3241. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3242. if (!lua_interface)
  3243. return 0;
  3244. Spawn* player = lua_interface->GetSpawn(state);
  3245. if (!player || !player->IsPlayer()) {
  3246. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3247. return 0;
  3248. }
  3249. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3250. if (quest_id <= 0) {
  3251. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3252. return 0;
  3253. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3254. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3255. return 0;
  3256. }
  3257. int32 step = lua_interface->GetInt32Value(state, 3);
  3258. if (step > 0) {
  3259. Client* client = ((Player*)player)->GetClient();
  3260. if (client)
  3261. client->AddPendingQuestUpdate(quest_id, step);
  3262. } else {
  3263. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3264. }
  3265. return 0;
  3266. }
  3267. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3268. Spawn* player = lua_interface->GetSpawn(state);
  3269. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3270. int32 step = lua_interface->GetInt32Value(state, 3);
  3271. int32 progress = lua_interface->GetInt32Value(state, 4);
  3272. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3273. Client* client = ((Player*)player)->GetClient();
  3274. if (client)
  3275. client->AddPendingQuestUpdate(quest_id, step, progress);
  3276. }
  3277. return 0;
  3278. }
  3279. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3280. if (!lua_interface)
  3281. return 0;
  3282. Spawn* player = lua_interface->GetSpawn(state);
  3283. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3284. if (player && player->IsPlayer() && quest_id > 0) {
  3285. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3286. return 1;
  3287. }
  3288. return 0;
  3289. }
  3290. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3291. if (!lua_interface)
  3292. return 0;
  3293. Spawn* player = lua_interface->GetSpawn(state);
  3294. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3295. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3296. if (player && player->IsPlayer() && quest_id > 0) {
  3297. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3298. return 1;
  3299. }
  3300. return 0;
  3301. }
  3302. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3303. if (!lua_interface)
  3304. return 0;
  3305. Spawn* player = lua_interface->GetSpawn(state);
  3306. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3307. if (player && player->IsPlayer() && quest_id > 0) {
  3308. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3309. return 1;
  3310. }
  3311. return 0;
  3312. }
  3313. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3314. if (!lua_interface)
  3315. return 0;
  3316. Quest* quest = lua_interface->GetQuest(state);
  3317. string name = lua_interface->GetStringValue(state, 2);
  3318. string type = lua_interface->GetStringValue(state, 3);
  3319. string zone = lua_interface->GetStringValue(state, 4);
  3320. int16 level = lua_interface->GetInt16Value(state, 5);
  3321. string description = lua_interface->GetStringValue(state, 6);
  3322. bool load = true;
  3323. if (!quest) {
  3324. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3325. load = false;
  3326. }
  3327. if (load && name.length() == 0) {
  3328. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3329. load = false;
  3330. }
  3331. if (load && type.length() == 0) {
  3332. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3333. load = false;
  3334. }
  3335. if (load && zone.length() == 0) {
  3336. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3337. load = false;
  3338. }
  3339. if (load && description.length() == 0) {
  3340. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3341. load = false;
  3342. }
  3343. if (load && level == 0) {
  3344. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3345. load = false;
  3346. }
  3347. if (load)
  3348. quest->RegisterQuest(name, type, zone, level, description);
  3349. return 0;
  3350. }
  3351. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3352. if (!lua_interface)
  3353. return 0;
  3354. Quest* quest = lua_interface->GetQuest(state);
  3355. if (quest) {
  3356. int8 level = lua_interface->GetInt16Value(state, 2);
  3357. quest->SetPrereqLevel(level);
  3358. }
  3359. return 0;
  3360. }
  3361. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3362. if (!lua_interface)
  3363. return 0;
  3364. Quest* quest = lua_interface->GetQuest(state);
  3365. if (quest) {
  3366. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3367. quest->AddPrereqQuest(quest_id);
  3368. }
  3369. return 0;
  3370. }
  3371. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3372. if (!lua_interface)
  3373. return 0;
  3374. Quest* quest = lua_interface->GetQuest(state);
  3375. if (quest) {
  3376. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3377. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3378. if (quantity == 0)
  3379. quantity = 1;
  3380. Item* master_item = master_item_list.GetItem(item_id);
  3381. if (master_item) {
  3382. Item* item = new Item(master_item);
  3383. item->details.count = quantity;
  3384. quest->AddPrereqItem(item);
  3385. }
  3386. }
  3387. return 0;
  3388. }
  3389. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3390. if (!lua_interface)
  3391. return 0;
  3392. Spawn* player = lua_interface->GetSpawn(state);
  3393. if(!player || !player->IsPlayer()) {
  3394. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3395. return 0;
  3396. }
  3397. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3398. if (quest_id > 0) {
  3399. lua_interface->SetBooleanValue(state, (((Player*)player)->HasActiveQuest(quest_id) == TRUE));
  3400. return 1;
  3401. } else {
  3402. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3403. }
  3404. return 0;
  3405. }
  3406. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3407. if (!lua_interface)
  3408. return 0;
  3409. Quest* quest = lua_interface->GetQuest(state);
  3410. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3411. lua_interface->ResetFunctionStack(state);
  3412. if (quest && spawn_id > 0)
  3413. quest->SetQuestReturnNPC(spawn_id);
  3414. return 0;
  3415. }
  3416. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3417. if (!lua_interface)
  3418. return 0;
  3419. Spawn* spawn = lua_interface->GetSpawn(state);
  3420. int32 time = lua_interface->GetInt32Value(state, 2);
  3421. string function = lua_interface->GetStringValue(state, 3);
  3422. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3423. Spawn* player = lua_interface->GetSpawn(state, 5);
  3424. lua_interface->ResetFunctionStack(state);
  3425. if (!spawn) {
  3426. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3427. return 0;
  3428. }
  3429. if (time <= 0) {
  3430. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3431. return 0;
  3432. }
  3433. if (function.length() == 0) {
  3434. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3435. return 0;
  3436. }
  3437. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3438. if ( time < 10)
  3439. time = 10;
  3440. timer->timer = Timer::GetCurrentTime2() + time;
  3441. timer->function = function;
  3442. timer->spawn = spawn->GetID();
  3443. timer->player = player ? player->GetID() : 0;
  3444. if (max_count == 0)
  3445. max_count = 1;
  3446. timer->max_count = max_count;
  3447. timer->current_count = 0;
  3448. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3449. return 0;
  3450. }
  3451. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3452. if (!lua_interface)
  3453. return 0;
  3454. Spawn* spawn = lua_interface->GetSpawn(state);
  3455. string function = lua_interface->GetStringValue(state, 2);
  3456. lua_interface->ResetFunctionStack(state);
  3457. if (!spawn) {
  3458. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3459. return 0;
  3460. }
  3461. if(!spawn->GetZone()) {
  3462. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3463. return 0;
  3464. }
  3465. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3466. return 0;
  3467. }
  3468. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3469. if (!lua_interface)
  3470. return 0;
  3471. Spawn* player = lua_interface->GetSpawn(state);
  3472. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3473. lua_interface->ResetFunctionStack(state);
  3474. if (player && player->IsPlayer() && quest_id > 0) {
  3475. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3476. return 1;
  3477. }
  3478. return 0;
  3479. }
  3480. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3481. if (!lua_interface)
  3482. return 0;
  3483. Spawn* player = lua_interface->GetSpawn(state);
  3484. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3485. lua_interface->ResetFunctionStack(state);
  3486. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3487. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3488. if (quest)
  3489. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3490. return 1;
  3491. }
  3492. return 0;
  3493. }
  3494. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3495. if (!lua_interface)
  3496. return 0;
  3497. Spawn* player = lua_interface->GetSpawn(state);
  3498. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3499. lua_interface->ResetFunctionStack(state);
  3500. if (player && player->IsPlayer() && quest_id > 0) {
  3501. lua_interface->SetBooleanValue(state, (((Player*)player)->HasQuestBeenCompleted(quest_id) != 0));
  3502. return 1;
  3503. }
  3504. return 0;
  3505. }
  3506. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3507. if (!lua_interface)
  3508. return 0;
  3509. Spawn* npc = lua_interface->GetSpawn(state);
  3510. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3511. lua_interface->ResetFunctionStack(state);
  3512. if (npc && !npc->IsPlayer() && quest_id > 0)
  3513. npc->AddProvidedQuest(quest_id);
  3514. return 0;
  3515. }
  3516. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3517. if (!lua_interface)
  3518. return 0;
  3519. Spawn* npc = lua_interface->GetSpawn(state);
  3520. Spawn* player = lua_interface->GetSpawn(state, 2);
  3521. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3522. bool forced = lua_interface->GetBooleanValue(state, 4);
  3523. lua_interface->ResetFunctionStack(state);
  3524. /* NPC is allowed to be null */
  3525. if (player && player->IsPlayer() && quest_id > 0) {
  3526. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3527. if (master_quest) {
  3528. Client* client = ((Player*)player)->GetClient();
  3529. if (!client) {
  3530. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3531. }
  3532. Quest* quest = new Quest(master_quest);
  3533. if (!quest) {
  3534. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3535. }
  3536. if (client && quest) {
  3537. if (npc)
  3538. quest->SetQuestGiver(npc->GetDatabaseID());
  3539. else
  3540. quest->SetQuestGiver(0);
  3541. client->AddPendingQuest(quest, forced);
  3542. }
  3543. }
  3544. else {
  3545. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3546. }
  3547. }
  3548. else {
  3549. lua_interface->LogError("%s: LUA OfferQuest command error: player is not set or bad quest id %p %d", lua_interface->GetScriptName(state), player, quest_id);
  3550. }
  3551. return 0;
  3552. }
  3553. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3554. if (!lua_interface)
  3555. return 0;
  3556. Quest* quest = lua_interface->GetQuest(state);
  3557. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3558. lua_interface->ResetFunctionStack(state);
  3559. if (quest) {
  3560. quest->AddPrereqClass(class_id);
  3561. }
  3562. return 0;
  3563. }
  3564. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3565. if (!lua_interface)
  3566. return 0;
  3567. Quest* quest = lua_interface->GetQuest(state);
  3568. int8 race = lua_interface->GetInt8Value(state, 2);
  3569. lua_interface->ResetFunctionStack(state);
  3570. if (quest) {
  3571. quest->AddPrereqRace(race);
  3572. }
  3573. return 0;
  3574. }
  3575. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3576. if (!lua_interface)
  3577. return 0;
  3578. Quest* quest = lua_interface->GetQuest(state);
  3579. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3580. lua_interface->ResetFunctionStack(state);
  3581. if (quest) {
  3582. quest->AddPrereqModelType(model_type);
  3583. }
  3584. return 0;
  3585. }
  3586. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3587. if (!lua_interface)
  3588. return 0;
  3589. Quest* quest = lua_interface->GetQuest(state);
  3590. int8 level = lua_interface->GetInt8Value(state, 2);
  3591. lua_interface->ResetFunctionStack(state);
  3592. if (!quest) {
  3593. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3594. return 0;
  3595. }
  3596. quest->SetPrereqTSLevel(level);
  3597. return 0;
  3598. }
  3599. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3600. if (!lua_interface)
  3601. return 0;
  3602. Quest* quest = lua_interface->GetQuest(state);
  3603. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3604. lua_interface->ResetFunctionStack(state);
  3605. if (!quest) {
  3606. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3607. return 0;
  3608. }
  3609. quest->AddPrereqTradeskillClass(class_id);
  3610. return 0;
  3611. }
  3612. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3613. if (!lua_interface)
  3614. return 0;
  3615. Quest* quest = lua_interface->GetQuest(state);
  3616. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3617. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3618. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3619. lua_interface->ResetFunctionStack(state);
  3620. if (quest) {
  3621. quest->AddPrereqFaction(faction_id, min, max);
  3622. }
  3623. return 0;
  3624. }
  3625. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3626. if (!lua_interface)
  3627. return 0;
  3628. Quest* quest = lua_interface->GetQuest(state);
  3629. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3630. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3631. lua_interface->ResetFunctionStack(state);
  3632. if (quest) {
  3633. if (quantity == 0)
  3634. quantity = 1;
  3635. Item* master_item = master_item_list.GetItem(item_id);
  3636. if (master_item) {
  3637. Item* item = new Item(master_item);
  3638. item->details.count = quantity;
  3639. quest->AddSelectableRewardItem(item);
  3640. }
  3641. }
  3642. return 0;
  3643. }
  3644. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3645. if (!lua_interface)
  3646. return 0;
  3647. Quest* quest = lua_interface->GetQuest(state);
  3648. if (quest) {
  3649. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3650. vector<Item*>* items = quest->GetRewardItems();
  3651. if (items) {
  3652. vector<Item*>::iterator itr;
  3653. for (itr = items->begin(); itr != items->end(); itr++) {
  3654. if (*itr && (*itr)->details.item_id == item_id) {
  3655. lua_interface->SetBooleanValue(state, true);
  3656. return 1;
  3657. }
  3658. }
  3659. }
  3660. }
  3661. lua_interface->SetBooleanValue(state, false);
  3662. return 1;
  3663. }
  3664. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3665. if (!lua_interface)
  3666. return 0;
  3667. Quest* quest = lua_interface->GetQuest(state);
  3668. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3669. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3670. lua_interface->ResetFunctionStack(state);
  3671. if (quest) {
  3672. if (quantity == 0)
  3673. quantity = 1;
  3674. Item* master_item = master_item_list.GetItem(item_id);
  3675. if (master_item) {
  3676. Item* item = new Item(master_item);
  3677. item->details.count = quantity;
  3678. quest->AddRewardItem(item);
  3679. }
  3680. }
  3681. return 0;
  3682. }
  3683. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3684. if (!lua_interface)
  3685. return 0;
  3686. Quest* quest = lua_interface->GetQuest(state);
  3687. int32 copper = lua_interface->GetInt32Value(state, 2);
  3688. int32 silver = lua_interface->GetInt32Value(state, 3);
  3689. int32 gold = lua_interface->GetInt32Value(state, 4);
  3690. int32 plat = lua_interface->GetInt32Value(state, 5);
  3691. lua_interface->ResetFunctionStack(state);
  3692. if (quest) {
  3693. quest->AddRewardCoins(copper, silver, gold, plat);
  3694. }
  3695. return 0;
  3696. }
  3697. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3698. if (!lua_interface)
  3699. return 0;
  3700. Quest* quest = lua_interface->GetQuest(state);
  3701. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3702. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3703. lua_interface->ResetFunctionStack(state);
  3704. if (quest && faction_id > 0 && amount != 0)
  3705. quest->AddRewardFaction(faction_id, amount);
  3706. return 0;
  3707. }
  3708. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3709. if (!lua_interface)
  3710. return 0;
  3711. Quest* quest = lua_interface->GetQuest(state);
  3712. int32 status = lua_interface->GetInt32Value(state, 2);
  3713. lua_interface->ResetFunctionStack(state);
  3714. if (quest) {
  3715. quest->SetRewardStatus(status);
  3716. }
  3717. return 0;
  3718. }
  3719. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3720. if (!lua_interface)
  3721. return 0;
  3722. Quest* quest = lua_interface->GetQuest(state);
  3723. int32 status = lua_interface->GetInt32Value(state, 2);
  3724. lua_interface->ResetFunctionStack(state);
  3725. if (quest) {
  3726. quest->SetStatusTmpReward(status);
  3727. }
  3728. return 0;
  3729. }
  3730. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3731. if (!lua_interface)
  3732. return 0;
  3733. Quest* quest = lua_interface->GetQuest(state);
  3734. int64 coins = lua_interface->GetInt64Value(state, 2);
  3735. lua_interface->ResetFunctionStack(state);
  3736. if (quest) {
  3737. quest->SetCoinTmpReward(coins);
  3738. }
  3739. return 0;
  3740. }
  3741. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3742. if (!lua_interface)
  3743. return 0;
  3744. Quest* quest = lua_interface->GetQuest(state);
  3745. string comment = lua_interface->GetStringValue(state, 2);
  3746. lua_interface->ResetFunctionStack(state);
  3747. if (quest) {
  3748. quest->SetRewardComment(comment);
  3749. }
  3750. return 0;
  3751. }
  3752. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3753. if (!lua_interface)
  3754. return 0;
  3755. Quest* quest = lua_interface->GetQuest(state);
  3756. int32 exp = lua_interface->GetInt32Value(state, 2);
  3757. lua_interface->ResetFunctionStack(state);
  3758. if (quest) {
  3759. quest->SetRewardXP(exp);
  3760. }
  3761. return 0;
  3762. }
  3763. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3764. Quest* quest = lua_interface->GetQuest(state);
  3765. int32 step = lua_interface->GetInt32Value(state, 2);
  3766. string description = lua_interface->GetStringValue(state, 3);
  3767. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3768. float percentage = lua_interface->GetFloatValue(state, 5);
  3769. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3770. int16 icon = lua_interface->GetInt16Value(state, 7);
  3771. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3772. if (quest) {
  3773. const char* taskgroup = 0;
  3774. if (str_taskgroup.length() > 0)
  3775. taskgroup = str_taskgroup.c_str();
  3776. int32 id = 0;
  3777. vector<int32>* ids = 0;
  3778. int i = 0;
  3779. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3780. if (ids == 0)
  3781. ids = new vector<int32>;
  3782. ids->push_back(id);
  3783. i++;
  3784. }
  3785. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3786. if (quest_step && icon && quantity > 0)
  3787. quest_step->SetIcon(icon);
  3788. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3789. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3790. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3791. }
  3792. }
  3793. lua_interface->ResetFunctionStack(state);
  3794. return 0;
  3795. }
  3796. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3797. {
  3798. if (!lua_interface)
  3799. return 0;
  3800. Quest* quest = lua_interface->GetQuest(state);
  3801. int32 step = lua_interface->GetInt32Value(state, 2);
  3802. string description = lua_interface->GetStringValue(state, 3);
  3803. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3804. float percentage = lua_interface->GetFloatValue(state, 5);
  3805. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3806. int16 icon = lua_interface->GetInt16Value(state, 7);
  3807. if (quest) {
  3808. const char* taskgroup = 0;
  3809. if (str_taskgroup.length() > 0)
  3810. taskgroup = str_taskgroup.c_str();
  3811. int32 id = 0;
  3812. vector<int32>* ids = 0;
  3813. int i = 0;
  3814. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3815. if (ids == 0)
  3816. ids = new vector<int32>;
  3817. ids->push_back(id);
  3818. i++;
  3819. }
  3820. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3821. if (quest_step && icon > 0 && quantity > 0)
  3822. quest_step->SetIcon(icon);
  3823. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3824. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3825. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3826. }
  3827. safe_delete(ids);
  3828. }
  3829. lua_interface->ResetFunctionStack(state);
  3830. return 0;
  3831. }
  3832. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3833. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3834. }
  3835. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3836. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3837. }
  3838. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3839. if (!lua_interface)
  3840. return 0;
  3841. Quest* quest = lua_interface->GetQuest(state);
  3842. int32 step = lua_interface->GetInt32Value(state, 2);
  3843. string description = lua_interface->GetStringValue(state, 3);
  3844. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3845. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3846. int16 icon = lua_interface->GetInt16Value(state, 6);
  3847. if (quest) {
  3848. const char* taskgroup = 0;
  3849. if (str_taskgroup.length() > 0)
  3850. taskgroup = str_taskgroup.c_str();
  3851. int32 npc_id = 0;
  3852. vector<int32>* ids = 0;
  3853. int i = 0;
  3854. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3855. if (ids == 0)
  3856. ids = new vector<int32>;
  3857. ids->push_back(npc_id);
  3858. i++;
  3859. }
  3860. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3861. if (quest_step && icon > 0)
  3862. quest_step->SetIcon(icon);
  3863. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3864. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3865. if(client)
  3866. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3867. }
  3868. safe_delete(ids);
  3869. }
  3870. lua_interface->ResetFunctionStack(state);
  3871. return 0;
  3872. }
  3873. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3874. if (!lua_interface)
  3875. return 0;
  3876. Quest* quest = lua_interface->GetQuest(state);
  3877. int32 step = lua_interface->GetInt32Value(state, 2);
  3878. string description = lua_interface->GetStringValue(state, 3);
  3879. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3880. float percentage = lua_interface->GetFloatValue(state, 5);
  3881. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3882. int16 icon = lua_interface->GetInt16Value(state, 7);
  3883. if (quest) {
  3884. const char* taskgroup = 0;
  3885. if (str_taskgroup.length() > 0)
  3886. taskgroup = str_taskgroup.c_str();
  3887. int32 item_id = 0;
  3888. vector<int32>* ids = 0;
  3889. int i = 0;
  3890. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3891. if (ids == 0)
  3892. ids = new vector<int32>;
  3893. ids->push_back(item_id);
  3894. i++;
  3895. }
  3896. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3897. if (quest_step && icon > 0 && quantity > 0)
  3898. quest_step->SetIcon(icon);
  3899. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3900. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3901. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3902. }
  3903. safe_delete(ids);
  3904. }
  3905. lua_interface->ResetFunctionStack(state);
  3906. return 0;
  3907. }
  3908. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3909. if (!lua_interface)
  3910. return 0;
  3911. Quest* quest = lua_interface->GetQuest(state);
  3912. int32 step = lua_interface->GetInt32Value(state, 2);
  3913. string description = lua_interface->GetStringValue(state, 3);
  3914. float max_variation = lua_interface->GetFloatValue(state, 4);
  3915. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3916. int16 icon = lua_interface->GetInt16Value(state, 6);
  3917. if (quest) {
  3918. const char* taskgroup = 0;
  3919. if (str_taskgroup.length() > 0)
  3920. taskgroup = str_taskgroup.c_str();
  3921. vector<Location>* locations = 0;
  3922. int8 i = 7;
  3923. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3924. while (true) {
  3925. Location loc;
  3926. loc.x = lua_interface->GetFloatValue(state, i);
  3927. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3928. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3929. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3930. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3931. break;
  3932. if (locations == 0)
  3933. locations = new vector<Location>;
  3934. locations->push_back(loc);
  3935. i += 4;
  3936. }
  3937. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3938. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3939. if (quest_step && icon > 0)
  3940. quest_step->SetIcon(icon);
  3941. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3942. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3943. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3944. }
  3945. }
  3946. lua_interface->ResetFunctionStack(state);
  3947. return 0;
  3948. }
  3949. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3950. if (!lua_interface)
  3951. return 0;
  3952. Quest* quest = lua_interface->GetQuest(state);
  3953. int32 step = lua_interface->GetInt32Value(state, 2);
  3954. string description = lua_interface->GetStringValue(state, 3);
  3955. float max_variation = lua_interface->GetFloatValue(state, 4);
  3956. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3957. int16 icon = lua_interface->GetInt16Value(state, 6);
  3958. if (quest) {
  3959. const char* taskgroup = 0;
  3960. if (str_taskgroup.length() > 0)
  3961. taskgroup = str_taskgroup.c_str();
  3962. vector<Location>* locations = 0;
  3963. int8 i = 7;
  3964. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3965. while (true) {
  3966. Location loc;
  3967. loc.x = lua_interface->GetFloatValue(state, i);
  3968. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3969. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3970. loc.zone_id = 0;
  3971. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3972. break;
  3973. if (locations == 0)
  3974. locations = new vector<Location>;
  3975. locations->push_back(loc);
  3976. i += 3;
  3977. }
  3978. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3979. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3980. if (quest_step && icon > 0)
  3981. quest_step->SetIcon(icon);
  3982. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3983. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3984. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3985. }
  3986. }
  3987. lua_interface->ResetFunctionStack(state);
  3988. return 0;
  3989. }
  3990. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3991. if (!lua_interface)
  3992. return 0;
  3993. Quest* quest = lua_interface->GetQuest(state);
  3994. int32 step = lua_interface->GetInt32Value(state, 2);
  3995. string description = lua_interface->GetStringValue(state, 3);
  3996. float max_variation = lua_interface->GetFloatValue(state, 4);
  3997. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3998. int16 icon = lua_interface->GetInt16Value(state, 6);
  3999. if (quest) {
  4000. const char* taskgroup = 0;
  4001. if (str_taskgroup.length() > 0)
  4002. taskgroup = str_taskgroup.c_str();
  4003. vector<Location>* locations = 0;
  4004. int i = 7;
  4005. while (true) {
  4006. Location loc;
  4007. loc.x = lua_interface->GetFloatValue(state, i);
  4008. loc.y = lua_interface->GetFloatValue(state, i + 1);
  4009. loc.z = lua_interface->GetFloatValue(state, i + 2);
  4010. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  4011. break;
  4012. if (locations == 0)
  4013. locations = new vector<Location>;
  4014. locations->push_back(loc);
  4015. i += 3;
  4016. }
  4017. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  4018. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  4019. if (quest_step && icon > 0)
  4020. quest_step->SetIcon(icon);
  4021. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4022. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4023. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4024. }
  4025. }
  4026. lua_interface->ResetFunctionStack(state);
  4027. return 0;
  4028. }
  4029. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  4030. Quest* quest = lua_interface->GetQuest(state);
  4031. int32 step = lua_interface->GetInt32Value(state, 2);
  4032. string description = lua_interface->GetStringValue(state, 3);
  4033. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4034. float percentage = lua_interface->GetFloatValue(state, 5);
  4035. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4036. int16 icon = lua_interface->GetInt16Value(state, 7);
  4037. if (quest) {
  4038. const char* taskgroup = 0;
  4039. if (str_taskgroup.length() > 0)
  4040. taskgroup = str_taskgroup.c_str();
  4041. int32 spell_id = 0;
  4042. vector<int32>* ids = 0;
  4043. int i = 0;
  4044. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4045. if (ids == 0)
  4046. ids = new vector<int32>;
  4047. ids->push_back(spell_id);
  4048. i++;
  4049. }
  4050. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4051. if (quest_step && icon > 0 && quantity > 0)
  4052. quest_step->SetIcon(icon);
  4053. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4054. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4055. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4056. }
  4057. safe_delete(ids);
  4058. }
  4059. lua_interface->ResetFunctionStack(state);
  4060. return 0;
  4061. }
  4062. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  4063. if (!lua_interface)
  4064. return 0;
  4065. Quest* quest = lua_interface->GetQuest(state);
  4066. int32 step = lua_interface->GetInt32Value(state, 2);
  4067. string description = lua_interface->GetStringValue(state, 3);
  4068. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4069. float percentage = lua_interface->GetFloatValue(state, 5);
  4070. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4071. int16 icon = lua_interface->GetInt16Value(state, 7);
  4072. if (quest) {
  4073. const char* taskgroup = 0;
  4074. if (str_taskgroup.length() > 0)
  4075. taskgroup = str_taskgroup.c_str();
  4076. int32 item_id = 0;
  4077. vector<int32>* ids = 0;
  4078. int i = 0;
  4079. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4080. if (ids == 0)
  4081. ids = new vector<int32>;
  4082. ids->push_back(item_id);
  4083. i++;
  4084. }
  4085. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4086. if (quest_step && icon > 0 && quantity > 0)
  4087. quest_step->SetIcon(icon);
  4088. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4089. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4090. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4091. }
  4092. safe_delete(ids);
  4093. }
  4094. lua_interface->ResetFunctionStack(state);
  4095. return 0;
  4096. }
  4097. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  4098. if (!lua_interface)
  4099. return 0;
  4100. Quest* quest = lua_interface->GetQuest(state);
  4101. int32 step = lua_interface->GetInt32Value(state, 2);
  4102. string description = lua_interface->GetStringValue(state, 3);
  4103. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4104. float percentage = lua_interface->GetFloatValue(state, 5);
  4105. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4106. int16 icon = lua_interface->GetInt16Value(state, 7);
  4107. if (quest) {
  4108. const char* taskgroup = 0;
  4109. if (str_taskgroup.length() > 0)
  4110. taskgroup = str_taskgroup.c_str();
  4111. int32 item_id = 0;
  4112. vector<int32>* ids = 0;
  4113. int i = 0;
  4114. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4115. if (ids == 0)
  4116. ids = new vector<int32>;
  4117. ids->push_back(item_id);
  4118. i++;
  4119. }
  4120. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4121. if (quest_step && icon > 0 && quantity > 0)
  4122. quest_step->SetIcon(icon);
  4123. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4124. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4125. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4126. }
  4127. safe_delete(ids);
  4128. }
  4129. lua_interface->ResetFunctionStack(state);
  4130. return 0;
  4131. }
  4132. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  4133. if (!lua_interface)
  4134. return 0;
  4135. Quest* quest = lua_interface->GetQuest(state);
  4136. string action = lua_interface->GetStringValue(state, 2);
  4137. lua_interface->ResetFunctionStack(state);
  4138. if (quest) {
  4139. if (action.length() > 0)
  4140. quest->SetCompleteAction(action);
  4141. }
  4142. return 0;
  4143. }
  4144. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  4145. if (!lua_interface)
  4146. return 0;
  4147. Quest* quest = lua_interface->GetQuest(state);
  4148. int32 step = lua_interface->GetInt32Value(state, 2);
  4149. string action = lua_interface->GetStringValue(state, 3);
  4150. lua_interface->ResetFunctionStack(state);
  4151. if (quest) {
  4152. if (step > 0 && action.length() > 0)
  4153. quest->AddCompleteAction(step, action);
  4154. }
  4155. return 0;
  4156. }
  4157. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  4158. if (!lua_interface)
  4159. return 0;
  4160. Quest* quest = lua_interface->GetQuest(state);
  4161. int32 step = lua_interface->GetInt32Value(state, 2);
  4162. string action = lua_interface->GetStringValue(state, 3);
  4163. lua_interface->ResetFunctionStack(state);
  4164. if (quest) {
  4165. if (step > 0 && action.length() > 0)
  4166. quest->AddProgressAction(step, action);
  4167. }
  4168. return 0;
  4169. }
  4170. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  4171. if (!lua_interface)
  4172. return 0;
  4173. Quest* quest = lua_interface->GetQuest(state);
  4174. string description = lua_interface->GetStringValue(state, 2);
  4175. lua_interface->ResetFunctionStack(state);
  4176. if (quest && description.length() > 0)
  4177. quest->SetDescription(description);
  4178. return 0;
  4179. }
  4180. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4181. if (!lua_interface)
  4182. return 0;
  4183. Quest* quest = lua_interface->GetQuest(state);
  4184. string description = lua_interface->GetStringValue(state, 2);
  4185. lua_interface->ResetFunctionStack(state);
  4186. if (quest && description.length() > 0)
  4187. quest->SetCompletedDescription(description);
  4188. return 0;
  4189. }
  4190. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4191. if (!lua_interface)
  4192. return 0;
  4193. Quest* quest = lua_interface->GetQuest(state);
  4194. int32 step = lua_interface->GetInt32Value(state, 2);
  4195. string description = lua_interface->GetStringValue(state, 3);
  4196. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4197. lua_interface->ResetFunctionStack(state);
  4198. if (quest && step > 0 && description.length() > 0) {
  4199. quest->SetTaskGroupDescription(step, description, display_bullets);
  4200. }
  4201. return 0;
  4202. }
  4203. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4204. if (!lua_interface)
  4205. return 0;
  4206. Quest* quest = lua_interface->GetQuest(state);
  4207. int32 step = lua_interface->GetInt32Value(state, 2);
  4208. string description = lua_interface->GetStringValue(state, 3);
  4209. lua_interface->ResetFunctionStack(state);
  4210. if (quest && step > 0 && description.length() > 0) {
  4211. quest->SetStepDescription(step, description);
  4212. }
  4213. return 0;
  4214. }
  4215. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4216. Quest* quest = lua_interface->GetQuest(state);
  4217. string zone = lua_interface->GetStringValue(state, 2);
  4218. lua_interface->ResetFunctionStack(state);
  4219. if (quest && zone.length() > 0)
  4220. quest->SetZone(zone);
  4221. return 0;
  4222. }
  4223. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4224. if (!lua_interface)
  4225. return 0;
  4226. Quest* quest = lua_interface->GetQuest(state);
  4227. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4228. lua_interface->ResetFunctionStack(state);
  4229. if (quest && spawn) {
  4230. if (spawn->IsPlayer()) {
  4231. Client* client = ((Player*)spawn)->GetClient();
  4232. if (client) {
  4233. client->AddPendingQuestReward(quest);
  4234. }
  4235. }
  4236. }
  4237. return 0;
  4238. }
  4239. int EQ2Emu_lua_Harvest(lua_State* state) {
  4240. if (!lua_interface)
  4241. return 0;
  4242. Spawn* player = lua_interface->GetSpawn(state);
  4243. Spawn* node = lua_interface->GetSpawn(state, 2);
  4244. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4245. Client* client = ((Player*)player)->GetClient();
  4246. if (client) {
  4247. ((GroundSpawn*)node)->ProcessHarvest(client);
  4248. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4249. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4250. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4251. }
  4252. }
  4253. }
  4254. else if (player && player->IsPlayer()) {
  4255. Client* client = ((Player*)player)->GetClient();
  4256. if (client)
  4257. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4258. }
  4259. lua_interface->ResetFunctionStack(state);
  4260. return 0;
  4261. }
  4262. int EQ2Emu_lua_Bind(lua_State* state) {
  4263. if (!lua_interface)
  4264. return 0;
  4265. Spawn* spawn = lua_interface->GetSpawn(state);
  4266. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4267. float x = lua_interface->GetFloatValue(state, 3);
  4268. float y = lua_interface->GetFloatValue(state, 4);
  4269. float z = lua_interface->GetFloatValue(state, 5);
  4270. float h = lua_interface->GetFloatValue(state, 6);
  4271. lua_interface->ResetFunctionStack(state);
  4272. if (!spawn) {
  4273. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4274. return 0;
  4275. }
  4276. if (!spawn->IsPlayer()) {
  4277. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4278. return 0;
  4279. }
  4280. if (zone_id == 0) {
  4281. Client* client = ((Player*)spawn)->GetClient();
  4282. if (!client) {
  4283. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4284. return 0;
  4285. }
  4286. if (!client->Bind())
  4287. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4288. }
  4289. else {
  4290. Player* player = (Player*)spawn;
  4291. player->GetPlayerInfo()->SetBindZone(zone_id);
  4292. player->GetPlayerInfo()->SetBindX(x);
  4293. player->GetPlayerInfo()->SetBindY(y);
  4294. player->GetPlayerInfo()->SetBindZ(z);
  4295. player->GetPlayerInfo()->SetBindHeading(h);
  4296. }
  4297. return 0;
  4298. }
  4299. int EQ2Emu_lua_Gate(lua_State* state) {
  4300. if (!lua_interface)
  4301. return 0;
  4302. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4303. Spawn* spawn = lua_interface->GetSpawn(state);
  4304. lua_interface->ResetFunctionStack(state);
  4305. if (spawn) {
  4306. if (spawn->IsPlayer()) {
  4307. Client* client = ((Player*)spawn)->GetClient();
  4308. if (client) {
  4309. if (!client->Gate((spell != nullptr) ? true : false))
  4310. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4311. }
  4312. }
  4313. }
  4314. return 0;
  4315. }
  4316. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4317. if (!lua_interface)
  4318. return 0;
  4319. bool ret = false;
  4320. Spawn* spawn = lua_interface->GetSpawn(state);
  4321. lua_interface->ResetFunctionStack(state);
  4322. if (spawn) {
  4323. if (spawn->IsPlayer()) {
  4324. Client* client = ((Player*)spawn)->GetClient();
  4325. if (client)
  4326. ret = client->BindAllowed();
  4327. }
  4328. }
  4329. lua_interface->SetBooleanValue(state, ret);
  4330. return 1;
  4331. }
  4332. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4333. if (!lua_interface)
  4334. return 0;
  4335. bool ret = false;
  4336. Spawn* spawn = lua_interface->GetSpawn(state);
  4337. lua_interface->ResetFunctionStack(state);
  4338. if (spawn) {
  4339. if (spawn->IsPlayer()) {
  4340. Client* client = ((Player*)spawn)->GetClient();
  4341. ZoneServer* zone = lua_interface->GetZone(state);
  4342. if (client && zone){
  4343. ret = zone->GetCanGate();
  4344. }
  4345. }
  4346. }
  4347. lua_interface->SetBooleanValue(state, ret);
  4348. return 1;
  4349. }
  4350. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4351. Spawn* spawn = lua_interface->GetSpawn(state);
  4352. lua_interface->ResetFunctionStack(state);
  4353. if (spawn) {
  4354. lua_interface->SetBooleanValue(state, spawn->Alive());
  4355. return 1;
  4356. }
  4357. return 0;
  4358. }
  4359. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4360. if (!lua_interface)
  4361. return 0;
  4362. Spawn* spawn = lua_interface->GetSpawn(state);
  4363. lua_interface->ResetFunctionStack(state);
  4364. if (spawn && spawn->IsEntity()) {
  4365. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4366. return 1;
  4367. }
  4368. return 0;
  4369. }
  4370. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4371. Spawn* spawn = lua_interface->GetSpawn(state);
  4372. string message = lua_interface->GetStringValue(state, 2);
  4373. string color_str = lua_interface->GetStringValue(state, 3);
  4374. lua_interface->ResetFunctionStack(state);
  4375. int8 color = CHANNEL_NARRATIVE;
  4376. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4377. Client* client = ((Player*)spawn)->GetClient();
  4378. if (client) {
  4379. if (color_str.length() > 0) {
  4380. // leave for backwards compat, but all future should just use the number
  4381. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4382. color = CHANNEL_COLOR_RED;
  4383. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4384. color = CHANNEL_COLOR_YELLOW;
  4385. else
  4386. {
  4387. // use a number to specify the channel as per Commands/Commands.h defines
  4388. color = (int8)atoul(color_str.c_str());
  4389. }
  4390. }
  4391. client->SimpleMessage(color, message.c_str());
  4392. }
  4393. }
  4394. return 0;
  4395. }
  4396. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4397. Spawn* spawn = lua_interface->GetSpawn(state);
  4398. string message = lua_interface->GetStringValue(state, 2);
  4399. int8 red = lua_interface->GetInt8Value(state, 3);
  4400. int8 green = lua_interface->GetInt8Value(state, 4);
  4401. int8 blue = lua_interface->GetInt8Value(state, 5);
  4402. lua_interface->ResetFunctionStack(state);
  4403. if (!spawn) {
  4404. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4405. return 0;
  4406. }
  4407. if (!spawn->IsPlayer()) {
  4408. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not a player.", lua_interface->GetScriptName(state));
  4409. return 0;
  4410. }
  4411. int32 words = ::CountWordsInString(message.c_str());
  4412. if (words < 5)
  4413. words = 5;
  4414. Client* client = ((Player*)spawn)->GetClient();
  4415. if (client)
  4416. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4417. return 0;
  4418. }
  4419. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4420. Spawn* spawn = lua_interface->GetSpawn(state);
  4421. int8 param = lua_interface->GetInt8Value(state, 2);
  4422. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4423. int8 value = lua_interface->GetInt8Value(state, 4);
  4424. lua_interface->ResetFunctionStack(state);
  4425. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4426. Client* client = ((Player*)spawn)->GetClient();
  4427. if (client) {
  4428. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4429. switch (param) {
  4430. case 1: {
  4431. packet->setDataByName("parameter1", param_value);
  4432. break;
  4433. }
  4434. case 2: {
  4435. packet->setDataByName("parameter2", param_value);
  4436. break;
  4437. }
  4438. case 3: {
  4439. packet->setDataByName("parameter3", param_value);
  4440. break;
  4441. }
  4442. case 4: {
  4443. packet->setDataByName("parameter4", param_value);
  4444. break;
  4445. }
  4446. case 5: {
  4447. packet->setDataByName("parameter5", param_value);
  4448. break;
  4449. }
  4450. }
  4451. packet->setDataByName("value", value);
  4452. client->QueuePacket(packet->serialize());
  4453. safe_delete(packet);
  4454. }
  4455. }
  4456. return 0;
  4457. }
  4458. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4459. Spawn* spawn = lua_interface->GetSpawn(state);
  4460. lua_interface->ResetFunctionStack(state);
  4461. if (spawn && spawn->IsPlayer()) {
  4462. if (((Player*)spawn)->GetIsTracking())
  4463. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4464. else
  4465. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4466. }
  4467. return 0;
  4468. }
  4469. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4470. Spawn* player = lua_interface->GetSpawn(state);
  4471. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4472. string name = lua_interface->GetStringValue(state, 3);
  4473. float distance = lua_interface->GetFloatValue(state, 4);
  4474. string command = lua_interface->GetStringValue(state, 5);
  4475. string error_text = lua_interface->GetStringValue(state, 6);
  4476. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4477. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4478. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4479. lua_interface->ResetFunctionStack(state);
  4480. if (spawn) {
  4481. if (distance == 0)
  4482. distance = 10.0f;
  4483. if (command.length() == 0)
  4484. command = name;
  4485. if (command.length() < 1 && name.length() < 1)
  4486. {
  4487. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4488. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4489. spawn->RemovePrimaryCommands();
  4490. }
  4491. else
  4492. {
  4493. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4494. }
  4495. }
  4496. return 0;
  4497. }
  4498. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4499. if (!lua_interface)
  4500. return 0;
  4501. Spawn* player = lua_interface->GetSpawn(state);
  4502. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4503. int16 tier = lua_interface->GetInt16Value(state, 3);
  4504. lua_interface->ResetFunctionStack(state);
  4505. if (player && player->IsPlayer()) {
  4506. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4507. return 1;
  4508. }
  4509. return 0;
  4510. }
  4511. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4512. if (!lua_interface)
  4513. return 0;
  4514. Spawn* player = lua_interface->GetSpawn(state);
  4515. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4516. int16 tier = lua_interface->GetInt16Value(state, 3);
  4517. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4518. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4519. bool add_to_hotbar = true;
  4520. if (num_args > 4) {
  4521. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4522. }
  4523. lua_interface->ResetFunctionStack(state);
  4524. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4525. if (player && spell && player->IsPlayer()) {
  4526. Client* client = player->GetClient();
  4527. if (client) {
  4528. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4529. {
  4530. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4531. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4532. client->GetPlayer()->UnlockSpell(spell);
  4533. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4534. }
  4535. else
  4536. {
  4537. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4538. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4539. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4540. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4541. client->GetPlayer()->UnlockSpell(spell);
  4542. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4543. }
  4544. //if (client ) {
  4545. // ((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);
  4546. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4547. if (outapp)
  4548. client->QueuePacket(outapp);
  4549. }
  4550. }
  4551. return 0;
  4552. }
  4553. int EQ2Emu_lua_DeleteSpellBook(lua_State* state) {
  4554. if (!lua_interface)
  4555. return 0;
  4556. Spawn* player = lua_interface->GetSpawn(state);
  4557. int8 type_selection = lua_interface->GetInt8Value(state, 2);
  4558. lua_interface->ResetFunctionStack(state);
  4559. if (player && player->IsPlayer()) {
  4560. Client* client = player->GetClient();
  4561. if (client) {
  4562. ((Player*)player)->DeleteSpellBook(type_selection);
  4563. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4564. if (outapp)
  4565. client->QueuePacket(outapp);
  4566. }
  4567. }
  4568. return 0;
  4569. }
  4570. int EQ2Emu_lua_SendNewAdventureSpells(lua_State* state) {
  4571. if (!lua_interface)
  4572. return 0;
  4573. Spawn* player = lua_interface->GetSpawn(state);
  4574. lua_interface->ResetFunctionStack(state);
  4575. if (player && player->IsPlayer()) {
  4576. Client* client = player->GetClient();
  4577. if (client) {
  4578. client->SendNewAdventureSpells();
  4579. }
  4580. }
  4581. return 0;
  4582. }
  4583. int EQ2Emu_lua_SendNewTradeskillSpells(lua_State* state) {
  4584. if (!lua_interface)
  4585. return 0;
  4586. Spawn* player = lua_interface->GetSpawn(state);
  4587. lua_interface->ResetFunctionStack(state);
  4588. if (player && player->IsPlayer()) {
  4589. Client* client = player->GetClient();
  4590. if (client) {
  4591. client->SendNewTradeskillSpells();
  4592. }
  4593. }
  4594. return 0;
  4595. }
  4596. int EQ2Emu_lua_RemoveSpellBookEntry(lua_State* state) {
  4597. if (!lua_interface)
  4598. return 0;
  4599. Spawn* player = lua_interface->GetSpawn(state);
  4600. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4601. lua_interface->ResetFunctionStack(state);
  4602. if (player && player->IsPlayer()) {
  4603. SpellBookEntry* sbe = ((Player*)player)->GetSpellBookSpell(spellid);
  4604. Client* client = player->GetClient();
  4605. if (sbe && client) {
  4606. ((Player*)player)->RemoveSpellBookEntry(spellid);
  4607. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4608. if (outapp)
  4609. client->QueuePacket(outapp);
  4610. }
  4611. }
  4612. return 0;
  4613. }
  4614. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4615. if (!lua_interface)
  4616. return 0;
  4617. Spawn* player = lua_interface->GetSpawn(state);
  4618. lua_interface->ResetFunctionStack(state);
  4619. if (player && player->IsPlayer()) {
  4620. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4621. return 1;
  4622. }
  4623. return 0;
  4624. }
  4625. int EQ2Emu_lua_Attack(lua_State* state) {
  4626. if (lua_interface) {
  4627. Spawn* npc = lua_interface->GetSpawn(state);
  4628. Spawn* player = lua_interface->GetSpawn(state, 2);
  4629. lua_interface->ResetFunctionStack(state);
  4630. if (npc && player && npc->IsNPC() && player->IsEntity())
  4631. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4632. }
  4633. return 0;
  4634. }
  4635. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4636. if (lua_interface) {
  4637. Spawn* target = lua_interface->GetSpawn(state);
  4638. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4639. lua_interface->ResetFunctionStack(state);
  4640. if (target && target->GetZone())
  4641. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4642. }
  4643. return 0;
  4644. }
  4645. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4646. Spawn* player;
  4647. if (lua_interface) {
  4648. player = lua_interface->GetSpawn(state);
  4649. lua_interface->ResetFunctionStack(state);
  4650. if (player && player->IsPlayer()) {
  4651. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4652. return 1;
  4653. }
  4654. }
  4655. return 0;
  4656. }
  4657. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4658. Spawn* player;
  4659. Client* client;
  4660. if (lua_interface) {
  4661. player = lua_interface->GetSpawn(state);
  4662. lua_interface->ResetFunctionStack(state);
  4663. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4664. if ((client = ((Player*)player)->GetClient()))
  4665. client->HandInCollections();
  4666. }
  4667. return 0;
  4668. }
  4669. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4670. Spawn* widget;
  4671. if (lua_interface) {
  4672. widget = lua_interface->GetSpawn(state);
  4673. lua_interface->ResetFunctionStack(state);
  4674. if (widget && widget->IsWidget())
  4675. ((Widget*)widget)->HandleUse(nullptr, "");
  4676. }
  4677. return 0;
  4678. }
  4679. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4680. Spawn* spawn = 0;
  4681. int32 primary_list = 0;
  4682. int32 secondary_list = 0;
  4683. if (lua_interface) {
  4684. spawn = lua_interface->GetSpawn(state);
  4685. primary_list = lua_interface->GetInt32Value(state, 2);
  4686. secondary_list = lua_interface->GetInt32Value(state, 3);
  4687. lua_interface->ResetFunctionStack(state);
  4688. if (!spawn->IsNPC()) {
  4689. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4690. return 0;
  4691. }
  4692. NPC* npc = (NPC*)spawn;
  4693. npc->SetPrimarySpellList(primary_list);
  4694. npc->SetSecondarySpellList(secondary_list);
  4695. npc->SetSpells(world.GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4696. }
  4697. return 0;
  4698. }
  4699. int EQ2Emu_lua_GetPet(lua_State* state) {
  4700. if (!lua_interface)
  4701. return 0;
  4702. Spawn* spawn = lua_interface->GetSpawn(state);
  4703. lua_interface->ResetFunctionStack(state);
  4704. if (spawn) {
  4705. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4706. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4707. return 1;
  4708. }
  4709. }
  4710. return 0;
  4711. }
  4712. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4713. if (!lua_interface)
  4714. return 0;
  4715. Spawn* spawn = lua_interface->GetSpawn(state);
  4716. lua_interface->ResetFunctionStack(state);
  4717. if (spawn) {
  4718. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4719. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4720. return 1;
  4721. }
  4722. }
  4723. return 0;
  4724. }
  4725. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4726. if (!lua_interface)
  4727. return 0;
  4728. Spawn* spawn = lua_interface->GetSpawn(state);
  4729. lua_interface->ResetFunctionStack(state);
  4730. if (spawn) {
  4731. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4732. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4733. return 1;
  4734. }
  4735. }
  4736. return 0;
  4737. }
  4738. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4739. if (!lua_interface)
  4740. return 0;
  4741. Spawn* spawn = lua_interface->GetSpawn(state);
  4742. lua_interface->ResetFunctionStack(state);
  4743. if (spawn) {
  4744. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4745. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4746. return 1;
  4747. }
  4748. }
  4749. return 0;
  4750. }
  4751. int EQ2Emu_lua_Charm(lua_State* state) {
  4752. if (!lua_interface)
  4753. return 0;
  4754. Spawn* owner = lua_interface->GetSpawn(state);
  4755. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4756. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4757. lua_interface->ResetFunctionStack(state);
  4758. if (!luaspell) {
  4759. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4760. return 0;
  4761. }
  4762. if(luaspell->resisted) {
  4763. return 0;
  4764. }
  4765. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4766. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4767. pet->SetPet(true);
  4768. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4769. ((NPC*)pet)->SetOwner((Entity*)owner);
  4770. // If owner is player and player does not have a summoned pet set the players charsheet
  4771. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4772. Player* player = (Player*)owner;
  4773. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4774. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4775. player->GetInfoStruct()->set_pet_movement(2);
  4776. player->GetInfoStruct()->set_pet_behavior(3);
  4777. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4778. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4779. // Make sure the values get sent to the client
  4780. player->SetCharSheetChanged(true);
  4781. }
  4782. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4783. pet->SetSpawnScript("");
  4784. // Set faction to the same as the owner
  4785. pet->SetFactionID(owner->GetFactionID());
  4786. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4787. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4788. // Clear hate list
  4789. ((NPC*)pet)->Brain()->ClearHate();
  4790. // Set the brain to a pet brain
  4791. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4792. }
  4793. return 0;
  4794. }
  4795. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4796. if (!lua_interface)
  4797. return 0;
  4798. Spawn* spawn = lua_interface->GetSpawn(state);
  4799. lua_interface->ResetFunctionStack(state);
  4800. if (!spawn) {
  4801. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4802. return 0;
  4803. }
  4804. vector<Spawn*> groupMembers;
  4805. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4806. groupMembers = *spawn->GetSpawnGroup();
  4807. }
  4808. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4809. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4810. deque<GroupMemberInfo*>::iterator itr;
  4811. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4812. if (group)
  4813. {
  4814. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4815. deque<GroupMemberInfo*>* members = group->GetMembers();
  4816. GroupMemberInfo* info = 0;
  4817. for (itr = members->begin(); itr != members->end(); itr++) {
  4818. info = *itr;
  4819. if (info->client)
  4820. groupMembers.push_back(info->client->GetPlayer());
  4821. }
  4822. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4823. }
  4824. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4825. }
  4826. else
  4827. return 0;
  4828. lua_createtable(state, groupMembers.size(), 0);
  4829. int newTable = lua_gettop(state);
  4830. for (int32 i = 0; i < groupMembers.size(); i++) {
  4831. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4832. lua_rawseti(state, newTable, i + 1);
  4833. }
  4834. return 1;
  4835. }
  4836. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4837. if (!lua_interface)
  4838. return 0;
  4839. lua_interface->ResetFunctionStack(state);
  4840. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4841. lua_interface->SetOptionWindowValue(state, option_window);
  4842. return 1;
  4843. }
  4844. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4845. if (!lua_interface)
  4846. return 0;
  4847. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4848. if (option_window) {
  4849. OptionWindowOption option_window_option;
  4850. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4851. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4852. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4853. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4854. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4855. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4856. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4857. option_window->push_back(option_window_option);
  4858. }
  4859. lua_interface->ResetFunctionStack(state);
  4860. return 0;
  4861. }
  4862. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4863. if (!lua_interface)
  4864. return 0;
  4865. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4866. Spawn* player = lua_interface->GetSpawn(state, 2);
  4867. string window_title = lua_interface->GetStringValue(state, 3);
  4868. string cancel_command = lua_interface->GetStringValue(state, 4);
  4869. lua_interface->ResetFunctionStack(state);
  4870. if (!player->IsPlayer()) {
  4871. lua_interface->LogError("%s: LUA SendOptionWindow command error: spawn is not a player", lua_interface->GetScriptName(state));
  4872. return 0;
  4873. }
  4874. Client* client = ((Player*)player)->GetClient();
  4875. if (option_window && window_title.length() > 0 && client) {
  4876. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4877. if (!packet)
  4878. return 0;
  4879. packet->setDataByName("title_text", window_title.c_str());
  4880. if (cancel_command.length() > 0)
  4881. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4882. packet->setArrayLengthByName("num_selections", option_window->size());
  4883. vector<OptionWindowOption>::iterator itr;
  4884. int8 i = 0;
  4885. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4886. OptionWindowOption opt = *itr;
  4887. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4888. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4889. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4890. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4891. if (opt.optionCommand.length() > 0)
  4892. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4893. if (opt.optionConfirmTitle.length() > 0)
  4894. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4895. i++;
  4896. }
  4897. client->QueuePacket(packet->serialize());
  4898. lua_interface->SetLuaUserDataStale(option_window);
  4899. safe_delete(option_window);
  4900. safe_delete(packet);
  4901. }
  4902. return 0;
  4903. }
  4904. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4905. if (!lua_interface)
  4906. return 0;
  4907. Spawn* spawn = lua_interface->GetSpawn(state);
  4908. lua_interface->ResetFunctionStack(state);
  4909. if (spawn) {
  4910. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4911. return 1;
  4912. }
  4913. else
  4914. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4915. return 0;
  4916. }
  4917. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4918. if (!lua_interface)
  4919. return 0;
  4920. Spawn* spawn = lua_interface->GetSpawn(state);
  4921. lua_interface->ResetFunctionStack(state);
  4922. if (spawn) {
  4923. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4924. return 1;
  4925. }
  4926. else
  4927. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4928. return 0;
  4929. }
  4930. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4931. if (!lua_interface)
  4932. return 0;
  4933. Spawn* spawn = lua_interface->GetSpawn(state);
  4934. lua_interface->ResetFunctionStack(state);
  4935. if (spawn) {
  4936. int8 class_id = spawn->GetTradeskillClass();
  4937. // Need to add 42 for the offset in the array
  4938. class_id += 44;
  4939. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4940. return 1;
  4941. }
  4942. else
  4943. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4944. return 0;
  4945. }
  4946. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4947. if (!lua_interface)
  4948. return 0;
  4949. Spawn* spawn = lua_interface->GetSpawn(state);
  4950. int16 level = lua_interface->GetInt8Value(state, 2);
  4951. lua_interface->ResetFunctionStack(state);
  4952. if (spawn) {
  4953. if (spawn->IsPlayer() && ((Player*)spawn)->GetClient())
  4954. ((Player*)spawn)->GetClient()->ChangeTSLevel(spawn->GetTSLevel(), level);
  4955. else
  4956. spawn->SetTSLevel(level);
  4957. }
  4958. else
  4959. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4960. return 0;
  4961. }
  4962. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4963. if (!lua_interface)
  4964. return 0;
  4965. Spawn* spawn = lua_interface->GetSpawn(state);
  4966. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4967. lua_interface->ResetFunctionStack(state);
  4968. if (spawn) {
  4969. spawn->SetAttackable(attackable);
  4970. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4971. }
  4972. return 0;
  4973. }
  4974. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4975. // Check to see if we have a valid lua_interface
  4976. if (!lua_interface)
  4977. return 0;
  4978. // Get the spawn that is getting the pet
  4979. Spawn* spawn = lua_interface->GetSpawn(state);
  4980. // Get the DB ID of the pet
  4981. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4982. // The max level the pet can gain
  4983. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4984. // Get the spell that this command was called from
  4985. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4986. lua_interface->ResetFunctionStack(state);
  4987. // Check to make sure the spawn pointer is valid
  4988. if (!spawn) {
  4989. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4990. return 0;
  4991. }
  4992. // Check to make sure the spawn is an entity
  4993. if (!spawn->IsEntity()) {
  4994. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4995. return 0;
  4996. }
  4997. // Check to make sure the spawn doesn't already have a pet of this type
  4998. if (((Entity*)spawn)->GetPet()) {
  4999. if (spawn->IsPlayer()) {
  5000. Client* client = ((Player*)spawn)->GetClient();
  5001. if (client)
  5002. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  5003. }
  5004. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5005. return 0;
  5006. }
  5007. // Check to see if the DB ID for the pet is set
  5008. if (pet_id == 0) {
  5009. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5010. return 0;
  5011. }
  5012. // Check to see if the pointer to the spell is valid
  5013. if (!luaspell) {
  5014. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5015. return 0;
  5016. }
  5017. if(luaspell->resisted) {
  5018. return 0;
  5019. }
  5020. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  5021. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5022. if (!pet) {
  5023. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5024. return 0;
  5025. }
  5026. // Check to make sure the pet is an npc
  5027. if (!pet->IsNPC()) {
  5028. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  5029. return 0;
  5030. }
  5031. // Spawn the pet at the same location as the owner
  5032. pet->SetX(spawn->GetX());
  5033. pet->SetY(spawn->GetY());
  5034. pet->SetZ(spawn->GetZ());
  5035. pet->SetLocation(spawn->GetLocation());
  5036. pet->SetHeading(spawn->GetHeading());
  5037. std::string petName = std::string("");
  5038. if(spawn->IsEntity()) {
  5039. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  5040. }
  5041. if(petName.size() < 1) {
  5042. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5043. petName = spawn->GetZone()->pet_names.at(rand_index);
  5044. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  5045. }
  5046. // If player set various values for the char sheet (pet window)
  5047. if (spawn->IsPlayer()) {
  5048. Player* player = (Player*)spawn;
  5049. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  5050. player->GetInfoStruct()->set_pet_name(petName);
  5051. player->GetInfoStruct()->set_pet_movement(2);
  5052. player->GetInfoStruct()->set_pet_behavior(3);
  5053. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  5054. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  5055. // Make sure the values get sent to the client
  5056. player->SetCharSheetChanged(true);
  5057. }
  5058. // Set the pets name
  5059. pet->SetName(petName.c_str());
  5060. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  5061. if (max_level > 0)
  5062. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  5063. else
  5064. pet->SetLevel(spawn->GetLevel());
  5065. // Set the max level this pet can reach
  5066. ((NPC*)pet)->SetMaxPetLevel(max_level);
  5067. ((NPC*)pet)->UpdateWeapons();
  5068. // Set the faction of the pet to the same faction as the owner
  5069. pet->SetFactionID(spawn->GetFactionID());
  5070. // Set the spawn as a pet
  5071. pet->SetPet(true);
  5072. // Give a pointer of the owner to the pet
  5073. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5074. // Give a pointer of the pet to the owner
  5075. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  5076. // Set the pet type
  5077. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  5078. // Set the spell id used to create this pet
  5079. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5080. // Set the spell tier used to create this pet
  5081. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5082. // Set the pets spawn type to 6
  5083. pet->SetSpawnType(6);
  5084. // Set the pets brain
  5085. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  5086. // Check to see if the pet has a subtitle
  5087. if (strlen(pet->GetSubTitle()) > 0) {
  5088. // Add the players name to the front of the sub title
  5089. string pet_subtitle;
  5090. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5091. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5092. // Set the pets subtitle to the new one
  5093. pet->SetSubTitle(pet_subtitle.c_str());
  5094. }
  5095. // Add the "Pet Options" entity command to the pet
  5096. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5097. const char* spawn_script = world.GetSpawnScript(pet_id);
  5098. bool runScript = false;
  5099. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  5100. runScript = true;
  5101. pet->SetSpawnScript(string(spawn_script));
  5102. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_PRESPAWN);
  5103. }
  5104. spawn->GetZone()->AddSpawn(pet);
  5105. if(runScript){
  5106. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_SPAWN);
  5107. }
  5108. // Set the pet as the return value for this function
  5109. lua_interface->SetSpawnValue(state, pet);
  5110. return 1;
  5111. }
  5112. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  5113. if (!lua_interface)
  5114. return 0;
  5115. Spawn* spawn = lua_interface->GetSpawn(state);
  5116. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5117. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5118. lua_interface->ResetFunctionStack(state);
  5119. if (!spawn) {
  5120. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5121. return 0;
  5122. }
  5123. if (!spawn->IsEntity()) {
  5124. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5125. return 0;
  5126. }
  5127. if (((Entity*)spawn)->GetDeityPet()) {
  5128. if (spawn->IsPlayer()) {
  5129. Client* client = ((Player*)spawn)->GetClient();
  5130. if (client)
  5131. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  5132. }
  5133. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5134. return 0;
  5135. }
  5136. if (pet_id == 0) {
  5137. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5138. return 0;
  5139. }
  5140. if (!luaspell) {
  5141. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5142. return 0;
  5143. }
  5144. if(luaspell->resisted) {
  5145. return 0;
  5146. }
  5147. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5148. if (!pet) {
  5149. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5150. return 0;
  5151. }
  5152. if (!pet->IsNPC()) {
  5153. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5154. return 0;
  5155. }
  5156. pet->SetX(spawn->GetX());
  5157. pet->SetY(spawn->GetY());
  5158. pet->SetZ(spawn->GetZ());
  5159. pet->SetLocation(spawn->GetLocation());
  5160. pet->SetHeading(spawn->GetHeading());
  5161. spawn->GetZone()->AddSpawn(pet);
  5162. string random_pet_name;
  5163. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5164. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5165. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5166. pet->SetName(random_pet_name.c_str());
  5167. pet->SetLevel(spawn->GetLevel());
  5168. pet->SetFactionID(spawn->GetFactionID());
  5169. pet->SetPet(true);
  5170. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  5171. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5172. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  5173. pet->SetSpawnType(6);
  5174. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5175. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5176. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5177. if (strlen(pet->GetSubTitle()) > 0) {
  5178. string pet_subtitle;
  5179. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5180. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5181. pet->SetSubTitle(pet_subtitle.c_str());
  5182. }
  5183. // deity and cosmetic pets are not attackable
  5184. pet->SetAttackable(false);
  5185. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5186. lua_interface->SetSpawnValue(state, pet);
  5187. return 1;
  5188. }
  5189. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  5190. if (!lua_interface)
  5191. return 0;
  5192. Spawn* spawn = lua_interface->GetSpawn(state);
  5193. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5194. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5195. lua_interface->ResetFunctionStack(state);
  5196. if (!spawn) {
  5197. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5198. return 0;
  5199. }
  5200. if (!spawn->IsEntity()) {
  5201. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5202. return 0;
  5203. }
  5204. if (((Entity*)spawn)->GetCosmeticPet()) {
  5205. if (spawn->IsPlayer()) {
  5206. Client* client = ((Player*)spawn)->GetClient();
  5207. if (client)
  5208. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  5209. }
  5210. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5211. return 0;
  5212. }
  5213. if (pet_id == 0) {
  5214. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5215. return 0;
  5216. }
  5217. if (!luaspell) {
  5218. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5219. return 0;
  5220. }
  5221. if(luaspell->resisted) {
  5222. return 0;
  5223. }
  5224. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5225. if (!pet) {
  5226. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5227. return 0;
  5228. }
  5229. if (!pet->IsNPC()) {
  5230. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5231. return 0;
  5232. }
  5233. pet->SetX(spawn->GetX());
  5234. pet->SetY(spawn->GetY());
  5235. pet->SetZ(spawn->GetZ());
  5236. pet->SetLocation(spawn->GetLocation());
  5237. pet->SetHeading(spawn->GetHeading());
  5238. spawn->GetZone()->AddSpawn(pet);
  5239. string random_pet_name;
  5240. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5241. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5242. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5243. pet->SetName(random_pet_name.c_str());
  5244. pet->SetLevel(spawn->GetLevel());
  5245. pet->SetFactionID(spawn->GetFactionID());
  5246. pet->SetPet(true);
  5247. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  5248. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5249. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5250. pet->SetSpawnType(6);
  5251. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5252. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5253. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5254. if (strlen(pet->GetSubTitle()) > 0) {
  5255. string pet_subtitle;
  5256. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5257. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5258. pet->SetSubTitle(pet_subtitle.c_str());
  5259. }
  5260. pet->SetAttackable(false);
  5261. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5262. lua_interface->SetSpawnValue(state, pet);
  5263. return 1;
  5264. }
  5265. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5266. if (!lua_interface)
  5267. return 0;
  5268. Spawn* spawn = lua_interface->GetSpawn(state);
  5269. lua_interface->ResetFunctionStack(state);
  5270. if (!spawn) {
  5271. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5272. return 0;
  5273. }
  5274. if (!spawn->IsPet()) {
  5275. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5276. return 0;
  5277. }
  5278. if (!((NPC*)spawn)->IsDismissing() && ((NPC*)spawn)->GetOwner())
  5279. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5280. return 0;
  5281. }
  5282. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5283. if (!lua_interface)
  5284. return 0;
  5285. Quest* quest = lua_interface->GetQuest(state);
  5286. if (!quest) {
  5287. 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));
  5288. lua_interface->ResetFunctionStack(state);
  5289. return 0;
  5290. }
  5291. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5292. lua_interface->ResetFunctionStack(state);
  5293. if (feather_color > 0)
  5294. quest->SetFeatherColor(feather_color);
  5295. return 0;
  5296. }
  5297. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5298. if (!lua_interface)
  5299. return 0;
  5300. Spawn* spawn = lua_interface->GetSpawn(state);
  5301. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5302. lua_interface->ResetFunctionStack(state);
  5303. if (!spawn) {
  5304. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5305. return 0;
  5306. }
  5307. if (!spawn2) {
  5308. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5309. return 0;
  5310. }
  5311. spawn->RemoveSpawnAccess(spawn2);
  5312. return 0;
  5313. }
  5314. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5315. if (!lua_interface)
  5316. return 0;
  5317. ZoneServer* zone = lua_interface->GetZone(state);
  5318. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5319. lua_interface->ResetFunctionStack(state);
  5320. if (!zone) {
  5321. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5322. return 0;
  5323. }
  5324. if (location_id == 0) {
  5325. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5326. return 0;
  5327. }
  5328. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5329. if (!location) {
  5330. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5331. return 0;
  5332. }
  5333. Spawn* spawn = 0;
  5334. if (location->entities[0]) {
  5335. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5336. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5337. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5338. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5339. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5340. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5341. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5342. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5343. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5344. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5345. if(spawn && spawn->IsOmittedByDBFlag())
  5346. {
  5347. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5348. safe_delete(spawn);
  5349. spawn = 0;
  5350. return 0;
  5351. }
  5352. if (spawn) {
  5353. const char* script = 0;
  5354. for (int x = 0; x < 3; x++) {
  5355. switch (x) {
  5356. case 0:
  5357. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5358. break;
  5359. case 1:
  5360. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5361. break;
  5362. case 2:
  5363. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5364. break;
  5365. }
  5366. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5367. spawn->SetSpawnScript(string(script));
  5368. break;
  5369. }
  5370. }
  5371. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5372. lua_interface->SetSpawnValue(state, spawn);
  5373. return 1;
  5374. }
  5375. else {
  5376. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5377. safe_delete(spawn);
  5378. }
  5379. }
  5380. return 0;
  5381. }
  5382. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5383. if (!lua_interface)
  5384. return 0;
  5385. Spawn* caster = lua_interface->GetSpawn(state);
  5386. Spawn* target = lua_interface->GetSpawn(state, 2);
  5387. int32 id = lua_interface->GetInt32Value(state, 3);
  5388. string command = lua_interface->GetStringValue(state, 4);
  5389. lua_interface->ResetFunctionStack(state);
  5390. if (!caster) {
  5391. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5392. return 0;
  5393. }
  5394. if (!target) {
  5395. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5396. return 0;
  5397. }
  5398. if (!caster->IsPlayer()) {
  5399. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5400. return 0;
  5401. }
  5402. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5403. if (!entity_command) {
  5404. 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());
  5405. return 0;
  5406. }
  5407. Client* client = ((Player*)caster)->GetClient();
  5408. if (!client) {
  5409. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5410. return 0;
  5411. }
  5412. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5413. return 0;
  5414. }
  5415. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5416. if (!lua_interface)
  5417. return 0;
  5418. Spawn* spawn = lua_interface->GetSpawn(state);
  5419. lua_interface->ResetFunctionStack(state);
  5420. if (!spawn) {
  5421. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5422. return 0;
  5423. }
  5424. if (!spawn->IsNPC()) {
  5425. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5426. return 0;
  5427. }
  5428. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5429. return 0;
  5430. }
  5431. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5432. if (!lua_interface)
  5433. return 0;
  5434. Spawn* spawn = lua_interface->GetSpawn(state);
  5435. int16 tick = lua_interface->GetInt16Value(state, 2);
  5436. lua_interface->ResetFunctionStack(state);
  5437. if (!spawn) {
  5438. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5439. return 0;
  5440. }
  5441. if (!spawn->IsNPC()) {
  5442. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5443. return 0;
  5444. }
  5445. if (tick < 20) {
  5446. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5447. return 0;
  5448. }
  5449. ((NPC*)spawn)->Brain()->SetTick(tick);
  5450. return 0;
  5451. }
  5452. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5453. if (!lua_interface)
  5454. return 0;
  5455. Spawn* spawn = lua_interface->GetSpawn(state);
  5456. Spawn* target = lua_interface->GetSpawn(state, 2);
  5457. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5458. lua_interface->ResetFunctionStack(state);
  5459. if (!spawn) {
  5460. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5461. return 0;
  5462. }
  5463. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5464. spawn->SetFollowTarget(target, follow_distance);
  5465. return 0;
  5466. }
  5467. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5468. if (!lua_interface)
  5469. return 0;
  5470. Spawn* spawn = lua_interface->GetSpawn(state);
  5471. lua_interface->ResetFunctionStack(state);
  5472. if (!spawn) {
  5473. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5474. return 0;
  5475. }
  5476. Spawn* target = spawn->GetFollowTarget();
  5477. if (target) {
  5478. lua_interface->SetSpawnValue(state, target);
  5479. return 1;
  5480. }
  5481. return 0;
  5482. }
  5483. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5484. if (!lua_interface)
  5485. return 0;
  5486. Spawn* spawn = lua_interface->GetSpawn(state);
  5487. lua_interface->ResetFunctionStack(state);
  5488. if (!spawn) {
  5489. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5490. return 0;
  5491. }
  5492. if (spawn->following)
  5493. spawn->following = false;
  5494. else
  5495. spawn->following = true;
  5496. return 0;
  5497. }
  5498. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5499. if (!lua_interface)
  5500. return 0;
  5501. Spawn* spawn = lua_interface->GetSpawn(state);
  5502. lua_interface->ResetFunctionStack(state);
  5503. if (!spawn) {
  5504. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5505. return 0;
  5506. }
  5507. lua_interface->SetBooleanValue(state, spawn->following);
  5508. return 1;
  5509. }
  5510. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5511. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5512. // I will attempt to explain how this function works for future refrence
  5513. // Fist lets make sure lua_interface is valid, if not return out
  5514. if (!lua_interface)
  5515. return 0;
  5516. // Next we grab the first 2 params same as we usually would
  5517. Spawn* spawn = lua_interface->GetSpawn(state);
  5518. string var = lua_interface->GetStringValue(state, 2);
  5519. // 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
  5520. // 1 = Spawn
  5521. // 2 = Zone
  5522. // 3 = Item
  5523. // 4 = Quest
  5524. // 5 = String
  5525. // 6 = nil (null)
  5526. int8 dataType = 0;
  5527. // Define pointers for each potential type
  5528. Spawn* spawnVal = 0;
  5529. ZoneServer* zone = 0;
  5530. Item* item = 0;
  5531. Quest* quest = 0;
  5532. string val;
  5533. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5534. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5535. // options window are also light user data be we do not handle those.
  5536. // We check with lua_islightuserdata(lua_State*, index)
  5537. if (lua_islightuserdata(state, 3)) {
  5538. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5539. // and convert it to LUAUserData*
  5540. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5541. // Check to make sure the data we got is valid, if not give an error
  5542. if (!data || !data->IsCorrectlyInitialized()) {
  5543. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5544. }
  5545. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5546. else if (data->IsSpawn()) {
  5547. spawnVal = data->spawn;
  5548. dataType = 1;
  5549. }
  5550. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5551. else if (data->IsZone()) {
  5552. zone = data->zone;
  5553. dataType = 2;
  5554. }
  5555. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5556. else if (data->IsItem()) {
  5557. item = data->item;
  5558. dataType = 3;
  5559. }
  5560. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5561. else if (data->IsQuest()) {
  5562. quest = data->quest;
  5563. dataType = 4;
  5564. }
  5565. }
  5566. // Wasn't light user data, check if it is nil(null)
  5567. else if (lua_isnil(state, 3)) {
  5568. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5569. dataType = 6;
  5570. }
  5571. // Wasn't light user data or nil (null), must be a string
  5572. else {
  5573. // Set the string and dataType variable
  5574. val = lua_interface->GetStringValue(state, 3);
  5575. dataType = 5;
  5576. }
  5577. lua_interface->ResetFunctionStack(state);
  5578. // We now have all the params, lets check to make sure they are valid
  5579. if (!spawn) {
  5580. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5581. return 0;
  5582. }
  5583. if (var.length() == 0) {
  5584. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5585. return 0;
  5586. }
  5587. if (dataType == 0) {
  5588. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5589. return 0;
  5590. }
  5591. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5592. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5593. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5594. switch (dataType) {
  5595. case 1:
  5596. // 1 = Spawn
  5597. spawn->AddTempVariable(var, spawnVal);
  5598. break;
  5599. case 2:
  5600. // 2 = Zone
  5601. spawn->AddTempVariable(var, zone);
  5602. break;
  5603. case 3:
  5604. // 3 = Item
  5605. spawn->AddTempVariable(var, item);
  5606. break;
  5607. case 4:
  5608. // 4 = Quest
  5609. spawn->AddTempVariable(var, quest);
  5610. break;
  5611. case 5:
  5612. // 5 = String
  5613. spawn->AddTempVariable(var, val);
  5614. break;
  5615. case 6:
  5616. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5617. spawn->DeleteTempVariable(var);
  5618. break;
  5619. }
  5620. // And we are done so return out
  5621. return 0;
  5622. }
  5623. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5624. if (!lua_interface)
  5625. return 0;
  5626. Spawn* spawn = lua_interface->GetSpawn(state);
  5627. string var = lua_interface->GetStringValue(state, 2);
  5628. lua_interface->ResetFunctionStack(state);
  5629. if (!spawn) {
  5630. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5631. return 0;
  5632. }
  5633. if (var.length() == 0) {
  5634. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5635. return 0;
  5636. }
  5637. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5638. int8 type = spawn->GetTempVariableType(var);
  5639. Spawn* spawn2 = 0;
  5640. ZoneServer* zone = 0;
  5641. Item* item = 0;
  5642. Quest* quest = 0;
  5643. // Set the lua function return value based on the type of data the variable contains
  5644. switch (type) {
  5645. case 1:
  5646. spawn2 = spawn->GetTempVariableSpawn(var);
  5647. if (!spawn2)
  5648. return 0;
  5649. lua_interface->SetSpawnValue(state, spawn2);
  5650. break;
  5651. case 2:
  5652. zone = spawn->GetTempVariableZone(var);
  5653. if (!zone)
  5654. return 0;
  5655. lua_interface->SetZoneValue(state, zone);
  5656. break;
  5657. case 3:
  5658. item = spawn->GetTempVariableItem(var);
  5659. if (!item)
  5660. return 0;
  5661. lua_interface->SetItemValue(state, item);
  5662. break;
  5663. case 4:
  5664. quest = spawn->GetTempVariableQuest(var);
  5665. if (!quest)
  5666. return 0;
  5667. lua_interface->SetQuestValue(state, quest);
  5668. break;
  5669. case 5:
  5670. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5671. break;
  5672. default:
  5673. // Not a valid type then the variable was not set so return out
  5674. return 0;
  5675. }
  5676. // Return value was set so return out
  5677. return 1;
  5678. }
  5679. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5680. {
  5681. if (!lua_interface)
  5682. return 0;
  5683. Quest* quest = lua_interface->GetQuest(state);
  5684. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5685. string description = lua_interface->GetStringValue(state, 3);
  5686. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5687. if (!quest) {
  5688. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5689. lua_interface->ResetFunctionStack(state);
  5690. lua_interface->SetBooleanValue(state, false);
  5691. return 1;
  5692. }
  5693. if (!spawn) {
  5694. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5695. lua_interface->ResetFunctionStack(state);
  5696. lua_interface->SetBooleanValue(state, false);
  5697. return 1;
  5698. }
  5699. if (!spawn->IsPlayer()) {
  5700. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5701. lua_interface->ResetFunctionStack(state);
  5702. lua_interface->SetBooleanValue(state, false);
  5703. return 1;
  5704. }
  5705. if (item_id == 0) {
  5706. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5707. lua_interface->ResetFunctionStack(state);
  5708. lua_interface->SetBooleanValue(state, false);
  5709. return 1;
  5710. }
  5711. Client* client = ((Player*)spawn)->GetClient();
  5712. if (!client) {
  5713. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given player spawn", lua_interface->GetScriptName(state));
  5714. lua_interface->ResetFunctionStack(state);
  5715. lua_interface->SetBooleanValue(state, false);
  5716. return 1;
  5717. }
  5718. Item* item = master_item_list.GetItem(item_id);
  5719. if (!item) {
  5720. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5721. lua_interface->ResetFunctionStack(state);
  5722. lua_interface->SetBooleanValue(state, false);
  5723. return 1;
  5724. }
  5725. Item* firstItem = new Item(item);
  5726. quest->AddTmpRewardItem(firstItem);
  5727. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5728. bool itemsAddedSuccessfully = true;
  5729. if(num_args > 4)
  5730. {
  5731. for(int8 n=5;n<num_args+1;n++)
  5732. {
  5733. int32 new_item = lua_interface->GetInt32Value(state, n);
  5734. Item* tmpItem = master_item_list.GetItem(new_item);
  5735. if(tmpItem)
  5736. {
  5737. Item* newTmpItem = new Item(tmpItem);
  5738. quest->AddTmpRewardItem(newTmpItem);
  5739. }
  5740. else
  5741. itemsAddedSuccessfully = false;
  5742. }
  5743. }
  5744. client->AddPendingQuestReward(quest, true, true, description); // queue for display
  5745. lua_interface->ResetFunctionStack(state);
  5746. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5747. return 1;
  5748. }
  5749. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5750. if (!lua_interface)
  5751. return 0;
  5752. Quest* quest = lua_interface->GetQuest(state);
  5753. lua_interface->ResetFunctionStack(state);
  5754. if (!quest) {
  5755. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5756. return 0;
  5757. }
  5758. quest->SetRepeatable(true);
  5759. return 0;
  5760. }
  5761. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5762. if (!lua_interface)
  5763. return 0;
  5764. Spawn* spawn = lua_interface->GetSpawn(state);
  5765. lua_interface->ResetFunctionStack(state);
  5766. if (!spawn) {
  5767. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5768. return 0;
  5769. }
  5770. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5771. string ret = classes.GetClassNameCase(base_class);
  5772. if (ret.length() > 0) {
  5773. lua_interface->SetStringValue(state, ret.c_str());
  5774. return 1;
  5775. }
  5776. return 0;
  5777. }
  5778. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5779. if (!lua_interface)
  5780. return 0;
  5781. Spawn* player = lua_interface->GetSpawn(state);
  5782. lua_interface->ResetFunctionStack(state);
  5783. if (player && player->IsPlayer()) {
  5784. Client* client = player->GetClient();
  5785. if (client)
  5786. client->SendWaypoints();
  5787. }
  5788. return 0;
  5789. }
  5790. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5791. if (!lua_interface)
  5792. return 0;
  5793. Spawn* player = lua_interface->GetSpawn(state);
  5794. string name = lua_interface->GetStringValue(state, 2);
  5795. int32 type = lua_interface->GetInt32Value(state, 3);
  5796. lua_interface->ResetFunctionStack(state);
  5797. if (type == 0)
  5798. type = 2;
  5799. if (name.length() > 0) {
  5800. if (player && player->IsPlayer()) {
  5801. Client* client = player->GetClient();
  5802. if (client)
  5803. client->AddWaypoint(name, type);
  5804. }
  5805. }
  5806. return 0;
  5807. }
  5808. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5809. if (!lua_interface)
  5810. return 0;
  5811. Spawn* player = lua_interface->GetSpawn(state);
  5812. string name = lua_interface->GetStringValue(state, 2);
  5813. lua_interface->ResetFunctionStack(state);
  5814. if (name.length() > 0) {
  5815. if (player && player->IsPlayer()) {
  5816. Client* client = player->GetClient();
  5817. if (client)
  5818. client->RemoveWaypoint(name);
  5819. }
  5820. }
  5821. return 0;
  5822. }
  5823. int EQ2Emu_lua_AddWard(lua_State* state) {
  5824. if (!lua_interface)
  5825. return 0;
  5826. int32 damage = lua_interface->GetInt32Value(state);
  5827. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5828. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5829. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5830. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5831. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5832. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5833. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5834. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5835. lua_interface->ResetFunctionStack(state);
  5836. if(!spell || spell->resisted) {
  5837. return 0;
  5838. }
  5839. bool ward_was_added = false;
  5840. ZoneServer* zone = spell->caster->GetZone();
  5841. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5842. for (int32 i = 0; i < spell->targets.size(); i++) {
  5843. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5844. if (!target)
  5845. continue;
  5846. if (target->IsEntity()) {
  5847. // If the ward is already active remove it
  5848. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5849. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5850. // Create new ward info
  5851. WardInfo* ward = new WardInfo;
  5852. ward->Spell = spell;
  5853. ward->BaseDamage = damage;
  5854. ward->DamageLeft = damage;
  5855. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5856. ward->keepWard = keepWard;
  5857. ward->WardType = wardType;
  5858. if (damageAbsorptionPercent > 100)
  5859. damageAbsorptionPercent = 100;
  5860. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5861. if (damageAbsorptionMaxHealthPercent > 100)
  5862. damageAbsorptionMaxHealthPercent = 100;
  5863. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5864. ward->RedirectDamagePercent = redirectDamagePercent;
  5865. ward->LastRedirectDamage = 0;
  5866. ward->LastAbsorbedDamage = 0;
  5867. ward->HitCount = 0;
  5868. spell->num_triggers = maxHitCount;
  5869. spell->had_triggers = true;
  5870. spell->cancel_after_all_triggers = false;
  5871. ward->MaxHitCount = maxHitCount;
  5872. ward->RoundTriggered = false;
  5873. if (wardType == WARD_TYPE_MAGICAL)
  5874. ward->DamageType = damageTypes;
  5875. // Add the ward to the entity
  5876. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5877. ward_was_added = true;
  5878. }
  5879. }
  5880. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5881. if (ward_was_added && spell->caster->IsPlayer()) {
  5882. spell->had_dmg_remaining = true;
  5883. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, damage, 1);
  5884. }
  5885. return 0;
  5886. }
  5887. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5888. if (!lua_interface)
  5889. return 0;
  5890. int32 amount = lua_interface->GetInt32Value(state);
  5891. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5892. lua_interface->ResetFunctionStack(state);
  5893. WardInfo* ward = 0;
  5894. if(!spell || spell->resisted) {
  5895. return 0;
  5896. }
  5897. ZoneServer* zone = spell->caster->GetZone();
  5898. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5899. if (spell->targets.size() > 0 && zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5900. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5901. ward = target->GetWard(spell->spell->GetSpellID());
  5902. if (target && ward) {
  5903. ward->DamageLeft += amount;
  5904. if (ward->DamageLeft > ward->BaseDamage)
  5905. ward->DamageLeft = ward->BaseDamage;
  5906. for (int32 i = 0; i < spell->targets.size(); i++) {
  5907. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5908. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5909. }
  5910. }
  5911. }
  5912. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5913. if (ward && spell->caster->IsPlayer())
  5914. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
  5915. return 0;
  5916. }
  5917. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5918. if (!lua_interface)
  5919. return 0;
  5920. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5921. lua_interface->ResetFunctionStack(state);
  5922. if (!spell) {
  5923. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5924. return 0;
  5925. }
  5926. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5927. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5928. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5929. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5930. if (ward) {
  5931. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5932. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5933. return 1;
  5934. }
  5935. }
  5936. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5937. return 0;
  5938. }
  5939. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5940. if (!lua_interface)
  5941. return 0;
  5942. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5943. if (!spell) {
  5944. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5945. lua_interface->ResetFunctionStack(state);
  5946. return 0;
  5947. }
  5948. string type = lua_interface->GetStringValue(state, 2);
  5949. lua_interface->ResetFunctionStack(state);
  5950. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5951. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5952. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5953. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5954. if (ward) {
  5955. if (boost::iequals(type, "damageleft"))
  5956. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5957. else if (boost::iequals(type, "basedamage"))
  5958. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5959. else if (boost::iequals(type, "keepward"))
  5960. lua_interface->SetBooleanValue(state, ward->keepWard);
  5961. else if (boost::iequals(type, "wardtype"))
  5962. lua_interface->SetInt32Value(state, ward->WardType);
  5963. else if (boost::iequals(type, "dmgabsorptionpct"))
  5964. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5965. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5966. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5967. else if (boost::iequals(type, "redirectdamagepercent"))
  5968. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5969. else if (boost::iequals(type, "lastredirectdamage"))
  5970. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5971. else if (boost::iequals(type, "lastabsorbeddamage"))
  5972. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5973. else if (boost::iequals(type, "hitcount"))
  5974. lua_interface->SetInt32Value(state, ward->HitCount);
  5975. else if (boost::iequals(type, "maxhitcount"))
  5976. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5977. else
  5978. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5979. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5980. return 1;
  5981. }
  5982. }
  5983. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5984. return 0;
  5985. }
  5986. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5987. if (!lua_interface)
  5988. return 0;
  5989. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5990. lua_interface->ResetFunctionStack(state);
  5991. if(!spell) {
  5992. return 0;
  5993. }
  5994. ZoneServer* zone = spell->caster->GetZone();
  5995. Spawn* target = 0;
  5996. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5997. for (int32 i = 0; i < spell->targets.size(); i++) {
  5998. target = zone->GetSpawnByID(spell->targets.at(i));
  5999. if (target && target->IsEntity()) {
  6000. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  6001. }
  6002. }
  6003. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6004. return 0;
  6005. }
  6006. int EQ2Emu_lua_Interrupt(lua_State* state)
  6007. {
  6008. if (!lua_interface)
  6009. return 0;
  6010. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  6011. Spawn* target = lua_interface->GetSpawn(state, 2);
  6012. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6013. lua_interface->ResetFunctionStack(state);
  6014. if (!caster)
  6015. {
  6016. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6017. return 0;
  6018. }
  6019. if (!target)
  6020. {
  6021. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6022. return 0;
  6023. }
  6024. if (!spell) {
  6025. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  6026. return 0;
  6027. }
  6028. if (!target->IsEntity() && !spell)
  6029. {
  6030. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  6031. return 0;
  6032. }
  6033. if (!target && spell) {
  6034. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6035. for (int8 i = 0; i < spell->targets.size(); i++) {
  6036. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6037. if (!target || !target->IsEntity())
  6038. continue;
  6039. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  6040. }
  6041. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6042. }
  6043. else
  6044. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  6045. return 0;
  6046. }
  6047. int EQ2Emu_lua_Stealth(lua_State* state) {
  6048. if (!lua_interface)
  6049. return 0;
  6050. int8 type = lua_interface->GetInt8Value(state);
  6051. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6052. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6053. lua_interface->ResetFunctionStack(state);
  6054. if (!spell) {
  6055. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  6056. return 0;
  6057. }
  6058. ZoneServer* zone = spell->caster->GetZone();
  6059. if (spawn) {
  6060. if (spawn->IsEntity()) {
  6061. if (type == 1) {
  6062. ((Entity*)spawn)->AddStealthSpell(spell);
  6063. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  6064. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  6065. }
  6066. else if (type == 2) {
  6067. ((Entity*)spawn)->AddInvisSpell(spell);
  6068. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  6069. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  6070. }
  6071. return 0;
  6072. }
  6073. else {
  6074. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  6075. return 0;
  6076. }
  6077. }
  6078. else {
  6079. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6080. for (int32 i = 0; i < spell->targets.size(); i++) {
  6081. spawn = zone->GetSpawnByID(spell->targets.at(i));
  6082. if (!spawn || !spawn->IsEntity())
  6083. continue;
  6084. if (type == 1) {
  6085. ((Entity*)spawn)->AddStealthSpell(spell);
  6086. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  6087. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  6088. }
  6089. else if (type == 2) {
  6090. ((Entity*)spawn)->AddInvisSpell(spell);
  6091. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  6092. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  6093. }
  6094. else {
  6095. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  6096. break;
  6097. }
  6098. }
  6099. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6100. }
  6101. return 0;
  6102. }
  6103. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  6104. if (!lua_interface)
  6105. return 0;
  6106. Spawn* spawn = lua_interface->GetSpawn(state);
  6107. lua_interface->ResetFunctionStack(state);
  6108. if (!spawn) {
  6109. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6110. return 0;
  6111. }
  6112. if (spawn->IsEntity()) {
  6113. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  6114. return 1;
  6115. }
  6116. else
  6117. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  6118. return 0;
  6119. }
  6120. int EQ2Emu_lua_IsInvis(lua_State* state) {
  6121. if (!lua_interface)
  6122. return 0;
  6123. Spawn* spawn = lua_interface->GetSpawn(state);
  6124. lua_interface->ResetFunctionStack(state);
  6125. if (!spawn) {
  6126. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  6127. return 0;
  6128. }
  6129. if (spawn->IsEntity()) {
  6130. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  6131. return 1;
  6132. }
  6133. else
  6134. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  6135. return 0;
  6136. }
  6137. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  6138. if (!lua_interface)
  6139. return 0;
  6140. Spawn* player = lua_interface->GetSpawn(state);
  6141. int32 item_id = lua_interface->GetInt32Value(state, 2);
  6142. lua_interface->ResetFunctionStack(state);
  6143. if (!player->IsPlayer()) {
  6144. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  6145. return 0;
  6146. }
  6147. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  6148. return 1;
  6149. }
  6150. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  6151. if (!lua_interface)
  6152. return 0;
  6153. Spawn* spawn = lua_interface->GetSpawn(state);
  6154. int8 slot = lua_interface->GetInt8Value(state, 2);
  6155. lua_interface->ResetFunctionStack(state);
  6156. if (!spawn) {
  6157. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6158. return 0;
  6159. }
  6160. if (!spawn->IsEntity()) {
  6161. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6162. return 0;
  6163. }
  6164. Item* item = ((Entity*)spawn)->GetEquipmentList()->GetItem(slot);
  6165. if (!item) {
  6166. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  6167. return 0;
  6168. }
  6169. lua_interface->SetItemValue(state, item);
  6170. return 1;
  6171. }
  6172. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  6173. if (!lua_interface)
  6174. return 0;
  6175. Spawn* player = lua_interface->GetSpawn(state);
  6176. int32 id = lua_interface->GetInt32Value(state, 2);
  6177. lua_interface->ResetFunctionStack(state);
  6178. if (!player) {
  6179. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6180. return 0;
  6181. }
  6182. if (!player->IsPlayer()) {
  6183. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6184. return 0;
  6185. }
  6186. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  6187. if (!item) {
  6188. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  6189. return 0;
  6190. }
  6191. lua_interface->SetItemValue(state, item);
  6192. return 1;
  6193. }
  6194. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  6195. if (!lua_interface)
  6196. return 0;
  6197. Spawn* spawn = lua_interface->GetSpawn(state);
  6198. int8 slot = lua_interface->GetInt8Value(state, 2);
  6199. int32 item_id = lua_interface->GetInt32Value(state, 3);
  6200. lua_interface->ResetFunctionStack(state);
  6201. if (!spawn) {
  6202. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6203. return 0;
  6204. }
  6205. if (!spawn->IsEntity()) {
  6206. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6207. return 0;
  6208. }
  6209. Item* item = master_item_list.GetItem(item_id);
  6210. if (!item) {
  6211. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  6212. return 0;
  6213. }
  6214. Item* copy = new Item(item);
  6215. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  6216. if(result)
  6217. {
  6218. ((Entity*)spawn)->SetEquipment(copy, slot);
  6219. spawn->vis_changed = true;
  6220. if(spawn->IsPlayer())
  6221. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6222. }
  6223. else
  6224. {
  6225. safe_delete(copy);
  6226. }
  6227. lua_interface->SetBooleanValue(state, result);
  6228. return 1;
  6229. }
  6230. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  6231. if (!lua_interface)
  6232. return 0;
  6233. Spawn* spawn = lua_interface->GetSpawn(state);
  6234. int8 slot = lua_interface->GetInt8Value(state, 2);
  6235. Item* item = lua_interface->GetItem(state, 3);
  6236. lua_interface->ResetFunctionStack(state);
  6237. if (!spawn) {
  6238. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  6239. return 0;
  6240. }
  6241. if (!spawn->IsEntity()) {
  6242. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6243. return 0;
  6244. }
  6245. if (!item) {
  6246. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  6247. return 0;
  6248. }
  6249. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  6250. if(result)
  6251. {
  6252. ((Entity*)spawn)->SetEquipment(item, slot);
  6253. spawn->vis_changed = true;
  6254. if(spawn->IsPlayer())
  6255. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6256. }
  6257. lua_interface->SetBooleanValue(state, result);
  6258. return 1;
  6259. }
  6260. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  6261. if (!lua_interface)
  6262. return 0;
  6263. Spawn* spawn = lua_interface->GetSpawn(state);
  6264. int8 slot = lua_interface->GetInt8Value(state, 2);
  6265. 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
  6266. lua_interface->ResetFunctionStack(state);
  6267. if (!spawn) {
  6268. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6269. return 0;
  6270. }
  6271. if (!spawn->IsEntity()) {
  6272. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6273. return 0;
  6274. }
  6275. if(slot >= NUM_SLOTS) {
  6276. lua_interface->LogError("%s: LUA UnequipSlot command error: wrong slot id given %u, max %u", lua_interface->GetScriptName(state), slot, NUM_SLOTS);
  6277. return 0;
  6278. }
  6279. if(spawn->IsPlayer() && ((Player*)spawn)->GetClient()) {
  6280. Item* item = ((Player*)spawn)->GetEquipmentList()->GetItem(slot);
  6281. if(item) {
  6282. item->save_needed = true;
  6283. if(no_delete_item) {
  6284. database.DeleteItem(((Player*)spawn)->GetClient()->GetCharacterID(), item, 0);
  6285. ((Player*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6286. }
  6287. else{
  6288. Client* client = ((Player*)spawn)->GetClient();
  6289. client->UnequipItem(item->details.index);
  6290. }
  6291. }
  6292. }
  6293. else
  6294. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6295. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  6296. spawn->vis_changed = true;
  6297. if(spawn->IsPlayer())
  6298. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6299. lua_interface->SetBooleanValue(state, true);
  6300. return 1;
  6301. }
  6302. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  6303. if (!lua_interface)
  6304. return 0;
  6305. Spawn* spawn = lua_interface->GetSpawn(state);
  6306. int8 slot = lua_interface->GetInt8Value(state, 2);
  6307. int16 type = lua_interface->GetInt16Value(state, 3);
  6308. int8 r = lua_interface->GetInt8Value(state, 4);
  6309. int8 g = lua_interface->GetInt8Value(state, 5);
  6310. int8 b = lua_interface->GetInt8Value(state, 6);
  6311. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6312. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6313. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6314. lua_interface->ResetFunctionStack(state);
  6315. if (!spawn) {
  6316. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6317. return 0;
  6318. }
  6319. if (!spawn->IsEntity()) {
  6320. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6321. return 0;
  6322. }
  6323. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6324. spawn->vis_changed = true;
  6325. lua_interface->SetBooleanValue(state, true);
  6326. return 1;
  6327. }
  6328. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6329. if (!lua_interface)
  6330. return 0;
  6331. Spawn* player = lua_interface->GetSpawn(state);
  6332. int32 id = lua_interface->GetInt32Value(state, 2);
  6333. int8 count = lua_interface->GetInt8Value(state, 3);
  6334. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6335. lua_interface->ResetFunctionStack(state);
  6336. if (!player) {
  6337. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6338. return 0;
  6339. }
  6340. if (!player->IsPlayer()) {
  6341. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6342. return 0;
  6343. }
  6344. if (!count)
  6345. count = 1;
  6346. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6347. if (!item) {
  6348. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6349. return 0;
  6350. }
  6351. lua_interface->SetItemValue(state, item);
  6352. return 1;
  6353. }
  6354. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6355. if (!lua_interface)
  6356. return 0;
  6357. Spawn* spawn = lua_interface->GetSpawn(state);
  6358. int32 anim = lua_interface->GetInt32Value(state, 2);
  6359. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6360. int8 type = lua_interface->GetInt8Value(state, 4);
  6361. lua_interface->ResetFunctionStack(state);
  6362. if (!spawn) {
  6363. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6364. return 0;
  6365. }
  6366. if (spawn2) {
  6367. if (spawn2->IsPlayer()) {
  6368. if (type != 1 && type != 2)
  6369. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6370. else
  6371. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6372. return 0;
  6373. }
  6374. else {
  6375. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6376. return 0;
  6377. }
  6378. }
  6379. else
  6380. spawn->GetZone()->PlayAnimation(spawn, anim);
  6381. return 0;
  6382. }
  6383. int EQ2Emu_lua_IsPet(lua_State* state) {
  6384. if (!lua_interface)
  6385. return 0;
  6386. Spawn* spawn = lua_interface->GetSpawn(state);
  6387. lua_interface->ResetFunctionStack(state);
  6388. if (!spawn) {
  6389. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6390. return 0;
  6391. }
  6392. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6393. return 1;
  6394. }
  6395. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6396. if (!lua_interface)
  6397. return 0;
  6398. Spawn* spawn = lua_interface->GetSpawn(state);
  6399. lua_interface->ResetFunctionStack(state);
  6400. if (!spawn) {
  6401. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6402. return 0;
  6403. }
  6404. if (!spawn->IsNPC()) {
  6405. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6406. return 0;
  6407. }
  6408. if (((NPC*)spawn)->GetOwner()) {
  6409. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6410. return 1;
  6411. }
  6412. return 0;
  6413. }
  6414. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6415. if (!lua_interface)
  6416. return 0;
  6417. Spawn* spawn = lua_interface->GetSpawn(state);
  6418. Spawn* target = lua_interface->GetSpawn(state, 2);
  6419. lua_interface->ResetFunctionStack(state);
  6420. if (!spawn) {
  6421. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6422. return 0;
  6423. }
  6424. if (!spawn) {
  6425. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6426. return 0;
  6427. }
  6428. spawn->SetTarget(target);
  6429. return 0;
  6430. }
  6431. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6432. if (!lua_interface)
  6433. return 0;
  6434. Spawn* spawn = lua_interface->GetSpawn(state);
  6435. bool val = lua_interface->GetBooleanValue(state, 2);
  6436. lua_interface->ResetFunctionStack(state);
  6437. if (!spawn) {
  6438. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6439. return 0;
  6440. }
  6441. if (!spawn->IsEntity()) {
  6442. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6443. return 0;
  6444. }
  6445. ((Entity*)spawn)->InCombat(val);
  6446. if (val) {
  6447. spawn->ClearRunningLocations();
  6448. spawn->CalculateRunningLocation(true);
  6449. }
  6450. return 0;
  6451. }
  6452. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6453. if (!lua_interface)
  6454. return 0;
  6455. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6456. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6457. lua_interface->ResetFunctionStack(state);
  6458. if (!spawn1) {
  6459. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6460. return 0;
  6461. }
  6462. if (!spawn2) {
  6463. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6464. return 0;
  6465. }
  6466. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6467. return 1;
  6468. }
  6469. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6470. if (!lua_interface)
  6471. return 0;
  6472. Spawn* spawn = lua_interface->GetSpawn(state);
  6473. lua_interface->ResetFunctionStack(state);
  6474. if (!spawn) {
  6475. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6476. return 0;
  6477. }
  6478. if (!spawn->IsNPC()) {
  6479. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6480. return 0;
  6481. }
  6482. ((NPC*)spawn)->ClearRunback();
  6483. return 0;
  6484. }
  6485. int EQ2Emu_lua_Runback(lua_State* state) {
  6486. if (!lua_interface)
  6487. return 0;
  6488. Spawn* spawn = lua_interface->GetSpawn(state);
  6489. lua_interface->ResetFunctionStack(state);
  6490. if (!spawn) {
  6491. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6492. return 0;
  6493. }
  6494. if (!spawn->IsNPC()) {
  6495. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6496. return 0;
  6497. }
  6498. ((NPC*)spawn)->Runback();
  6499. return 0;
  6500. }
  6501. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6502. if (!lua_interface)
  6503. return 0;
  6504. Spawn* spawn = lua_interface->GetSpawn(state);
  6505. lua_interface->ResetFunctionStack(state);
  6506. if (!spawn) {
  6507. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6508. return 0;
  6509. }
  6510. if (!spawn->IsNPC()) {
  6511. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6512. return 0;
  6513. }
  6514. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6515. return 1;
  6516. }
  6517. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6518. if (!lua_interface)
  6519. return 0;
  6520. Spawn* spawn = lua_interface->GetSpawn(state);
  6521. lua_interface->ResetFunctionStack(state);
  6522. if (!spawn) {
  6523. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6524. return 0;
  6525. }
  6526. if (!spawn->IsEntity()) {
  6527. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6528. return 0;
  6529. }
  6530. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6531. return 1;
  6532. }
  6533. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6534. if (!lua_interface)
  6535. return 0;
  6536. Spawn* spawn = lua_interface->GetSpawn(state);
  6537. lua_interface->ResetFunctionStack(state);
  6538. if (!spawn) {
  6539. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6540. return 0;
  6541. }
  6542. if (!spawn->IsEntity()) {
  6543. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6544. return 0;
  6545. }
  6546. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6547. return 1;
  6548. }
  6549. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6550. if (!lua_interface)
  6551. return 0;
  6552. Spawn* spawn = lua_interface->GetSpawn(state);
  6553. lua_interface->ResetFunctionStack(state);
  6554. if (!spawn) {
  6555. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6556. return 0;
  6557. }
  6558. if (!spawn->IsEntity()) {
  6559. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6560. return 0;
  6561. }
  6562. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6563. return 1;
  6564. }
  6565. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6566. if (!lua_interface)
  6567. return 0;
  6568. Spawn* spawn = lua_interface->GetSpawn(state);
  6569. lua_interface->ResetFunctionStack(state);
  6570. if (!spawn) {
  6571. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6572. return 0;
  6573. }
  6574. if (!spawn->IsEntity()) {
  6575. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6576. return 0;
  6577. }
  6578. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6579. return 1;
  6580. }
  6581. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6582. if (!lua_interface)
  6583. return 0;
  6584. Spawn* spawn = lua_interface->GetSpawn(state);
  6585. Spawn* target = lua_interface->GetSpawn(state, 2);
  6586. float distance = lua_interface->GetFloatValue(state, 3);
  6587. lua_interface->ResetFunctionStack(state);
  6588. if (!spawn) {
  6589. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6590. return 0;
  6591. }
  6592. if (!target) {
  6593. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6594. return 0;
  6595. }
  6596. if (!spawn->IsNPC()) {
  6597. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6598. return 0;
  6599. }
  6600. if (!target->IsEntity()) {
  6601. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6602. return 0;
  6603. }
  6604. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6605. return 1;
  6606. }
  6607. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6608. if (!lua_interface)
  6609. return 0;
  6610. Spawn* spawn = lua_interface->GetSpawn(state);
  6611. Spawn* target = lua_interface->GetSpawn(state, 2);
  6612. float distance = lua_interface->GetFloatValue(state, 3);
  6613. lua_interface->ResetFunctionStack(state);
  6614. if (!spawn) {
  6615. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6616. return 0;
  6617. }
  6618. if (!target) {
  6619. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6620. return 0;
  6621. }
  6622. if (!spawn->IsNPC()) {
  6623. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6624. return 0;
  6625. }
  6626. if (!target->IsEntity()) {
  6627. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6628. return 0;
  6629. }
  6630. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6631. return 0;
  6632. }
  6633. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6634. if (!lua_interface)
  6635. return 0;
  6636. Spawn* spawn = lua_interface->GetSpawn(state);
  6637. lua_interface->ResetFunctionStack(state);
  6638. if (!spawn) {
  6639. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6640. return 0;
  6641. }
  6642. if (!spawn->IsNPC()) {
  6643. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6644. return 0;
  6645. }
  6646. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6647. return 1;
  6648. }
  6649. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6650. if (!lua_interface)
  6651. return 0;
  6652. Spawn* spawn = lua_interface->GetSpawn(state);
  6653. lua_interface->ResetFunctionStack(state);
  6654. if (!spawn) {
  6655. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6656. return 0;
  6657. }
  6658. if (!spawn->IsNPC()) {
  6659. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6660. return 0;
  6661. }
  6662. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6663. return 1;
  6664. }
  6665. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6666. if (!lua_interface)
  6667. return 0;
  6668. Spawn* spawn = lua_interface->GetSpawn(state);
  6669. lua_interface->ResetFunctionStack(state);
  6670. if (!spawn) {
  6671. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6672. return 0;
  6673. }
  6674. if (!spawn->IsNPC()) {
  6675. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6676. return 0;
  6677. }
  6678. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6679. if (hated) {
  6680. lua_interface->SetSpawnValue(state, hated);
  6681. return 1;
  6682. }
  6683. return 0;
  6684. }
  6685. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6686. if (!lua_interface)
  6687. return 0;
  6688. Spawn* spawn = lua_interface->GetSpawn(state);
  6689. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6690. lua_interface->ResetFunctionStack(state);
  6691. if (!spawn) {
  6692. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6693. return 0;
  6694. }
  6695. if (!spawn->IsNPC()) {
  6696. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6697. return 0;
  6698. }
  6699. if (!hated) {
  6700. ((NPC*)spawn)->Brain()->ClearHate();
  6701. return 0;
  6702. }
  6703. else
  6704. {
  6705. if (!hated->IsEntity()) {
  6706. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6707. return 0;
  6708. }
  6709. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6710. return 0;
  6711. }
  6712. return 0;
  6713. }
  6714. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6715. if (!lua_interface)
  6716. return 0;
  6717. Spawn* spawn = lua_interface->GetSpawn(state);
  6718. lua_interface->ResetFunctionStack(state);
  6719. if (!spawn) {
  6720. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6721. return 0;
  6722. }
  6723. if (!spawn->IsNPC()) {
  6724. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6725. return 0;
  6726. }
  6727. ((NPC*)spawn)->Brain()->ClearEncounter();
  6728. return 0;
  6729. }
  6730. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6731. if (!lua_interface)
  6732. return 0;
  6733. Spawn* spawn = lua_interface->GetSpawn(state);
  6734. lua_interface->ResetFunctionStack(state);
  6735. if (!spawn) {
  6736. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6737. return 0;
  6738. }
  6739. if (!spawn->IsNPC()) {
  6740. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6741. return 0;
  6742. }
  6743. // Temp list to store hate list
  6744. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6745. if (encounterList->size() == 0) {
  6746. safe_delete(encounterList);
  6747. return 0;
  6748. }
  6749. lua_createtable(state, encounterList->size(), 0);
  6750. int newTable = lua_gettop(state);
  6751. for (int32 i = 0; i < encounterList->size(); i++) {
  6752. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6753. if (temp)
  6754. lua_interface->SetSpawnValue(state, temp);
  6755. lua_rawseti(state, newTable, i + 1);
  6756. }
  6757. safe_delete(encounterList);
  6758. return 1;
  6759. }
  6760. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6761. if (!lua_interface)
  6762. return 0;
  6763. Spawn* spawn = lua_interface->GetSpawn(state);
  6764. lua_interface->ResetFunctionStack(state);
  6765. if (!spawn) {
  6766. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6767. return 0;
  6768. }
  6769. if (!spawn->IsNPC()) {
  6770. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6771. return 0;
  6772. }
  6773. // Temp list to store hate list
  6774. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6775. if (hateList->size() == 0) {
  6776. safe_delete(hateList);
  6777. return 0;
  6778. }
  6779. lua_createtable(state, hateList->size(), 0);
  6780. int newTable = lua_gettop(state);
  6781. for (int32 i = 0; i < hateList->size(); i++) {
  6782. lua_interface->SetSpawnValue(state, hateList->at(i));
  6783. lua_rawseti(state, newTable, i + 1);
  6784. }
  6785. safe_delete(hateList);
  6786. return 1;
  6787. }
  6788. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6789. if (!lua_interface)
  6790. return 0;
  6791. Spawn* spawn = lua_interface->GetSpawn(state);
  6792. lua_interface->ResetFunctionStack(state);
  6793. if (!spawn) {
  6794. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6795. return 0;
  6796. }
  6797. if (spawn->IsPlayer()) {
  6798. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6799. lua_interface->SetBooleanValue(state, true);
  6800. else
  6801. lua_interface->SetBooleanValue(state, false);
  6802. return 1;
  6803. }
  6804. else {
  6805. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6806. return 1;
  6807. }
  6808. }
  6809. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6810. if (!lua_interface)
  6811. return 0;
  6812. Quest* quest = lua_interface->GetQuest(state);
  6813. lua_interface->ResetFunctionStack(state);
  6814. if (!quest) {
  6815. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6816. return 0;
  6817. }
  6818. quest->SetCompletedFlag(true);
  6819. return 0;
  6820. }
  6821. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6822. if (!lua_interface)
  6823. return 0;
  6824. Spawn* spawn = lua_interface->GetSpawn(state);
  6825. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6826. int8 tier = lua_interface->GetInt8Value(state, 3);
  6827. lua_interface->ResetFunctionStack(state);
  6828. if (!spawn) {
  6829. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6830. return 0;
  6831. }
  6832. if (!spawn->IsEntity()) {
  6833. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6834. return 0;
  6835. }
  6836. if (spellID == 0) {
  6837. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6838. return 0;
  6839. }
  6840. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6841. if (effect) {
  6842. if (tier > 0) {
  6843. // If a tier was passed chec to see if it is the same as the effect
  6844. if (tier == effect->tier)
  6845. lua_interface->SetBooleanValue(state, true);
  6846. else
  6847. lua_interface->SetBooleanValue(state, false);
  6848. return 1;
  6849. }
  6850. else {
  6851. // Have an effect but no tier was passed so return true
  6852. lua_interface->SetBooleanValue(state, true);
  6853. }
  6854. return 1;
  6855. }
  6856. // no effect so return false
  6857. lua_interface->SetBooleanValue(state, false);
  6858. return 1;
  6859. }
  6860. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6861. if (!lua_interface)
  6862. return 0;
  6863. Spawn* spawn = lua_interface->GetSpawn(state);
  6864. int32 id = lua_interface->GetInt32Value(state, 2);
  6865. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6866. lua_interface->ResetFunctionStack(state);
  6867. Spawn* spawn2 = 0;
  6868. vector<Spawn*> list;
  6869. if (!spawn) {
  6870. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6871. return 0;
  6872. }
  6873. //If zone not provided, use spawn's zone
  6874. if (!zone)
  6875. zone = spawn->GetZone();
  6876. list = zone->GetSpawnsByID(id);
  6877. if (list.size() == 0) {
  6878. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6879. return 0;
  6880. }
  6881. vector<Spawn*>::iterator itr = list.begin();
  6882. for (int8 i = 0; i < list.size(); i++) {
  6883. spawn2 = itr[i];
  6884. if (spawn2)
  6885. spawn2->AddAllowAccessSpawn(spawn);
  6886. }
  6887. return 0;
  6888. }
  6889. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6890. if (!lua_interface)
  6891. return 0;
  6892. Spawn* spawn = lua_interface->GetSpawn(state);
  6893. int32 id = lua_interface->GetInt32Value(state, 2);
  6894. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6895. lua_interface->ResetFunctionStack(state);
  6896. Spawn* spawn2 = 0;
  6897. if (!spawn) {
  6898. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6899. return 0;
  6900. }
  6901. //If zone not provided, use spawn's zone
  6902. if (!zone)
  6903. zone = spawn->GetZone();
  6904. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6905. vector<Spawn*>::iterator itr = list.begin();
  6906. if (list.size() == 0) {
  6907. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6908. return 0;
  6909. }
  6910. for (int8 i = 0; i < list.size(); i++) {
  6911. spawn2 = itr[i];
  6912. if (spawn2)
  6913. spawn2->RemoveSpawnAccess(spawn);
  6914. }
  6915. return 0;
  6916. }
  6917. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6918. if (!lua_interface)
  6919. return 0;
  6920. Quest* quest = lua_interface->GetQuest(state);
  6921. lua_interface->ResetFunctionStack(state);
  6922. if (!quest) {
  6923. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6924. return 0;
  6925. }
  6926. quest->SetYellowName(true);
  6927. return 0;
  6928. }
  6929. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6930. if (!lua_interface)
  6931. return 0;
  6932. Spawn* spawn = lua_interface->GetSpawn(state);
  6933. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6934. lua_interface->ResetFunctionStack(state);
  6935. if (!spawn) {
  6936. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6937. return 0;
  6938. }
  6939. if (!spawn->IsPlayer()) {
  6940. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6941. return 0;
  6942. }
  6943. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6944. return 1;
  6945. }
  6946. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6947. if (!lua_interface)
  6948. return 0;
  6949. Spawn* spawn = lua_interface->GetSpawn(state);
  6950. lua_interface->ResetFunctionStack(state);
  6951. if (!spawn) {
  6952. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6953. return 0;
  6954. }
  6955. if (!spawn->IsPlayer()) {
  6956. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6957. return 0;
  6958. }
  6959. ZoneServer* zone = spawn->GetZone();
  6960. if (!zone) {
  6961. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6962. return 0;
  6963. }
  6964. Instance_Type iType = zone->GetInstanceType();
  6965. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6966. iType == GROUP_LOCKOUT_INSTANCE ||
  6967. iType == RAID_LOCKOUT_INSTANCE ||
  6968. iType == SOLO_PERSIST_INSTANCE ||
  6969. iType == GROUP_PERSIST_INSTANCE ||
  6970. iType == RAID_PERSIST_INSTANCE) {
  6971. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6972. if (data) {
  6973. // Check to see if the timer has already been set, if it has return out.
  6974. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6975. return 0;
  6976. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6977. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6978. if(spawn->IsPlayer()) {
  6979. Client* client = ((Player*)spawn)->GetClient();
  6980. if (client) {
  6981. string time_msg = "";
  6982. int32 time = data->success_lockout_time;
  6983. int16 hour;
  6984. int8 min;
  6985. int8 sec;
  6986. hour = time / 3600;
  6987. time = time % 3600;
  6988. min = time / 60;
  6989. time = time % 60;
  6990. sec = time;
  6991. if (hour > 0) {
  6992. char temp[10];
  6993. sprintf(temp, " %i", hour);
  6994. time_msg.append(temp);
  6995. time_msg.append(" hour");
  6996. time_msg.append((hour > 1) ? "s" : "");
  6997. }
  6998. if (min > 0) {
  6999. char temp[5];
  7000. sprintf(temp, " %i", min);
  7001. time_msg.append(temp);
  7002. time_msg.append(" minute");
  7003. time_msg.append((min > 1) ? "s" : "");
  7004. }
  7005. // Only add seconds if minutes and hours are 0
  7006. if (hour == 0 && min == 0 && sec > 0) {
  7007. char temp[5];
  7008. sprintf(temp, " %i", sec);
  7009. time_msg.append(temp);
  7010. time_msg.append(" second");
  7011. time_msg.append((sec > 1) ? "s" : "");
  7012. }
  7013. 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());
  7014. }
  7015. else {
  7016. lua_interface->LogError("LUA SetSuccessTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7017. }
  7018. }
  7019. }
  7020. else
  7021. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7022. }
  7023. else
  7024. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  7025. return 0;
  7026. }
  7027. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  7028. if (!lua_interface)
  7029. return 0;
  7030. Spawn* spawn = lua_interface->GetSpawn(state);
  7031. lua_interface->ResetFunctionStack(state);
  7032. if (!spawn) {
  7033. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7034. return 0;
  7035. }
  7036. if (!spawn->IsPlayer()) {
  7037. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  7038. return 0;
  7039. }
  7040. ZoneServer* zone = spawn->GetZone();
  7041. if (!zone) {
  7042. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  7043. return 0;
  7044. }
  7045. Instance_Type iType = zone->GetInstanceType();
  7046. if (iType == SOLO_LOCKOUT_INSTANCE ||
  7047. iType == GROUP_LOCKOUT_INSTANCE ||
  7048. iType == RAID_LOCKOUT_INSTANCE ||
  7049. iType == SOLO_PERSIST_INSTANCE ||
  7050. iType == GROUP_PERSIST_INSTANCE ||
  7051. iType == RAID_PERSIST_INSTANCE) {
  7052. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  7053. if (data) {
  7054. // Check to see if the timer has already been set, if it has return out.
  7055. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  7056. return 0;
  7057. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  7058. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  7059. if(spawn->IsPlayer()) {
  7060. Client* client = ((Player*)spawn)->GetClient();
  7061. if (client) {
  7062. string time_msg = "";
  7063. int32 time = data->failure_lockout_time;
  7064. int16 hour;
  7065. int8 min;
  7066. int8 sec;
  7067. hour = time / 3600;
  7068. time = time % 3600;
  7069. min = time / 60;
  7070. time = time % 60;
  7071. sec = time;
  7072. if (hour > 0) {
  7073. char temp[10];
  7074. sprintf(temp, " %i", hour);
  7075. time_msg.append(temp);
  7076. time_msg.append(" hour");
  7077. time_msg.append((hour > 1) ? "s" : "");
  7078. }
  7079. if (min > 0) {
  7080. char temp[5];
  7081. sprintf(temp, " %i", min);
  7082. time_msg.append(temp);
  7083. time_msg.append(" minute");
  7084. time_msg.append((min > 1) ? "s" : "");
  7085. }
  7086. // Only add seconds if minutes and hours are 0
  7087. if (hour == 0 && min == 0 && sec > 0) {
  7088. char temp[5];
  7089. sprintf(temp, " %i", sec);
  7090. time_msg.append(temp);
  7091. time_msg.append(" second");
  7092. time_msg.append((sec > 1) ? "s" : "");
  7093. }
  7094. 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());
  7095. }
  7096. }
  7097. else {
  7098. lua_interface->LogError("LUA SetFailureTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7099. }
  7100. }
  7101. else
  7102. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7103. }
  7104. else
  7105. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  7106. return 0;
  7107. }
  7108. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  7109. if (!lua_interface)
  7110. return 0;
  7111. Spawn* spawn = lua_interface->GetSpawn(state);
  7112. lua_interface->ResetFunctionStack(state);
  7113. if (!spawn) {
  7114. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  7115. return 0;
  7116. }
  7117. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  7118. return 1;
  7119. }
  7120. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  7121. if (!lua_interface)
  7122. return 0;
  7123. Spawn* player = lua_interface->GetSpawn(state);
  7124. Spawn* ground = lua_interface->GetSpawn(state, 2);
  7125. if (!player) {
  7126. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7127. lua_interface->ResetFunctionStack(state);
  7128. return 0;
  7129. }
  7130. if (!player->IsPlayer()) {
  7131. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  7132. lua_interface->ResetFunctionStack(state);
  7133. return 0;
  7134. }
  7135. if (!ground) {
  7136. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7137. lua_interface->ResetFunctionStack(state);
  7138. return 0;
  7139. }
  7140. if (!ground->IsGroundSpawn()) {
  7141. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  7142. lua_interface->ResetFunctionStack(state);
  7143. return 0;
  7144. }
  7145. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7146. if (!groundspawn_entries) {
  7147. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7148. lua_interface->ResetFunctionStack(state);
  7149. return 0;
  7150. }
  7151. Skill* skill = 0;
  7152. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  7153. if (collection_skill == "Collecting")
  7154. skill = ((Player*)player)->GetSkillByName("Gathering");
  7155. else
  7156. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  7157. if (!skill) {
  7158. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  7159. lua_interface->ResetFunctionStack(state);
  7160. return 0;
  7161. }
  7162. vector<GroundSpawnEntry*>::iterator itr;
  7163. GroundSpawnEntry* entry = 0;
  7164. bool can_harvest = false;
  7165. sint32 min_skill = -1;
  7166. int16 totalSkill = skill->current_val;
  7167. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  7168. if(skillID != 0xFFFFFFFF)
  7169. {
  7170. ((Entity*)player)->MStats.lock();
  7171. totalSkill += ((Entity*)player)->stats[skillID];
  7172. ((Entity*)player)->MStats.unlock();
  7173. }
  7174. // first, iterate through groundspawn_entries, discard tables player cannot use
  7175. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  7176. {
  7177. entry = *itr;
  7178. if (min_skill == -1 || entry->min_skill_level < min_skill)
  7179. min_skill = entry->min_skill_level;
  7180. // if player lacks skill, skip table
  7181. if (entry->min_skill_level > totalSkill)
  7182. continue;
  7183. // if bonus, but player lacks level, skip table
  7184. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  7185. continue;
  7186. can_harvest = true;
  7187. break;
  7188. }
  7189. lua_interface->SetBooleanValue(state, can_harvest);
  7190. // If false, send the message to the client
  7191. if (!can_harvest) {
  7192. Client* client = ((Player*)player)->GetClient();
  7193. if (client) {
  7194. string msg = "You do not have enough skill to ";
  7195. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  7196. msg.append("gather");
  7197. else if (collection_skill == "Mining")
  7198. msg.append("mine");
  7199. else if (collection_skill == "Trapping")
  7200. msg.append("trap");
  7201. else if (collection_skill == "Foresting")
  7202. msg.append("forest");
  7203. else if (collection_skill == "Fishing")
  7204. msg.append("catch");
  7205. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  7206. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  7207. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  7208. }
  7209. }
  7210. lua_interface->ResetFunctionStack(state);
  7211. return 1;
  7212. }
  7213. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  7214. if (!lua_interface)
  7215. return 0;
  7216. Spawn* player = lua_interface->GetSpawn(state);
  7217. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  7218. lua_interface->ResetFunctionStack(state);
  7219. if (!player) {
  7220. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  7221. return 0;
  7222. }
  7223. if (!player->IsPlayer()) {
  7224. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  7225. return 0;
  7226. }
  7227. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  7228. lua_interface->SetBooleanValue(state, ret);
  7229. return 1;
  7230. }
  7231. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  7232. // Check to see if we have a valid lua_interface
  7233. if (!lua_interface)
  7234. return 0;
  7235. // Get the spawn that is getting the pet
  7236. Spawn* spawn = lua_interface->GetSpawn(state);
  7237. Spawn* target = lua_interface->GetSpawn(state, 2);
  7238. // Get the DB ID of the pet
  7239. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  7240. float x = lua_interface->GetFloatValue(state, 4);
  7241. float y = lua_interface->GetFloatValue(state, 5);
  7242. float z = lua_interface->GetFloatValue(state, 6);
  7243. // Get the spell that this command was called from
  7244. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7245. lua_interface->ResetFunctionStack(state);
  7246. // Check to make sure the spawn pointer is valid
  7247. if (!spawn) {
  7248. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  7249. return 0;
  7250. }
  7251. // Check to make sure the spawn is an entity
  7252. if (!spawn->IsEntity()) {
  7253. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  7254. return 0;
  7255. }
  7256. if (!target) {
  7257. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  7258. return 0;
  7259. }
  7260. if (!target->IsEntity()) {
  7261. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  7262. return 0;
  7263. }
  7264. // Check to see if the DB ID for the pet is set
  7265. if (pet_id == 0) {
  7266. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  7267. return 0;
  7268. }
  7269. // Check to see if the pointer to the spell is valid
  7270. if (!luaspell) {
  7271. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  7272. return 0;
  7273. }
  7274. if(luaspell->resisted) {
  7275. return 0;
  7276. }
  7277. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  7278. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  7279. if (!pet) {
  7280. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  7281. return 0;
  7282. }
  7283. // Check to make sure the pet is an npc
  7284. if (!pet->IsNPC()) {
  7285. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  7286. return 0;
  7287. }
  7288. if (x == 0)
  7289. x = spawn->GetX();
  7290. if (y == 0)
  7291. y = spawn->GetY();
  7292. if (z == 0)
  7293. z = spawn->GetZ();
  7294. // Spawn the pet at the same location as the owner
  7295. pet->SetX(x);
  7296. pet->SetY(y);
  7297. pet->SetZ(z);
  7298. pet->SetLocation(spawn->GetLocation());
  7299. pet->SetHeading(spawn->GetHeading());
  7300. spawn->GetZone()->AddSpawn(pet);
  7301. const char* spawn_script = world.GetSpawnScript(pet_id);
  7302. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  7303. spawn->SetSpawnScript(string(spawn_script));
  7304. spawn->GetZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7305. }
  7306. std::string petName = std::string("");
  7307. if(spawn->IsEntity()) {
  7308. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  7309. }
  7310. if(petName.size() < 1) {
  7311. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  7312. petName = spawn->GetZone()->pet_names.at(rand_index);
  7313. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  7314. }
  7315. // Set the pets name
  7316. pet->SetName(petName.c_str());
  7317. // Set the level of the pet to the owners level
  7318. pet->SetLevel(spawn->GetLevel());
  7319. // Set the faction of the pet to the same faction as the owner
  7320. pet->SetFactionID(spawn->GetFactionID());
  7321. // Set the spawn as a pet
  7322. pet->SetPet(true);
  7323. // Give a pointer of the owner to the pet
  7324. ((NPC*)pet)->SetOwner((Entity*)spawn);
  7325. // Set the pet type
  7326. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  7327. // Set the spell id used to create this pet
  7328. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  7329. // Set the spell tier used to create this pet
  7330. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  7331. // Set the pets spawn type to 6
  7332. pet->SetSpawnType(6);
  7333. // Set the pets brain
  7334. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  7335. // Check to see if the pet has a subtitle
  7336. if (strlen(pet->GetSubTitle()) > 0) {
  7337. // Add the players name to the front of the sub title
  7338. string pet_subtitle;
  7339. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  7340. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  7341. // Set the pets subtitle to the new one
  7342. pet->SetSubTitle(pet_subtitle.c_str());
  7343. }
  7344. // Set the pet as the return value for this function
  7345. lua_interface->SetSpawnValue(state, pet);
  7346. return 1;
  7347. }
  7348. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  7349. if (!lua_interface)
  7350. return 0;
  7351. Spawn* spawn = lua_interface->GetSpawn(state);
  7352. Spawn* player = lua_interface->GetSpawn(state, 2);
  7353. float max_distance = lua_interface->GetFloatValue(state, 3);
  7354. string type = lua_interface->GetStringValue(state, 4);
  7355. lua_interface->ResetFunctionStack(state);
  7356. if (!spawn || (spawn && spawn->IsPlayer())) {
  7357. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  7358. return 0;
  7359. }
  7360. if (!player || !player->IsPlayer()) {
  7361. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  7362. return 0;
  7363. }
  7364. Client* client = ((Player*)player)->GetClient();
  7365. if (!client) {
  7366. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7367. return 0;
  7368. }
  7369. //Set max_distance to default if not set or not proper value
  7370. if (max_distance <= 0)
  7371. max_distance = 500;
  7372. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7373. if (packet) {
  7374. float unknown2_3 = 0;
  7375. int8 placement_mode = 0;
  7376. if (type == "wall") {
  7377. placement_mode = 2;
  7378. unknown2_3 = 150;
  7379. }
  7380. else if (type == "ceiling")
  7381. placement_mode = 1;
  7382. packet->setDataByName("placement_mode", placement_mode);
  7383. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7384. packet->setDataByName("model_type", spawn->GetModelType());
  7385. packet->setDataByName("unknown", 1); //size
  7386. packet->setDataByName("unknown2", 1); //size 2
  7387. packet->setDataByName("unknown2", .5, 1); //size 3
  7388. packet->setDataByName("unknown2", 3, 2);
  7389. packet->setDataByName("unknown2", unknown2_3, 3);
  7390. packet->setDataByName("max_distance", max_distance);
  7391. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7392. client->QueuePacket(packet->serialize());
  7393. safe_delete(packet);
  7394. }
  7395. return 0;
  7396. }
  7397. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7398. if (!lua_interface)
  7399. return 0;
  7400. Item* item = lua_interface->GetItem(state);
  7401. lua_interface->ResetFunctionStack(state);
  7402. if (!item) {
  7403. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7404. return 0;
  7405. }
  7406. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7407. return 1;
  7408. }
  7409. int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
  7410. if (!lua_interface)
  7411. return 0;
  7412. Item* item = lua_interface->GetItem(state);
  7413. lua_interface->ResetFunctionStack(state);
  7414. if (!item) {
  7415. lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7416. return 0;
  7417. }
  7418. lua_interface->SetInt32Value(state, item->effect_type);
  7419. return 1;
  7420. }
  7421. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7422. if (!lua_interface)
  7423. return 0;
  7424. Spawn* spawn = lua_interface->GetSpawn(state);
  7425. lua_interface->ResetFunctionStack(state);
  7426. if (!spawn) {
  7427. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7428. return 0;
  7429. }
  7430. if (spawn->GetZone())
  7431. spawn->GetZone()->AddTransportSpawn(spawn);
  7432. return 0;
  7433. }
  7434. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7435. if (!lua_interface)
  7436. return 0;
  7437. Spawn* spawn = lua_interface->GetSpawn(state);
  7438. lua_interface->ResetFunctionStack(state);
  7439. if (!spawn) {
  7440. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7441. return 0;
  7442. }
  7443. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7444. return 1;
  7445. }
  7446. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7447. if (!lua_interface)
  7448. return 0;
  7449. Skill* skill = lua_interface->GetSkill(state);
  7450. lua_interface->ResetFunctionStack(state);
  7451. if (!skill) {
  7452. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7453. return 0;
  7454. }
  7455. lua_interface->SetInt32Value(state, skill->current_val);
  7456. return 1;
  7457. }
  7458. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7459. if (!lua_interface)
  7460. return 0;
  7461. Skill* skill = lua_interface->GetSkill(state);
  7462. lua_interface->ResetFunctionStack(state);
  7463. if (!skill) {
  7464. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7465. return 0;
  7466. }
  7467. lua_interface->SetInt32Value(state, skill->max_val);
  7468. return 1;
  7469. }
  7470. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7471. if (!lua_interface)
  7472. return 0;
  7473. Skill* skill = lua_interface->GetSkill(state);
  7474. lua_interface->ResetFunctionStack(state);
  7475. if (!skill) {
  7476. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7477. return 0;
  7478. }
  7479. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7480. return 1;
  7481. }
  7482. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7483. if (!lua_interface)
  7484. return 0;
  7485. Skill* skill = lua_interface->GetSkill(state);
  7486. int16 value = lua_interface->GetInt16Value(state, 2);
  7487. lua_interface->ResetFunctionStack(state);
  7488. if (!skill) {
  7489. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7490. return 0;
  7491. }
  7492. skill->max_val = value;
  7493. if (skill->max_val < skill->current_val)
  7494. skill->current_val = skill->max_val;
  7495. return 0;
  7496. }
  7497. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7498. if (!lua_interface)
  7499. return 0;
  7500. Skill* skill = lua_interface->GetSkill(state);
  7501. int16 value = lua_interface->GetInt16Value(state, 2);
  7502. lua_interface->ResetFunctionStack(state);
  7503. if (!skill) {
  7504. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7505. return 0;
  7506. }
  7507. if (value > skill->max_val)
  7508. skill->current_val = skill->max_val;
  7509. else
  7510. skill->current_val = value;
  7511. return 0;
  7512. }
  7513. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7514. if (!lua_interface)
  7515. return 0;
  7516. Spawn* player = lua_interface->GetSpawn(state);
  7517. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7518. lua_interface->ResetFunctionStack(state);
  7519. if (skill_id > 0 && player && player->IsPlayer()) {
  7520. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7521. return 1;
  7522. }
  7523. return 0;
  7524. }
  7525. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7526. if (!lua_interface)
  7527. return 0;
  7528. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7529. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7530. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7531. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7532. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7533. lua_interface->ResetFunctionStack(state);
  7534. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7535. if (player_spawn && player_spawn->IsPlayer()) {
  7536. Player* player = (Player*)player_spawn;
  7537. bool added = false;
  7538. if (!player->skill_list.HasSkill(skill_id)) {
  7539. player->AddSkill(skill_id, current_val, max_val, true);
  7540. added = true;
  7541. }
  7542. 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
  7543. Client* client = player->GetClient();
  7544. if (client) {
  7545. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7546. if (packet)
  7547. client->QueuePacket(packet);
  7548. }
  7549. }
  7550. if (added) {
  7551. lua_interface->SetBooleanValue(state, true);
  7552. return 1;
  7553. }
  7554. }
  7555. else {
  7556. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7557. }
  7558. }
  7559. else {
  7560. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7561. }
  7562. lua_interface->SetBooleanValue(state, false);
  7563. return 1;
  7564. }
  7565. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7566. if (!lua_interface)
  7567. return 0;
  7568. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7569. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7570. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7571. lua_interface->ResetFunctionStack(state);
  7572. if (skill_id > 0) {
  7573. if (player_spawn && player_spawn->IsPlayer()) {
  7574. Player* player = (Player*)player_spawn;
  7575. if (player->skill_list.HasSkill(skill_id)) {
  7576. player->RemovePlayerSkill(skill_id, true);
  7577. if (!more_to_remove) {
  7578. Client* client = player->GetClient();
  7579. if (client) {
  7580. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7581. if (packet)
  7582. client->QueuePacket(packet);
  7583. }
  7584. }
  7585. }
  7586. }
  7587. else {
  7588. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7589. }
  7590. }
  7591. else {
  7592. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7593. }
  7594. return 0;
  7595. }
  7596. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7597. if (!lua_interface)
  7598. return 0;
  7599. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7600. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7601. int16 amount = lua_interface->GetInt8Value(state, 3);
  7602. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7603. lua_interface->ResetFunctionStack(state);
  7604. if (amount > 0 && skill_type < 100) {
  7605. if (player_spawn && player_spawn->IsPlayer()) {
  7606. Player* player = (Player*)player_spawn;
  7607. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7608. if (!more_to_increase) {
  7609. Client* client = player->GetClient();
  7610. if (client) {
  7611. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7612. if (packet)
  7613. client->QueuePacket(packet);
  7614. }
  7615. }
  7616. }
  7617. else {
  7618. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7619. }
  7620. }
  7621. else {
  7622. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7623. }
  7624. return 0;
  7625. }
  7626. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7627. if (!lua_interface)
  7628. return 0;
  7629. Spawn* spawn = lua_interface->GetSpawn(state);
  7630. string name = lua_interface->GetStringValue(state, 2);
  7631. lua_interface->ResetFunctionStack(state);
  7632. if (!spawn) {
  7633. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7634. return 0;
  7635. }
  7636. if (!spawn->IsEntity()) {
  7637. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7638. return 0;
  7639. }
  7640. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7641. if (skill) {
  7642. lua_interface->SetSkillValue(state, skill);
  7643. return 1;
  7644. }
  7645. return 0;
  7646. }
  7647. int EQ2Emu_lua_AddProc(lua_State* state) {
  7648. if (!lua_interface)
  7649. return 0;
  7650. Spawn* spawn = lua_interface->GetSpawn(state);
  7651. int8 type = lua_interface->GetInt8Value(state, 2);
  7652. float chance = lua_interface->GetFloatValue(state, 3);
  7653. Item* item = lua_interface->GetItem(state, 4);
  7654. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7655. LuaSpell* spell = 0;
  7656. if (!item)
  7657. spell = lua_interface->GetCurrentSpell(state);
  7658. if (!spawn && (!spell || !use_all_spelltargets)) {
  7659. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7660. return 0;
  7661. }
  7662. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7663. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7664. return 0;
  7665. }
  7666. if (!item && !spell) {
  7667. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7668. return 0;
  7669. }
  7670. if(spell && spell->resisted) {
  7671. return 0;
  7672. }
  7673. if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
  7674. Spawn* target;
  7675. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7676. for (int8 i = 0; i < spell->targets.size(); i++) {
  7677. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7678. if (!target || !target->IsEntity())
  7679. continue;
  7680. ((Entity*)target)->AddProc(type, chance, item, spell);
  7681. }
  7682. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7683. }
  7684. else
  7685. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7686. return 0;
  7687. }
  7688. int EQ2Emu_lua_AddProcExt(lua_State* state) {
  7689. if (!lua_interface)
  7690. return 0;
  7691. Spawn* spawn = lua_interface->GetSpawn(state);
  7692. int8 type = lua_interface->GetInt8Value(state, 2);
  7693. int8 damage_type = lua_interface->GetInt8Value(state, 3);
  7694. float chance = lua_interface->GetFloatValue(state, 4);
  7695. int8 hp_ratio = lua_interface->GetInt8Value(state, 5);
  7696. bool below_health = lua_interface->GetBooleanValue(state, 6);
  7697. bool target_health = lua_interface->GetBooleanValue(state, 7);
  7698. Item* item = lua_interface->GetItem(state, 8);
  7699. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 9) == 1);
  7700. bool extended_version = true;
  7701. LuaSpell* spell = 0;
  7702. if (!item)
  7703. spell = lua_interface->GetCurrentSpell(state);
  7704. if (!spawn && (!spell || !use_all_spelltargets)) {
  7705. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7706. return 0;
  7707. }
  7708. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7709. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7710. return 0;
  7711. }
  7712. if (!item && !spell) {
  7713. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7714. return 0;
  7715. }
  7716. if(spell && spell->resisted) {
  7717. return 0;
  7718. }
  7719. if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
  7720. Spawn* target;
  7721. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7722. for (int8 i = 0; i < spell->targets.size(); i++) {
  7723. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7724. if (!target || !target->IsEntity())
  7725. continue;
  7726. ((Entity*)target)->AddProc(type, chance, item, spell, damage_type, hp_ratio, below_health, target_health, extended_version);
  7727. }
  7728. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7729. }
  7730. else
  7731. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7732. return 0;
  7733. }
  7734. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7735. if (!lua_interface)
  7736. return 0;
  7737. Spawn* spawn = lua_interface->GetSpawn(state);
  7738. Item* item = lua_interface->GetItem(state, 2);
  7739. LuaSpell* spell = 0;
  7740. if (!spawn) {
  7741. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7742. lua_interface->ResetFunctionStack(state);
  7743. return 0;
  7744. }
  7745. if (!spawn->IsEntity()) {
  7746. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7747. lua_interface->ResetFunctionStack(state);
  7748. return 0;
  7749. }
  7750. if (!item)
  7751. spell = lua_interface->GetCurrentSpell(state);
  7752. lua_interface->ResetFunctionStack(state);
  7753. if (!item && !spell) {
  7754. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7755. return 0;
  7756. }
  7757. if (spell && spell->caster && spell->caster->GetZone()) {
  7758. Spawn* target;
  7759. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7760. for (int8 i = 0; i < spell->targets.size(); i++) {
  7761. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7762. if (!target || !target->IsEntity())
  7763. continue;
  7764. ((Entity*)target)->RemoveProc(item, spell);
  7765. }
  7766. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7767. spell->caster->RemoveProc(item, spell);
  7768. }
  7769. else
  7770. ((Entity*)spawn)->RemoveProc(item, spell);
  7771. return 0;
  7772. }
  7773. int EQ2Emu_lua_Knockback(lua_State* state) {
  7774. if (!lua_interface)
  7775. return 0;
  7776. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7777. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7778. int32 duration = lua_interface->GetInt32Value(state, 3);
  7779. float vertical = lua_interface->GetFloatValue(state, 4);
  7780. float horizontal = lua_interface->GetFloatValue(state, 5);
  7781. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7782. lua_interface->ResetFunctionStack(state);
  7783. if (!target_spawn) {
  7784. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7785. return 0;
  7786. }
  7787. if (!spawn) {
  7788. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7789. return 0;
  7790. }
  7791. if ((vertical != 0 || horizontal != 0)) {
  7792. if(spawn->IsPlayer()) {
  7793. Client* client = ((Player*)spawn)->GetClient();
  7794. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7795. if (packet) {
  7796. packet->setDataByName("target_x", target_spawn->GetX());
  7797. packet->setDataByName("target_y", target_spawn->GetY());
  7798. packet->setDataByName("target_z", target_spawn->GetZ());
  7799. packet->setDataByName("vertical_movement", vertical);
  7800. packet->setDataByName("horizontal_movement", horizontal);
  7801. if (use_heading)
  7802. packet->setDataByName("use_player_heading", 1);
  7803. client->QueuePacket(packet->serialize());
  7804. }
  7805. safe_delete(packet);
  7806. }
  7807. else {
  7808. spawn->SetKnockback(target_spawn, duration, vertical, horizontal);
  7809. }
  7810. }
  7811. return 0;
  7812. }
  7813. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7814. if (!lua_interface)
  7815. return 0;
  7816. Spawn* spawn = lua_interface->GetSpawn(state);
  7817. lua_interface->ResetFunctionStack(state);
  7818. if (!spawn) {
  7819. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7820. return 0;
  7821. }
  7822. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7823. return 1;
  7824. }
  7825. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7826. if (!lua_interface)
  7827. return 0;
  7828. Spawn* caster = lua_interface->GetSpawn(state);
  7829. Spawn* target = lua_interface->GetSpawn(state, 2);
  7830. string name = lua_interface->GetStringValue(state, 3);
  7831. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7832. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7833. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7834. string success_msg = lua_interface->GetStringValue(state, 7);
  7835. string effect_msg = lua_interface->GetStringValue(state, 8);
  7836. lua_interface->ResetFunctionStack(state);
  7837. if (!caster) {
  7838. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7839. return 0;
  7840. }
  7841. if (!caster->IsEntity()) {
  7842. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7843. return 0;
  7844. }
  7845. if (!target) {
  7846. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7847. return 0;
  7848. }
  7849. if (!target->IsEntity()) {
  7850. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7851. return 0;
  7852. }
  7853. if (name.length() == 0) {
  7854. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7855. return 0;
  7856. }
  7857. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7858. return 0;
  7859. }
  7860. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7861. if (!lua_interface)
  7862. return 0;
  7863. string name = lua_interface->GetStringValue(state);
  7864. lua_interface->ResetFunctionStack(state);
  7865. if (name.length() == 0) {
  7866. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7867. return 0;
  7868. }
  7869. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7870. if (!skill) {
  7871. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7872. return 0;
  7873. }
  7874. lua_interface->SetInt32Value(state, skill->skill_id);
  7875. return 1;
  7876. }
  7877. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7878. if (!lua_interface)
  7879. return 0;
  7880. Spawn* spawn = lua_interface->GetSpawn(state);
  7881. lua_interface->ResetFunctionStack(state);
  7882. if (!spawn) {
  7883. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7884. return 0;
  7885. }
  7886. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7887. return 1;
  7888. }
  7889. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7890. if (!lua_interface)
  7891. return 0;
  7892. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7893. lua_interface->ResetFunctionStack(state);
  7894. if (!luaspell) {
  7895. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7896. return 0;
  7897. }
  7898. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7899. return 1;
  7900. }
  7901. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7902. if (!lua_interface)
  7903. return 0;
  7904. Spawn* spawn = lua_interface->GetSpawn(state);
  7905. Spawn* target = lua_interface->GetSpawn(state, 2);
  7906. lua_interface->ResetFunctionStack(state);
  7907. if (!spawn) {
  7908. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7909. return 0;
  7910. }
  7911. if (!spawn->IsEntity()) {
  7912. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7913. return 0;
  7914. }
  7915. if (!target) {
  7916. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7917. return 0;
  7918. }
  7919. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7920. return 1;
  7921. }
  7922. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7923. if (!lua_interface)
  7924. return 0;
  7925. Spawn* spawn = lua_interface->GetSpawn(state);
  7926. Spawn* target = lua_interface->GetSpawn(state, 2);
  7927. lua_interface->ResetFunctionStack(state);
  7928. if (!spawn) {
  7929. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7930. return 0;
  7931. }
  7932. if (!spawn->IsEntity()) {
  7933. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7934. return 0;
  7935. }
  7936. if (!target) {
  7937. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7938. return 0;
  7939. }
  7940. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7941. return 1;
  7942. }
  7943. int EQ2Emu_lua_InFront(lua_State* state) {
  7944. if (!lua_interface)
  7945. return 0;
  7946. Spawn* spawn = lua_interface->GetSpawn(state);
  7947. Spawn* target = lua_interface->GetSpawn(state, 2);
  7948. lua_interface->ResetFunctionStack(state);
  7949. if (!spawn) {
  7950. lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7951. return 0;
  7952. }
  7953. if (!spawn->IsEntity()) {
  7954. lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7955. return 0;
  7956. }
  7957. if (!target) {
  7958. lua_interface->LogError("%s: LUA InFrontSpawn command error: target is not valid", lua_interface->GetScriptName(state));
  7959. return 0;
  7960. }
  7961. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->InFrontSpawn(target, spawn->GetX(), spawn->GetZ()));
  7962. return 1;
  7963. }
  7964. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7965. if (!lua_interface)
  7966. return 0;
  7967. Item* item = lua_interface->GetItem(state);
  7968. lua_interface->ResetFunctionStack(state);
  7969. if (!item) {
  7970. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7971. return 0;
  7972. }
  7973. lua_interface->SetInt32Value(state, item->details.count);
  7974. return 1;
  7975. }
  7976. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7977. if (!lua_interface)
  7978. return 0;
  7979. Item* item = lua_interface->GetItem(state);
  7980. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7981. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7982. lua_interface->ResetFunctionStack(state);
  7983. if (!item) {
  7984. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7985. return 0;
  7986. }
  7987. if (!owner) {
  7988. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7989. return 0;
  7990. }
  7991. if (!owner->IsPlayer()) {
  7992. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7993. return 0;
  7994. }
  7995. if (item->stack_count < new_count) {
  7996. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7997. return 0;
  7998. }
  7999. if (new_count > 0) {
  8000. item->details.count = new_count;
  8001. item->save_needed = true;
  8002. }
  8003. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  8004. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  8005. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  8006. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  8007. else
  8008. {
  8009. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  8010. return 0;
  8011. }
  8012. Client* client = ((Player*)owner)->GetClient();
  8013. if (!client)
  8014. return 0;
  8015. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  8016. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  8017. if (app)
  8018. client->QueuePacket(app);
  8019. return 0;
  8020. }
  8021. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  8022. if (!lua_interface)
  8023. return 0;
  8024. int32 time = lua_interface->GetInt32Value(state);
  8025. string function = lua_interface->GetStringValue(state, 2);
  8026. Spawn* caster = lua_interface->GetSpawn(state, 3);
  8027. Spawn* target = lua_interface->GetSpawn(state, 4);
  8028. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8029. lua_interface->ResetFunctionStack(state);
  8030. if (time == 0) {
  8031. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  8032. return 0;
  8033. }
  8034. if (function.length() == 0) {
  8035. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  8036. return 0;
  8037. }
  8038. if (!spell || (!spell->caster || !spell->caster->GetZone())) {
  8039. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  8040. return 0;
  8041. }
  8042. SpellScriptTimer* timer = new SpellScriptTimer;
  8043. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  8044. #ifdef WIN32
  8045. ZeroMemory(timer, sizeof(SpellScriptTimer));
  8046. #else
  8047. bzero(timer, sizeof(SpellScriptTimer));
  8048. #endif*/
  8049. timer->caster = 0;
  8050. timer->deleteWhenDone = false;
  8051. timer->target = 0;
  8052. timer->time = Timer::GetCurrentTime2() + time;
  8053. timer->customFunction = function;
  8054. timer->spell = spell;
  8055. if (caster)
  8056. timer->caster = caster->GetID();
  8057. if (target)
  8058. timer->target = target->GetID();
  8059. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  8060. return 0;
  8061. }
  8062. int EQ2Emu_lua_Resurrect(lua_State* state) {
  8063. if (!lua_interface)
  8064. return 0;
  8065. float hp_perc = lua_interface->GetFloatValue(state);
  8066. float power_perc = lua_interface->GetFloatValue(state, 2);
  8067. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  8068. Spawn* target = lua_interface->GetSpawn(state, 4);
  8069. string heal_name = lua_interface->GetStringValue(state, 5);
  8070. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  8071. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  8072. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8073. lua_interface->ResetFunctionStack(state);
  8074. if (!spell) {
  8075. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  8076. return 0;
  8077. }
  8078. Entity* caster = spell->caster;
  8079. if (!caster) {
  8080. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  8081. return 0;
  8082. }
  8083. Client* client = 0;
  8084. PendingResurrection* rez = 0;
  8085. ZoneServer* zone = spell->caster->GetZone();
  8086. if (!target) {
  8087. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8088. if (spell->targets.size() > 0) {
  8089. vector<int32> spell_targets = spell->targets;
  8090. for (int8 i = 0; i < spell_targets.size(); i++) {
  8091. target = zone->GetSpawnByID(spell_targets.at(i));
  8092. if (!target)
  8093. continue;
  8094. if (!target->IsPlayer())
  8095. continue;
  8096. client = ((Player*)target)->GetClient();
  8097. if (!client)
  8098. continue;
  8099. rez = client->GetCurrentRez();
  8100. if (rez->active)
  8101. continue;
  8102. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  8103. rez->active = true;
  8104. rez->caster = caster;
  8105. rez->expire_timer = new Timer;
  8106. int32 duration = spell->spell->GetSpellDuration();
  8107. rez->expire_timer->Start(duration * 100);
  8108. rez->hp_perc = hp_perc;
  8109. rez->mp_perc = power_perc;
  8110. rez->range = spell->spell->GetSpellData()->range;
  8111. rez->spell_name = spell->spell->GetName();
  8112. if (heal_name.length() > 0)
  8113. rez->heal_name = heal_name;
  8114. else
  8115. rez->heal_name = rez->spell_name;
  8116. rez->no_calcs = no_calcs;
  8117. rez->crit_mod = crit_mod;
  8118. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  8119. if (send_window)
  8120. client->SendResurrectionWindow();
  8121. else {
  8122. target->GetZone()->ResurrectSpawn(target, client);
  8123. rez->should_delete = true;
  8124. }
  8125. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  8126. }
  8127. }
  8128. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8129. }
  8130. else {
  8131. if(!target->IsPlayer())
  8132. return 0;
  8133. client = ((Player*)target)->GetClient();
  8134. if (!client)
  8135. return 0;
  8136. rez = client->GetCurrentRez();
  8137. if (rez->active)
  8138. return 0;
  8139. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  8140. rez->active = true;
  8141. rez->caster = caster;
  8142. rez->expire_timer = new Timer;
  8143. int32 duration = spell->spell->GetSpellDuration();
  8144. rez->expire_timer->Start(duration * 100);
  8145. rez->hp_perc = hp_perc;
  8146. rez->mp_perc = power_perc;
  8147. rez->range = spell->spell->GetSpellData()->range;
  8148. rez->spell_name = spell->spell->GetName();
  8149. if (heal_name.length() > 0)
  8150. rez->heal_name = heal_name;
  8151. else
  8152. rez->heal_name = rez->spell_name;
  8153. rez->no_calcs = no_calcs;
  8154. rez->crit_mod = crit_mod;
  8155. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  8156. if (send_window)
  8157. client->SendResurrectionWindow();
  8158. else {
  8159. target->GetZone()->ResurrectSpawn(target, client);
  8160. rez->should_delete = true;
  8161. }
  8162. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  8163. }
  8164. return 0;
  8165. }
  8166. int EQ2Emu_lua_SetVision(lua_State* state) {
  8167. if (!lua_interface)
  8168. return 0;
  8169. Spawn* spawn = lua_interface->GetSpawn(state);
  8170. int32 vision = lua_interface->GetInt32Value(state, 2);
  8171. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8172. lua_interface->ResetFunctionStack(state);
  8173. if (!spawn) {
  8174. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8175. return 0;
  8176. }
  8177. if (!spawn->IsEntity()) {
  8178. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8179. return 0;
  8180. }
  8181. if (spell && spell->targets.size() > 0) {
  8182. ZoneServer* zone = spell->caster->GetZone();
  8183. for (int8 i = 0; i < spell->targets.size(); i++) {
  8184. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8185. if (target && target->IsEntity()) {
  8186. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  8187. if (target->IsPlayer())
  8188. ((Player*)target)->SetCharSheetChanged(true);
  8189. }
  8190. }
  8191. }
  8192. else {
  8193. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  8194. if (spawn->IsPlayer())
  8195. ((Player*)spawn)->SetCharSheetChanged(true);
  8196. }
  8197. return 0;
  8198. }
  8199. int EQ2Emu_lua_BlurVision(lua_State* state) {
  8200. if (!lua_interface)
  8201. return 0;
  8202. Spawn* spawn = lua_interface->GetSpawn(state);
  8203. float intensity = lua_interface->GetFloatValue(state, 2);
  8204. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8205. lua_interface->ResetFunctionStack(state);
  8206. if (!spawn) {
  8207. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8208. return 0;
  8209. }
  8210. if (!spawn->IsEntity()) {
  8211. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8212. return 0;
  8213. }
  8214. if (spell && spell->targets.size() > 0) {
  8215. ZoneServer* zone = spell->caster->GetZone();
  8216. for (int8 i = 0; i < spell->targets.size(); i++) {
  8217. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8218. if (target && target->IsEntity()) {
  8219. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  8220. if (target->IsPlayer())
  8221. ((Player*)target)->SetCharSheetChanged(true);
  8222. }
  8223. }
  8224. }
  8225. else {
  8226. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  8227. if (spawn->IsPlayer())
  8228. ((Player*)spawn)->SetCharSheetChanged(true);
  8229. }
  8230. return 0;
  8231. }
  8232. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  8233. if (!lua_interface)
  8234. return 0;
  8235. Spawn* spawn = lua_interface->GetSpawn(state);
  8236. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  8237. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8238. lua_interface->ResetFunctionStack(state);
  8239. if (!spawn) {
  8240. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  8241. return 0;
  8242. }
  8243. if (!spawn->IsEntity()) {
  8244. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  8245. return 0;
  8246. }
  8247. if (spell && spell->targets.size() > 0) {
  8248. ZoneServer* zone = spell->caster->GetZone();
  8249. for (int8 i = 0; i < spell->targets.size(); i++) {
  8250. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8251. if (target && target->IsEntity()) {
  8252. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8253. if (target->IsPlayer())
  8254. ((Player*)target)->SetCharSheetChanged(true);
  8255. }
  8256. }
  8257. }
  8258. else {
  8259. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8260. if (spawn->IsPlayer())
  8261. ((Player*)spawn)->SetCharSheetChanged(true);
  8262. }
  8263. return 0;
  8264. }
  8265. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  8266. if (!lua_interface)
  8267. return 0;
  8268. Item* item = lua_interface->GetItem(state);
  8269. int8 type = lua_interface->GetInt32Value(state, 2);
  8270. lua_interface->ResetFunctionStack(state);
  8271. if (!item) {
  8272. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  8273. return 0;
  8274. }
  8275. if (type == 1)
  8276. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  8277. else if (type == 2)
  8278. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  8279. return 1;
  8280. }
  8281. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  8282. if (!lua_interface)
  8283. return 0;
  8284. Spawn* target = lua_interface->GetSpawn(state);
  8285. float val = lua_interface->GetFloatValue(state, 2);
  8286. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8287. lua_interface->ResetFunctionStack(state);
  8288. // Added from Gangrenous post
  8289. if (spell && spell->resisted)
  8290. return 0;
  8291. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  8292. if (val > 1.0f)
  8293. val = 1.0f - (val / 100.0f);
  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* spawn = zone->GetSpawnByID(spell->targets.at(i));
  8298. if (spawn && spawn->IsEntity()) {
  8299. ((Entity*)spawn)->SetSpeedMultiplier(val);
  8300. if (spawn->IsPlayer())
  8301. ((Player*)spawn)->SetCharSheetChanged(true);
  8302. }
  8303. }
  8304. }
  8305. else {
  8306. if (target && target->IsEntity()) {
  8307. ((Entity*)target)->SetSpeedMultiplier(val);
  8308. if (target->IsPlayer())
  8309. ((Player*)target)->SetCharSheetChanged(true);
  8310. }
  8311. }
  8312. return 0;
  8313. }
  8314. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  8315. if (!lua_interface)
  8316. return 0;
  8317. Spawn* spawn = lua_interface->GetSpawn(state);
  8318. int16 model = lua_interface->GetInt16Value(state, 2);
  8319. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8320. lua_interface->ResetFunctionStack(state);
  8321. if (spell && spell->spell && spell->targets.size() > 0) {
  8322. ZoneServer* zone = spell->caster->GetZone();
  8323. for (int32 i = 0; i < spell->targets.size(); i++) {
  8324. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8325. if (target)
  8326. target->SetIllusionModel(model);
  8327. }
  8328. }
  8329. else {
  8330. if (!spawn) {
  8331. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8332. return 0;
  8333. }
  8334. spawn->SetIllusionModel(model);
  8335. }
  8336. return 0;
  8337. }
  8338. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  8339. if (!lua_interface)
  8340. return 0;
  8341. Spawn* spawn = lua_interface->GetSpawn(state);
  8342. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8343. lua_interface->ResetFunctionStack(state);
  8344. if (spell && spell->spell && spell->targets.size() > 0) {
  8345. ZoneServer* zone = spell->caster->GetZone();
  8346. for (int32 i = 0; i < spell->targets.size(); i++) {
  8347. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8348. if (target)
  8349. target->SetIllusionModel(0);
  8350. }
  8351. }
  8352. else {
  8353. if (!spawn) {
  8354. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8355. return 0;
  8356. }
  8357. spawn->SetIllusionModel(0);
  8358. }
  8359. return 0;
  8360. }
  8361. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  8362. if (!lua_interface)
  8363. return 0;
  8364. Spawn* caster = lua_interface->GetSpawn(state);
  8365. Spawn* target = lua_interface->GetSpawn(state, 2);
  8366. float chance = lua_interface->GetFloatValue(state, 3);
  8367. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8368. lua_interface->ResetFunctionStack(state);
  8369. if (!caster) {
  8370. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8371. return 0;
  8372. }
  8373. if (!caster->IsEntity()) {
  8374. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  8375. return 0;
  8376. }
  8377. if (!target) {
  8378. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8379. return 0;
  8380. }
  8381. if (!target->IsEntity()) {
  8382. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  8383. return 0;
  8384. }
  8385. if (chance <= 0) {
  8386. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  8387. return 0;
  8388. }
  8389. if (!spell) {
  8390. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8391. return 0;
  8392. }
  8393. if(spell->resisted) {
  8394. return 0;
  8395. }
  8396. if (((Entity*)caster)->GetThreatTransfer()) {
  8397. return 0;
  8398. }
  8399. ThreatTransfer* transfer = new ThreatTransfer;
  8400. transfer->Target = target->GetID();
  8401. transfer->Amount = chance;
  8402. transfer->Spell = spell;
  8403. ((Entity*)caster)->SetThreatTransfer(transfer);
  8404. return 0;
  8405. }
  8406. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  8407. if (!lua_interface)
  8408. return 0;
  8409. Spawn* spawn = lua_interface->GetSpawn(state);
  8410. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8411. lua_interface->ResetFunctionStack(state);
  8412. if (!spawn) {
  8413. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  8414. return 0;
  8415. }
  8416. if (!spell) {
  8417. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8418. return 0;
  8419. }
  8420. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  8421. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  8422. if(transfer && transfer->Spell != spell) {
  8423. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  8424. return 0;
  8425. }
  8426. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  8427. }
  8428. return 0;
  8429. }
  8430. int EQ2Emu_lua_CureByType(lua_State* state) {
  8431. if (!lua_interface)
  8432. return 0;
  8433. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8434. int8 cure_count = lua_interface->GetInt8Value(state);
  8435. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8436. string cure_name = lua_interface->GetStringValue(state, 3);
  8437. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8438. Spawn* target = lua_interface->GetSpawn(state, 5);
  8439. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  8440. lua_interface->ResetFunctionStack(state);
  8441. if(spell && spell->resisted) {
  8442. return 0;
  8443. }
  8444. if (target) {
  8445. if (!target->IsEntity()) {
  8446. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8447. return 0;
  8448. }
  8449. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8450. std::string alternate_name = "item";
  8451. if(spell)
  8452. alternate_name = std::string(spell->spell->GetName());
  8453. if(!caster && spell)
  8454. caster = (Spawn*)spell->caster;
  8455. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  8456. }
  8457. }
  8458. else {
  8459. ZoneServer* zone = spell->caster->GetZone();
  8460. vector<int32> targets = spell->targets;
  8461. vector<Entity*> targets_to_cure;
  8462. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8463. for (int8 i = 0; i < targets.size(); i++) {
  8464. target = zone->GetSpawnByID(targets.at(i));
  8465. if (!target || !target->IsEntity())
  8466. continue;
  8467. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8468. targets_to_cure.push_back((Entity*)target);
  8469. }
  8470. }
  8471. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8472. vector<Entity*>::iterator itr;
  8473. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  8474. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8475. }
  8476. }
  8477. return 0;
  8478. }
  8479. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  8480. if (!lua_interface)
  8481. return 0;
  8482. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8483. if (!spell) {
  8484. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8485. lua_interface->ResetFunctionStack(state);
  8486. return 0;
  8487. }
  8488. if(spell->resisted) {
  8489. lua_interface->ResetFunctionStack(state);
  8490. return 0;
  8491. }
  8492. int8 cure_count = lua_interface->GetInt8Value(state);
  8493. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8494. string cure_name = lua_interface->GetStringValue(state, 3);
  8495. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8496. Spawn* target = lua_interface->GetSpawn(state, 5);
  8497. lua_interface->ResetFunctionStack(state);
  8498. if (target) {
  8499. if (!target->IsEntity()) {
  8500. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8501. return 0;
  8502. }
  8503. if (((Entity*)target)->GetDetCount() > 0)
  8504. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8505. }
  8506. else {
  8507. ZoneServer* zone = spell->caster->GetZone();
  8508. vector<int32> targets = spell->targets;
  8509. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8510. for (int8 i = 0; i < targets.size(); i++) {
  8511. target = zone->GetSpawnByID(targets.at(i));
  8512. if (!target || !target->IsEntity())
  8513. continue;
  8514. if (((Entity*)target)->GetDetCount() > 0)
  8515. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8516. }
  8517. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8518. }
  8519. return 0;
  8520. }
  8521. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8522. if (!lua_interface)
  8523. return 0;
  8524. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8525. lua_interface->ResetFunctionStack(state);
  8526. if (!spell) {
  8527. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8528. return 0;
  8529. }
  8530. if (!spell->caster) {
  8531. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8532. return 0;
  8533. }
  8534. if (!spell->caster->GetZone()) {
  8535. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8536. return 0;
  8537. }
  8538. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8539. return 0;
  8540. }
  8541. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8542. if (!lua_interface)
  8543. return 0;
  8544. Spawn* spawn = lua_interface->GetSpawn(state);
  8545. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8546. lua_interface->ResetFunctionStack(state);
  8547. if (!spell) {
  8548. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8549. return 0;
  8550. }
  8551. if (spawn && spawn->IsEntity())
  8552. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8553. else {
  8554. ZoneServer* zone = spell->caster->GetZone();
  8555. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8556. for (int32 i = 0; i < spell->targets.size(); i++) {
  8557. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8558. if (!spawn || !spawn->IsEntity())
  8559. continue;
  8560. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8561. }
  8562. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8563. }
  8564. return 0;
  8565. }
  8566. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8567. if (!lua_interface)
  8568. return 0;
  8569. Spawn* spawn = lua_interface->GetSpawn(state);
  8570. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8571. lua_interface->ResetFunctionStack(state);
  8572. if (!spell) {
  8573. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8574. return 0;
  8575. }
  8576. if (spawn && spawn->IsEntity())
  8577. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8578. else {
  8579. ZoneServer* zone = spell->caster->GetZone();
  8580. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8581. for (int32 i = 0; i < spell->targets.size(); i++) {
  8582. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8583. if (!spawn || !spawn->IsEntity())
  8584. continue;
  8585. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8586. }
  8587. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8588. }
  8589. return 0;
  8590. }
  8591. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8592. if (!lua_interface)
  8593. return 0;
  8594. Spawn* caster = lua_interface->GetSpawn(state);
  8595. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8596. lua_interface->ResetFunctionStack(state);
  8597. if (!caster) {
  8598. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8599. return 0;
  8600. }
  8601. if (!caster->IsPlayer()) {
  8602. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8603. return 0;
  8604. }
  8605. Spawn* target = caster->GetTarget();
  8606. if (!target) {
  8607. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8608. return 0;
  8609. }
  8610. Client* client = ((Player*)caster)->GetClient();
  8611. if (!client) {
  8612. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8613. return 0;
  8614. }
  8615. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8616. if (ho) {
  8617. ho->SetTarget(target->GetID());
  8618. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8619. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8620. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8621. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8622. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8623. deque<GroupMemberInfo*>::iterator itr;
  8624. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8625. if (group)
  8626. {
  8627. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8628. deque<GroupMemberInfo*>* members = group->GetMembers();
  8629. for (itr = members->begin(); itr != members->end(); itr++) {
  8630. if ((*itr)->client)
  8631. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8632. }
  8633. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8634. }
  8635. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8636. }
  8637. else
  8638. safe_delete(ho);
  8639. }
  8640. else {
  8641. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8642. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8643. }
  8644. else
  8645. safe_delete(ho);
  8646. }
  8647. }
  8648. return 0;
  8649. }
  8650. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8651. if (!lua_interface)
  8652. return 0;
  8653. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8654. if (!spell) {
  8655. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8656. return 0;
  8657. }
  8658. int16 triggerCount = lua_interface->GetInt16Value(state);
  8659. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8660. if (!triggerCount) {
  8661. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8662. return 0;
  8663. }
  8664. spell->num_triggers = triggerCount;
  8665. spell->had_triggers = true;
  8666. spell->cancel_after_all_triggers = cancel_after_triggers;
  8667. return 0;
  8668. }
  8669. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8670. if (!lua_interface)
  8671. return 0;
  8672. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8673. lua_interface->ResetFunctionStack(state);
  8674. if (!spell) {
  8675. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8676. return 0;
  8677. }
  8678. lua_interface->SetInt32Value(state, spell->num_triggers);
  8679. return 1;
  8680. }
  8681. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8682. if (!lua_interface)
  8683. return 0;
  8684. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8685. if (!spell) {
  8686. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8687. lua_interface->ResetFunctionStack(state);
  8688. return 0;
  8689. }
  8690. if (!spell->caster || !spell->caster->GetZone()) {
  8691. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: caster / caster zone must be set!", lua_interface->GetScriptName(state));
  8692. lua_interface->ResetFunctionStack(state);
  8693. return 0;
  8694. }
  8695. int16 remove_count = lua_interface->GetInt16Value(state);
  8696. lua_interface->ResetFunctionStack(state);
  8697. if (!remove_count)
  8698. remove_count = 1;
  8699. if (remove_count >= spell->num_triggers) {
  8700. spell->num_triggers = 0;
  8701. if (spell->cancel_after_all_triggers)
  8702. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8703. }
  8704. else {
  8705. spell->num_triggers -= remove_count;
  8706. Client* client = spell->caster->IsPlayer() ? ((Player*)spell->caster)->GetClient() : nullptr;
  8707. ClientPacketFunctions::SendMaintainedExamineUpdate(client, spell->slot_pos, spell->num_triggers, 0);
  8708. }
  8709. return 0;
  8710. }
  8711. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8712. if (!lua_interface)
  8713. return 0;
  8714. Spawn* spawn = lua_interface->GetSpawn(state);
  8715. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8716. lua_interface->ResetFunctionStack(state);
  8717. if (!spawn) {
  8718. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8719. return 0;
  8720. }
  8721. if (!copy_spawn) {
  8722. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8723. return 0;
  8724. }
  8725. spawn->CopySpawnAppearance(copy_spawn);
  8726. return 0;
  8727. }
  8728. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8729. Spawn* spawn = lua_interface->GetSpawn(state);
  8730. int8 type = lua_interface->GetInt8Value(state, 2);
  8731. lua_interface->ResetFunctionStack(state);
  8732. if (!spawn) {
  8733. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8734. return 0;
  8735. }
  8736. else if (!spawn->IsEntity()) {
  8737. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8738. return 0;
  8739. }
  8740. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8741. return 1;
  8742. }
  8743. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8744. if (!lua_interface)
  8745. return 0;
  8746. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8747. int8 type = lua_interface->GetInt8Value(state);
  8748. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8749. lua_interface->ResetFunctionStack(state);
  8750. if (!spell) {
  8751. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8752. return 0;
  8753. }
  8754. if(spell->resisted) {
  8755. return 0;
  8756. }
  8757. if (spawn) {
  8758. if (!spawn->IsEntity()) {
  8759. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8760. return 0;
  8761. }
  8762. Entity* entity = ((Entity*)spawn);
  8763. entity->AddImmunity(spell, type);
  8764. }
  8765. else if(spell->caster && spell->caster->GetZone()) {
  8766. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8767. for (int8 i = 0; i < spell->targets.size(); i++) {
  8768. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8769. if (!spawn || !spawn->IsEntity())
  8770. continue;
  8771. Entity* entity = ((Entity*)spawn);
  8772. entity->AddImmunity(spell, type);
  8773. }
  8774. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8775. }
  8776. return 0;
  8777. }
  8778. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8779. if (!lua_interface)
  8780. return 0;
  8781. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8782. int8 type = lua_interface->GetInt8Value(state);
  8783. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8784. lua_interface->ResetFunctionStack(state);
  8785. if (!spell) {
  8786. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8787. return 0;
  8788. }
  8789. if (spawn) {
  8790. if (!spawn->IsEntity()) {
  8791. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8792. return 0;
  8793. }
  8794. Entity* entity = ((Entity*)spawn);
  8795. entity->RemoveImmunity(spell, type);
  8796. }
  8797. else if(spell->caster && spell->caster->GetZone()) {
  8798. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8799. for (int8 i = 0; i < spell->targets.size(); i++) {
  8800. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8801. if (!spawn || !spawn->IsEntity())
  8802. continue;
  8803. Entity* entity = ((Entity*)spawn);
  8804. entity->RemoveImmunity(spell, type);
  8805. }
  8806. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8807. }
  8808. return 0;
  8809. }
  8810. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8811. if (!lua_interface)
  8812. return 0;
  8813. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8814. if (!spell) {
  8815. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8816. lua_interface->ResetFunctionStack(state);
  8817. return 0;
  8818. }
  8819. if(spell->resisted) {
  8820. lua_interface->ResetFunctionStack(state);
  8821. return 0;
  8822. }
  8823. float snare = lua_interface->GetFloatValue(state);
  8824. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8825. lua_interface->ResetFunctionStack(state);
  8826. // convert the val to the speed multipler value (100 - val)
  8827. float val = 100.0 - snare;
  8828. val /= 100.0;
  8829. if (spawn) {
  8830. if (!spawn->IsEntity()) {
  8831. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8832. return 0;
  8833. }
  8834. ((Entity*)spawn)->SetSnareValue(spell, val);
  8835. }
  8836. else if(spell->caster && spell->caster->GetZone()) {
  8837. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8838. for (int8 i = 0; i < spell->targets.size(); i++) {
  8839. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8840. if (!spawn || !spawn->IsEntity())
  8841. continue;
  8842. ((Entity*)spawn)->SetSnareValue(spell, val);
  8843. }
  8844. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8845. }
  8846. return 0;
  8847. }
  8848. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8849. if (!lua_interface)
  8850. return 0;
  8851. Spawn* spawn = lua_interface->GetSpawn(state);
  8852. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8853. lua_interface->ResetFunctionStack(state);
  8854. if (!spawn) {
  8855. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8856. return 0;
  8857. }
  8858. if (race_id == 0) {
  8859. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8860. return 0;
  8861. }
  8862. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8863. return 1;
  8864. }
  8865. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8866. if (!lua_interface)
  8867. return 0;
  8868. Spawn* spawn = lua_interface->GetSpawn(state);
  8869. lua_interface->ResetFunctionStack(state);
  8870. if (!spawn) {
  8871. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8872. return 0;
  8873. }
  8874. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8875. return 1;
  8876. }
  8877. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8878. if (!lua_interface)
  8879. return 0;
  8880. Spawn* spawn = lua_interface->GetSpawn(state);
  8881. lua_interface->ResetFunctionStack(state);
  8882. if (!spawn) {
  8883. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8884. return 0;
  8885. }
  8886. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8887. return 1;
  8888. }
  8889. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8890. if (!lua_interface)
  8891. return 0;
  8892. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8893. lua_interface->ResetFunctionStack(state);
  8894. if (!spell) {
  8895. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8896. return 0;
  8897. }
  8898. lua_interface->SetStringValue(state, spell->spell->GetName());
  8899. return 1;
  8900. }
  8901. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8902. if (!lua_interface)
  8903. return 0;
  8904. Quest* quest = lua_interface->GetQuest(state);
  8905. lua_interface->ResetFunctionStack(state);
  8906. if (!quest) {
  8907. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8908. return 0;
  8909. }
  8910. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8911. return 1;
  8912. }
  8913. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8914. if (!lua_interface)
  8915. return 0;
  8916. Quest* quest = lua_interface->GetQuest(state);
  8917. int32 flags = lua_interface->GetInt32Value(state, 2);
  8918. lua_interface->ResetFunctionStack(state);
  8919. if (!quest) {
  8920. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8921. return 0;
  8922. }
  8923. quest->SetQuestFlags(flags);
  8924. return 0;
  8925. }
  8926. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8927. if (!lua_interface)
  8928. return 0;
  8929. Quest* quest = lua_interface->GetQuest(state);
  8930. Spawn* player = lua_interface->GetSpawn(state, 2);
  8931. int32 step = lua_interface->GetInt32Value(state, 3);
  8932. int32 duration = lua_interface->GetInt32Value(state, 4);
  8933. string action = lua_interface->GetStringValue(state, 5);
  8934. lua_interface->ResetFunctionStack(state);
  8935. if (!quest) {
  8936. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8937. return 0;
  8938. }
  8939. if (!player) {
  8940. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8941. return 0;
  8942. }
  8943. if (!player->IsPlayer()) {
  8944. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8945. return 0;
  8946. }
  8947. if (step == 0) {
  8948. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8949. return 0;
  8950. }
  8951. if (duration == 0) {
  8952. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8953. return 0;
  8954. }
  8955. if (action.length() == 0) {
  8956. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8957. return 0;
  8958. }
  8959. Client* client = ((Player*)player)->GetClient();
  8960. if (!client) {
  8961. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8962. return 0;
  8963. }
  8964. quest->SetTimerStep(step);
  8965. quest->AddFailedAction(step, action);
  8966. quest->SetStepTimer(duration);
  8967. client->AddQuestTimer(quest->GetQuestID());
  8968. return 0;
  8969. }
  8970. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8971. if (!lua_interface)
  8972. return 0;
  8973. Quest* quest = lua_interface->GetQuest(state);
  8974. Spawn* player = lua_interface->GetSpawn(state, 2);
  8975. lua_interface->ResetFunctionStack(state);
  8976. if (!quest) {
  8977. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8978. return 0;
  8979. }
  8980. if (!player) {
  8981. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8982. return 0;
  8983. }
  8984. if (!player->IsPlayer()) {
  8985. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8986. return 0;
  8987. }
  8988. Client* client = ((Player*)player)->GetClient();
  8989. if (!client) {
  8990. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8991. return 0;
  8992. }
  8993. quest->SetTimerStep(0);
  8994. quest->SetStepTimer(0);
  8995. client->RemoveQuestTimer(quest->GetQuestID());
  8996. return 0;
  8997. }
  8998. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8999. if (!lua_interface)
  9000. return 0;
  9001. Spawn* player = lua_interface->GetSpawn(state);
  9002. Quest* quest = lua_interface->GetQuest(state, 2);
  9003. int32 step = lua_interface->GetInt32Value(state, 3);
  9004. lua_interface->ResetFunctionStack(state);
  9005. if (!player) {
  9006. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  9007. return 0;
  9008. }
  9009. if (!player->IsPlayer()) {
  9010. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9011. return 0;
  9012. }
  9013. if (!quest) {
  9014. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  9015. return 0;
  9016. }
  9017. if (step == 0) {
  9018. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  9019. return 0;
  9020. }
  9021. Client* client = ((Player*)player)->GetClient();
  9022. if (!client) {
  9023. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  9024. return 0;
  9025. }
  9026. if (quest->RemoveQuestStep(step, client)) {
  9027. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  9028. client->GetCurrentZone()->SendQuestUpdates(client);
  9029. }
  9030. else
  9031. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  9032. return 0;
  9033. }
  9034. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  9035. if (!lua_interface)
  9036. return 0;
  9037. Quest* quest = lua_interface->GetQuest(state, 1);
  9038. int32 step = lua_interface->GetInt32Value(state, 2);
  9039. string desc = lua_interface->GetStringValue(state, 3);
  9040. string task_group = lua_interface->GetStringValue(state, 4);
  9041. lua_interface->ResetFunctionStack(state);
  9042. if (!quest) {
  9043. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  9044. return 0;
  9045. }
  9046. if (step == 0) {
  9047. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  9048. return 0;
  9049. }
  9050. QuestStep* quest_step = quest->GetQuestStep(step);
  9051. if (!quest_step) {
  9052. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  9053. return 0;
  9054. }
  9055. quest_step->SetStepProgress(0);
  9056. quest_step->SetTaskGroup(task_group);
  9057. quest_step->SetDescription(desc);
  9058. return 0;
  9059. }
  9060. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  9061. if (!lua_interface)
  9062. return 0;
  9063. Quest* quest = lua_interface->GetQuest(state);
  9064. int32 step = lua_interface->GetInt32Value(state, 2);
  9065. string action = lua_interface->GetStringValue(state, 3);
  9066. lua_interface->ResetFunctionStack(state);
  9067. if (!quest) {
  9068. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  9069. return 0;
  9070. }
  9071. if (step == 0) {
  9072. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  9073. return 0;
  9074. }
  9075. if (action.length() == 0) {
  9076. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  9077. return 0;
  9078. }
  9079. quest->AddFailedAction(step, action);
  9080. return 0;
  9081. }
  9082. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  9083. if (!lua_interface)
  9084. return 0;
  9085. Spawn* player = lua_interface->GetSpawn(state);
  9086. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9087. int32 step = lua_interface->GetInt32Value(state, 3);
  9088. lua_interface->ResetFunctionStack(state);
  9089. if (!player) {
  9090. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  9091. return 0;
  9092. }
  9093. if (!player->IsPlayer()) {
  9094. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9095. return 0;
  9096. }
  9097. if (quest_id == 0) {
  9098. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  9099. return 0;
  9100. }
  9101. if (step == 0) {
  9102. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  9103. return 0;
  9104. }
  9105. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  9106. if (!quest) {
  9107. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  9108. return 0;
  9109. }
  9110. quest->StepFailed(step);
  9111. return 0;
  9112. }
  9113. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  9114. if (!lua_interface)
  9115. return 0;
  9116. Spawn* player = lua_interface->GetSpawn(state);
  9117. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9118. lua_interface->ResetFunctionStack(state);
  9119. if (!player) {
  9120. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  9121. return 0;
  9122. }
  9123. if (!player->IsPlayer()) {
  9124. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  9125. return 0;
  9126. }
  9127. if (quest_id == 0) {
  9128. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  9129. return 0;
  9130. }
  9131. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestCompletedCount(quest_id));
  9132. return 1;
  9133. }
  9134. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  9135. if (!lua_interface)
  9136. return 0;
  9137. string name = lua_interface->GetStringValue(state);
  9138. string value = lua_interface->GetStringValue(state, 2);
  9139. string comment = lua_interface->GetStringValue(state, 3);
  9140. lua_interface->ResetFunctionStack(state);
  9141. if (name.length() == 0) {
  9142. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  9143. return 0;
  9144. }
  9145. if (value.length() == 0) {
  9146. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  9147. return 0;
  9148. }
  9149. string varname = string("lua_").append(name);
  9150. Variable* var = variables.FindVariable(varname);
  9151. if (var)
  9152. var->SetValue(value.c_str());
  9153. else {
  9154. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  9155. variables.AddVariable(var);
  9156. }
  9157. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  9158. return 0;
  9159. }
  9160. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  9161. if (!lua_interface)
  9162. return 0;
  9163. string name = lua_interface->GetStringValue(state);
  9164. lua_interface->ResetFunctionStack(state);
  9165. if (name.length() == 0) {
  9166. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  9167. return 0;
  9168. }
  9169. string varname = string("lua_").append(name);
  9170. Variable* var = variables.FindVariable(varname);
  9171. if (var)
  9172. lua_interface->SetStringValue(state, var->GetValue());
  9173. else
  9174. lua_interface->SetStringValue(state, "NULL");
  9175. return 1;
  9176. }
  9177. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  9178. if (!lua_interface)
  9179. return 0;
  9180. Spawn* player = lua_interface->GetSpawn(state);
  9181. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9182. lua_interface->ResetFunctionStack(state);
  9183. if (!player) {
  9184. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9185. return 0;
  9186. }
  9187. if (!player->IsPlayer()) {
  9188. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9189. return 0;
  9190. }
  9191. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  9192. return 1;
  9193. }
  9194. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  9195. if (!lua_interface)
  9196. return 0;
  9197. Spawn* player = lua_interface->GetSpawn(state);
  9198. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9199. lua_interface->ResetFunctionStack(state);
  9200. if (!player) {
  9201. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9202. return 0;
  9203. }
  9204. if (!player->IsPlayer()) {
  9205. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9206. return 0;
  9207. }
  9208. Language* language = master_languages_list.GetLanguage(language_id);
  9209. if (language)
  9210. {
  9211. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  9212. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID(), 0);
  9213. }
  9214. return 0;
  9215. }
  9216. int EQ2Emu_lua_IsNight(lua_State* state) {
  9217. if (!lua_interface)
  9218. return 0;
  9219. ZoneServer* zone = lua_interface->GetZone(state);
  9220. lua_interface->ResetFunctionStack(state);
  9221. if (!zone) {
  9222. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  9223. return 0;
  9224. }
  9225. lua_interface->SetBooleanValue(state, zone->IsDusk());
  9226. return 1;
  9227. }
  9228. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  9229. if (!lua_interface)
  9230. return 0;
  9231. Spawn* spawn = lua_interface->GetSpawn(state);
  9232. lua_interface->ResetFunctionStack(state);
  9233. if (!spawn) {
  9234. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  9235. return 0;
  9236. }
  9237. if (!spawn->IsWidget()) {
  9238. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  9239. return 0;
  9240. }
  9241. ((Widget*)spawn)->SetMultiFloorLift(true);
  9242. if (spawn->GetZone())
  9243. spawn->GetZone()->AddTransportSpawn(spawn);
  9244. return 0;
  9245. }
  9246. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  9247. if (!lua_interface)
  9248. return 0;
  9249. Spawn* player = lua_interface->GetSpawn(state);
  9250. int32 path = lua_interface->GetInt32Value(state, 2);
  9251. lua_interface->ResetFunctionStack(state);
  9252. if (!player) {
  9253. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9254. return 0;
  9255. }
  9256. if (!player->IsPlayer()) {
  9257. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9258. return 0;
  9259. }
  9260. if (path == 0) {
  9261. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  9262. return 0;
  9263. }
  9264. Client* client = ((Player*)player)->GetClient();
  9265. if (!client) {
  9266. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9267. return 0;
  9268. }
  9269. client->SendFlightAutoMount(path);
  9270. return 0;
  9271. }
  9272. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  9273. if (!lua_interface)
  9274. return 0;
  9275. Spawn* player = lua_interface->GetSpawn(state);
  9276. if (!player) {
  9277. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9278. return 0;
  9279. }
  9280. if (!player->IsPlayer()) {
  9281. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9282. return 0;
  9283. }
  9284. Client* client = ((Player*)player)->GetClient();
  9285. if (!client) {
  9286. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9287. return 0;
  9288. }
  9289. client->EndAutoMount();
  9290. return 0;
  9291. }
  9292. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  9293. if (!lua_interface)
  9294. return 0;
  9295. Spawn* player = lua_interface->GetSpawn(state);
  9296. lua_interface->ResetFunctionStack(state);
  9297. if (!player) {
  9298. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  9299. return 0;
  9300. }
  9301. if (!player->IsPlayer()) {
  9302. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9303. return 0;
  9304. }
  9305. Client* client = ((Player*)player)->GetClient();
  9306. if (!client) {
  9307. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9308. return 0;
  9309. }
  9310. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  9311. return 1;
  9312. }
  9313. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  9314. if (!lua_interface)
  9315. return 0;
  9316. Spawn* player = lua_interface->GetSpawn(state);
  9317. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9318. int32 value = lua_interface->GetInt32Value(state, 3);
  9319. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9320. lua_interface->ResetFunctionStack(state);
  9321. if (!player) {
  9322. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9323. return 0;
  9324. }
  9325. if (!player->IsPlayer()) {
  9326. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9327. return 0;
  9328. }
  9329. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  9330. return 0;
  9331. }
  9332. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  9333. if (!lua_interface)
  9334. return 0;
  9335. Spawn* player = lua_interface->GetSpawn(state);
  9336. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9337. lua_interface->ResetFunctionStack(state);
  9338. if (!player) {
  9339. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9340. return 0;
  9341. }
  9342. if (!player->IsPlayer()) {
  9343. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9344. return 0;
  9345. }
  9346. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  9347. if (!hd)
  9348. return 0;
  9349. lua_interface->SetInt32Value(state, hd->Value);
  9350. lua_interface->SetInt32Value(state, hd->Value2);
  9351. return 2;
  9352. }
  9353. int EQ2Emu_lua_SetGridID(lua_State* state) {
  9354. if (!lua_interface)
  9355. return 0;
  9356. Spawn* spawn = lua_interface->GetSpawn(state);
  9357. int32 grid = lua_interface->GetInt32Value(state, 2);
  9358. lua_interface->ResetFunctionStack(state);
  9359. if (!spawn) {
  9360. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9361. return 0;
  9362. }
  9363. if (grid == 0) {
  9364. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  9365. return 0;
  9366. }
  9367. spawn->SetLocation(grid);
  9368. return 0;
  9369. }
  9370. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  9371. if (!lua_interface)
  9372. return 0;
  9373. Spawn* spawn = lua_interface->GetSpawn(state);
  9374. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9375. int32 value1 = lua_interface->GetInt32Value(state, 3);
  9376. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9377. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  9378. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  9379. lua_interface->ResetFunctionStack(state);
  9380. if (!spawn) {
  9381. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9382. return 0;
  9383. }
  9384. //Add this quest to the list of required quests for this spawn
  9385. spawn->SetRequiredHistory(event_id, value1, value2);
  9386. //If private spawn value set
  9387. if (private_spawn) {
  9388. //Set the spawn to be private when not granted access via history
  9389. spawn->AddAllowAccessSpawn(spawn);
  9390. spawn->SetPrivateQuestSpawn(true);
  9391. }
  9392. //This value will override vis_flags in the vis packet
  9393. if (flag_override > 0)
  9394. spawn->SetQuestsRequiredOverride(flag_override);
  9395. return 0;
  9396. }
  9397. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  9398. if (!lua_interface)
  9399. return 0;
  9400. Spawn* player = lua_interface->GetSpawn(state);
  9401. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9402. int32 step_id = lua_interface->GetInt32Value(state, 3);
  9403. lua_interface->ResetFunctionStack(state);
  9404. if (!player) {
  9405. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  9406. return 0;
  9407. }
  9408. if (!player->IsPlayer()) {
  9409. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  9410. return 0;
  9411. }
  9412. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  9413. return 1;
  9414. }
  9415. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  9416. if (!lua_interface)
  9417. return 0;
  9418. Spawn* player = lua_interface->GetSpawn(state);
  9419. int8 level = lua_interface->GetInt8Value(state, 2);
  9420. lua_interface->ResetFunctionStack(state);
  9421. if (!player) {
  9422. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  9423. return 0;
  9424. }
  9425. if (!player->IsPlayer()) {
  9426. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  9427. return 0;
  9428. }
  9429. if (level == 0) {
  9430. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  9431. return 0;
  9432. }
  9433. Client* client = ((Player*)player)->GetClient();
  9434. if (!client) {
  9435. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  9436. return 0;
  9437. }
  9438. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  9439. return 0;
  9440. }
  9441. int EQ2Emu_lua_AddCoin(lua_State* state) {
  9442. if (!lua_interface)
  9443. return 0;
  9444. Spawn* player = lua_interface->GetSpawn(state);
  9445. int32 amount = lua_interface->GetInt32Value(state, 2);
  9446. lua_interface->ResetFunctionStack(state);
  9447. if (!player) {
  9448. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9449. return 0;
  9450. }
  9451. if (!player->IsPlayer()) {
  9452. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9453. return 0;
  9454. }
  9455. if (amount == 0) {
  9456. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9457. return 0;
  9458. }
  9459. ((Player*)player)->AddCoins(amount);
  9460. return 0;
  9461. }
  9462. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  9463. if (!lua_interface)
  9464. return 0;
  9465. Spawn* player = lua_interface->GetSpawn(state);
  9466. int32 amount = lua_interface->GetInt32Value(state, 2);
  9467. lua_interface->ResetFunctionStack(state);
  9468. if (!player) {
  9469. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9470. return 0;
  9471. }
  9472. if (!player->IsPlayer()) {
  9473. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9474. return 0;
  9475. }
  9476. if (amount == 0) {
  9477. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9478. return 0;
  9479. }
  9480. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  9481. return 1;
  9482. }
  9483. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  9484. if (!lua_interface)
  9485. return 0;
  9486. ZoneServer* zone = lua_interface->GetZone(state);
  9487. lua_interface->ResetFunctionStack(state);
  9488. if (!zone) {
  9489. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9490. return 0;
  9491. }
  9492. vector<Entity*> players = zone->GetPlayers();
  9493. if (players.size() == 0)
  9494. return 0;
  9495. lua_createtable(state, players.size(), 0);
  9496. int newTable = lua_gettop(state);
  9497. for (int32 i = 0; i < players.size(); i++) {
  9498. lua_interface->SetSpawnValue(state, players.at(i));
  9499. lua_rawseti(state, newTable, i + 1);
  9500. }
  9501. return 1;
  9502. }
  9503. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  9504. if (!lua_interface)
  9505. return 0;
  9506. ZoneServer* zone = lua_interface->GetZone(state, 1);
  9507. if (!zone) {
  9508. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9509. return 0;
  9510. }
  9511. int32 group_id = lua_interface->GetInt32Value(state, 2);
  9512. lua_interface->ResetFunctionStack(state);
  9513. //Map of <placement_id, location_id>
  9514. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  9515. map<int32, int32>::iterator itr;
  9516. vector<Spawn*> group;
  9517. Spawn* leader = 0;
  9518. for (itr = locs->begin(); itr != locs->end(); itr++) {
  9519. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  9520. if (!location) {
  9521. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  9522. return 0;
  9523. }
  9524. Spawn* spawn = 0;
  9525. if (location->entities[0]) {
  9526. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  9527. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  9528. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  9529. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  9530. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  9531. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  9532. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  9533. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  9534. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9535. spawn = zone->AddSignSpawn(location, location->entities[0]);
  9536. if(spawn && spawn->IsOmittedByDBFlag())
  9537. {
  9538. 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);
  9539. safe_delete(spawn);
  9540. continue;
  9541. }
  9542. if (spawn) {
  9543. if(!leader)
  9544. leader = spawn;
  9545. if(leader)
  9546. leader->AddSpawnToGroup(spawn);
  9547. spawn->SetSpawnGroupID(group_id);
  9548. const char* script = 0;
  9549. for (int x = 0; x < 3; x++) {
  9550. switch (x) {
  9551. case 0:
  9552. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  9553. break;
  9554. case 1:
  9555. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  9556. break;
  9557. case 2:
  9558. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  9559. break;
  9560. }
  9561. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9562. spawn->SetSpawnScript(string(script));
  9563. break;
  9564. }
  9565. }
  9566. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9567. lua_interface->SetSpawnValue(state, spawn);
  9568. group.push_back(spawn);
  9569. }
  9570. else {
  9571. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  9572. safe_delete(spawn);
  9573. }
  9574. }
  9575. }
  9576. if (!group.empty()) {
  9577. lua_createtable(state, group.size(), 0);
  9578. int newTable = lua_gettop(state);
  9579. for (int32 i = 0; i < group.size(); i++) {
  9580. lua_interface->SetSpawnValue(state, group[i]);
  9581. lua_rawseti(state, newTable, i + 1);
  9582. }
  9583. }
  9584. else
  9585. lua_pushnil(state);
  9586. return 1;
  9587. }
  9588. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9589. if (!lua_interface)
  9590. return 0;
  9591. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9592. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9593. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9594. lua_interface->ResetFunctionStack(state);
  9595. if (!spawn) {
  9596. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9597. return 0;
  9598. }
  9599. if (anim_id == 0) {
  9600. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9601. return 0;
  9602. }
  9603. if (leeway == 0)
  9604. leeway = 5000;
  9605. spawn->SetSpawnAnim(anim_id);
  9606. spawn->SetSpawnAnimLeeway(leeway);
  9607. return 0;
  9608. }
  9609. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9610. if (!lua_interface)
  9611. return 0;
  9612. Spawn* player = lua_interface->GetSpawn(state);
  9613. lua_interface->ResetFunctionStack(state);
  9614. if (!player || !player->IsPlayer()) {
  9615. return 0;
  9616. }
  9617. Client* client = ((Player*)player)->GetClient();
  9618. if (!client) {
  9619. return 0;
  9620. }
  9621. lua_interface->SetInt32Value(state, client->GetVersion());
  9622. return 1;
  9623. }
  9624. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9625. if (!lua_interface)
  9626. return 0;
  9627. Item* item = lua_interface->GetItem(state);
  9628. lua_interface->ResetFunctionStack(state);
  9629. if (!item) {
  9630. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9631. return 0;
  9632. }
  9633. lua_interface->SetInt32Value(state, item->details.item_id);
  9634. return 1;
  9635. }
  9636. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9637. if (!lua_interface)
  9638. return 0;
  9639. Spawn* spawn = lua_interface->GetSpawn(state);
  9640. lua_interface->ResetFunctionStack(state);
  9641. if (!spawn) {
  9642. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9643. return 0;
  9644. }
  9645. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9646. return 1;
  9647. }
  9648. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9649. if (!lua_interface)
  9650. return 0;
  9651. Spawn* spawn = lua_interface->GetSpawn(state);
  9652. lua_interface->ResetFunctionStack(state);
  9653. if (!spawn) {
  9654. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9655. return 0;
  9656. }
  9657. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9658. return 1;
  9659. }
  9660. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9661. if (!lua_interface)
  9662. return 0;
  9663. Spawn* spawn = lua_interface->GetSpawn(state);
  9664. lua_interface->ResetFunctionStack(state);
  9665. if (!spawn) {
  9666. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9667. return 0;
  9668. }
  9669. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9670. return 1;
  9671. }
  9672. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9673. if (!lua_interface)
  9674. return 0;
  9675. Spawn* spawn = lua_interface->GetSpawn(state);
  9676. lua_interface->ResetFunctionStack(state);
  9677. if (!spawn) {
  9678. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9679. return 0;
  9680. }
  9681. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9682. return 1;
  9683. }
  9684. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9685. if (!lua_interface)
  9686. return 0;
  9687. Spawn* spawn = lua_interface->GetSpawn(state);
  9688. float pct = lua_interface->GetFloatValue(state, 2);
  9689. lua_interface->ResetFunctionStack(state);
  9690. if (!spawn) {
  9691. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9692. return 0;
  9693. }
  9694. if (pct == 0) {
  9695. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9696. return 0;
  9697. }
  9698. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9699. lua_interface->SetInt32Value(state, amount);
  9700. return 1;
  9701. }
  9702. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9703. if (!lua_interface)
  9704. return 0;
  9705. Spawn* spawn = lua_interface->GetSpawn(state);
  9706. float pct = lua_interface->GetFloatValue(state, 2);
  9707. lua_interface->ResetFunctionStack(state);
  9708. if (!spawn) {
  9709. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9710. return 0;
  9711. }
  9712. if (pct == 0) {
  9713. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9714. return 0;
  9715. }
  9716. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9717. lua_interface->SetInt32Value(state, amount);
  9718. return 1;
  9719. }
  9720. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9721. if (!lua_interface)
  9722. return 0;
  9723. Spawn* spawn = lua_interface->GetSpawn(state);
  9724. lua_interface->ResetFunctionStack(state);
  9725. if (!spawn) {
  9726. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9727. return 0;
  9728. }
  9729. if (!spawn->IsPlayer()) {
  9730. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9731. return 0;
  9732. }
  9733. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9734. return 1;
  9735. }
  9736. int EQ2Emu_lua_Evac(lua_State* state) {
  9737. if (!lua_interface)
  9738. return 0;
  9739. Spawn* target = lua_interface->GetSpawn(state);
  9740. if (target) {
  9741. float x = target->GetZone()->GetSafeX();
  9742. float y = target->GetZone()->GetSafeY();
  9743. float z = target->GetZone()->GetSafeZ();
  9744. float h = target->GetZone()->GetSafeHeading();
  9745. target->SetX(x);
  9746. target->SetY(y);
  9747. target->SetZ(z);
  9748. target->SetHeading(h);
  9749. target->SetSpawnOrigX(x);
  9750. target->SetSpawnOrigY(y);
  9751. target->SetSpawnOrigZ(z);
  9752. target->SetSpawnOrigHeading(h);
  9753. if (target->IsPlayer()) {
  9754. Client* client = ((Player*)target)->GetClient();
  9755. if (client) {
  9756. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9757. int numargs = lua_interface->GetNumberOfArgs(state);
  9758. if(numargs == 4) {
  9759. x = lua_interface->GetFloatValue(state,1);
  9760. y = lua_interface->GetFloatValue(state,2);
  9761. z = lua_interface->GetFloatValue(state,3);
  9762. h = lua_interface->GetFloatValue(state,4);
  9763. }
  9764. client->SetReloadingZone(true);
  9765. target->SetX(x);
  9766. target->SetY(y);
  9767. target->SetZ(z);
  9768. target->SetHeading(h);
  9769. target->SetSpawnOrigX(x);
  9770. target->SetSpawnOrigY(y);
  9771. target->SetSpawnOrigZ(z);
  9772. target->SetSpawnOrigHeading(h);
  9773. target->SetAppearancePosition(x,y,z);
  9774. client->SetZoningCoords(x,y,z,h);
  9775. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9776. if (packet)
  9777. {
  9778. packet->setDataByName("x", x);
  9779. packet->setDataByName("y", y);
  9780. packet->setDataByName("z", z);
  9781. client->QueuePacket(packet->serialize());
  9782. safe_delete(packet);
  9783. }
  9784. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9785. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9786. }
  9787. }
  9788. lua_interface->ResetFunctionStack(state);
  9789. }
  9790. else {
  9791. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9792. if(!spell || !spell->caster || !spell->caster->GetZone()) {
  9793. lua_interface->ResetFunctionStack(state);
  9794. return 0;
  9795. }
  9796. ZoneServer* zone = spell->caster->GetZone();
  9797. float x = spell->caster->GetZone()->GetSafeX();
  9798. float y = spell->caster->GetZone()->GetSafeY();
  9799. float z = spell->caster->GetZone()->GetSafeZ();
  9800. float h = spell->caster->GetZone()->GetSafeHeading();
  9801. int numargs = lua_interface->GetNumberOfArgs(state);
  9802. if(numargs == 4) {
  9803. x = lua_interface->GetFloatValue(state,1);
  9804. y = lua_interface->GetFloatValue(state,2);
  9805. z = lua_interface->GetFloatValue(state,3);
  9806. h = lua_interface->GetFloatValue(state,4);
  9807. }
  9808. lua_interface->ResetFunctionStack(state);
  9809. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9810. for (int32 i = 0; i < spell->targets.size(); i++) {
  9811. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9812. if (!target2)
  9813. continue;
  9814. if (target2->IsPlayer()) {
  9815. Client* client = ((Player*)target2)->GetClient();
  9816. if (client) {
  9817. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9818. client->SetReloadingZone(true);
  9819. target2->SetX(x);
  9820. target2->SetY(y);
  9821. target2->SetZ(z);
  9822. target2->SetHeading(h);
  9823. target2->SetSpawnOrigX(x);
  9824. target2->SetSpawnOrigY(y);
  9825. target2->SetSpawnOrigZ(z);
  9826. target2->SetSpawnOrigHeading(h);
  9827. target2->SetAppearancePosition(x,y,z);
  9828. client->SetZoningCoords(x,y,z,h);
  9829. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9830. if (packet)
  9831. {
  9832. packet->setDataByName("x", x);
  9833. packet->setDataByName("y", y);
  9834. packet->setDataByName("z", z);
  9835. client->QueuePacket(packet->serialize());
  9836. safe_delete(packet);
  9837. }
  9838. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9839. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9840. }
  9841. }
  9842. }
  9843. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9844. }
  9845. return 0;
  9846. }
  9847. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9848. if (!lua_interface)
  9849. return 0;
  9850. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9851. lua_interface->ResetFunctionStack(state);
  9852. if (!luaspell || !luaspell->spell) {
  9853. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9854. return 0;
  9855. }
  9856. int8 tier = luaspell->spell->GetSpellTier();
  9857. lua_interface->SetInt32Value(state, tier);
  9858. return 1;
  9859. }
  9860. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9861. if (!lua_interface)
  9862. return 0;
  9863. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9864. lua_interface->ResetFunctionStack(state);
  9865. if (!luaspell || !luaspell->spell) {
  9866. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9867. return 0;
  9868. }
  9869. int32 spell_id = luaspell->spell->GetSpellID();
  9870. lua_interface->SetInt32Value(state, spell_id);
  9871. return 1;
  9872. }
  9873. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9874. if (!lua_interface)
  9875. return 0;
  9876. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9877. lua_interface->ResetFunctionStack(state);
  9878. if (!spawn) {
  9879. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9880. return 0;
  9881. }
  9882. if (!spawn->IsPlayer()) {
  9883. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9884. return 0;
  9885. }
  9886. ZoneServer* zone = spawn->GetZone();
  9887. if (!zone) {
  9888. return 0;
  9889. }
  9890. Client* client = ((Player*)spawn)->GetClient();
  9891. if (!client) {
  9892. return 0;
  9893. }
  9894. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9895. return 0;
  9896. }
  9897. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9898. if (!lua_interface)
  9899. return 0;
  9900. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9901. lua_interface->ResetFunctionStack(state);
  9902. if (!spawn) {
  9903. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9904. return 0;
  9905. }
  9906. if (!spawn->IsPlayer()) {
  9907. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9908. return 0;
  9909. }
  9910. ZoneServer* zone = spawn->GetZone();
  9911. if (!zone) {
  9912. return 0;
  9913. }
  9914. Client* client = ((Player*)spawn)->GetClient();
  9915. if (!client) {
  9916. return 0;
  9917. }
  9918. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9919. return 0;
  9920. }
  9921. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9922. if (!lua_interface)
  9923. return 0;
  9924. Spawn* caster = lua_interface->GetSpawn(state);
  9925. Spawn* target = lua_interface->GetSpawn(state, 2);
  9926. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9927. string spell_name = lua_interface->GetStringValue(state, 4);
  9928. lua_interface->ResetFunctionStack(state);
  9929. if (!caster) {
  9930. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9931. return 0;
  9932. }
  9933. if (!caster->IsEntity()) {
  9934. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9935. return 0;
  9936. }
  9937. if (!target) {
  9938. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9939. return 0;
  9940. }
  9941. if (!target->IsEntity()) {
  9942. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9943. return 0;
  9944. }
  9945. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9946. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9947. return 0;
  9948. }
  9949. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9950. if (!lua_interface)
  9951. return 0;
  9952. Spawn* player = lua_interface->GetSpawn(state);
  9953. int32 amount = lua_interface->GetInt32Value(state, 2);
  9954. lua_interface->ResetFunctionStack(state);
  9955. if (player && player->IsPlayer() && amount > 0) {
  9956. ((Player*)player)->AddXP(amount);
  9957. }
  9958. return 0;
  9959. }
  9960. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9961. if (!lua_interface)
  9962. return 0;
  9963. Spawn* player = lua_interface->GetSpawn(state);
  9964. int8 type = lua_interface->GetInt8Value(state, 2);
  9965. string text = lua_interface->GetStringValue(state, 3);
  9966. lua_interface->ResetFunctionStack(state);
  9967. Client* client = 0;
  9968. if (player && player->IsPlayer())
  9969. client = ((Player*)player)->GetClient();
  9970. if (!client || text.length() == 0) {
  9971. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9972. return 0;
  9973. }
  9974. client->SimpleMessage(type, text.c_str());
  9975. return 0;
  9976. }
  9977. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9978. if (!lua_interface)
  9979. return 0;
  9980. Spawn* player = lua_interface->GetSpawn(state);
  9981. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9982. lua_interface->ResetFunctionStack(state);
  9983. Client* client = 0;
  9984. if (player && player->IsPlayer())
  9985. client = ((Player*)player)->GetClient();
  9986. if (!client || !spawn) {
  9987. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9988. return 0;
  9989. }
  9990. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9991. if (!items) {
  9992. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9993. return 0;
  9994. }
  9995. client->SendLootResponsePacket(spawn->GetLootCoins(), items, spawn, true);
  9996. return 0;
  9997. }
  9998. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9999. if (!lua_interface)
  10000. return 0;
  10001. Spawn* spawnref = lua_interface->GetSpawn(state);
  10002. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  10003. lua_interface->ResetFunctionStack(state);
  10004. if (spawn_id > 0 && spawnref) {
  10005. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  10006. if (spawns.size() == 0) {
  10007. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  10008. return 0;
  10009. }
  10010. Spawn* spawn = 0;
  10011. int16 index = MakeRandomInt(0, spawns.size());
  10012. if (index >= spawns.size() || index < 0)
  10013. index = 0;
  10014. spawn = spawns[index];
  10015. lua_interface->SetSpawnValue(state, spawn);
  10016. return 1;
  10017. }
  10018. else {
  10019. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  10020. }
  10021. return 0;
  10022. }
  10023. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  10024. Spawn* player = lua_interface->GetSpawn(state);
  10025. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  10026. string name = lua_interface->GetStringValue(state, 3);
  10027. float distance = lua_interface->GetFloatValue(state, 4);
  10028. string command = lua_interface->GetStringValue(state, 5);
  10029. string error_text = lua_interface->GetStringValue(state, 6);
  10030. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  10031. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  10032. lua_interface->ResetFunctionStack(state);
  10033. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  10034. if (distance == 0)
  10035. distance = 10.0f;
  10036. if (command.length() == 0)
  10037. command = name;
  10038. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  10039. if (spawns.size() == 0) {
  10040. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  10041. return 0;
  10042. }
  10043. Spawn* spawn = 0;
  10044. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  10045. spawn = *itr;
  10046. if (spawn) {
  10047. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  10048. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  10049. }
  10050. }
  10051. }
  10052. return 0;
  10053. }
  10054. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  10055. if (!lua_interface)
  10056. return 0;
  10057. Client* client = 0;
  10058. Spawn* player = lua_interface->GetSpawn(state);
  10059. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  10060. lua_interface->ResetFunctionStack(state);
  10061. if (player && player->IsPlayer() && player->GetZone())
  10062. client = ((Player*)player)->GetClient();
  10063. else{
  10064. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  10065. return 0;
  10066. }
  10067. if (client) {
  10068. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  10069. if (packet) {
  10070. packet->setDataByName("goal_num", goal_num);
  10071. client->QueuePacket(packet->serialize());
  10072. safe_delete(packet);
  10073. }
  10074. }
  10075. return 0;
  10076. }
  10077. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  10078. if (!lua_interface)
  10079. return 0;
  10080. Client* client = 0;
  10081. Spawn* player = lua_interface->GetSpawn(state);
  10082. lua_interface->ResetFunctionStack(state);
  10083. if (player && player->IsPlayer() && player->GetZone())
  10084. client = ((Player*)player)->GetClient();
  10085. else {
  10086. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  10087. return 0;
  10088. }
  10089. if (client && client->GetVersion() >= 374) {
  10090. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  10091. }
  10092. return 0;
  10093. }
  10094. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  10095. if (!lua_interface)
  10096. return 0;
  10097. Client* client = 0;
  10098. Spawn* player = lua_interface->GetSpawn(state);
  10099. float duration = lua_interface->GetFloatValue(state, 2);
  10100. string text = lua_interface->GetStringValue(state, 3);
  10101. string voice = lua_interface->GetStringValue(state, 4);
  10102. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  10103. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  10104. string signal = lua_interface->GetStringValue(state, 7);
  10105. string goal1 = lua_interface->GetStringValue(state, 8);
  10106. string task1 = lua_interface->GetStringValue(state, 9);
  10107. string goal2 = lua_interface->GetStringValue(state, 10);
  10108. string task2 = lua_interface->GetStringValue(state, 11);
  10109. string goal3 = lua_interface->GetStringValue(state, 12);
  10110. string task3 = lua_interface->GetStringValue(state, 13);
  10111. string goal4 = lua_interface->GetStringValue(state, 14);
  10112. string task4 = lua_interface->GetStringValue(state, 15);
  10113. lua_interface->ResetFunctionStack(state);
  10114. if (!player) {
  10115. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  10116. return 0;
  10117. }
  10118. if (!player->IsPlayer()) {
  10119. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  10120. return 0;
  10121. }
  10122. else
  10123. client = ((Player*)player)->GetClient();
  10124. if (!client) {
  10125. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  10126. return 0;
  10127. }
  10128. if (text.length() == 0) {
  10129. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  10130. return 0;
  10131. }
  10132. if (duration >= 0 && duration < 2)
  10133. duration = 2;
  10134. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  10135. if (packet) {
  10136. packet->setDataByName("open_seconds_max", duration);
  10137. packet->setDataByName("text", text.c_str());
  10138. packet->setDataByName("voice", voice.c_str());
  10139. int8 num_goals = 1;
  10140. if (task2.length() > 0)
  10141. num_goals++;
  10142. if (task3.length() > 0)
  10143. num_goals++;
  10144. if (task4.length() > 0)
  10145. num_goals++;
  10146. packet->setArrayLengthByName("num_goals", num_goals);
  10147. for (int8 i = 0; i < num_goals; i++) {
  10148. packet->setSubArrayLengthByName("num_tasks", 1, i);
  10149. }
  10150. if (goal1.length() > 0)
  10151. packet->setArrayDataByName("goal_text", goal1.c_str());
  10152. if (goal2.length() > 0)
  10153. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  10154. if (goal3.length() > 0)
  10155. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  10156. if (goal4.length() > 0)
  10157. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  10158. packet->setSubArrayDataByName("task_text", task1.c_str());
  10159. if (task2.length() > 0)
  10160. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  10161. if (task3.length() > 0)
  10162. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  10163. if (task4.length() > 0)
  10164. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  10165. packet->setDataByName("complete_sound", "click");
  10166. packet->setDataByName("signal", signal.c_str());
  10167. packet->setDataByName("voice_key1", voice_key1);
  10168. packet->setDataByName("voice_key2", voice_key2);
  10169. client->QueuePacket(packet->serialize());
  10170. safe_delete(packet);
  10171. }
  10172. return 0;
  10173. }
  10174. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  10175. if (!lua_interface)
  10176. return 0;
  10177. Client* client = 0;
  10178. Spawn* player = lua_interface->GetSpawn(state);
  10179. string window = lua_interface->GetStringValue(state, 2);
  10180. int8 show = lua_interface->GetInt8Value(state, 3);
  10181. lua_interface->ResetFunctionStack(state);
  10182. if (!player) {
  10183. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  10184. return 0;
  10185. }
  10186. if (!player->IsPlayer()) {
  10187. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  10188. return 0;
  10189. }
  10190. else
  10191. client = ((Player*)player)->GetClient();
  10192. if (!client) {
  10193. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  10194. return 0;
  10195. }
  10196. if (window.length() == 0) {
  10197. lua_interface->LogError("LUA ShowWindow required parameters not given");
  10198. return 0;
  10199. }
  10200. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  10201. if (packet) {
  10202. packet->setDataByName("window", window.c_str());
  10203. packet->setDataByName("show", show);
  10204. client->QueuePacket(packet->serialize());
  10205. safe_delete(packet);
  10206. }
  10207. return 0;
  10208. }
  10209. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  10210. //See GameEvents.txt for options that can be used for this function
  10211. if (!lua_interface)
  10212. return 0;
  10213. Client* client = 0;
  10214. Spawn* player = lua_interface->GetSpawn(state);
  10215. string event_name = lua_interface->GetStringValue(state, 2);
  10216. int8 enabled = lua_interface->GetInt8Value(state, 3);
  10217. lua_interface->ResetFunctionStack(state);
  10218. if (!player || !player->IsPlayer()) {
  10219. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  10220. return 0;
  10221. }
  10222. client = ((Player*)player)->GetClient();
  10223. if (!client) {
  10224. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  10225. return 0;
  10226. }
  10227. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  10228. if (packet) {
  10229. packet->setDataByName("event_name", event_name.c_str());
  10230. packet->setDataByName("enabled", enabled);
  10231. client->QueuePacket(packet->serialize());
  10232. safe_delete(packet);
  10233. }
  10234. return 0;
  10235. }
  10236. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  10237. if (!lua_interface)
  10238. return 0;
  10239. Spawn* player = lua_interface->GetSpawn(state);
  10240. lua_interface->ResetFunctionStack(state);
  10241. if (player && player->IsPlayer()) {
  10242. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  10243. return 1;
  10244. }
  10245. return 0;
  10246. }
  10247. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  10248. if (!lua_interface)
  10249. return 0;
  10250. Spawn* player = lua_interface->GetSpawn(state);
  10251. int8 step = lua_interface->GetInt8Value(state, 2);
  10252. lua_interface->ResetFunctionStack(state);
  10253. if (player && player->IsPlayer() && step > 0) {
  10254. ((Player*)player)->SetTutorialStep(step);
  10255. }
  10256. return 0;
  10257. }
  10258. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  10259. if (!lua_interface)
  10260. return 0;
  10261. Client* client = 0;
  10262. Spawn* player = lua_interface->GetSpawn(state);
  10263. string window = lua_interface->GetStringValue(state, 2);
  10264. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  10265. lua_interface->ResetFunctionStack(state);
  10266. if (!player) {
  10267. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  10268. return 0;
  10269. }
  10270. if (!player->IsPlayer()) {
  10271. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  10272. return 0;
  10273. }
  10274. else
  10275. client = ((Player*)player)->GetClient();
  10276. if (!client) {
  10277. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  10278. return 0;
  10279. }
  10280. if (window.length() == 0) {
  10281. lua_interface->LogError("LUA FlashWindow required parameters not given");
  10282. return 0;
  10283. }
  10284. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  10285. if (packet) {
  10286. packet->setDataByName("window", window.c_str());
  10287. packet->setDataByName("flash_seconds", flash_seconds);
  10288. client->QueuePacket(packet->serialize());
  10289. safe_delete(packet);
  10290. }
  10291. return 0;
  10292. }
  10293. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  10294. if (!lua_interface)
  10295. return 0;
  10296. Spawn* spawn = lua_interface->GetSpawn(state);
  10297. Spawn* target = lua_interface->GetSpawn(state, 2);
  10298. lua_interface->ResetFunctionStack(state);
  10299. if (spawn && target)
  10300. return spawn->CheckLoS(target);
  10301. return 0;
  10302. }
  10303. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  10304. if (!lua_interface)
  10305. return 0;
  10306. Spawn* spawn = lua_interface->GetSpawn(state);
  10307. float x = lua_interface->GetFloatValue(state, 2);
  10308. float y = lua_interface->GetFloatValue(state, 3);
  10309. float z = lua_interface->GetFloatValue(state, 4);
  10310. lua_interface->ResetFunctionStack(state);
  10311. if (spawn)
  10312. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  10313. return 0;
  10314. }
  10315. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  10316. if (!lua_interface)
  10317. return 0;
  10318. ZoneServer* zone = lua_interface->GetZone(state);
  10319. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  10320. lua_interface->ResetFunctionStack(state);
  10321. if (zone)
  10322. zone->SetExpansionFlag(xpackFlag);
  10323. return 0;
  10324. }
  10325. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  10326. if (!lua_interface)
  10327. return 0;
  10328. ZoneServer* zone = lua_interface->GetZone(state);
  10329. lua_interface->ResetFunctionStack(state);
  10330. if (zone) {
  10331. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  10332. return 1;
  10333. }
  10334. return 0;
  10335. }
  10336. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  10337. if (!lua_interface)
  10338. return 0;
  10339. ZoneServer* zone = lua_interface->GetZone(state);
  10340. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  10341. lua_interface->ResetFunctionStack(state);
  10342. if (zone)
  10343. zone->SetHolidayFlag(holidayFlag);
  10344. return 0;
  10345. }
  10346. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  10347. if (!lua_interface)
  10348. return 0;
  10349. ZoneServer* zone = lua_interface->GetZone(state);
  10350. lua_interface->ResetFunctionStack(state);
  10351. if (zone) {
  10352. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  10353. return 1;
  10354. }
  10355. return 0;
  10356. }
  10357. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  10358. if (!lua_interface)
  10359. return 0;
  10360. Spawn* spawn = lua_interface->GetSpawn(state);
  10361. bool canbind = lua_interface->GetInt32Value(state, 2);
  10362. lua_interface->ResetFunctionStack(state);
  10363. if(!spawn) {
  10364. lua_interface->LogError("%s: LUA SetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10365. return 0;
  10366. }
  10367. ZoneServer* zone = spawn->GetZone();
  10368. if (zone)
  10369. zone->SetCanBind(canbind);
  10370. return 0;
  10371. }
  10372. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  10373. if (!lua_interface)
  10374. return 0;
  10375. Spawn* spawn = lua_interface->GetSpawn(state);
  10376. lua_interface->ResetFunctionStack(state);
  10377. if(!spawn) {
  10378. lua_interface->LogError("%s: LUA GetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10379. return 0;
  10380. }
  10381. ZoneServer* zone = spawn->GetZone();
  10382. if (zone) {
  10383. lua_interface->SetInt32Value(state, zone->GetCanBind());
  10384. return 1;
  10385. }
  10386. return 0;
  10387. }
  10388. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  10389. if (!lua_interface)
  10390. return 0;
  10391. Spawn* spawn = lua_interface->GetSpawn(state);
  10392. bool cangate = lua_interface->GetInt32Value(state, 2);
  10393. lua_interface->ResetFunctionStack(state);
  10394. if(!spawn) {
  10395. lua_interface->LogError("%s: LUA SetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10396. return 0;
  10397. }
  10398. ZoneServer* zone = spawn->GetZone();
  10399. if (zone)
  10400. zone->SetCanGate(cangate);
  10401. return 0;
  10402. }
  10403. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  10404. if (!lua_interface)
  10405. return 0;
  10406. Spawn* spawn = lua_interface->GetSpawn(state);
  10407. lua_interface->ResetFunctionStack(state);
  10408. if(!spawn) {
  10409. lua_interface->LogError("%s: LUA GetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10410. return 0;
  10411. }
  10412. ZoneServer* zone = spawn->GetZone();
  10413. if (zone) {
  10414. lua_interface->SetInt32Value(state, zone->GetCanGate());
  10415. return 1;
  10416. }
  10417. return 0;
  10418. }
  10419. int EQ2Emu_lua_SetCanEvac(lua_State* state) {
  10420. if (!lua_interface)
  10421. return 0;
  10422. Spawn* spawn = lua_interface->GetSpawn(state);
  10423. bool canevac = lua_interface->GetInt32Value(state, 2);
  10424. lua_interface->ResetFunctionStack(state);
  10425. if(!spawn) {
  10426. lua_interface->LogError("%s: LUA SetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10427. return 0;
  10428. }
  10429. ZoneServer* zone = spawn->GetZone();
  10430. if (zone)
  10431. zone->SetCanEvac(canevac);
  10432. return 0;
  10433. }
  10434. int EQ2Emu_lua_GetCanEvac(lua_State* state) {
  10435. if (!lua_interface)
  10436. return 0;
  10437. Spawn* spawn = lua_interface->GetSpawn(state);
  10438. lua_interface->ResetFunctionStack(state);
  10439. if(!spawn) {
  10440. lua_interface->LogError("%s: LUA GetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10441. return 0;
  10442. }
  10443. ZoneServer* zone = spawn->GetZone();
  10444. if (zone) {
  10445. lua_interface->SetInt32Value(state, zone->GetCanEvac());
  10446. return 1;
  10447. }
  10448. return 0;
  10449. }
  10450. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  10451. if (!lua_interface)
  10452. return 0;
  10453. Spawn* spawn = lua_interface->GetSpawn(state);
  10454. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  10455. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  10456. float distance = lua_interface->GetFloatValue(state, 4);
  10457. string in_range_function = lua_interface->GetStringValue(state, 5);
  10458. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  10459. lua_interface->ResetFunctionStack(state);
  10460. if (spawn && distance > 0 && in_range_function.length() > 0)
  10461. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  10462. return 0;
  10463. }
  10464. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  10465. if (!lua_interface)
  10466. return 0;
  10467. Spawn* spawn = lua_interface->GetSpawn(state);
  10468. Spawn* target = lua_interface->GetSpawn(state, 2);
  10469. lua_interface->ResetFunctionStack(state);
  10470. if (spawn && target)
  10471. {
  10472. if (spawn->IsPlayer() && target->IsEntity())
  10473. {
  10474. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  10475. return 1;
  10476. }
  10477. else if (spawn->IsEntity() && target->IsEntity())
  10478. {
  10479. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  10480. return 1;
  10481. }
  10482. }
  10483. return 0;
  10484. }
  10485. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  10486. if (!lua_interface)
  10487. return 0;
  10488. Spawn* spawn = lua_interface->GetSpawn(state);
  10489. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10490. lua_interface->ResetFunctionStack(state);
  10491. if (spawn && spawn->IsEntity())
  10492. {
  10493. ((Entity*)spawn)->SetSeeInvisSpell(val);
  10494. if (spawn->IsPlayer())
  10495. {
  10496. Client* client = ((Player*)spawn)->GetClient();
  10497. if (client)
  10498. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  10499. }
  10500. }
  10501. return 0;
  10502. }
  10503. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  10504. if (!lua_interface)
  10505. return 0;
  10506. Spawn* spawn = lua_interface->GetSpawn(state);
  10507. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10508. lua_interface->ResetFunctionStack(state);
  10509. if (spawn && spawn->IsEntity())
  10510. {
  10511. ((Entity*)spawn)->SetSeeHideSpell(val);
  10512. if (spawn->IsPlayer())
  10513. {
  10514. Client* client = ((Player*)spawn)->GetClient();
  10515. if (client)
  10516. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  10517. }
  10518. }
  10519. return 0;
  10520. }
  10521. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  10522. {
  10523. if (!lua_interface)
  10524. return 0;
  10525. Spawn* player = lua_interface->GetSpawn(state);
  10526. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10527. string command = lua_interface->GetStringValue(state, 3);
  10528. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10529. lua_interface->ResetFunctionStack(state);
  10530. if (spawn && player && player->IsPlayer())
  10531. {
  10532. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10533. bool res = false;
  10534. if (cmd)
  10535. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  10536. lua_interface->SetBooleanValue(state, res);
  10537. return 1;
  10538. }
  10539. return 0;
  10540. }
  10541. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  10542. {
  10543. if (!lua_interface)
  10544. return 0;
  10545. Spawn* spawn = lua_interface->GetSpawn(state);
  10546. int32 charID = lua_interface->GetInt32Value(state, 2);
  10547. string command = lua_interface->GetStringValue(state, 3);
  10548. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10549. lua_interface->ResetFunctionStack(state);
  10550. if (spawn && charID)
  10551. {
  10552. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10553. bool res = false;
  10554. if (cmd)
  10555. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  10556. lua_interface->SetBooleanValue(state, res);
  10557. return 1;
  10558. }
  10559. return 0;
  10560. }
  10561. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  10562. {
  10563. if (!lua_interface)
  10564. return 0;
  10565. Spawn* spawn = lua_interface->GetSpawn(state);
  10566. string command = lua_interface->GetStringValue(state, 2);
  10567. lua_interface->ResetFunctionStack(state);
  10568. if (spawn && command.length() > 0)
  10569. spawn->RemovePrimaryEntityCommand(command.c_str());
  10570. return 0;
  10571. }
  10572. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  10573. if (!lua_interface)
  10574. return 0;
  10575. Spawn* spawn = lua_interface->GetSpawn(state);
  10576. float distance = lua_interface->GetFloatValue(state, 2);
  10577. string command = lua_interface->GetStringValue(state, 3);
  10578. Spawn* player = lua_interface->GetSpawn(state, 4);
  10579. lua_interface->ResetFunctionStack(state);
  10580. if (spawn) {
  10581. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  10582. }
  10583. return 0;
  10584. }
  10585. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  10586. if (!lua_interface)
  10587. return 0;
  10588. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10589. Spawn* spawn = lua_interface->GetSpawn(state);
  10590. Spawn* player = lua_interface->GetSpawn(state, 2);
  10591. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  10592. lua_interface->ResetFunctionStack(state);
  10593. if (spawn && player && transport_id && player->IsPlayer()) {
  10594. Client* client = 0;
  10595. if (player && player->IsPlayer())
  10596. client = ((Player*)player)->GetClient();
  10597. if (!client)
  10598. return 0;
  10599. vector<TransportDestination*> destinations;
  10600. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  10601. if (destinations.size())
  10602. {
  10603. client->SetTemporaryTransportID(transport_id);
  10604. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  10605. }
  10606. else
  10607. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  10608. }
  10609. return 0;
  10610. }
  10611. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  10612. if (!lua_interface)
  10613. return 0;
  10614. Spawn* player = lua_interface->GetSpawn(state);
  10615. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  10616. lua_interface->ResetFunctionStack(state);
  10617. if (player && player->IsPlayer()) {
  10618. Client* client = 0;
  10619. if (player && player->IsPlayer())
  10620. client = ((Player*)player)->GetClient();
  10621. if (!client)
  10622. return 0;
  10623. client->SetTemporaryTransportID(transport_id);
  10624. }
  10625. return 0;
  10626. }
  10627. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10628. if (!lua_interface)
  10629. return 0;
  10630. Spawn* player = lua_interface->GetSpawn(state);
  10631. lua_interface->ResetFunctionStack(state);
  10632. if (player && player->IsPlayer()) {
  10633. Client* client = 0;
  10634. if (player && player->IsPlayer())
  10635. client = ((Player*)player)->GetClient();
  10636. if (!client)
  10637. return 0;
  10638. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10639. return 1;
  10640. }
  10641. return 0;
  10642. }
  10643. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10644. if (!lua_interface)
  10645. return 0;
  10646. Spawn* spawn = lua_interface->GetSpawn(state);
  10647. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10648. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10649. if (!spawn) {
  10650. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10651. return 0;
  10652. }
  10653. if (!spawn->IsEntity()) {
  10654. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10655. return 0;
  10656. }
  10657. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10658. {
  10659. 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);
  10660. return 0;
  10661. }
  10662. lua_interface->ResetFunctionStack(state);
  10663. if (spell && spell->targets.size() > 0) {
  10664. ZoneServer* zone = spell->caster->GetZone();
  10665. for (int8 i = 0; i < spell->targets.size(); i++) {
  10666. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10667. if (target && target->IsEntity()) {
  10668. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10669. if (target->IsPlayer())
  10670. ((Player*)target)->SetCharSheetChanged(true);
  10671. }
  10672. }
  10673. }
  10674. else {
  10675. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10676. if (spawn->IsPlayer())
  10677. ((Player*)spawn)->SetCharSheetChanged(true);
  10678. }
  10679. return 0;
  10680. }
  10681. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10682. if (!lua_interface)
  10683. return 0;
  10684. Spawn* spawn = lua_interface->GetSpawn(state);
  10685. lua_interface->ResetFunctionStack(state);
  10686. if (!spawn) {
  10687. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10688. return 0;
  10689. }
  10690. if (!spawn->IsEntity()) {
  10691. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10692. return 0;
  10693. }
  10694. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10695. return 1;
  10696. }
  10697. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10698. if (!lua_interface)
  10699. return 0;
  10700. int32 spell_id = lua_interface->GetInt32Value(state);
  10701. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10702. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10703. if (spell_id > 0) {
  10704. if (spell_tier == 0)
  10705. spell_tier = 1;
  10706. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10707. if(!spell) {
  10708. lua_interface->LogError("%s: GetSpell: Failed, spell id %u spell tier %u does not exist.", lua_interface->GetScriptName(state), spell_id, spell_tier);
  10709. lua_interface->ResetFunctionStack(state);
  10710. return 0;
  10711. }
  10712. LuaSpell* lua_spell = 0;
  10713. if(custom_lua_script.size() > 0)
  10714. {
  10715. // attempt to load the custom script since it isn't already loaded
  10716. // we will re-obtain the lua_spell further below
  10717. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10718. {
  10719. 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());
  10720. lua_interface->LoadLuaSpell(custom_lua_script);
  10721. }
  10722. }
  10723. else
  10724. custom_lua_script = spell->GetSpellData()->lua_script;
  10725. if (!lua_spell && lua_interface)
  10726. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10727. lua_interface->ResetFunctionStack(state);
  10728. if (!lua_spell)
  10729. {
  10730. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10731. return 0;
  10732. }
  10733. lua_spell->spell = new Spell(spell);
  10734. lua_interface->AddCustomSpell(lua_spell);
  10735. lua_interface->SetSpellValue(state, lua_spell);
  10736. return 1;
  10737. }
  10738. return 0;
  10739. }
  10740. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10741. if (!lua_interface)
  10742. return 0;
  10743. LuaSpell* spell = lua_interface->GetSpell(state);
  10744. string field = lua_interface->GetStringValue(state, 2);
  10745. lua_interface->ResetFunctionStack(state);
  10746. if (!spell) {
  10747. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10748. return 0;
  10749. }
  10750. if (!spell->spell || !spell->spell->GetSpellData()) {
  10751. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10752. return 0;
  10753. }
  10754. boost::to_lower(field);
  10755. return spell->spell->GetSpellData(state, field);
  10756. }
  10757. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10758. if (!lua_interface)
  10759. return 0;
  10760. LuaSpell* spell = lua_interface->GetSpell(state);
  10761. string field = lua_interface->GetStringValue(state, 2);
  10762. int8 fieldArg = 3; // field value after the initial set
  10763. if (!spell) {
  10764. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10765. lua_interface->ResetFunctionStack(state);
  10766. return 0;
  10767. }
  10768. if (!spell->spell || !spell->spell->GetSpellData()) {
  10769. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10770. lua_interface->ResetFunctionStack(state);
  10771. return 0;
  10772. }
  10773. boost::to_lower(field);
  10774. bool valSet = false;
  10775. spell->spell->SetSpellData(state, field, fieldArg);
  10776. lua_interface->ResetFunctionStack(state);
  10777. return valSet;
  10778. }
  10779. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10780. if (!lua_interface)
  10781. return 0;
  10782. LuaSpell* spell = lua_interface->GetSpell(state);
  10783. int8 idx = lua_interface->GetInt32Value(state, 2);
  10784. if (!spell) {
  10785. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10786. lua_interface->ResetFunctionStack(state);
  10787. return 0;
  10788. }
  10789. if (!spell->spell || !spell->spell->GetSpellData()) {
  10790. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10791. lua_interface->ResetFunctionStack(state);
  10792. return 0;
  10793. }
  10794. if (spell->spell->lua_data.size() <= idx)
  10795. {
  10796. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10797. lua_interface->ResetFunctionStack(state);
  10798. return 0;
  10799. }
  10800. bool setVal = true;
  10801. LUAData* data = spell->spell->lua_data[idx];
  10802. switch (data->type)
  10803. {
  10804. case 0:
  10805. {
  10806. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10807. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10808. data->int_value = value;
  10809. data->int_value2 = value2;
  10810. break;
  10811. }
  10812. case 1:
  10813. {
  10814. float value = lua_interface->GetFloatValue(state, 3);
  10815. float value2 = lua_interface->GetFloatValue(state, 4);
  10816. data->float_value = value;
  10817. data->float_value2 = value2;
  10818. break;
  10819. }
  10820. case 2:
  10821. {
  10822. bool value = lua_interface->GetBooleanValue(state, 3);
  10823. data->bool_value = value;
  10824. break;
  10825. }
  10826. case 3:
  10827. {
  10828. string value = lua_interface->GetStringValue(state, 3);
  10829. string value2 = lua_interface->GetStringValue(state, 4);
  10830. data->string_value = value;
  10831. data->string_value2 = value2;
  10832. break;
  10833. }
  10834. default:
  10835. setVal = false;
  10836. }
  10837. lua_interface->ResetFunctionStack(state);
  10838. return setVal;
  10839. }
  10840. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10841. if (!lua_interface)
  10842. return 0;
  10843. LuaSpell* spell = lua_interface->GetSpell(state);
  10844. int8 idx = lua_interface->GetInt32Value(state, 2);
  10845. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10846. lua_interface->ResetFunctionStack(state);
  10847. if (!spell) {
  10848. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10849. return 0;
  10850. }
  10851. if (!spell->spell || !spell->spell->GetSpellData()) {
  10852. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10853. return 0;
  10854. }
  10855. if (spell->spell->lua_data.size() <= idx)
  10856. {
  10857. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10858. return 0;
  10859. }
  10860. bool setVal = true;
  10861. LUAData* data = spell->spell->lua_data[idx];
  10862. switch (data->type)
  10863. {
  10864. case 0:
  10865. {
  10866. if(!secondfield)
  10867. lua_interface->SetSInt32Value(state, data->int_value);
  10868. else
  10869. lua_interface->SetSInt32Value(state, data->int_value2);
  10870. break;
  10871. }
  10872. case 1:
  10873. {
  10874. if (!secondfield)
  10875. lua_interface->SetFloatValue(state, data->float_value);
  10876. else
  10877. lua_interface->SetFloatValue(state, data->float_value2);
  10878. break;
  10879. }
  10880. case 2:
  10881. {
  10882. lua_interface->SetBooleanValue(state, data->bool_value);
  10883. break;
  10884. }
  10885. case 3:
  10886. {
  10887. if (!secondfield)
  10888. lua_interface->SetStringValue(state, data->string_value.c_str());
  10889. else
  10890. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10891. break;
  10892. }
  10893. default:
  10894. setVal = false;
  10895. }
  10896. return setVal;
  10897. }
  10898. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10899. if (!lua_interface)
  10900. return 0;
  10901. LuaSpell* spell = lua_interface->GetSpell(state);
  10902. int8 idx = lua_interface->GetInt32Value(state, 2);
  10903. string field = lua_interface->GetStringValue(state, 3);
  10904. boost::to_lower(field);
  10905. if (!spell) {
  10906. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10907. lua_interface->ResetFunctionStack(state);
  10908. return 0;
  10909. }
  10910. if (!spell->spell || !spell->spell->GetSpellData()) {
  10911. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10912. lua_interface->ResetFunctionStack(state);
  10913. return 0;
  10914. }
  10915. if (spell->spell->effects.size() <= idx)
  10916. {
  10917. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10918. lua_interface->ResetFunctionStack(state);
  10919. return 0;
  10920. }
  10921. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10922. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10923. if (field == "description")
  10924. effect->description = string(lua_interface->GetStringValue(state, 4));
  10925. else if (field == "bullet")
  10926. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10927. else if (field == "percentage")
  10928. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10929. else { // no match
  10930. lua_interface->ResetFunctionStack(state);
  10931. return 0;
  10932. }
  10933. lua_interface->ResetFunctionStack(state);
  10934. return 1;
  10935. }
  10936. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10937. if (!lua_interface)
  10938. return 0;
  10939. LuaSpell* spell = lua_interface->GetSpell(state);
  10940. int8 idx = lua_interface->GetInt32Value(state, 2);
  10941. string field = lua_interface->GetStringValue(state, 3);
  10942. lua_interface->ResetFunctionStack(state);
  10943. boost::to_lower(field);
  10944. if (!spell) {
  10945. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10946. return 0;
  10947. }
  10948. if (!spell->spell || !spell->spell->GetSpellData()) {
  10949. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10950. return 0;
  10951. }
  10952. if (spell->spell->effects.size() <= idx)
  10953. {
  10954. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10955. return 0;
  10956. }
  10957. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10958. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10959. if (field == "description")
  10960. lua_interface->SetStringValue(state, effect->description.c_str());
  10961. else if (field == "bullet")
  10962. lua_interface->SetInt32Value(state, effect->subbullet);
  10963. else if (field == "percentage")
  10964. lua_interface->SetInt32Value(state, effect->percentage);
  10965. else // no match
  10966. return 0;
  10967. return 1;
  10968. }
  10969. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10970. if (!lua_interface)
  10971. return 0;
  10972. LuaSpell* spell = lua_interface->GetSpell(state);
  10973. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10974. Spawn* target = lua_interface->GetSpawn(state, 3);
  10975. lua_interface->ResetFunctionStack(state);
  10976. if (!target) {
  10977. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10978. return 0;
  10979. }
  10980. if (!target->IsEntity()) {
  10981. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10982. return 0;
  10983. }
  10984. if (!spell) {
  10985. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10986. return 0;
  10987. }
  10988. if (caster && !caster->IsEntity()) {
  10989. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10990. return 0;
  10991. }
  10992. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10993. return 0;
  10994. }
  10995. int EQ2Emu_lua_InWater(lua_State* state) {
  10996. if (!lua_interface)
  10997. return 0;
  10998. Spawn* spawn = lua_interface->GetSpawn(state);
  10999. lua_interface->ResetFunctionStack(state);
  11000. if (spawn) {
  11001. lua_interface->SetBooleanValue(state, spawn->InWater());
  11002. return 1;
  11003. }
  11004. return 0;
  11005. }
  11006. int EQ2Emu_lua_InLava(lua_State* state) {
  11007. if (!lua_interface)
  11008. return 0;
  11009. Spawn* spawn = lua_interface->GetSpawn(state);
  11010. lua_interface->ResetFunctionStack(state);
  11011. if (spawn) {
  11012. lua_interface->SetBooleanValue(state, spawn->InLava());
  11013. return 1;
  11014. }
  11015. return 0;
  11016. }
  11017. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  11018. if (!lua_interface)
  11019. return 0;
  11020. Spawn* attacker = lua_interface->GetSpawn(state);
  11021. Spawn* victim = lua_interface->GetSpawn(state, 2);
  11022. int8 type = lua_interface->GetInt8Value(state, 3);
  11023. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  11024. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  11025. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  11026. string spell_name = lua_interface->GetStringValue(state, 7);
  11027. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  11028. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  11029. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  11030. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  11031. bool take_power = (lua_interface->GetInt8Value(state, 12) == 1);
  11032. lua_interface->ResetFunctionStack(state);
  11033. if (!attacker) {
  11034. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  11035. lua_interface->SetBooleanValue(state, false);
  11036. return 1;
  11037. }
  11038. if (!attacker->IsEntity()) {
  11039. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  11040. lua_interface->SetBooleanValue(state, false);
  11041. return 1;
  11042. }
  11043. if (!victim) {
  11044. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  11045. lua_interface->SetBooleanValue(state, false);
  11046. return 1;
  11047. }
  11048. if (!victim->IsEntity()) {
  11049. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  11050. lua_interface->SetBooleanValue(state, false);
  11051. return 1;
  11052. }
  11053. 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);
  11054. lua_interface->SetBooleanValue(state, has_damaged);
  11055. return 1;
  11056. }
  11057. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  11058. if (!lua_interface)
  11059. return 0;
  11060. Spawn* spawn = lua_interface->GetSpawn(state);
  11061. lua_interface->ResetFunctionStack(state);
  11062. if (spawn) {
  11063. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  11064. return 1;
  11065. }
  11066. return 0;
  11067. }
  11068. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  11069. if (!lua_interface)
  11070. return 0;
  11071. Spawn* spawn = lua_interface->GetSpawn(state);
  11072. bool invul = lua_interface->GetBooleanValue(state, 2);
  11073. lua_interface->ResetFunctionStack(state);
  11074. if (spawn) {
  11075. spawn->SetInvulnerable(invul);
  11076. }
  11077. return 0;
  11078. }
  11079. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  11080. if (!lua_interface)
  11081. return 0;
  11082. string category = lua_interface->GetStringValue(state);
  11083. string name = lua_interface->GetStringValue(state, 2);
  11084. lua_interface->ResetFunctionStack(state);
  11085. Rule *ret = 0;
  11086. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11087. lua_interface->SetBooleanValue(state, ret->GetBool());
  11088. return 1;
  11089. }
  11090. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11091. return 0;
  11092. }
  11093. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  11094. if (!lua_interface)
  11095. return 0;
  11096. string category = lua_interface->GetStringValue(state);
  11097. string name = lua_interface->GetStringValue(state, 2);
  11098. lua_interface->ResetFunctionStack(state);
  11099. Rule *ret = 0;
  11100. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11101. lua_interface->SetInt32Value(state, ret->GetInt32());
  11102. return 1;
  11103. }
  11104. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11105. return 0;
  11106. }
  11107. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  11108. if (!lua_interface)
  11109. return 0;
  11110. string category = lua_interface->GetStringValue(state);
  11111. string name = lua_interface->GetStringValue(state, 2);
  11112. lua_interface->ResetFunctionStack(state);
  11113. Rule *ret = 0;
  11114. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11115. lua_interface->SetFloatValue(state, ret->GetFloat());
  11116. return 1;
  11117. }
  11118. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11119. return 0;
  11120. }
  11121. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  11122. if (!lua_interface)
  11123. return 0;
  11124. Spawn* spawn = lua_interface->GetSpawn(state);
  11125. string type = lua_interface->GetStringValue(state, 2);
  11126. lua_interface->ResetFunctionStack(state);
  11127. if (spawn) {
  11128. int res = 1;
  11129. boost::to_lower(type);
  11130. if(type == "assigned_aa")
  11131. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  11132. else if ( type == "unassigned_aa")
  11133. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  11134. else if ( type == "assigned_tradeskill_aa")
  11135. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  11136. else if ( type == "unassigned_tradeskill_aa")
  11137. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  11138. else if ( type == "assigned_prestige_aa")
  11139. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  11140. else if ( type == "unassigned_prestige_aa")
  11141. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  11142. else if ( type == "assigned_tradeskill_prestige_aa")
  11143. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  11144. else if ( type == "unassigned_tradeskill_prestige_aa")
  11145. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  11146. else
  11147. res = 0;
  11148. return res;
  11149. }
  11150. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  11151. return 0;
  11152. }
  11153. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  11154. if (!lua_interface)
  11155. return 0;
  11156. Spawn* spawn = lua_interface->GetSpawn(state);
  11157. string type = lua_interface->GetStringValue(state, 2);
  11158. sint32 value = lua_interface->GetSInt32Value(state, 3);
  11159. lua_interface->ResetFunctionStack(state);
  11160. if (spawn) {
  11161. boost::to_lower(type);
  11162. if(type == "assigned_aa")
  11163. spawn->SetAssignedAA((sint16)value);
  11164. else if ( type == "unassigned_aa")
  11165. spawn->SetUnassignedAA((sint16)value);
  11166. else if ( type == "assigned_tradeskill_aa")
  11167. spawn->SetTradeskillAA((sint16)value);
  11168. else if ( type == "unassigned_tradeskill_aa")
  11169. spawn->SetUnassignedTradeskillAA((sint16)value);
  11170. else if ( type == "assigned_prestige_aa")
  11171. spawn->SetPrestigeAA((sint16)value);
  11172. else if ( type == "unassigned_prestige_aa")
  11173. spawn->SetUnassignedPrestigeAA((sint16)value);
  11174. else if ( type == "assigned_tradeskill_prestige_aa")
  11175. spawn->SetTradeskillPrestigeAA((sint16)value);
  11176. else if ( type == "unassigned_tradeskill_prestige_aa")
  11177. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  11178. if(spawn->IsPlayer())
  11179. ((Player*)spawn)->SetCharSheetChanged(true);
  11180. }
  11181. return 0;
  11182. }
  11183. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  11184. if (!lua_interface)
  11185. return 0;
  11186. string titleName = lua_interface->GetStringValue(state);
  11187. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  11188. lua_interface->ResetFunctionStack(state);
  11189. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  11190. lua_interface->SetSInt32Value(state, index);
  11191. return 1;
  11192. }
  11193. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  11194. if (!lua_interface)
  11195. return 0;
  11196. Spawn* spawn = lua_interface->GetSpawn(state);
  11197. string titleName = lua_interface->GetStringValue(state, 2);
  11198. lua_interface->ResetFunctionStack(state);
  11199. if(!spawn->IsPlayer())
  11200. {
  11201. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  11202. lua_interface->SetSInt32Value(state, -1);
  11203. return 1;
  11204. }
  11205. Player* player = (Player*)spawn;
  11206. // check if player already has the title, don't need to add twice
  11207. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11208. if ( playerHasTitle)
  11209. {
  11210. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  11211. return 1;
  11212. }
  11213. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  11214. if(!title)
  11215. {
  11216. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11217. lua_interface->SetSInt32Value(state, -1);
  11218. return 1;
  11219. }
  11220. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  11221. if(returnIdx < 0)
  11222. {
  11223. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11224. }
  11225. lua_interface->SetSInt32Value(state, returnIdx);
  11226. player->GetClient()->SendTitleUpdate();
  11227. return 1;
  11228. }
  11229. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  11230. if (!lua_interface)
  11231. return 0;
  11232. Spawn* spawn = lua_interface->GetSpawn(state);
  11233. string titleName = lua_interface->GetStringValue(state, 2);
  11234. lua_interface->ResetFunctionStack(state);
  11235. if(!spawn->IsPlayer())
  11236. {
  11237. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11238. return 0;
  11239. }
  11240. Player* player = (Player*)spawn;
  11241. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11242. if(!title)
  11243. {
  11244. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11245. return 0;
  11246. }
  11247. if(title->GetPrefix())
  11248. {
  11249. 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());
  11250. return 0;
  11251. }
  11252. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  11253. player->GetClient()->SendTitleUpdate();
  11254. return 1;
  11255. }
  11256. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  11257. if (!lua_interface)
  11258. return 0;
  11259. Spawn* spawn = lua_interface->GetSpawn(state);
  11260. string titleName = lua_interface->GetStringValue(state, 2);
  11261. lua_interface->ResetFunctionStack(state);
  11262. if(!spawn->IsPlayer())
  11263. {
  11264. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11265. return 0;
  11266. }
  11267. Player* player = (Player*)spawn;
  11268. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11269. if(!title)
  11270. {
  11271. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11272. return 0;
  11273. }
  11274. if(!title->GetPrefix())
  11275. {
  11276. 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());
  11277. return 0;
  11278. }
  11279. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  11280. player->GetClient()->SendTitleUpdate();
  11281. return 1;
  11282. }
  11283. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  11284. if (!lua_interface)
  11285. return 0;
  11286. Spawn* spawn = lua_interface->GetSpawn(state);
  11287. lua_interface->ResetFunctionStack(state);
  11288. if(!spawn->IsPlayer())
  11289. {
  11290. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11291. return 0;
  11292. }
  11293. Player* player = (Player*)spawn;
  11294. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  11295. player->GetClient()->SendTitleUpdate();
  11296. return 1;
  11297. }
  11298. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  11299. if (!lua_interface)
  11300. return 0;
  11301. Spawn* spawn = lua_interface->GetSpawn(state);
  11302. lua_interface->ResetFunctionStack(state);
  11303. if(!spawn->IsPlayer())
  11304. {
  11305. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11306. return 0;
  11307. }
  11308. Player* player = (Player*)spawn;
  11309. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  11310. player->GetClient()->SendTitleUpdate();
  11311. return 1;
  11312. }
  11313. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  11314. if (!lua_interface)
  11315. return 0;
  11316. Spawn* spawn = lua_interface->GetSpawn(state);
  11317. string field = lua_interface->GetStringValue(state, 2);
  11318. lua_interface->ResetFunctionStack(state);
  11319. if(!spawn || !spawn->IsEntity())
  11320. {
  11321. 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));
  11322. return 0;
  11323. }
  11324. Entity* ent = (Entity*)spawn;
  11325. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  11326. return 1;
  11327. }
  11328. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  11329. if (!lua_interface)
  11330. return 0;
  11331. Spawn* spawn = lua_interface->GetSpawn(state);
  11332. string field = lua_interface->GetStringValue(state, 2);
  11333. lua_interface->ResetFunctionStack(state);
  11334. if(!spawn || !spawn->IsEntity())
  11335. {
  11336. 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));
  11337. return 0;
  11338. }
  11339. Entity* ent = (Entity*)spawn;
  11340. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  11341. return 1;
  11342. }
  11343. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  11344. if (!lua_interface)
  11345. return 0;
  11346. Spawn* spawn = lua_interface->GetSpawn(state);
  11347. string field = lua_interface->GetStringValue(state, 2);
  11348. lua_interface->ResetFunctionStack(state);
  11349. if(!spawn || !spawn->IsEntity())
  11350. {
  11351. 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));
  11352. return 0;
  11353. }
  11354. Entity* ent = (Entity*)spawn;
  11355. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  11356. return 1;
  11357. }
  11358. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  11359. if (!lua_interface)
  11360. return 0;
  11361. Spawn* spawn = lua_interface->GetSpawn(state);
  11362. string field = lua_interface->GetStringValue(state, 2);
  11363. lua_interface->ResetFunctionStack(state);
  11364. if(!spawn || !spawn->IsEntity())
  11365. {
  11366. 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));
  11367. return 0;
  11368. }
  11369. Entity* ent = (Entity*)spawn;
  11370. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  11371. return 1;
  11372. }
  11373. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  11374. if (!lua_interface)
  11375. return 0;
  11376. Spawn* spawn = lua_interface->GetSpawn(state);
  11377. string field = lua_interface->GetStringValue(state, 2);
  11378. string value = lua_interface->GetStringValue(state, 3);
  11379. lua_interface->ResetFunctionStack(state);
  11380. if(!spawn || !spawn->IsEntity())
  11381. {
  11382. 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));
  11383. return 0;
  11384. }
  11385. Entity* ent = (Entity*)spawn;
  11386. bool set_ = ent->SetInfoStructString(field, value);
  11387. lua_interface->SetBooleanValue(state, set_);
  11388. return 1;
  11389. }
  11390. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  11391. if (!lua_interface)
  11392. return 0;
  11393. Spawn* spawn = lua_interface->GetSpawn(state);
  11394. string field = lua_interface->GetStringValue(state, 2);
  11395. int64 value = lua_interface->GetInt64Value(state, 3);
  11396. lua_interface->ResetFunctionStack(state);
  11397. if(!spawn || !spawn->IsEntity())
  11398. {
  11399. 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));
  11400. return 0;
  11401. }
  11402. Entity* ent = (Entity*)spawn;
  11403. bool set_ = ent->SetInfoStructUInt(field, value);
  11404. lua_interface->SetBooleanValue(state, set_);
  11405. return 1;
  11406. }
  11407. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  11408. if (!lua_interface)
  11409. return 0;
  11410. Spawn* spawn = lua_interface->GetSpawn(state);
  11411. string field = lua_interface->GetStringValue(state, 2);
  11412. sint64 value = lua_interface->GetSInt64Value(state, 3);
  11413. lua_interface->ResetFunctionStack(state);
  11414. if(!spawn || !spawn->IsEntity())
  11415. {
  11416. 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));
  11417. return 0;
  11418. }
  11419. Entity* ent = (Entity*)spawn;
  11420. bool set_ = ent->SetInfoStructSInt(field, value);
  11421. lua_interface->SetBooleanValue(state, set_);
  11422. return 1;
  11423. }
  11424. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  11425. if (!lua_interface)
  11426. return 0;
  11427. Spawn* spawn = lua_interface->GetSpawn(state);
  11428. string field = lua_interface->GetStringValue(state, 2);
  11429. float value = lua_interface->GetFloatValue(state, 3);
  11430. lua_interface->ResetFunctionStack(state);
  11431. if(!spawn || !spawn->IsEntity())
  11432. {
  11433. 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));
  11434. return 0;
  11435. }
  11436. Entity* ent = (Entity*)spawn;
  11437. bool set_ = ent->SetInfoStructFloat(field, value);
  11438. lua_interface->SetBooleanValue(state, set_);
  11439. return 1;
  11440. }
  11441. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  11442. if (!lua_interface)
  11443. return 0;
  11444. Spawn* spawn = lua_interface->GetSpawn(state);
  11445. bool value = lua_interface->GetBooleanValue(state, 2);
  11446. lua_interface->ResetFunctionStack(state);
  11447. if(!spawn || !spawn->IsPlayer())
  11448. {
  11449. 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));
  11450. return 0;
  11451. }
  11452. ((Player*)spawn)->SetCharSheetChanged(value);
  11453. return 0;
  11454. }
  11455. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  11456. if (!lua_interface)
  11457. return 0;
  11458. Spawn* spawn = lua_interface->GetSpawn(state);
  11459. std::string fromName = lua_interface->GetStringValue(state, 2);
  11460. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11461. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11462. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11463. int32 copper = lua_interface->GetInt32Value(state, 6);
  11464. int32 silver = lua_interface->GetInt32Value(state, 7);
  11465. int32 gold = lua_interface->GetInt32Value(state, 8);
  11466. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11467. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11468. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11469. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11470. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11471. lua_interface->ResetFunctionStack(state);
  11472. if(!spawn || !spawn->IsPlayer())
  11473. {
  11474. 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));
  11475. lua_interface->SetBooleanValue(state, false);
  11476. return 1;
  11477. }
  11478. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11479. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11480. lua_interface->SetBooleanValue(state, true);
  11481. return 1;
  11482. }
  11483. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  11484. if (!lua_interface)
  11485. return 0;
  11486. int32 char_id = lua_interface->GetInt32Value(state);
  11487. std::string fromName = lua_interface->GetStringValue(state, 2);
  11488. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11489. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11490. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11491. int32 copper = lua_interface->GetInt32Value(state, 6);
  11492. int32 silver = lua_interface->GetInt32Value(state, 7);
  11493. int32 gold = lua_interface->GetInt32Value(state, 8);
  11494. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11495. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11496. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11497. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11498. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11499. lua_interface->ResetFunctionStack(state);
  11500. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11501. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11502. lua_interface->SetBooleanValue(state, true);
  11503. return 1;
  11504. }
  11505. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  11506. Spawn* widget;
  11507. if (lua_interface) {
  11508. widget = lua_interface->GetSpawn(state);
  11509. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  11510. lua_interface->ResetFunctionStack(state);
  11511. if (widget && widget->IsWidget())
  11512. {
  11513. ((Widget*)widget)->OpenDoor();
  11514. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  11515. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11516. }
  11517. else
  11518. 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));
  11519. }
  11520. return 0;
  11521. }
  11522. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  11523. Spawn* widget;
  11524. if (lua_interface) {
  11525. widget = lua_interface->GetSpawn(state);
  11526. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  11527. lua_interface->ResetFunctionStack(state);
  11528. if (widget && widget->IsWidget())
  11529. {
  11530. ((Widget*)widget)->CloseDoor();
  11531. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  11532. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11533. }
  11534. else
  11535. 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));
  11536. }
  11537. return 0;
  11538. }
  11539. int EQ2Emu_lua_IsOpen(lua_State* state) {
  11540. if (!lua_interface)
  11541. return 0;
  11542. Spawn* widget = lua_interface->GetSpawn(state);
  11543. lua_interface->ResetFunctionStack(state);
  11544. if (widget && widget->IsWidget())
  11545. {
  11546. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  11547. return 1;
  11548. }
  11549. return 0;
  11550. }
  11551. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  11552. if (!lua_interface)
  11553. return 0;
  11554. sint32 min = lua_interface->GetSInt32Value(state);
  11555. sint32 max = lua_interface->GetSInt32Value(state, 2);
  11556. lua_interface->ResetFunctionStack(state);
  11557. sint32 result = MakeRandomInt(min, max);
  11558. lua_interface->SetSInt32Value(state, result);
  11559. return 1;
  11560. }
  11561. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  11562. if (!lua_interface)
  11563. return 0;
  11564. float min = lua_interface->GetFloatValue(state);
  11565. float max = lua_interface->GetFloatValue(state, 2);
  11566. lua_interface->ResetFunctionStack(state);
  11567. float result = MakeRandomFloat(min, max);
  11568. lua_interface->SetFloatValue(state, result);
  11569. return 1;
  11570. }
  11571. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  11572. if (!lua_interface)
  11573. return 0;
  11574. Spawn* spawn = lua_interface->GetSpawn(state);
  11575. int32 value = lua_interface->GetInt32Value(state, 2);
  11576. lua_interface->ResetFunctionStack(state);
  11577. if(!spawn)
  11578. {
  11579. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11580. lua_interface->SetBooleanValue(state, false);
  11581. return 1;
  11582. }
  11583. spawn->AddIconValue(value);
  11584. lua_interface->SetBooleanValue(state, true);
  11585. return 1;
  11586. }
  11587. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  11588. if (!lua_interface)
  11589. return 0;
  11590. Spawn* spawn = lua_interface->GetSpawn(state);
  11591. int32 value = lua_interface->GetInt32Value(state, 2);
  11592. lua_interface->ResetFunctionStack(state);
  11593. if(!spawn)
  11594. {
  11595. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11596. lua_interface->SetBooleanValue(state, false);
  11597. return 1;
  11598. }
  11599. spawn->RemoveIconValue(value);
  11600. lua_interface->SetBooleanValue(state, true);
  11601. return 1;
  11602. }
  11603. int EQ2Emu_lua_GetShardID(lua_State* state) {
  11604. Spawn* npc = lua_interface->GetSpawn(state);
  11605. lua_interface->ResetFunctionStack(state);
  11606. if (npc && npc->IsNPC()) {
  11607. NPC* shard = (NPC*)npc;
  11608. int32 shardid = shard->GetShardID();
  11609. lua_interface->SetInt32Value(state, shardid);
  11610. return 1;
  11611. }
  11612. lua_interface->SetInt32Value(state, 0);
  11613. return 1;
  11614. }
  11615. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  11616. Spawn* npc = lua_interface->GetSpawn(state);
  11617. lua_interface->ResetFunctionStack(state);
  11618. if (npc && npc->IsNPC()) {
  11619. NPC* shard = (NPC*)npc;
  11620. int32 charid = shard->GetShardCharID();
  11621. lua_interface->SetInt32Value(state, charid);
  11622. return 1;
  11623. }
  11624. lua_interface->SetInt32Value(state, 0);
  11625. return 1;
  11626. }
  11627. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  11628. Spawn* npc = lua_interface->GetSpawn(state);
  11629. lua_interface->ResetFunctionStack(state);
  11630. if (npc && npc->IsNPC()) {
  11631. NPC* shard = (NPC*)npc;
  11632. int64 timestamp = shard->GetShardCreatedTimestamp();
  11633. lua_interface->SetSInt64Value(state, timestamp);
  11634. return 1;
  11635. }
  11636. lua_interface->SetSInt64Value(state, 0);
  11637. return 1;
  11638. }
  11639. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  11640. if (!lua_interface)
  11641. return 0;
  11642. int32 shardid = lua_interface->GetInt32Value(state);
  11643. lua_interface->ResetFunctionStack(state);
  11644. if(shardid < 1)
  11645. lua_interface->SetBooleanValue(state, false);
  11646. else
  11647. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  11648. return 1;
  11649. }
  11650. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  11651. if (!lua_interface)
  11652. return 0;
  11653. Spawn* spawn = lua_interface->GetSpawn(state);
  11654. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11655. if (spawn) {
  11656. spawn->PauseMovement(delay_in_ms);
  11657. }
  11658. lua_interface->ResetFunctionStack(state);
  11659. return 0;
  11660. }
  11661. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11662. if (!lua_interface)
  11663. return 0;
  11664. Spawn* spawn = lua_interface->GetSpawn(state);
  11665. if (spawn) {
  11666. spawn->ResetMovement();
  11667. }
  11668. lua_interface->ResetFunctionStack(state);
  11669. return 0;
  11670. }
  11671. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11672. Player* player = (Player*)lua_interface->GetSpawn(state);
  11673. int8 level = lua_interface->GetInt8Value(state, 2);
  11674. lua_interface->ResetFunctionStack(state);
  11675. if (player && player->IsPlayer() && level > 0) {
  11676. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11677. return 1;
  11678. }
  11679. return 0;
  11680. }
  11681. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11682. Player* player = (Player*)lua_interface->GetSpawn(state);
  11683. int8 level = lua_interface->GetInt8Value(state, 2);
  11684. lua_interface->ResetFunctionStack(state);
  11685. if (player && player->IsPlayer() && level > 0) {
  11686. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11687. return 1;
  11688. }
  11689. return 0;
  11690. }
  11691. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11692. ZoneServer* zone = lua_interface->GetZone(state);
  11693. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11694. lua_interface->ResetFunctionStack(state);
  11695. if (zone) {
  11696. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11697. if (spawn) {
  11698. lua_interface->SetSpawnValue(state, spawn);
  11699. return 1;
  11700. }
  11701. }
  11702. return 0;
  11703. }
  11704. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11705. if (!lua_interface)
  11706. return 0;
  11707. Spawn* spawn = lua_interface->GetSpawn(state);
  11708. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11709. lua_interface->ResetFunctionStack(state);
  11710. bool res = false;
  11711. if(spawn && spawn->IsTransportSpawn())
  11712. {
  11713. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11714. spawn->SetRailID(rail_id);
  11715. res = true;
  11716. }
  11717. else if (!spawn) {
  11718. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11719. }
  11720. else if(!spawn->IsTransportSpawn()) {
  11721. 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());
  11722. }
  11723. lua_interface->SetBooleanValue(state, res);
  11724. return 1;
  11725. }
  11726. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11727. if (!lua_interface)
  11728. return 0;
  11729. ZoneServer* zone = lua_interface->GetZone(state);
  11730. lua_interface->ResetFunctionStack(state);
  11731. if (zone) {
  11732. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11733. return 1;
  11734. }
  11735. return 0;
  11736. }
  11737. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11738. if (!lua_interface)
  11739. return 0;
  11740. Spawn* spawn = lua_interface->GetSpawn(state);
  11741. lua_interface->ResetFunctionStack(state);
  11742. if (spawn) {
  11743. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11744. return 1;
  11745. }
  11746. return 0;
  11747. }
  11748. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11749. if (!lua_interface)
  11750. return 0;
  11751. Spawn* player = lua_interface->GetSpawn(state);
  11752. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11753. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11754. lua_interface->ResetFunctionStack(state);
  11755. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11756. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11757. }
  11758. else if(!zoneID) {
  11759. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11760. }
  11761. else
  11762. {
  11763. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11764. return 1;
  11765. }
  11766. return 0;
  11767. }
  11768. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11769. if (!lua_interface)
  11770. return 0;
  11771. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11772. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11773. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11774. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11775. lua_interface->ResetFunctionStack(state);
  11776. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11777. world.GetWorldTimeStruct()->year = newYear;
  11778. world.GetWorldTimeStruct()->month = newMonth;
  11779. world.GetWorldTimeStruct()->hour = newHour;
  11780. world.GetWorldTimeStruct()->minute = newMinute;
  11781. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11782. return 0;
  11783. }
  11784. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11785. if (!lua_interface)
  11786. return 0;
  11787. lua_interface->ResetFunctionStack(state);
  11788. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11789. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11790. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11791. return 1;
  11792. }
  11793. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11794. if (!lua_interface)
  11795. return 0;
  11796. lua_interface->ResetFunctionStack(state);
  11797. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11798. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11799. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11800. return 1;
  11801. }
  11802. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11803. if (!lua_interface)
  11804. return 0;
  11805. lua_interface->ResetFunctionStack(state);
  11806. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11807. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11808. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11809. return 1;
  11810. }
  11811. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11812. if (!lua_interface)
  11813. return 0;
  11814. lua_interface->ResetFunctionStack(state);
  11815. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11816. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11817. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11818. return 1;
  11819. }
  11820. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11821. if (!lua_interface)
  11822. return 0;
  11823. lua_interface->ResetFunctionStack(state);
  11824. world.SendTimeUpdate();
  11825. return 0;
  11826. }
  11827. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11828. bool update_result = false;
  11829. Faction* faction = 0;
  11830. Spawn* spawn = lua_interface->GetSpawn(state);
  11831. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11832. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11833. lua_interface->ResetFunctionStack(state);
  11834. if(!spawn || !spawn->IsPlayer()) {
  11835. lua_interface->LogError("LUA ChangeFaction command error: player is not valid");
  11836. return 0;
  11837. }
  11838. Player* player = (Player*)spawn;
  11839. Client* client = player->GetClient();
  11840. if (faction_id > 0) {
  11841. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11842. if(hasfaction == 0) {
  11843. //they do not have the faction. Lets get the default value and feed it in.
  11844. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11845. //add the default faction for the player.
  11846. player->SetFactionValue(faction_id, defaultfaction);
  11847. }
  11848. if(increase >= 0) {
  11849. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11850. faction = master_faction_list.GetFaction(faction_id);
  11851. if(faction && update_result)
  11852. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11853. else if(faction)
  11854. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11855. lua_interface->SetBooleanValue(state, true);
  11856. return 1;
  11857. }
  11858. if(increase < 0){
  11859. //change the negative to a positive, since thats how decreasefaction() likes it.
  11860. increase *= -1;
  11861. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11862. faction = master_faction_list.GetFaction(faction_id);
  11863. if(faction && update_result)
  11864. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11865. else if(faction)
  11866. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11867. lua_interface->SetBooleanValue(state, true);
  11868. return 1;
  11869. }
  11870. }
  11871. lua_interface->SetBooleanValue(state, false);
  11872. return 1;
  11873. }
  11874. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11875. bool hascoin = 0;
  11876. Player* player = (Player*)lua_interface->GetSpawn(state);
  11877. int32 coins = lua_interface->GetInt32Value(state, 2);
  11878. lua_interface->ResetFunctionStack(state);
  11879. if (player && player->IsPlayer()) {
  11880. hascoin = player->HasCoins(coins);
  11881. if(hascoin == 0) {
  11882. lua_interface->SetBooleanValue(state, false);
  11883. return 1;
  11884. }
  11885. if(hascoin == 1) {
  11886. lua_interface->SetBooleanValue(state, true);
  11887. return 1;
  11888. }
  11889. }
  11890. return 0;
  11891. }
  11892. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11893. int32 loot_tier = 0;
  11894. Spawn* spawn = lua_interface->GetSpawn(state);
  11895. lua_interface->ResetFunctionStack(state);
  11896. if (spawn) {
  11897. loot_tier = spawn->GetLootTier();
  11898. lua_interface->SetInt32Value(state, loot_tier);
  11899. return 1;
  11900. }
  11901. return 0;
  11902. }
  11903. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11904. if (!lua_interface)
  11905. return 0;
  11906. Spawn* spawn = lua_interface->GetSpawn(state);
  11907. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11908. lua_interface->ResetFunctionStack(state);
  11909. if (spawn) {
  11910. spawn->SetLootTier(loot_tier);
  11911. lua_interface->SetBooleanValue(state, true);
  11912. return 1;
  11913. }
  11914. lua_interface->SetBooleanValue(state, false);
  11915. return 1;
  11916. }
  11917. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11918. int32 loot_drop_type = 0;
  11919. Spawn* spawn = lua_interface->GetSpawn(state);
  11920. lua_interface->ResetFunctionStack(state);
  11921. if (spawn) {
  11922. loot_drop_type = spawn->GetLootDropType();
  11923. lua_interface->SetInt32Value(state, loot_drop_type);
  11924. return 1;
  11925. }
  11926. return 0;
  11927. }
  11928. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11929. if (!lua_interface)
  11930. return 0;
  11931. Spawn* spawn = lua_interface->GetSpawn(state);
  11932. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11933. lua_interface->ResetFunctionStack(state);
  11934. if (spawn) {
  11935. spawn->SetLootDropType(loot_drop_type);
  11936. lua_interface->SetBooleanValue(state, true);
  11937. return 1;
  11938. }
  11939. lua_interface->SetBooleanValue(state, false);
  11940. return 1;
  11941. }
  11942. int EQ2Emu_lua_DamageEquippedItems(lua_State* state) {
  11943. if (!lua_interface)
  11944. return 0;
  11945. Spawn* spawn = lua_interface->GetSpawn(state);
  11946. int8 damage_amount = lua_interface->GetInt32Value(state, 2);
  11947. if(damage_amount > 100) {
  11948. damage_amount = 100;
  11949. }
  11950. if (!spawn) {
  11951. lua_interface->LogError("%s: LUA DamageEquippedItems command error: spawn is not valid", lua_interface->GetScriptName(state));
  11952. lua_interface->ResetFunctionStack(state);
  11953. return 0;
  11954. }
  11955. lua_interface->ResetFunctionStack(state);
  11956. if (spawn->IsPlayer()) {
  11957. if (((Player*)spawn)->GetClient() && ((Player*)spawn)->DamageEquippedItems(damage_amount, ((Player*)spawn)->GetClient()))
  11958. lua_interface->SetBooleanValue(state, true);
  11959. else
  11960. lua_interface->SetBooleanValue(state, false);
  11961. }
  11962. else {
  11963. lua_interface->SetBooleanValue(state, false);
  11964. }
  11965. return 1;
  11966. }
  11967. int EQ2Emu_lua_CreateWidgetRegion(lua_State* state) {
  11968. ZoneServer* zone = lua_interface->GetZone(state);
  11969. int32 version = lua_interface->GetInt32Value(state, 2);
  11970. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11971. if(region_map == nullptr) {
  11972. lua_interface->LogError("%s: LUA CreateWidgetRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11973. lua_interface->ResetFunctionStack(state);
  11974. return 0;
  11975. }
  11976. string region_name = lua_interface->GetStringValue(state, 3);
  11977. string env_name = lua_interface->GetStringValue(state, 4);
  11978. int32 grid_id = lua_interface->GetInt32Value(state, 5);
  11979. int32 widget_id = lua_interface->GetInt32Value(state, 6);
  11980. float dist = lua_interface->GetFloatValue(state, 7);
  11981. region_map->InsertRegionNode(zone, version, region_name, env_name, grid_id, widget_id, dist);
  11982. lua_interface->ResetFunctionStack(state);
  11983. lua_interface->SetBooleanValue(state, true);
  11984. return 1;
  11985. }
  11986. int EQ2Emu_lua_RemoveRegion(lua_State* state) {
  11987. ZoneServer* zone = lua_interface->GetZone(state);
  11988. int32 version = lua_interface->GetInt32Value(state, 2);
  11989. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11990. if(region_map == nullptr) {
  11991. lua_interface->LogError("%s: LUA RemoveRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11992. lua_interface->ResetFunctionStack(state);
  11993. return 0;
  11994. }
  11995. string region_name = lua_interface->GetStringValue(state, 3);
  11996. region_map->RemoveRegionNode(region_name);
  11997. lua_interface->ResetFunctionStack(state);
  11998. lua_interface->SetBooleanValue(state, true);
  11999. return 1;
  12000. }
  12001. int EQ2Emu_lua_SetPlayerPOVGhost(lua_State* state) {
  12002. Client* client = nullptr;
  12003. Spawn* player = lua_interface->GetSpawn(state);
  12004. if (!player) {
  12005. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not valid");
  12006. lua_interface->SetBooleanValue(state, false);
  12007. lua_interface->ResetFunctionStack(state);
  12008. return 1;
  12009. }
  12010. if (!player->IsPlayer()) {
  12011. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
  12012. lua_interface->SetBooleanValue(state, false);
  12013. lua_interface->ResetFunctionStack(state);
  12014. return 1;
  12015. }
  12016. client = player->GetClient();
  12017. if (!client) {
  12018. lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
  12019. lua_interface->SetBooleanValue(state, false);
  12020. lua_interface->ResetFunctionStack(state);
  12021. return 1;
  12022. }
  12023. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  12024. bool success_sight = client->SetPlayerPOVGhost(spawn);
  12025. lua_interface->ResetFunctionStack(state);
  12026. lua_interface->SetBooleanValue(state, success_sight);
  12027. return 1;
  12028. }
  12029. int EQ2Emu_lua_SetCastOnAggroComplete(lua_State* state) {
  12030. if (!lua_interface)
  12031. return 0;
  12032. bool result = false;
  12033. Spawn* spawn = lua_interface->GetSpawn(state);
  12034. bool cast_completed = (lua_interface->GetInt8Value(state, 2) == 1);
  12035. lua_interface->ResetFunctionStack(state);
  12036. if (!spawn)
  12037. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  12038. else if (!spawn->IsNPC())
  12039. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  12040. else
  12041. {
  12042. ((NPC*)spawn)->cast_on_aggro_completed = cast_completed;
  12043. result = true;
  12044. }
  12045. lua_interface->SetBooleanValue(state, result);
  12046. return 1;
  12047. }
  12048. int EQ2Emu_lua_IsCastOnAggroComplete(lua_State* state) {
  12049. if (!lua_interface)
  12050. return 0;
  12051. bool result = false;
  12052. Spawn* spawn = lua_interface->GetSpawn(state);
  12053. lua_interface->ResetFunctionStack(state);
  12054. if (!spawn)
  12055. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  12056. else if (!spawn->IsNPC())
  12057. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  12058. else
  12059. {
  12060. if(((NPC*)spawn)->cast_on_aggro_completed)
  12061. result = true;
  12062. }
  12063. lua_interface->SetBooleanValue(state, result);
  12064. return 1;
  12065. }
  12066. int EQ2Emu_lua_AddRecipeBookToPlayer(lua_State* state) {
  12067. Client* client = nullptr;
  12068. Spawn* player = lua_interface->GetSpawn(state);
  12069. int32 recipe_book_id = lua_interface->GetInt32Value(state, 2);
  12070. lua_interface->ResetFunctionStack(state);
  12071. if (!player) {
  12072. lua_interface->LogError("LUA AddRecipeBookToPlayer 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 AddRecipeBookToPlayer command error: spawn is not a player");
  12078. lua_interface->SetBooleanValue(state, false);
  12079. return 1;
  12080. }
  12081. client = player->GetClient();
  12082. if (!client) {
  12083. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: could not find client");
  12084. lua_interface->SetBooleanValue(state, false);
  12085. return 1;
  12086. }
  12087. bool result = client->AddRecipeBookToPlayer(recipe_book_id);
  12088. lua_interface->SetBooleanValue(state, result);
  12089. return 1;
  12090. }
  12091. int EQ2Emu_lua_RemoveRecipeFromPlayer(lua_State* state) {
  12092. Client* client = nullptr;
  12093. Spawn* player = lua_interface->GetSpawn(state);
  12094. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  12095. lua_interface->ResetFunctionStack(state);
  12096. if (!player) {
  12097. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not valid");
  12098. lua_interface->SetBooleanValue(state, false);
  12099. return 1;
  12100. }
  12101. if (!player->IsPlayer()) {
  12102. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not a player");
  12103. lua_interface->SetBooleanValue(state, false);
  12104. return 1;
  12105. }
  12106. client = player->GetClient();
  12107. if (!client) {
  12108. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: could not find client");
  12109. lua_interface->SetBooleanValue(state, false);
  12110. return 1;
  12111. }
  12112. bool result = client->RemoveRecipeFromPlayer(recipe_id);
  12113. lua_interface->SetBooleanValue(state, result);
  12114. return 1;
  12115. }
  12116. int EQ2Emu_lua_ReplaceWidgetFromClient(lua_State* state) {
  12117. Client* client = nullptr;
  12118. Spawn* player = lua_interface->GetSpawn(state);
  12119. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12120. bool delete_widget = (lua_interface->GetInt8Value(state, 3) == 1);
  12121. // rest are all optional fields
  12122. float x = lua_interface->GetFloatValue(state, 4);
  12123. float y = lua_interface->GetFloatValue(state, 5);
  12124. float z = lua_interface->GetFloatValue(state, 6);
  12125. int32 grid_id = lua_interface->GetInt32Value(state, 7);
  12126. lua_interface->ResetFunctionStack(state);
  12127. if (!player) {
  12128. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not valid");
  12129. lua_interface->SetBooleanValue(state, false);
  12130. return 1;
  12131. }
  12132. if (!player->IsPlayer()) {
  12133. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not a player");
  12134. lua_interface->SetBooleanValue(state, false);
  12135. return 1;
  12136. }
  12137. if(!player->GetZone()) {
  12138. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  12139. lua_interface->SetBooleanValue(state, false);
  12140. return 1;
  12141. }
  12142. client = player->GetClient();
  12143. if (!client) {
  12144. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: could not find client");
  12145. lua_interface->SetBooleanValue(state, false);
  12146. return 1;
  12147. }
  12148. if(!client->IsReadyForUpdates()) {
  12149. lua_interface->LogError("LUA ReplaceWidgetFromClient command failed: client has not signaled sys_client_avatar_ready");
  12150. lua_interface->SetBooleanValue(state, false);
  12151. return 1;
  12152. }
  12153. client->SendReplaceWidget(widget_id, delete_widget, x, y, z, grid_id);
  12154. lua_interface->SetBooleanValue(state, true);
  12155. return 1;
  12156. }
  12157. int EQ2Emu_lua_RemoveWidgetFromSpawnMap(lua_State* state) {
  12158. Client* client = nullptr;
  12159. Spawn* spawn = lua_interface->GetSpawn(state);
  12160. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12161. lua_interface->ResetFunctionStack(state);
  12162. if (!spawn) {
  12163. lua_interface->LogError("LUA RemoveWidgetFromSpawnMap command error: spawn is not valid");
  12164. lua_interface->SetBooleanValue(state, false);
  12165. return 1;
  12166. }
  12167. if(!spawn->GetZone()) {
  12168. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  12169. lua_interface->SetBooleanValue(state, false);
  12170. return 1;
  12171. }
  12172. spawn->AddIgnoredWidget(widget_id);
  12173. lua_interface->SetBooleanValue(state, true);
  12174. return 1;
  12175. }
  12176. int EQ2Emu_lua_RemoveWidgetFromZoneMap(lua_State* state) {
  12177. ZoneServer* zone = lua_interface->GetZone(state);
  12178. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12179. lua_interface->ResetFunctionStack(state);
  12180. if(!zone) {
  12181. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: zone is not valid");
  12182. lua_interface->SetBooleanValue(state, false);
  12183. return 1;
  12184. }
  12185. if(!zone->IsLoading()) {
  12186. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: can only be called during zone loading, in preinit_zone_script ZoneScript function");
  12187. lua_interface->SetBooleanValue(state, false);
  12188. return 1;
  12189. }
  12190. zone->AddIgnoredWidget(widget_id);
  12191. lua_interface->SetBooleanValue(state, true);
  12192. return 1;
  12193. }
  12194. int EQ2Emu_lua_SendHearCast(lua_State* state) {
  12195. if (!lua_interface)
  12196. return 0;
  12197. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  12198. Spawn* spawn = lua_interface->GetSpawn(state);
  12199. int32 spell_visual_id = lua_interface->GetInt32Value(state, 2);
  12200. int16 cast_time = lua_interface->GetInt16Value(state, 3);
  12201. Spawn* caster = lua_interface->GetSpawn(state, 4);
  12202. Spawn* target = lua_interface->GetSpawn(state, 5);
  12203. lua_interface->ResetFunctionStack(state);
  12204. if(spell && spawn && spawn->IsEntity()) {
  12205. ZoneServer* zone = spawn->GetZone();
  12206. if(zone) {
  12207. zone->SendCastSpellPacket(spell, caster && caster->IsEntity() ? (Entity*)caster : (Entity*)spawn, spell_visual_id, cast_time > 0 ? cast_time : 0xFFFF);
  12208. }
  12209. }
  12210. else if (spawn) {
  12211. if (spawn->IsPlayer()) {
  12212. Client* client = ((Player*)spawn)->GetClient();
  12213. if (client) {
  12214. client->SendHearCast(caster ? caster : client->GetPlayer(), target ? target : client->GetPlayer(), spell_visual_id, cast_time);
  12215. }
  12216. }
  12217. }
  12218. return 0;
  12219. }
  12220. int EQ2Emu_lua_GetCharacterFlag(lua_State* state) {
  12221. if (!lua_interface)
  12222. return 0;
  12223. Spawn* player = lua_interface->GetSpawn(state);
  12224. sint32 flag_id = lua_interface->GetSInt32Value(state, 2);
  12225. lua_interface->ResetFunctionStack(state);
  12226. if (!player) {
  12227. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  12228. return 0;
  12229. }
  12230. if (!player->IsPlayer()) {
  12231. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  12232. return 0;
  12233. }
  12234. bool ret = ((Player*)player)->get_character_flag(flag_id);
  12235. lua_interface->SetBooleanValue(state, ret);
  12236. return 1;
  12237. }
  12238. int EQ2Emu_lua_ToggleCharacterFlag(lua_State* state) {
  12239. if (!lua_interface)
  12240. return 0;
  12241. Spawn* player = lua_interface->GetSpawn(state);
  12242. sint32 flag_id = lua_interface->GetSInt32Value(state, 2);
  12243. lua_interface->ResetFunctionStack(state);
  12244. if (!player) {
  12245. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  12246. return 0;
  12247. }
  12248. if (!player->IsPlayer()) {
  12249. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  12250. return 0;
  12251. }
  12252. ((Player*)player)->toggle_character_flag(flag_id);
  12253. return 0;
  12254. }
  12255. int EQ2Emu_lua_GetSpellInitialTarget(lua_State* state) {
  12256. LuaSpell* spell = lua_interface->GetSpell(state);
  12257. if(!spell) {
  12258. spell = lua_interface->GetCurrentSpell(state);
  12259. }
  12260. lua_interface->ResetFunctionStack(state);
  12261. if (spell) {
  12262. if(!spell->caster) {
  12263. lua_interface->LogError("%s: LUA GetSpellTarget command error, caster does not exist.", lua_interface->GetScriptName(state));
  12264. return 0;
  12265. }
  12266. if(!spell->caster->GetZone()) {
  12267. lua_interface->LogError("%s: LUA GetSpellTarget command error, zone does not exist.", lua_interface->GetScriptName(state));
  12268. return 0;
  12269. }
  12270. Spawn* spawn = spell->caster->GetZone()->GetSpawnByID(spell->initial_target);
  12271. if (spawn) {
  12272. lua_interface->SetSpawnValue(state, spawn);
  12273. return 1;
  12274. }
  12275. else {
  12276. lua_interface->LogError("%s: LUA GetSpellTarget command error, could not find initial target %u to map to spawn.", lua_interface->GetScriptName(state), spell->initial_target);
  12277. }
  12278. }
  12279. return 0;
  12280. }