LuaFunctions.cpp 431 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaFunctions.h"
  17. #include "Spawn.h"
  18. #include "WorldDatabase.h"
  19. #include "LuaInterface.h"
  20. #include "../common/ConfigReader.h"
  21. #include "client.h"
  22. #include "World.h"
  23. #include "Commands/Commands.h"
  24. #include "races.h"
  25. #include "classes.h"
  26. #include "Variables.h"
  27. #include "SpellProcess.h"
  28. #include "Rules/Rules.h"
  29. #include "../common/Log.h"
  30. #include <math.h>
  31. #include "HeroicOp/HeroicOp.h"
  32. #include "RaceTypes/RaceTypes.h"
  33. #include "ClientPacketFunctions.h"
  34. #include "Transmute.h"
  35. #include "Titles.h"
  36. #include <boost/algorithm/string/predicate.hpp>
  37. #include <sstream>
  38. #include <boost/algorithm/string.hpp>
  39. extern MasterFactionList master_faction_list;
  40. extern WorldDatabase database;
  41. extern LuaInterface* lua_interface;
  42. extern ConfigReader configReader;
  43. extern MasterQuestList master_quest_list;
  44. extern MasterItemList master_item_list;
  45. extern MasterSpellList master_spell_list;
  46. extern World world;
  47. extern Commands commands;
  48. extern ZoneList zone_list;
  49. extern Races races;
  50. extern Classes classes;
  51. extern Variables variables;
  52. extern MasterSkillList master_skill_list;
  53. extern MasterHeroicOPList master_ho_list;
  54. extern MasterRaceTypeList race_types_list;
  55. extern MasterLanguagesList master_languages_list;
  56. extern MasterTitlesList master_titles_list;
  57. extern RuleManager rule_manager;
  58. vector<string> ParseString(string strVal, char delim) {
  59. stringstream ss(strVal);
  60. vector<string> ret;
  61. while (ss.good())
  62. {
  63. string substr;
  64. getline(ss, substr, delim);
  65. ret.push_back(substr);
  66. }
  67. return ret;
  68. }
  69. vector<unsigned int> ParseStringToInt32(string strVal, char delim) {
  70. stringstream ss(strVal);
  71. vector<unsigned int> ret;
  72. while (ss.good())
  73. {
  74. string substr;
  75. getline(ss, substr, delim);
  76. stringstream valss(substr);
  77. unsigned int val = 0;
  78. valss >> val;
  79. ret.push_back(val);
  80. }
  81. return ret;
  82. }
  83. map<string, signed int> ParseStringMap(string strVal, char delim) {
  84. vector<string> pairs = ParseString(strVal, delim);
  85. vector<string>::iterator itr;
  86. map<string, signed int> ret;
  87. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  88. vector<string> keyvaluepair = ParseString(*itr, ':');
  89. if (keyvaluepair.size() == 2) {
  90. stringstream valss(keyvaluepair[1]);
  91. int32 val = 0;
  92. valss >> val;
  93. ret[keyvaluepair[0]] = val;
  94. }
  95. }
  96. return ret;
  97. }
  98. map<unsigned int, unsigned short> ParseIntMap(string strVal, char delim) {
  99. vector<string> pairs = ParseString(strVal, delim);
  100. vector<string>::iterator itr;
  101. map<unsigned int, unsigned short> ret;
  102. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  103. vector<string> keyvaluepair = ParseString(*itr, ':');
  104. int32 key = 0;
  105. if (keyvaluepair.size() > 0) {
  106. stringstream keyss(keyvaluepair[0]);
  107. keyss >> key;
  108. }
  109. if (keyvaluepair.size() == 1) {
  110. ret[key] = 1;
  111. }
  112. else if (keyvaluepair.size() == 2) {
  113. stringstream valss(keyvaluepair[1]);
  114. unsigned short val = 0;
  115. valss >> val;
  116. ret[key] = val;
  117. }
  118. }
  119. return ret;
  120. }
  121. map<unsigned int, signed int> ParseSInt32Map(string strVal, char delim) {
  122. vector<string> pairs = ParseString(strVal, delim);
  123. vector<string>::iterator itr;
  124. map<unsigned int, signed int> ret;
  125. for (itr = pairs.begin(); itr != pairs.end(); itr++) {
  126. vector<string> keyvaluepair = ParseString(*itr, ':');
  127. int32 key = 0;
  128. if (keyvaluepair.size() > 0) {
  129. stringstream keyss(keyvaluepair[0]);
  130. keyss >> key;
  131. }
  132. if (keyvaluepair.size() == 1) {
  133. ret[key] = 1;
  134. }
  135. else if (keyvaluepair.size() == 2) {
  136. stringstream valss(keyvaluepair[1]);
  137. signed int val = 0;
  138. valss >> val;
  139. ret[key] = val;
  140. }
  141. }
  142. return ret;
  143. }
  144. int EQ2Emu_lua_PlayFlavor(lua_State* state) {
  145. if (!lua_interface)
  146. return 0;
  147. Spawn* spawn = lua_interface->GetSpawn(state);
  148. string mp3_string = lua_interface->GetStringValue(state, 2);
  149. string text_string = lua_interface->GetStringValue(state, 3);
  150. string emote_string = lua_interface->GetStringValue(state, 4);
  151. int32 key1 = lua_interface->GetInt32Value(state, 5);
  152. int32 key2 = lua_interface->GetInt32Value(state, 6);
  153. Spawn* player = lua_interface->GetSpawn(state, 7);
  154. int8 language = lua_interface->GetInt8Value(state, 8);
  155. lua_interface->ResetFunctionStack(state);
  156. if (spawn) {
  157. const char* mp3 = 0;
  158. const char* text = 0;
  159. const char* emote = 0;
  160. if (mp3_string.length() > 0)
  161. mp3 = mp3_string.c_str();
  162. if (text_string.length() > 0)
  163. text = text_string.c_str();
  164. if (emote_string.length() > 0)
  165. emote = emote_string.c_str();
  166. Client* client = 0;
  167. if (player && player->IsPlayer())
  168. client = ((Player*)player)->GetClient();
  169. if (client) {
  170. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  171. spawn->GetZone()->PlayFlavor(client, spawn, mp3, text, emote, key1, key2, language);
  172. }
  173. else
  174. spawn->GetZone()->PlayFlavor(spawn, mp3, text, emote, key1, key2, language);
  175. }
  176. return 0;
  177. }
  178. int EQ2Emu_lua_PlayFlavorID(lua_State* state) {
  179. if (!lua_interface)
  180. return 0;
  181. Spawn* spawn = lua_interface->GetSpawn(state);
  182. int8 type = lua_interface->GetInt8Value(state, 2);
  183. int32 id = lua_interface->GetInt32Value(state, 3);
  184. int16 index = lua_interface->GetInt16Value(state, 4);
  185. Spawn* player = lua_interface->GetSpawn(state, 5);
  186. int8 language = lua_interface->GetInt8Value(state, 6);
  187. lua_interface->ResetFunctionStack(state);
  188. if (spawn) {
  189. Client* client = 0;
  190. if (player && player->IsPlayer())
  191. client = ((Player*)player)->GetClient();
  192. if (client) {
  193. VoiceOverStruct non_garble, garble;
  194. bool garble_success = false;
  195. bool success = world.FindVoiceOver(type, id, index, &non_garble, &garble_success, &garble);
  196. client->SendPlayFlavor(spawn, language, &non_garble, &garble, success, garble_success);
  197. }
  198. else
  199. spawn->GetZone()->PlayFlavorID(spawn, type, id, index, language);
  200. }
  201. return 0;
  202. }
  203. int EQ2Emu_lua_PlaySound(lua_State* state) {
  204. if (!lua_interface)
  205. return 0;
  206. Spawn* spawn = lua_interface->GetSpawn(state);
  207. string sound_string = lua_interface->GetStringValue(state, 2);
  208. float x = lua_interface->GetFloatValue(state, 3);
  209. float y = lua_interface->GetFloatValue(state, 4);
  210. float z = lua_interface->GetFloatValue(state, 5);
  211. Spawn* player = lua_interface->GetSpawn(state, 6);
  212. lua_interface->ResetFunctionStack(state);
  213. if (spawn && sound_string.length() > 0) {
  214. Client* client = 0;
  215. if (player && player->IsPlayer())
  216. client = ((Player*)player)->GetClient();
  217. if (client)
  218. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  219. else
  220. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  221. }
  222. return 0;
  223. }
  224. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  225. if (!lua_interface)
  226. return 0;
  227. Spawn* spawn = lua_interface->GetSpawn(state);
  228. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  229. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  230. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  231. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  232. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  233. lua_interface->ResetFunctionStack(state);
  234. if (!spawn) {
  235. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  236. return 0;
  237. }
  238. if (quest_id > 0) {
  239. //Add this quest to the list of required quests for this spawn
  240. spawn->SetQuestsRequired(quest_id, quest_step);
  241. //If private spawn value set
  242. if (private_spawn) {
  243. //Set the spawn to be private when not granted access through this quest
  244. spawn->AddAllowAccessSpawn(spawn);
  245. spawn->SetPrivateQuestSpawn(true);
  246. }
  247. //This value allows access after a quest step, or the whole quest has been completed
  248. if (continued_access)
  249. spawn->SetQuestsRequiredContinuedAccess(true);
  250. //This value will override vis_flags in the vis packet
  251. if (flag_override > 0)
  252. spawn->SetQuestsRequiredOverride(flag_override);
  253. }
  254. return 0;
  255. }
  256. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  257. if (!lua_interface)
  258. return 0;
  259. Spawn* spawn = lua_interface->GetSpawn(state);
  260. float max_distance = lua_interface->GetFloatValue(state, 2);
  261. string variable = lua_interface->GetStringValue(state, 3);
  262. string value = lua_interface->GetStringValue(state, 4);
  263. lua_interface->ResetFunctionStack(state);
  264. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  265. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  266. return 0;
  267. }
  268. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  269. if (!lua_interface)
  270. return 0;
  271. Client* client = 0;
  272. Spawn* player = lua_interface->GetSpawn(state);
  273. float intensity = lua_interface->GetFloatValue(state, 2);
  274. int8 direction = lua_interface->GetInt8Value(state, 3);
  275. lua_interface->ResetFunctionStack(state);
  276. if (!player) {
  277. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  278. return 0;
  279. }
  280. if (!player->IsPlayer()) {
  281. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  282. return 0;
  283. }
  284. if (player->GetZone())
  285. client = ((Player*)player)->GetClient();
  286. if (!client) {
  287. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  288. return 0;
  289. }
  290. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  291. if (packet) {
  292. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  293. v1 = *(float *)(a1 + 4);
  294. if ( v1 > 0.0 )
  295. v2 = fminf(v1, 1.0);
  296. else
  297. v2 = 0.1;
  298. */
  299. packet->setDataByName("intensity", intensity);
  300. if ( client->GetVersion() > 546 )
  301. packet->setDataByName("direction", direction);
  302. client->QueuePacket(packet->serialize());
  303. safe_delete(packet);
  304. }
  305. return 0;
  306. }
  307. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  308. if (!lua_interface)
  309. return 0;
  310. Spawn* dead = lua_interface->GetSpawn(state);
  311. Spawn* killer = lua_interface->GetSpawn(state, 2);
  312. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  313. lua_interface->ResetFunctionStack(state);
  314. if (dead && dead->Alive() && dead->GetZone())
  315. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  316. return 0;
  317. }
  318. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  319. if (!lua_interface)
  320. return 0;
  321. Spawn* spawn = lua_interface->GetSpawn(state);
  322. float max_distance = lua_interface->GetFloatValue(state, 2);
  323. bool include_players = lua_interface->GetInt8Value(state, 3);
  324. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  325. lua_interface->ResetFunctionStack(state);
  326. if (max_distance > 0 && spawn && spawn->GetZone())
  327. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  328. return 0;
  329. }
  330. int EQ2Emu_lua_Despawn(lua_State* state) {
  331. if (!lua_interface)
  332. return 0;
  333. Spawn* spawn = lua_interface->GetSpawn(state);
  334. int32 delay = lua_interface->GetInt32Value(state, 2);
  335. lua_interface->ResetFunctionStack(state);
  336. if (spawn && spawn->GetZone())
  337. spawn->GetZone()->Despawn(spawn, delay);
  338. return 0;
  339. }
  340. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  341. if (!lua_interface)
  342. return 0;
  343. Spawn* spawn = lua_interface->GetSpawn(state);
  344. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  345. lua_interface->ResetFunctionStack(state);
  346. if (spawn) {
  347. spawn->info_changed = true;
  348. spawn->SetShowHandIcon(displayHandIcon);
  349. }
  350. return 0;
  351. }
  352. //this function is used to force an update packet to be sent.
  353. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  354. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  355. if (!lua_interface)
  356. return 0;
  357. Spawn* spawn = lua_interface->GetSpawn(state);
  358. lua_interface->ResetFunctionStack(state);
  359. if (spawn) {
  360. spawn->vis_changed = true;
  361. spawn->GetZone()->AddChangedSpawn(spawn);
  362. }
  363. return 0;
  364. }
  365. //this function is used to force an update packet to be sent.
  366. //Useful if certain calculated things change after the player is sent the spawn packet, like quest flags or player has access to an object now
  367. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  368. if (!lua_interface)
  369. return 0;
  370. Spawn* spawn = lua_interface->GetSpawn(state);
  371. lua_interface->ResetFunctionStack(state);
  372. if (spawn) {
  373. spawn->info_changed = true;
  374. spawn->GetZone()->AddChangedSpawn(spawn);
  375. }
  376. return 0;
  377. }
  378. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  379. if (!lua_interface)
  380. return 0;
  381. Spawn* spawn = lua_interface->GetSpawn(state);
  382. int32 new_state = lua_interface->GetInt32Value(state, 2);
  383. Spawn* player = lua_interface->GetSpawn(state, 3);
  384. lua_interface->ResetFunctionStack(state);
  385. if (spawn) {
  386. if(player)
  387. {
  388. if(player->IsPlayer())
  389. {
  390. Client* client = ((Player*)player)->GetClient();
  391. if(client)
  392. {
  393. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  394. lua_interface->SetBooleanValue(state, true);
  395. return 1;
  396. }
  397. else
  398. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument does not have active client.", spawn->GetName());
  399. }
  400. else
  401. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in SendStateCommand,attempted to pass player value in argument 3, but argument is NOT a player.", spawn->GetName());
  402. }
  403. else
  404. {
  405. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  406. lua_interface->SetBooleanValue(state, true);
  407. return 1;
  408. }
  409. }
  410. lua_interface->SetBooleanValue(state, false);
  411. return 1;
  412. }
  413. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  414. if (!lua_interface)
  415. return 0;
  416. Spawn* spawn = lua_interface->GetSpawn(state);
  417. string variable = lua_interface->GetStringValue(state, 2);
  418. string value = lua_interface->GetStringValue(state, 3);
  419. bool no_update = lua_interface->GetBooleanValue(state, 4); // send update is true by default in SetSpawnCommand, so allow user to specify 'true' to disable send update.
  420. bool temporary_flag = true;
  421. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  422. int8 index = 0;
  423. if(num_args >= 5)
  424. {
  425. temporary_flag = lua_interface->GetBooleanValue(state, 5); // this used to be false, but no one bothered to set it temporary, we don't need to update the DB
  426. index = lua_interface->GetInt8Value(state, 6);
  427. }
  428. lua_interface->ResetFunctionStack(state);
  429. int32 type = commands.GetSpawnSetType(variable);
  430. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  431. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  432. return 0;
  433. }
  434. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  435. if (!lua_interface)
  436. return 0;
  437. Spawn* spawn = lua_interface->GetSpawn(state);
  438. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  439. lua_interface->ResetFunctionStack(state);
  440. if (spawn && spawn_id > 0) {
  441. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  442. if (closest_spawn) {
  443. lua_interface->SetSpawnValue(state, closest_spawn);
  444. return 1;
  445. }
  446. }
  447. return 0;
  448. }
  449. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  450. if (!lua_interface)
  451. return 0;
  452. vector<Spawn*> spawns;
  453. int32 position = 0;
  454. if(lua_istable(state, 1)) {
  455. size_t len = lua_rawlen(state, 1);
  456. for(int i=1;i <= len; i++)
  457. {
  458. // get the entry to stack
  459. lua_rawgeti(state, 1, i);
  460. int Top = lua_gettop(state);
  461. if(lua_islightuserdata(state,Top)) {
  462. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  463. if(data->IsSpawn()) {
  464. spawns.push_back(data->spawn);
  465. }
  466. }
  467. // remove entry from stack
  468. lua_pop(state,1);
  469. }
  470. }
  471. position = lua_interface->GetInt32Value(state, 2);
  472. lua_interface->ResetFunctionStack(state);
  473. Spawn* spawn = 0;
  474. if(position < spawns.size()) {
  475. spawn = spawns.at(position);
  476. }
  477. if(spawn) {
  478. lua_interface->SetSpawnValue(state, spawn);
  479. return 1;
  480. }
  481. return 0;
  482. }
  483. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  484. if (!lua_interface)
  485. return 0;
  486. vector<Spawn*> spawns;
  487. if(lua_istable(state, 1)) {
  488. size_t len = lua_rawlen(state, 1);
  489. for(int i=1;i <= len; i++)
  490. {
  491. // get the entry to stack
  492. lua_rawgeti(state, 1, i);
  493. int Top = lua_gettop(state);
  494. if(lua_islightuserdata(state,Top)) {
  495. LUAUserData* data = (LUAUserData*)lua_touserdata(state, Top);
  496. if(data->IsSpawn()) {
  497. spawns.push_back(data->spawn);
  498. }
  499. }
  500. // remove entry from stack
  501. lua_pop(state,1);
  502. }
  503. }
  504. lua_interface->ResetFunctionStack(state);
  505. lua_interface->SetInt32Value(state, spawns.size());
  506. return 1;
  507. }
  508. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  509. if (!lua_interface)
  510. return 0;
  511. Spawn* spawn = lua_interface->GetSpawn(state);
  512. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  513. lua_interface->ResetFunctionStack(state);
  514. if (spawn) {
  515. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  516. if (spawns.size() > 0) {
  517. lua_createtable(state, spawns.size(), 0);
  518. int newTable = lua_gettop(state);
  519. for (int32 i = 0; i < spawns.size(); i++) {
  520. lua_interface->SetSpawnValue(state, spawns.at(i));
  521. lua_rawseti(state, newTable, i + 1);
  522. }
  523. return 1;
  524. }
  525. }
  526. return 0;
  527. }
  528. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  529. if (!lua_interface)
  530. return 0;
  531. Spawn* spawn = lua_interface->GetSpawn(state);
  532. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  533. lua_interface->ResetFunctionStack(state);
  534. if (spawn) {
  535. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  536. if (spawns.size() > 0) {
  537. lua_createtable(state, spawns.size(), 0);
  538. int newTable = lua_gettop(state);
  539. for (int32 i = 0; i < spawns.size(); i++) {
  540. lua_interface->SetSpawnValue(state, spawns.at(i));
  541. lua_rawseti(state, newTable, i + 1);
  542. }
  543. return 1;
  544. }
  545. }
  546. return 0;
  547. }
  548. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  549. if (!lua_interface)
  550. return 0;
  551. Spawn* spawn = lua_interface->GetSpawn(state);
  552. lua_interface->ResetFunctionStack(state);
  553. if (spawn) {
  554. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  555. if (spawns.size() > 0) {
  556. lua_createtable(state, spawns.size(), 0);
  557. int newTable = lua_gettop(state);
  558. for (int32 i = 0; i < spawns.size(); i++) {
  559. lua_interface->SetSpawnValue(state, spawns.at(i));
  560. lua_rawseti(state, newTable, i + 1);
  561. }
  562. return 1;
  563. }
  564. }
  565. return 0;
  566. }
  567. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  568. if (!lua_interface)
  569. return 0;
  570. string variable_name = lua_interface->GetStringValue(state);
  571. lua_interface->ResetFunctionStack(state);
  572. Variable* var = variables.FindVariable(variable_name);
  573. if (var) {
  574. lua_interface->SetStringValue(state, var->GetValue());
  575. return 1;
  576. }
  577. return 0;
  578. }
  579. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  580. if (!lua_interface)
  581. return 0;
  582. int32 total_coins = lua_interface->GetInt32Value(state);
  583. lua_interface->ResetFunctionStack(state);
  584. if (total_coins == 0) {
  585. lua_interface->SetStringValue(state, "0 copper");
  586. return 1;
  587. }
  588. char tmp[64] = { 0 };
  589. string message = "";
  590. int32 val = 0;
  591. if (total_coins >= 1000000) {
  592. val = total_coins / 1000000;
  593. total_coins -= 1000000 * val;
  594. sprintf(tmp, " %u Platinum", val);
  595. message.append(tmp);
  596. memset(tmp, 0, 64);
  597. }
  598. if (total_coins >= 10000) {
  599. val = total_coins / 10000;
  600. total_coins -= 10000 * val;
  601. sprintf(tmp, " %u Gold", val);
  602. message.append(tmp);
  603. memset(tmp, 0, 64);
  604. }
  605. if (total_coins >= 100) {
  606. val = total_coins / 100;
  607. total_coins -= 100 * val;
  608. sprintf(tmp, " %u Silver", val);
  609. message.append(tmp);
  610. memset(tmp, 0, 64);
  611. }
  612. if (total_coins > 0) {
  613. sprintf(tmp, " %u Copper", (int32)total_coins);
  614. message.append(tmp);
  615. }
  616. lua_interface->SetStringValue(state, message.c_str());
  617. return 1;
  618. }
  619. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  620. ZoneServer* zone = lua_interface->GetZone(state);
  621. int32 group_id = lua_interface->GetInt32Value(state, 2);
  622. lua_interface->ResetFunctionStack(state);
  623. if (zone) {
  624. Spawn* spawn = zone->GetSpawnGroup(group_id);
  625. if (spawn) {
  626. lua_interface->SetSpawnValue(state, spawn);
  627. return 1;
  628. }
  629. }
  630. return 0;
  631. }
  632. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  633. ZoneServer* zone = lua_interface->GetZone(state);
  634. int32 location_id = lua_interface->GetInt32Value(state, 2);
  635. lua_interface->ResetFunctionStack(state);
  636. if (zone) {
  637. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  638. if (spawn) {
  639. lua_interface->SetSpawnValue(state, spawn);
  640. return 1;
  641. }
  642. }
  643. return 0;
  644. }
  645. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  646. Spawn* spawn = lua_interface->GetSpawn(state);
  647. lua_interface->ResetFunctionStack(state);
  648. if (spawn) {
  649. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  650. return 1;
  651. }
  652. return 0;
  653. }
  654. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  655. Spawn* spawn = lua_interface->GetSpawn(state);
  656. lua_interface->ResetFunctionStack(state);
  657. if (spawn) {
  658. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  659. return 1;
  660. }
  661. return 0;
  662. }
  663. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  664. if (!lua_interface)
  665. return 0;
  666. Spawn* spawn = lua_interface->GetSpawn(state);
  667. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  668. lua_interface->ResetFunctionStack(state);
  669. if (spawn) {
  670. spawn->SetSpawnGroupID(new_group_id);
  671. lua_interface->SetBooleanValue(state, true);
  672. return 1;
  673. }
  674. lua_interface->SetBooleanValue(state, false);
  675. return 1;
  676. }
  677. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  678. if (!lua_interface)
  679. return 0;
  680. Spawn* spawn = lua_interface->GetSpawn(state);
  681. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  682. lua_interface->ResetFunctionStack(state);
  683. if (spawn) {
  684. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  685. lua_interface->SetBooleanValue(state, true);
  686. return 1;
  687. }
  688. lua_interface->SetBooleanValue(state, false);
  689. return 1;
  690. }
  691. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  692. Spawn* spawn = lua_interface->GetSpawn(state);
  693. lua_interface->ResetFunctionStack(state);
  694. if (spawn) {
  695. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  696. return 1;
  697. }
  698. return 0;
  699. }
  700. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  701. Spawn* spawn = lua_interface->GetSpawn(state);
  702. lua_interface->ResetFunctionStack(state);
  703. if (spawn) {
  704. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  705. return 1;
  706. }
  707. return 0;
  708. }
  709. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  710. Player* player = (Player*)lua_interface->GetSpawn(state);
  711. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  712. lua_interface->ResetFunctionStack(state);
  713. if (player && player->IsPlayer() && faction_id > 0) {
  714. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  715. return 1;
  716. }
  717. return 0;
  718. }
  719. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  720. if (!lua_interface)
  721. return 0;
  722. Spawn* spawn = lua_interface->GetSpawn(state);
  723. int32 value = lua_interface->GetInt32Value(state, 2);
  724. lua_interface->ResetFunctionStack(state);
  725. if (spawn) {
  726. spawn->SetFactionID(value);
  727. }
  728. return 0;
  729. }
  730. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  731. Spawn* spawn = lua_interface->GetSpawn(state);
  732. lua_interface->ResetFunctionStack(state);
  733. if (spawn) {
  734. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  735. return 1;
  736. }
  737. return 0;
  738. }
  739. int EQ2Emu_lua_GetGender(lua_State* state) {
  740. Spawn* spawn = lua_interface->GetSpawn(state);
  741. lua_interface->ResetFunctionStack(state);
  742. if (spawn) {
  743. lua_interface->SetInt32Value(state, spawn->GetGender());
  744. return 1;
  745. }
  746. return 0;
  747. }
  748. int EQ2Emu_lua_GetTarget(lua_State* state) {
  749. Spawn* spawn = lua_interface->GetSpawn(state);
  750. lua_interface->ResetFunctionStack(state);
  751. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  752. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  753. return 1;
  754. }
  755. return 0;
  756. }
  757. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  758. if (!lua_interface)
  759. return 0;
  760. Spawn* spawn = lua_interface->GetSpawn(state);
  761. string mp3_string = lua_interface->GetStringValue(state, 2);
  762. int32 key1 = lua_interface->GetInt32Value(state, 3);
  763. int32 key2 = lua_interface->GetInt32Value(state, 4);
  764. Spawn* player = lua_interface->GetSpawn(state, 5);
  765. lua_interface->ResetFunctionStack(state);
  766. if (spawn && mp3_string.length() > 0) {
  767. Client* client = 0;
  768. if (player && player->IsPlayer())
  769. client = ((Player*)player)->GetClient();
  770. if (client) {
  771. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  772. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  773. }
  774. else
  775. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  776. }
  777. return 0;
  778. }
  779. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  780. if (!lua_interface)
  781. return 0;
  782. Spawn* spawn = lua_interface->GetSpawn(state);
  783. lua_interface->ResetFunctionStack(state);
  784. if (spawn) {
  785. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  786. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  787. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  788. return 3;
  789. }
  790. return 0;
  791. }
  792. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  793. if (!lua_interface)
  794. return 0;
  795. Spawn* spawn = lua_interface->GetSpawn(state);
  796. if (spawn) {
  797. int32 item_id = lua_interface->GetInt32Value(state, 2);
  798. lua_interface->ResetFunctionStack(state);
  799. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  800. return 1;
  801. }
  802. lua_interface->ResetFunctionStack(state);
  803. return 0;
  804. }
  805. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  806. if (!lua_interface)
  807. return 0;
  808. Spawn* spawn = lua_interface->GetSpawn(state);
  809. if (spawn && spawn->IsEntity()) {
  810. int32 item_id = lua_interface->GetInt32Value(state, 2);
  811. int16 charges = lua_interface->GetInt16Value(state, 3);
  812. if (charges == 0)
  813. charges = 1;
  814. ((Entity*)spawn)->AddLootItem(item_id, charges);
  815. }
  816. lua_interface->ResetFunctionStack(state);
  817. return 0;
  818. }
  819. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  820. if (!lua_interface)
  821. return 0;
  822. Spawn* spawn = lua_interface->GetSpawn(state);
  823. if (spawn && spawn->IsEntity()) {
  824. int32 item_id = lua_interface->GetInt32Value(state, 2);
  825. Item* item = spawn->LootItem(item_id);
  826. lua_interface->SetLuaUserDataStale(item);
  827. safe_delete(item);
  828. }
  829. lua_interface->ResetFunctionStack(state);
  830. return 0;
  831. }
  832. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  833. if (!lua_interface)
  834. return 0;
  835. Spawn* spawn = lua_interface->GetSpawn(state);
  836. if (spawn) {
  837. int32 val = lua_interface->GetInt32Value(state, 2);
  838. spawn->AddLootCoins(val);
  839. }
  840. lua_interface->ResetFunctionStack(state);
  841. return 0;
  842. }
  843. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  844. if (!lua_interface)
  845. return 0;
  846. Spawn* entity = lua_interface->GetSpawn(state);
  847. Spawn* player = lua_interface->GetSpawn(state, 2);
  848. if (entity && player && player->IsPlayer()) {
  849. int32 coins = lua_interface->GetInt32Value(state, 3);
  850. vector<Item*>* items = 0;
  851. int i = 0;
  852. int32 item_id = 0;
  853. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  854. if (items == 0)
  855. items = new vector<Item*>;
  856. if (master_item_list.GetItem(item_id))
  857. items->push_back(master_item_list.GetItem(item_id));
  858. i++;
  859. }
  860. Client* client = 0;
  861. client = ((Player*)player)->GetClient();
  862. if (client)
  863. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  864. if(coins > 0)
  865. entity->AddLootCoins(coins);
  866. safe_delete(items);
  867. }
  868. lua_interface->ResetFunctionStack(state);
  869. return 0;
  870. }
  871. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  872. if (!lua_interface)
  873. return 0;
  874. Spawn* entity = lua_interface->GetSpawn(state);
  875. Spawn* player = lua_interface->GetSpawn(state, 2);
  876. int32 item_id = lua_interface->GetInt32Value(state, 3);
  877. lua_interface->ResetFunctionStack(state);
  878. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  879. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  880. return 1;
  881. }
  882. return 0;
  883. }
  884. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  885. if (!lua_interface)
  886. return 0;
  887. Spawn* entity = lua_interface->GetSpawn(state);
  888. Spawn* player = lua_interface->GetSpawn(state, 2);
  889. lua_interface->ResetFunctionStack(state);
  890. if (entity && player && player->IsPlayer()) {
  891. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  892. return 1;
  893. }
  894. return 0;
  895. }
  896. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  897. if (!lua_interface)
  898. return 0;
  899. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  900. lua_interface->SetLuaUserDataStale(conversation);
  901. safe_delete(conversation);
  902. lua_interface->ResetFunctionStack(state);
  903. conversation = new vector<ConversationOption>();
  904. lua_interface->SetConversationValue(state, conversation);
  905. return 1;
  906. }
  907. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  908. if (!lua_interface)
  909. return 0;
  910. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  911. if (conversation) {
  912. ConversationOption conv_option;
  913. conv_option.option = lua_interface->GetStringValue(state, 2);
  914. conv_option.function = lua_interface->GetStringValue(state, 3);
  915. if (conv_option.option.length() > 0)
  916. conversation->push_back(conv_option);
  917. }
  918. lua_interface->ResetFunctionStack(state);
  919. return 0;
  920. }
  921. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  922. if (!lua_interface)
  923. return 0;
  924. Spawn* npc = lua_interface->GetSpawn(state);
  925. Spawn* player = lua_interface->GetSpawn(state, 2);
  926. lua_interface->ResetFunctionStack(state);
  927. if (npc && player && player->IsPlayer() && player->GetZone()) {
  928. Client* client = ((Player*)player)->GetClient();
  929. if (client) {
  930. int32 conversation_id = client->GetConversationID(npc, 0);
  931. client->CloseDialog(conversation_id);
  932. }
  933. }
  934. return 0;
  935. }
  936. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  937. if (!lua_interface)
  938. return 0;
  939. Item* item = lua_interface->GetItem(state);
  940. Spawn* player = lua_interface->GetSpawn(state, 2);
  941. lua_interface->ResetFunctionStack(state);
  942. if (item && player && player->IsPlayer() && player->GetZone()) {
  943. Client* client = ((Player*)player)->GetClient();
  944. if (client) {
  945. int32 conversation_id = client->GetConversationID(0, item);
  946. client->CloseDialog(conversation_id);
  947. }
  948. }
  949. return 0;
  950. }
  951. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  952. if (!lua_interface)
  953. return 0;
  954. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  955. Spawn* spawn = 0;
  956. Item* item = 0;
  957. int8 type = lua_interface->GetInt8Value(state, 2);
  958. if (type == 1 || type == 3)
  959. spawn = lua_interface->GetSpawn(state, 3);
  960. else if (type == 2 || type == 4)
  961. item = lua_interface->GetItem(state, 3);
  962. Spawn* player = lua_interface->GetSpawn(state, 4);
  963. string text = lua_interface->GetStringValue(state, 5);
  964. string mp3 = lua_interface->GetStringValue(state, 6);
  965. int32 key1 = lua_interface->GetInt32Value(state, 7);
  966. int32 key2 = lua_interface->GetInt32Value(state, 8);
  967. int8 language = lua_interface->GetInt8Value(state, 9);
  968. int numargs = lua_interface->GetNumberOfArgs(state);
  969. int8 can_close = 1;
  970. if(numargs > 9)
  971. can_close = lua_interface->GetInt32Value(state, 10);
  972. lua_interface->ResetFunctionStack(state);
  973. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  974. Client* client = ((Player*)player)->GetClient();
  975. if (client) {
  976. if (spawn) {
  977. // Need to do this so the function works the same as it did before
  978. if (type == 1)
  979. type++;
  980. if (mp3.length() > 0)
  981. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2, language, can_close);
  982. else
  983. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), nullptr, 0, 0, language, can_close);
  984. }
  985. else {
  986. if (mp3.length() > 0)
  987. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2, language, can_close);
  988. else
  989. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, nullptr, 0, 0, language, can_close);
  990. }
  991. }
  992. }
  993. lua_interface->SetLuaUserDataStale(conversation);
  994. safe_delete(conversation);
  995. return 0;
  996. }
  997. int EQ2Emu_lua_StartConversation(lua_State* state) {
  998. if (!lua_interface)
  999. return 0;
  1000. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  1001. Spawn* source = lua_interface->GetSpawn(state, 2);
  1002. Spawn* player = lua_interface->GetSpawn(state, 3);
  1003. string text = lua_interface->GetStringValue(state, 4);
  1004. string mp3 = lua_interface->GetStringValue(state, 5);
  1005. int32 key1 = lua_interface->GetInt32Value(state, 6);
  1006. int32 key2 = lua_interface->GetInt32Value(state, 7);
  1007. int8 language = lua_interface->GetInt32Value(state, 8);
  1008. int numargs = lua_interface->GetNumberOfArgs(state);
  1009. int8 can_close = 1;
  1010. if(numargs > 8)
  1011. can_close = lua_interface->GetInt32Value(state, 9);
  1012. lua_interface->ResetFunctionStack(state);
  1013. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1014. Client* client = ((Player*)player)->GetClient();
  1015. if (mp3.length() > 0)
  1016. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2, language, can_close);
  1017. else
  1018. client->DisplayConversation(source, 1, conversation, text.c_str(), nullptr, 0, 0, language, can_close);
  1019. lua_interface->SetLuaUserDataStale(conversation);
  1020. safe_delete(conversation);
  1021. }
  1022. else
  1023. LogWrite(LUA__ERROR, 0, "LUA", "Spawn %s Error in StartConversation, potentially AddConversationOption not yet called or the StartConversation arguments are incorrect, text: %s, conversationSize: %i.", source ? source->GetName() : "UNKNOWN", text.size() ? text.c_str() : "", conversation ? conversation->size() : -1);
  1024. return 0;
  1025. }
  1026. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1027. if (!lua_interface)
  1028. return 0;
  1029. Spawn* spawn = lua_interface->GetSpawn(state);
  1030. float distance = lua_interface->GetFloatValue(state, 2);
  1031. string in_range_function = lua_interface->GetStringValue(state, 3);
  1032. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1033. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1034. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1035. return 0;
  1036. }
  1037. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1038. ZoneServer* zone = lua_interface->GetZone(state);
  1039. float x = lua_interface->GetFloatValue(state, 2);
  1040. float y = lua_interface->GetFloatValue(state, 3);
  1041. float z = lua_interface->GetFloatValue(state, 4);
  1042. float max_variation = lua_interface->GetFloatValue(state, 5);
  1043. string in_range_function = lua_interface->GetStringValue(state, 6);
  1044. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1045. lua_interface->ResetFunctionStack(state);
  1046. if (zone && in_range_function.length() > 0)
  1047. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1048. return 0;
  1049. }
  1050. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1051. if (!lua_interface)
  1052. return 0;
  1053. Spawn* spawn = lua_interface->GetSpawn(state);
  1054. if (spawn && spawn->IsEntity()) {
  1055. int32 val = lua_interface->GetInt32Value(state, 2);
  1056. ((Entity*)spawn)->SetLootCoins(val);
  1057. }
  1058. lua_interface->ResetFunctionStack(state);
  1059. return 0;
  1060. }
  1061. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1062. if (!lua_interface)
  1063. return 0;
  1064. Spawn* spawn = lua_interface->GetSpawn(state);
  1065. lua_interface->ResetFunctionStack(state);
  1066. if (spawn && spawn->IsEntity()) {
  1067. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1068. return 1;
  1069. }
  1070. return 0;
  1071. }
  1072. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1073. if (!lua_interface)
  1074. return 0;
  1075. Spawn* spawn = lua_interface->GetSpawn(state);
  1076. float x = lua_interface->GetFloatValue(state, 2);
  1077. float y = lua_interface->GetFloatValue(state, 3);
  1078. float z = lua_interface->GetFloatValue(state, 4);
  1079. float speed = lua_interface->GetFloatValue(state, 5);
  1080. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1081. string function = lua_interface->GetStringValue(state, 7);
  1082. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1083. float heading = lua_interface->GetFloatValue(state, 8);
  1084. if (spawn) {
  1085. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1086. spawn->GetZone()->AddMovementNPC(spawn);
  1087. }
  1088. lua_interface->ResetFunctionStack(state);
  1089. return 0;
  1090. }
  1091. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1092. if (!lua_interface)
  1093. return 0;
  1094. Spawn* spawn = lua_interface->GetSpawn(state);
  1095. lua_interface->ResetFunctionStack(state);
  1096. if (spawn) {
  1097. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1098. return 1;
  1099. }
  1100. return 0;
  1101. }
  1102. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1103. if (!lua_interface)
  1104. return 0;
  1105. Spawn* spawn = lua_interface->GetSpawn(state);
  1106. lua_interface->ResetFunctionStack(state);
  1107. if (spawn && spawn->IsPlayer()) {
  1108. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1109. return 1;
  1110. }
  1111. lua_interface->SetInt32Value(state, 0);
  1112. return 1;
  1113. }
  1114. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1115. if (!lua_interface)
  1116. return 0;
  1117. Spawn* spawn = lua_interface->GetSpawn(state);
  1118. Spawn* target = lua_interface->GetSpawn(state, 2);
  1119. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1120. bool reset_action_state = true;
  1121. if(num_args > 2)
  1122. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1123. if (spawn && target) {
  1124. if (spawn->IsEntity())
  1125. // ((Entity*)spawn)->FaceTarget(target);
  1126. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1127. }
  1128. lua_interface->ResetFunctionStack(state);
  1129. return 0;
  1130. }
  1131. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1132. if (!lua_interface)
  1133. return 0;
  1134. Spawn* spawn = lua_interface->GetSpawn(state);
  1135. float x = lua_interface->GetFloatValue(state, 2);
  1136. float y = lua_interface->GetFloatValue(state, 3);
  1137. float z = lua_interface->GetFloatValue(state, 4);
  1138. float speed = lua_interface->GetFloatValue(state, 5);
  1139. string lua_function = lua_interface->GetStringValue(state, 6);
  1140. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1141. if (spawn) {
  1142. if (speed == 0)
  1143. speed = spawn->GetSpeed();
  1144. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1145. }
  1146. lua_interface->ResetFunctionStack(state);
  1147. return 0;
  1148. }
  1149. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1150. if (!lua_interface)
  1151. return 0;
  1152. Spawn* spawn = lua_interface->GetSpawn(state);
  1153. lua_interface->ResetFunctionStack(state);
  1154. if (spawn) {
  1155. spawn->ClearRunningLocations();
  1156. }
  1157. return 0;
  1158. }
  1159. int EQ2Emu_lua_Say(lua_State* state) {
  1160. if (!lua_interface)
  1161. return 0;
  1162. Spawn* spawn = lua_interface->GetSpawn(state);
  1163. string message = lua_interface->GetStringValue(state, 2);
  1164. Spawn* player = lua_interface->GetSpawn(state, 3);
  1165. float dist = lua_interface->GetFloatValue(state, 4);
  1166. int32 language = lua_interface->GetInt32Value(state, 5);
  1167. if (spawn && message.length() > 0) {
  1168. Client* client = 0;
  1169. if (player && player->IsPlayer())
  1170. client = ((Player*)player)->GetClient();
  1171. if (client)
  1172. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1173. else
  1174. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1175. }
  1176. lua_interface->ResetFunctionStack(state);
  1177. return 0;
  1178. }
  1179. int EQ2Emu_lua_Shout(lua_State* state) {
  1180. if (!lua_interface)
  1181. return 0;
  1182. Spawn* spawn = lua_interface->GetSpawn(state);
  1183. string message = lua_interface->GetStringValue(state, 2);
  1184. Spawn* player = lua_interface->GetSpawn(state, 3);
  1185. float dist = lua_interface->GetFloatValue(state, 4);
  1186. int32 language = lua_interface->GetInt32Value(state, 5);
  1187. if (spawn && message.length() > 0) {
  1188. Client* client = 0;
  1189. if (player && player->IsPlayer())
  1190. client = ((Player*)player)->GetClient();
  1191. if (client)
  1192. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1193. else
  1194. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1195. }
  1196. lua_interface->ResetFunctionStack(state);
  1197. return 0;
  1198. }
  1199. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1200. if (!lua_interface)
  1201. return 0;
  1202. Spawn* spawn = lua_interface->GetSpawn(state);
  1203. string message = lua_interface->GetStringValue(state, 2);
  1204. Spawn* player = lua_interface->GetSpawn(state, 3);
  1205. float dist = lua_interface->GetFloatValue(state, 4);
  1206. int32 language = lua_interface->GetInt32Value(state, 5);
  1207. if (spawn && message.length() > 0) {
  1208. Client* client = 0;
  1209. if (player && player->IsPlayer())
  1210. client = ((Player*)player)->GetClient();
  1211. if (client)
  1212. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1213. else
  1214. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), (dist > 0.0f) ? dist : 30.0f, 0, true, language);
  1215. }
  1216. lua_interface->ResetFunctionStack(state);
  1217. return 0;
  1218. }
  1219. int EQ2Emu_lua_Emote(lua_State* state) {
  1220. if (!lua_interface)
  1221. return 0;
  1222. Spawn* spawn = lua_interface->GetSpawn(state);
  1223. string message = lua_interface->GetStringValue(state, 2);
  1224. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1225. Spawn* player = lua_interface->GetSpawn(state, 4);
  1226. char* to = 0;
  1227. if (spawn2)
  1228. to = spawn2->GetName();
  1229. if (spawn && message.length() > 0) {
  1230. Client* client = 0;
  1231. if (player && player->IsPlayer())
  1232. client = ((Player*)player)->GetClient();
  1233. if (client)
  1234. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1235. else
  1236. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1237. }
  1238. lua_interface->ResetFunctionStack(state);
  1239. return 0;
  1240. }
  1241. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1242. if (!lua_interface)
  1243. return 0;
  1244. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1245. if(!luaspell || luaspell->resisted) {
  1246. lua_interface->ResetFunctionStack(state);
  1247. return 0;
  1248. }
  1249. Spawn* caster = luaspell->caster;
  1250. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1251. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1252. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1253. Spawn* target = lua_interface->GetSpawn(state, 4);
  1254. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1255. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1256. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1257. lua_interface->ResetFunctionStack(state);
  1258. boost::to_lower(heal_type);
  1259. if (caster && caster->IsEntity()) {
  1260. bool success = false;
  1261. luaspell->resisted = false;
  1262. if (target) {
  1263. float distance = caster->GetDistance(target, true);
  1264. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1265. success = true;
  1266. }
  1267. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1268. Spawn* target = 0;
  1269. ZoneServer* zone = luaspell->caster->GetZone();
  1270. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1271. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1272. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1273. float distance = caster->GetDistance(target, true);
  1274. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1275. }
  1276. }
  1277. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1278. success = true;
  1279. }
  1280. if (success) {
  1281. if (caster->GetZone())
  1282. caster->GetZone()->TriggerCharSheetTimer();
  1283. }
  1284. }
  1285. return 0;
  1286. }
  1287. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1288. if (!lua_interface)
  1289. return 0;
  1290. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1291. if(!luaspell || luaspell->resisted) {
  1292. lua_interface->ResetFunctionStack(state);
  1293. return 0;
  1294. }
  1295. Spawn* caster = luaspell->caster;
  1296. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1297. float percentage = lua_interface->GetFloatValue(state, 2);
  1298. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1299. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1300. Spawn* target = lua_interface->GetSpawn(state, 5);
  1301. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1302. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1303. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1304. lua_interface->ResetFunctionStack(state);
  1305. boost::to_lower(heal_type);
  1306. int32 min_heal = 0, max_heal = 0;
  1307. if (caster && caster->IsEntity() && target) {
  1308. if(percentage <= 0.0f)
  1309. {
  1310. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1311. return 0;
  1312. }
  1313. if(heal_type == "power")
  1314. {
  1315. if(current_value)
  1316. {
  1317. if(caster_value)
  1318. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1319. else
  1320. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1321. }
  1322. else
  1323. {
  1324. if(caster_value)
  1325. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1326. else
  1327. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1328. }
  1329. }
  1330. else
  1331. {
  1332. if(current_value)
  1333. {
  1334. if(caster_value)
  1335. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1336. else
  1337. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1338. }
  1339. else
  1340. {
  1341. if(caster_value)
  1342. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1343. else
  1344. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1345. }
  1346. }
  1347. bool success = false;
  1348. luaspell->resisted = false;
  1349. if (target) {
  1350. float distance = caster->GetDistance(target, true);
  1351. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1352. success = true;
  1353. }
  1354. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1355. Spawn* target = 0;
  1356. ZoneServer* zone = luaspell->caster->GetZone();
  1357. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1358. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1359. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1360. float distance = caster->GetDistance(target, true);
  1361. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1362. }
  1363. }
  1364. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1365. success = true;
  1366. }
  1367. if (success) {
  1368. if (caster->GetZone())
  1369. caster->GetZone()->TriggerCharSheetTimer();
  1370. }
  1371. }
  1372. return 0;
  1373. }
  1374. int EQ2Emu_lua_AddItem(lua_State* state) {
  1375. if (!lua_interface)
  1376. return 0;
  1377. Spawn* spawn = lua_interface->GetSpawn(state);
  1378. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1379. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1380. lua_interface->ResetFunctionStack(state);
  1381. // default of 1 quantity to add
  1382. if (quantity == 0)
  1383. quantity = 1;
  1384. if (spawn && spawn->IsPlayer()) {
  1385. Client* client = ((Player*)spawn)->GetClient();
  1386. if (client && item_id > 0) {
  1387. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1388. return 1;
  1389. }
  1390. }
  1391. lua_interface->SetBooleanValue(state, false);
  1392. return 1;
  1393. }
  1394. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1395. if (!lua_interface)
  1396. return 0;
  1397. Spawn* spawn = lua_interface->GetSpawn(state);
  1398. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1399. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1400. string location = lua_interface->GetStringValue(state, 4);
  1401. int16 item_count = lua_interface->GetInt16Value(state,5);
  1402. //devn00b: if we dont have a count, assume 1 item.
  1403. if(!item_count) {
  1404. item_count = 1;
  1405. }
  1406. lua_interface->ResetFunctionStack(state);
  1407. if (spawn && spawn->IsPlayer()) {
  1408. Client* client = ((Player*)spawn)->GetClient();
  1409. if (client && item_id > 0) {
  1410. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1411. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1412. else
  1413. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1414. if (send_messages) {
  1415. Item* item = master_item_list.GetItem(item_id);
  1416. if (item) {
  1417. if(item_count > 1) {
  1418. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1419. string popup_text1 = "You receive "+ item_count;
  1420. string popup_text2 = " " + item->name;
  1421. string popup_text = popup_text1 + popup_text2;
  1422. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1423. // return 1;
  1424. } else {
  1425. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1426. string popup_text = "You receive " + item->name;
  1427. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1428. }
  1429. }
  1430. }
  1431. return 1;
  1432. }
  1433. }
  1434. lua_interface->SetBooleanValue(state, false);
  1435. return 1;
  1436. }
  1437. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1438. Spawn* spawn = lua_interface->GetSpawn(state);
  1439. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1440. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1441. lua_interface->ResetFunctionStack(state);
  1442. // default of 1 to remove
  1443. if (quantity == 0)
  1444. quantity = 1;
  1445. Client* client;
  1446. Item* item;
  1447. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1448. if ((client = ((Player*)spawn)->GetClient())) {
  1449. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1450. if (client->RemoveItem(item, quantity)) {
  1451. lua_interface->SetBooleanValue(state, true);
  1452. return 1;
  1453. }
  1454. }
  1455. }
  1456. }
  1457. lua_interface->SetBooleanValue(state, false);
  1458. return 1;
  1459. }
  1460. int EQ2Emu_lua_HasItem(lua_State* state) {
  1461. Spawn* player = lua_interface->GetSpawn(state);
  1462. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1463. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1464. lua_interface->ResetFunctionStack(state);
  1465. if (player && player->IsPlayer()) {
  1466. bool hasItem = false;
  1467. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1468. if (!hasItem)
  1469. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1470. lua_interface->SetBooleanValue(state, hasItem);
  1471. return 1;
  1472. }
  1473. lua_interface->SetBooleanValue(state, false);
  1474. return 1;
  1475. }
  1476. int EQ2Emu_lua_Spawn(lua_State* state) {
  1477. if (!lua_interface)
  1478. return 0;
  1479. ZoneServer* zone = lua_interface->GetZone(state);
  1480. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1481. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1482. float x = lua_interface->GetFloatValue(state, 4);
  1483. float y = lua_interface->GetFloatValue(state, 5);
  1484. float z = lua_interface->GetFloatValue(state, 6);
  1485. float heading = lua_interface->GetFloatValue(state, 7);
  1486. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1487. Spawn* spawn = zone->GetSpawn(spawn_id);
  1488. if (!spawn)
  1489. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1490. else {
  1491. spawn->SetX(x);
  1492. spawn->SetZ(z);
  1493. spawn->SetY(y,true,true);
  1494. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1495. spawn->SetHeading(heading);
  1496. if (restricted_npc)
  1497. spawn->AddAllowAccessSpawn(spawn);
  1498. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1499. bool scriptActive = false;
  1500. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1501. scriptActive = true;
  1502. spawn->SetSpawnScript(string(spawn_script));
  1503. }
  1504. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1505. zone->AddSpawn(spawn);
  1506. if (scriptActive) {
  1507. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1508. }
  1509. lua_interface->ResetFunctionStack(state);
  1510. lua_interface->SetSpawnValue(state, spawn);
  1511. return 1;
  1512. }
  1513. }
  1514. else {
  1515. string output = "Invalid paramaters to LUA Spawn command: \n";
  1516. if (!zone)
  1517. output = output.append("\t").append("Missing zone reference. \n");
  1518. if (spawn_id == 0)
  1519. output = output.append("\t").append("Missing spawn_id.");
  1520. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1521. }
  1522. lua_interface->ResetFunctionStack(state);
  1523. return 0;
  1524. }
  1525. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1526. if (!lua_interface)
  1527. return 0;
  1528. ZoneServer* zone = lua_interface->GetZone(state);
  1529. lua_interface->ResetFunctionStack(state);
  1530. if (zone) {
  1531. lua_interface->SetStringValue(state, zone->GetZoneName());
  1532. return 1;
  1533. }
  1534. return 0;
  1535. }
  1536. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1537. if (!lua_interface)
  1538. return 0;
  1539. ZoneServer* zone = lua_interface->GetZone(state);
  1540. lua_interface->ResetFunctionStack(state);
  1541. if (zone) {
  1542. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1543. return 1;
  1544. }
  1545. return 0;
  1546. }
  1547. int EQ2Emu_lua_GetZone(lua_State* state) {
  1548. if (!lua_interface)
  1549. return 0;
  1550. int32 zone_id = lua_interface->GetInt32Value(state);
  1551. ZoneServer* zone = 0;
  1552. if (zone_id > 0)
  1553. zone = zone_list.Get(zone_id, true, false, false);
  1554. else {
  1555. string zone_name = lua_interface->GetStringValue(state);
  1556. if (zone_name.length() > 0) {
  1557. zone = zone_list.Get(zone_name.c_str(), true, false, false);
  1558. }
  1559. else {
  1560. Spawn* spawn = lua_interface->GetSpawn(state);
  1561. if (spawn)
  1562. zone = spawn->GetZone();
  1563. }
  1564. }
  1565. lua_interface->ResetFunctionStack(state);
  1566. if (zone) {
  1567. lua_interface->SetZoneValue(state, zone);
  1568. return 1;
  1569. }
  1570. return 0;
  1571. }
  1572. int EQ2Emu_lua_AddHate(lua_State* state) {
  1573. Spawn* entity = lua_interface->GetSpawn(state);
  1574. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1575. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1576. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1577. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1578. if(luaspell && luaspell->resisted) {
  1579. lua_interface->ResetFunctionStack(state);
  1580. return 0;
  1581. }
  1582. if (entity && entity->IsEntity() && amount != 0) {
  1583. if (luaspell && luaspell->caster) {
  1584. ZoneServer* zone = luaspell->caster->GetZone();
  1585. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1586. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1587. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1588. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1589. entity->CheckEncounterState((Entity*)spawn);
  1590. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1591. if (send_packet)
  1592. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1593. }
  1594. }
  1595. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1596. }
  1597. else if (npc && npc->IsNPC() && npc->GetZone()) {
  1598. entity->CheckEncounterState((Entity*)npc);
  1599. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1600. }
  1601. }
  1602. lua_interface->ResetFunctionStack(state);
  1603. return 0;
  1604. }
  1605. int EQ2Emu_lua_Zone(lua_State* state) {
  1606. if (!lua_interface)
  1607. return 0;
  1608. ZoneServer* zone = lua_interface->GetZone(state);
  1609. Spawn* player = lua_interface->GetSpawn(state, 2);
  1610. Client* client = 0;
  1611. if (player && player->IsPlayer())
  1612. client = ((Player*)player)->GetClient();
  1613. float x = lua_interface->GetFloatValue(state, 3);
  1614. float y = lua_interface->GetFloatValue(state, 4);
  1615. float z = lua_interface->GetFloatValue(state, 5);
  1616. float heading = lua_interface->GetFloatValue(state, 6);
  1617. if (zone && client) {
  1618. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1619. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1620. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1621. {
  1622. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1623. return 0;
  1624. }
  1625. if (x != 0 || y != 0 || z != 0) {
  1626. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1627. player->SetX(x);
  1628. player->SetY(y);
  1629. player->SetZ(z);
  1630. player->SetHeading(heading);
  1631. client->Zone(zone->GetZoneName(), false);
  1632. }
  1633. else
  1634. client->Zone(zone->GetZoneName());
  1635. }
  1636. else
  1637. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1638. lua_interface->ResetFunctionStack(state);
  1639. return 0;
  1640. }
  1641. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1642. if (!lua_interface)
  1643. return 0;
  1644. Spawn* spawn = lua_interface->GetSpawn(state);
  1645. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1646. if (spawn && spawn2)
  1647. spawn->AddAllowAccessSpawn(spawn2);
  1648. lua_interface->ResetFunctionStack(state);
  1649. return 0;
  1650. }
  1651. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1652. if (!lua_interface)
  1653. return 0;
  1654. Spawn* target = lua_interface->GetSpawn(state);
  1655. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1656. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1657. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1658. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1659. lua_interface->ResetFunctionStack(state);
  1660. if (!target) {
  1661. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1662. return 0;
  1663. }
  1664. if (!target->IsEntity()) {
  1665. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1666. return 0;
  1667. }
  1668. if (spell_id <= 0) {
  1669. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1670. return 0;
  1671. }
  1672. if (caster && !caster->IsEntity()) {
  1673. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1674. return 0;
  1675. }
  1676. if (spell_tier == 0)
  1677. spell_tier = 1;
  1678. if (!caster)
  1679. caster = target;
  1680. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1681. return 0;
  1682. }
  1683. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1684. if (!lua_interface)
  1685. return 0;
  1686. Spawn* target = lua_interface->GetSpawn(state);
  1687. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1688. if(!luaspell || luaspell->resisted) {
  1689. lua_interface->ResetFunctionStack(state);
  1690. lua_interface->SetBooleanValue(state, false);
  1691. return 1;
  1692. }
  1693. Spawn* caster = luaspell->caster;
  1694. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1695. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1696. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1697. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1698. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1699. //lua_interface->ResetFunctionStack(state);
  1700. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1701. vector<int16> faction_req;
  1702. vector<int16> race_req;
  1703. int32 class_req = 0;
  1704. int32 i = 0;
  1705. int8 f = 0;
  1706. int8 r = 0;
  1707. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1708. if (class_id < 100) {
  1709. class_req += pow(2.0, double(class_id - 1));
  1710. }
  1711. else if (class_id > 100 && class_id < 1000) {
  1712. race_req.push_back(class_id);
  1713. r++;
  1714. }
  1715. else {
  1716. faction_req.push_back(class_id);
  1717. f++;
  1718. }
  1719. i++;
  1720. }
  1721. lua_interface->ResetFunctionStack(state);
  1722. if (caster && caster->IsEntity()) {
  1723. bool race_match = false;
  1724. bool success = false;
  1725. luaspell->resisted = false;
  1726. if (luaspell->targets.size() > 0) {
  1727. ZoneServer* zone = luaspell->caster->GetZone();
  1728. Spawn* target = 0;
  1729. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1730. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1731. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1732. if (race_req.size() > 0) {
  1733. for (int8 i = 0; i < race_req.size(); i++) {
  1734. if(race_req[i] == target->GetRace() ||
  1735. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1736. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1737. race_match = true;
  1738. }
  1739. }
  1740. }
  1741. else
  1742. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1743. if (race_match == true) {
  1744. float distance = caster->GetDistance(target, true);
  1745. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1746. }
  1747. }
  1748. }
  1749. success = true;
  1750. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1751. }
  1752. else if (target) {
  1753. //check class and race/faction here
  1754. if (race_req.size() > 0) {
  1755. for (int8 i = 0; i < race_req.size(); i++) {
  1756. if(race_req[i] == target->GetRace() ||
  1757. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1758. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1759. race_match = true;
  1760. }
  1761. }
  1762. }
  1763. else
  1764. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1765. if (race_match == true) {
  1766. float distance = caster->GetDistance(target, true);
  1767. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1768. success = true;
  1769. }
  1770. }
  1771. lua_interface->SetBooleanValue(state, luaspell->has_damaged);
  1772. if (success) {
  1773. Spell* spell = luaspell->spell;
  1774. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1775. ((Player*)caster)->InCombat(true);
  1776. if (caster->GetZone())
  1777. caster->GetZone()->TriggerCharSheetTimer();
  1778. }
  1779. }
  1780. }
  1781. else {
  1782. lua_interface->SetBooleanValue(state, false);
  1783. }
  1784. return 1;
  1785. }
  1786. int EQ2Emu_lua_SpellDamageExt(lua_State* state) {
  1787. if (!lua_interface)
  1788. return 0;
  1789. Spawn* target = lua_interface->GetSpawn(state);
  1790. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1791. if(!luaspell || luaspell->resisted) {
  1792. lua_interface->ResetFunctionStack(state);
  1793. lua_interface->SetBooleanValue(state, false);
  1794. return 1;
  1795. }
  1796. Spawn* caster = luaspell->caster;
  1797. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1798. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1799. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1800. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1801. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1802. int32 override_packet_type = lua_interface->GetInt32Value(state, 7);
  1803. bool take_power = lua_interface->GetInt32Value(state, 8) == 1;
  1804. //lua_interface->ResetFunctionStack(state);
  1805. int32 class_id = lua_interface->GetInt32Value(state, 9);
  1806. vector<int16> faction_req;
  1807. vector<int16> race_req;
  1808. int32 class_req = 0;
  1809. int32 i = 0;
  1810. int8 f = 0;
  1811. int8 r = 0;
  1812. while ((class_id = lua_interface->GetInt32Value(state, 9 + i))) {
  1813. if (class_id < 100) {
  1814. class_req += pow(2.0, double(class_id - 1));
  1815. }
  1816. else if (class_id > 100 && class_id < 1000) {
  1817. race_req.push_back(class_id);
  1818. r++;
  1819. }
  1820. else {
  1821. faction_req.push_back(class_id);
  1822. f++;
  1823. }
  1824. i++;
  1825. }
  1826. lua_interface->ResetFunctionStack(state);
  1827. if (caster && caster->IsEntity()) {
  1828. bool race_match = false;
  1829. bool success = false;
  1830. luaspell->resisted = false;
  1831. if (luaspell->targets.size() > 0) {
  1832. ZoneServer* zone = luaspell->caster->GetZone();
  1833. Spawn* target = 0;
  1834. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1835. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1836. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1837. if (race_req.size() > 0) {
  1838. for (int8 i = 0; i < race_req.size(); i++) {
  1839. if(race_req[i] == target->GetRace() ||
  1840. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1841. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1842. race_match = true;
  1843. }
  1844. }
  1845. }
  1846. else
  1847. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1848. if (race_match == true) {
  1849. float distance = caster->GetDistance(target, true);
  1850. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power);
  1851. }
  1852. }
  1853. }
  1854. success = true;
  1855. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1856. }
  1857. else if (target) {
  1858. //check class and race/faction here
  1859. if (race_req.size() > 0) {
  1860. for (int8 i = 0; i < race_req.size(); i++) {
  1861. if(race_req[i] == target->GetRace() ||
  1862. race_req[i] == race_types_list.GetRaceType(target->GetModelType()) ||
  1863. race_req[i] == race_types_list.GetRaceBaseType(target->GetModelType())) {
  1864. race_match = true;
  1865. }
  1866. }
  1867. }
  1868. else
  1869. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1870. if (race_match == true) {
  1871. float distance = caster->GetDistance(target, true);
  1872. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs, override_packet_type, take_power))
  1873. success = true;
  1874. }
  1875. }
  1876. lua_interface->SetBooleanValue(state, luaspell->has_damaged);
  1877. if (success) {
  1878. Spell* spell = luaspell->spell;
  1879. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1880. ((Player*)caster)->InCombat(true);
  1881. if (caster->GetZone())
  1882. caster->GetZone()->TriggerCharSheetTimer();
  1883. }
  1884. }
  1885. }
  1886. else {
  1887. lua_interface->SetBooleanValue(state, false);
  1888. }
  1889. return 1;
  1890. }
  1891. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1892. if (!lua_interface)
  1893. return 0;
  1894. Spawn* spawn = lua_interface->GetSpawn(state);
  1895. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1896. lua_interface->ResetFunctionStack(state);
  1897. if (spawn && value != 0) {
  1898. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1899. spawn->SetPower(spawn->GetTotalPower());
  1900. else
  1901. spawn->SetPower(spawn->GetPower() + value);
  1902. }
  1903. return 0;
  1904. }
  1905. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1906. if (!lua_interface)
  1907. return 0;
  1908. Spawn* spawn = lua_interface->GetSpawn(state);
  1909. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1910. lua_interface->ResetFunctionStack(state);
  1911. if (spawn && value != 0) {
  1912. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1913. spawn->SetHP(spawn->GetTotalHP());
  1914. else
  1915. spawn->SetHP(spawn->GetHP() + value);
  1916. }
  1917. return 0;
  1918. }
  1919. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1920. if (!lua_interface)
  1921. return 0;
  1922. Spawn* spawn = lua_interface->GetSpawn(state);
  1923. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1924. lua_interface->ResetFunctionStack(state);
  1925. if (spawn && value != 0) {
  1926. spawn->SetPower(spawn->GetPower() + value);
  1927. if (value > spawn->GetTotalHPBase())
  1928. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1929. }
  1930. return 0;
  1931. }
  1932. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1933. if (!lua_interface)
  1934. return 0;
  1935. Spawn* spawn = lua_interface->GetSpawn(state);
  1936. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1937. lua_interface->ResetFunctionStack(state);
  1938. if (spawn && value != 0) {
  1939. spawn->SetHP(spawn->GetHP() + value);
  1940. if (value > spawn->GetTotalHPBase())
  1941. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1942. }
  1943. return 0;
  1944. }
  1945. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1946. if (!lua_interface)
  1947. return 0;
  1948. Spawn* spawn = lua_interface->GetSpawn(state);
  1949. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1950. lua_interface->ResetFunctionStack(state);
  1951. if (spawn) {
  1952. spawn->SetHP(value);
  1953. if (value > spawn->GetTotalHPBase())
  1954. spawn->SetTotalHP(value);
  1955. }
  1956. return 0;
  1957. }
  1958. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1959. if (!lua_interface)
  1960. return 0;
  1961. Spawn* spawn = lua_interface->GetSpawn(state);
  1962. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1963. float value = lua_interface->GetFloatValue(state, 2);
  1964. lua_interface->ResetFunctionStack(state);
  1965. if (spawn && spawn->IsEntity() && value > 0)
  1966. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1967. if (spawn && spawn->IsPlayer())
  1968. ((Player*)spawn)->SetCharSheetChanged(true);
  1969. return 0;
  1970. }
  1971. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1972. if (!lua_interface)
  1973. return 0;
  1974. Spawn* spawn = lua_interface->GetSpawn(state);
  1975. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1976. lua_interface->ResetFunctionStack(state);
  1977. if (spawn && spawn->IsEntity() && value > 0)
  1978. ((Entity*)spawn)->SetTotalHPBase(value);
  1979. return 0;
  1980. }
  1981. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1982. if (!lua_interface)
  1983. return 0;
  1984. Spawn* spawn = lua_interface->GetSpawn(state);
  1985. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1986. lua_interface->ResetFunctionStack(state);
  1987. if (spawn && value > 0) {
  1988. spawn->SetPower(value);
  1989. if (value > spawn->GetTotalPowerBase())
  1990. spawn->SetTotalPower(value);
  1991. }
  1992. return 0;
  1993. }
  1994. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1995. if (!lua_interface)
  1996. return 0;
  1997. Spawn* spawn = lua_interface->GetSpawn(state);
  1998. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1999. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2000. lua_interface->ResetFunctionStack(state);
  2001. if (spawn && spawn->IsEntity() && value > 0)
  2002. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  2003. return 0;
  2004. }
  2005. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  2006. if (!lua_interface)
  2007. return 0;
  2008. Spawn* spawn = lua_interface->GetSpawn(state);
  2009. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2010. lua_interface->ResetFunctionStack(state);
  2011. if (spawn && spawn->IsEntity() && value > 0)
  2012. ((Entity*)spawn)->SetTotalPowerBase(value);
  2013. return 0;
  2014. }
  2015. int EQ2Emu_lua_SetPosition(lua_State* state) {
  2016. if (!lua_interface)
  2017. return 0;
  2018. Spawn* spawn = lua_interface->GetSpawn(state);
  2019. float x = lua_interface->GetFloatValue(state, 2);
  2020. float y = lua_interface->GetFloatValue(state, 3);
  2021. float z = lua_interface->GetFloatValue(state, 4);
  2022. float heading = lua_interface->GetFloatValue(state, 5);
  2023. lua_interface->ResetFunctionStack(state);
  2024. if (spawn) {
  2025. spawn->SetX(x);
  2026. spawn->SetY(y);
  2027. spawn->SetZ(z);
  2028. if (heading != 0)
  2029. spawn->SetHeading(heading);
  2030. spawn->SetSpawnOrigX(spawn->GetX());
  2031. spawn->SetSpawnOrigY(spawn->GetY());
  2032. spawn->SetSpawnOrigZ(spawn->GetZ());
  2033. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  2034. if (spawn->IsPlayer()) {
  2035. Client* client = ((Player*)spawn)->GetClient();
  2036. if (client) {
  2037. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  2038. client->QueuePacket(packet);
  2039. }
  2040. }
  2041. }
  2042. return 0;
  2043. }
  2044. int EQ2Emu_lua_SetHeading(lua_State* state) {
  2045. if (!lua_interface)
  2046. return 0;
  2047. Spawn* spawn = lua_interface->GetSpawn(state);
  2048. float value = lua_interface->GetFloatValue(state, 2);
  2049. lua_interface->ResetFunctionStack(state);
  2050. if (spawn) {
  2051. spawn->SetHeading(value);
  2052. if (spawn->IsPlayer()) {
  2053. Client* client = ((Player*)spawn)->GetClient();
  2054. if (client) {
  2055. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  2056. client->QueuePacket(packet);
  2057. }
  2058. }
  2059. }
  2060. return 0;
  2061. }
  2062. int EQ2Emu_lua_SetModelType(lua_State* state) {
  2063. if (!lua_interface)
  2064. return 0;
  2065. Spawn* spawn = lua_interface->GetSpawn(state);
  2066. int16 value = lua_interface->GetInt16Value(state, 2);
  2067. lua_interface->ResetFunctionStack(state);
  2068. if (spawn)
  2069. spawn->SetModelType(value);
  2070. return 0;
  2071. }
  2072. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  2073. if (!lua_interface)
  2074. return 0;
  2075. Spawn* spawn = lua_interface->GetSpawn(state);
  2076. int8 value = lua_interface->GetInt8Value(state, 2);
  2077. lua_interface->ResetFunctionStack(state);
  2078. if (spawn) {
  2079. if (spawn->IsPlayer())
  2080. ((Player*)spawn)->SetPlayerAdventureClass(value);
  2081. else
  2082. spawn->SetAdventureClass(value);
  2083. }
  2084. return 0;
  2085. }
  2086. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  2087. if (!lua_interface)
  2088. return 0;
  2089. Spawn* spawn = lua_interface->GetSpawn(state);
  2090. int8 value = lua_interface->GetInt8Value(state, 2);
  2091. lua_interface->ResetFunctionStack(state);
  2092. if (spawn) {
  2093. spawn->SetTradeskillClass(value);
  2094. if (spawn->IsEntity()) {
  2095. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  2096. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  2097. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  2098. }
  2099. if (spawn->IsPlayer())
  2100. ((Player*)spawn)->SetCharSheetChanged(true);
  2101. }
  2102. return 0;
  2103. }
  2104. int EQ2Emu_lua_SetMount(lua_State* state) {
  2105. if (!lua_interface)
  2106. return 0;
  2107. Spawn* spawn = lua_interface->GetSpawn(state);
  2108. int16 value = lua_interface->GetInt16Value(state, 2);
  2109. if (spawn && spawn->IsEntity()) {
  2110. ((Entity*)spawn)->SetMount(value);
  2111. EQ2_Color color;
  2112. color.red = 255;
  2113. color.green = 255;
  2114. color.blue = 255;
  2115. ((Entity*)spawn)->SetMountColor(&color);
  2116. ((Entity*)spawn)->SetMountSaddleColor(&color);
  2117. }
  2118. return 0;
  2119. }
  2120. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  2121. if (!lua_interface)
  2122. return 0;
  2123. Spawn* spawn = lua_interface->GetSpawn(state);
  2124. EQ2_Color mount_color;
  2125. EQ2_Color saddle_color;
  2126. mount_color.red = lua_interface->GetInt8Value(state, 2);
  2127. mount_color.green = lua_interface->GetInt8Value(state, 3);
  2128. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  2129. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  2130. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  2131. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  2132. if (spawn && spawn->IsEntity()) {
  2133. ((Entity*)spawn)->SetMountColor(&mount_color);
  2134. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  2135. }
  2136. return 0;
  2137. }
  2138. int EQ2Emu_lua_GetMount(lua_State* state) {
  2139. if (!lua_interface)
  2140. return 0;
  2141. Spawn* spawn = lua_interface->GetSpawn(state);
  2142. if (spawn && spawn->IsEntity()) {
  2143. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  2144. return 1;
  2145. }
  2146. return 0;
  2147. }
  2148. int EQ2Emu_lua_GetRace(lua_State* state) {
  2149. if (!lua_interface)
  2150. return 0;
  2151. Spawn* spawn = lua_interface->GetSpawn(state);
  2152. if (spawn)
  2153. {
  2154. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2155. lua_interface->SetInt32Value(state, spawn->GetRace());
  2156. return 1;
  2157. }
  2158. return 0;
  2159. }
  2160. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2161. if (!lua_interface)
  2162. return 0;
  2163. Spawn* spawn = lua_interface->GetSpawn(state);
  2164. if (spawn) {
  2165. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2166. return 1;
  2167. }
  2168. return 0;
  2169. }
  2170. int EQ2Emu_lua_GetClass(lua_State* state) {
  2171. Spawn* spawn = lua_interface->GetSpawn(state);
  2172. if (spawn) {
  2173. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2174. return 1;
  2175. }
  2176. return 0;
  2177. }
  2178. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2179. Spawn* spawn = lua_interface->GetSpawn(state);
  2180. if (spawn) {
  2181. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2182. return 1;
  2183. }
  2184. return 0;
  2185. }
  2186. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2187. if (!lua_interface)
  2188. return 0;
  2189. Spawn* spawn = lua_interface->GetSpawn(state);
  2190. float value = lua_interface->GetFloatValue(state, 2);
  2191. lua_interface->ResetFunctionStack(state);
  2192. if (spawn) {
  2193. spawn->SetSpeed(value);
  2194. if(spawn->IsEntity())
  2195. ((Entity*)spawn)->SetSpeed(value);
  2196. if (spawn->IsPlayer()) {
  2197. Client* client = ((Player*)spawn)->GetClient();
  2198. if (client) {
  2199. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2200. if (packet) {
  2201. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2202. packet->setDataByName("speed", value);
  2203. packet->setDataByName("size", 0.51);
  2204. EQ2Packet* app = packet->serialize();
  2205. client->QueuePacket(app);
  2206. safe_delete(packet);
  2207. }
  2208. }
  2209. }
  2210. }
  2211. return 0;
  2212. }
  2213. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2214. if (!lua_interface)
  2215. return 0;
  2216. Spawn* spawn = lua_interface->GetSpawn(state);
  2217. const int16 type = lua_interface->GetInt16Value(state, 2);
  2218. const float value = lua_interface->GetFloatValue(state, 3);
  2219. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2220. if(!luaspell || luaspell->resisted) {
  2221. lua_interface->ResetFunctionStack(state);
  2222. return 0;
  2223. }
  2224. int64 class_req = 0;
  2225. int32 class_id = 0;
  2226. vector<int16> faction_req;
  2227. vector<int16> race_req;
  2228. int32 i = 0;
  2229. int8 f = 0;
  2230. int8 r = 0;
  2231. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2232. if (class_id < 100) {
  2233. class_req += pow(2.0, double(class_id - 1));
  2234. }
  2235. else if (class_id > 100 && class_id < 1000) {
  2236. race_req.push_back(class_id);
  2237. r++;
  2238. }
  2239. else {
  2240. faction_req.push_back(class_id);
  2241. f++;
  2242. }
  2243. i++;
  2244. }
  2245. if (value != 0 && type >= 0) {
  2246. if (luaspell && luaspell->spell && luaspell->caster) {
  2247. ZoneServer* zone = luaspell->caster->GetZone();
  2248. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2249. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2250. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2251. if (target) {
  2252. if (target->IsPlayer()) {
  2253. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2254. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2255. if (((Player*)target)->GetGroupMemberInfo())
  2256. ((Player*)target)->UpdateGroupMemberInfo();
  2257. ((Player*)target)->SetCharSheetChanged(true);
  2258. }
  2259. else if (target->IsNPC())
  2260. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2261. else
  2262. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2263. }
  2264. }
  2265. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2266. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2267. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2268. }
  2269. else if (spawn && spawn->IsEntity()) {
  2270. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2271. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2272. if (spawn->IsPlayer())
  2273. ((Player*)spawn)->SetCharSheetChanged(true);
  2274. }
  2275. else
  2276. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2277. }
  2278. else
  2279. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2280. return 0;
  2281. }
  2282. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2283. if (!lua_interface)
  2284. return 0;
  2285. Spawn* spawn = lua_interface->GetSpawn(state);
  2286. int16 type = lua_interface->GetInt16Value(state, 2);
  2287. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2288. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2289. if (!spawn) {
  2290. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2291. return 0;
  2292. }
  2293. if (!spawn->IsEntity()) {
  2294. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2295. return 0;
  2296. }
  2297. if (value == 0) {
  2298. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2299. return 0;
  2300. }
  2301. if (!luaspell || !luaspell->spell) {
  2302. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2303. return 0;
  2304. }
  2305. if(luaspell->resisted) {
  2306. lua_interface->ResetFunctionStack(state);
  2307. return 0;
  2308. }
  2309. int32 class_req = 0;
  2310. vector<int16> faction_req;
  2311. vector<int16> race_req;
  2312. int32 class_id = 0;
  2313. int32 i = 0;
  2314. int8 f = 0;
  2315. int8 r = 0;
  2316. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2317. if (class_id < 100) {
  2318. class_req += pow(2.0, double(class_id - 1));
  2319. }
  2320. else if (class_id > 100 && class_id < 1000) {
  2321. race_req.push_back(class_id);
  2322. r++;
  2323. }
  2324. else {
  2325. faction_req.push_back(class_id);
  2326. f++;
  2327. }
  2328. i++;
  2329. }
  2330. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2331. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2332. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2333. if (spawn->IsPlayer())
  2334. ((Player*)spawn)->SetCharSheetChanged(true);
  2335. return 0;
  2336. }
  2337. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2338. if (!lua_interface)
  2339. return 0;
  2340. Spawn* spawn = lua_interface->GetSpawn(state);
  2341. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2342. if (!spawn) {
  2343. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2344. return 0;
  2345. }
  2346. if (!spawn->IsEntity()) {
  2347. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2348. return 0;
  2349. }
  2350. if (!luaspell || !luaspell->spell) {
  2351. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2352. return 0;
  2353. }
  2354. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2355. if (spawn->IsPlayer())
  2356. ((Player*)spawn)->SetCharSheetChanged(true);
  2357. return 0;
  2358. }
  2359. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2360. if (!lua_interface)
  2361. return 0;
  2362. Spawn* spawn = lua_interface->GetSpawn(state);
  2363. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2364. if (luaspell && luaspell->spell) {
  2365. ZoneServer* zone = nullptr;
  2366. if (luaspell->caster != nullptr)
  2367. zone = luaspell->caster->GetZone();
  2368. if(!zone) {
  2369. zone = spawn->GetZone(); // workaround to try to establish a zone to find the targets and remove the spells
  2370. }
  2371. Spawn* target = 0;
  2372. if(zone) {
  2373. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2374. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2375. target = zone->GetSpawnByID(luaspell->targets[i]);
  2376. if (target && target->IsEntity()) {
  2377. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2378. if (target->IsPlayer())
  2379. ((Player*)target)->SetCharSheetChanged(true);
  2380. }
  2381. }
  2382. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2383. }
  2384. else {
  2385. 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());
  2386. }
  2387. }
  2388. else if (spawn && spawn->IsEntity()) {
  2389. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2390. if (spawn->IsPlayer())
  2391. ((Player*)spawn)->SetCharSheetChanged(true);
  2392. }
  2393. return 0;
  2394. }
  2395. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2396. if (!lua_interface)
  2397. return 0;
  2398. Spawn* spawn = lua_interface->GetSpawn(state);
  2399. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2400. float value = lua_interface->GetFloatValue(state, 3);
  2401. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2402. if (value != 0) {
  2403. int32 spell_id = 0;
  2404. if (luaspell && luaspell->spell && luaspell->caster) {
  2405. if(luaspell->resisted) {
  2406. lua_interface->ResetFunctionStack(state);
  2407. return 0;
  2408. }
  2409. spell_id = luaspell->spell->GetSpellID();
  2410. ZoneServer* zone = luaspell->caster->GetZone();
  2411. Spawn* target = 0;
  2412. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2413. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2414. target = zone->GetSpawnByID(luaspell->targets[i]);
  2415. if (target && target->Alive()) {
  2416. if (target->IsPlayer()) {
  2417. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2418. Client* client = ((Player*)target)->GetClient();
  2419. if (client) {
  2420. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2421. if (packet)
  2422. client->QueuePacket(packet);
  2423. }
  2424. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2425. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2426. }
  2427. else if (target->IsNPC()) {
  2428. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2429. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2430. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2431. }
  2432. else
  2433. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2434. }
  2435. }
  2436. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2437. }
  2438. else if (spawn) {
  2439. if (spawn->IsPlayer()) {
  2440. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2441. Client* client = ((Player*)spawn)->GetClient();
  2442. if (client) {
  2443. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2444. if (packet)
  2445. client->QueuePacket(packet);
  2446. }
  2447. }
  2448. else if (spawn->IsNPC())
  2449. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2450. else
  2451. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2452. }
  2453. }
  2454. else
  2455. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2456. return 0;
  2457. }
  2458. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2459. if (!lua_interface)
  2460. return 0;
  2461. Spawn* spawn = lua_interface->GetSpawn(state);
  2462. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2463. if (spawn && spawn->IsPlayer()) {
  2464. int32 spell_id = 0;
  2465. if (luaspell && luaspell->spell && luaspell->caster) {
  2466. if(luaspell->resisted) {
  2467. lua_interface->ResetFunctionStack(state);
  2468. return 0;
  2469. }
  2470. spell_id = luaspell->spell->GetSpellID();
  2471. ZoneServer* zone = luaspell->caster->GetZone();
  2472. Spawn* target = 0;
  2473. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2474. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2475. target = zone->GetSpawnByID(luaspell->targets[i]);
  2476. if (target) {
  2477. if (target->IsPlayer()) {
  2478. ((Player*)target)->RemoveSkillBonus(spell_id);
  2479. Client* client = ((Player*)target)->GetClient();
  2480. if (client) {
  2481. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2482. if (packet)
  2483. client->QueuePacket(packet);
  2484. }
  2485. }
  2486. else if (target->IsNPC())
  2487. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2488. else
  2489. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2490. }
  2491. }
  2492. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2493. }
  2494. else if (spawn) {
  2495. if (spawn->IsPlayer()) {
  2496. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2497. Client* client = ((Player*)spawn)->GetClient();
  2498. if (client) {
  2499. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2500. if (packet)
  2501. client->QueuePacket(packet);
  2502. }
  2503. }
  2504. else if (spawn->IsNPC())
  2505. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2506. else
  2507. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2508. }
  2509. }
  2510. return 0;
  2511. }
  2512. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2513. if (!lua_interface)
  2514. return 0;
  2515. Spawn* spawn = lua_interface->GetSpawn(state);
  2516. int8 type = lua_interface->GetInt32Value(state, 2);
  2517. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2518. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2519. if(luaspell && luaspell->resisted) {
  2520. lua_interface->ResetFunctionStack(state);
  2521. return 0;
  2522. }
  2523. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2524. ZoneServer* zone = luaspell->caster->GetZone();
  2525. Spawn* target = 0;
  2526. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2527. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2528. target = zone->GetSpawnByID(luaspell->targets[i]);
  2529. if (target && target->IsEntity()) {
  2530. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2531. ((Entity*)target)->AddMezSpell(luaspell);
  2532. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2533. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2534. if (target->IsNPC())
  2535. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2536. }
  2537. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2538. ((Entity*)target)->AddStifleSpell(luaspell);
  2539. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2540. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2541. if (target->IsNPC())
  2542. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2543. }
  2544. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2545. ((Entity*)target)->AddDazeSpell(luaspell);
  2546. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2547. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2548. if (target->IsNPC())
  2549. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2550. }
  2551. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2552. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2553. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2554. ((Entity*)target)->AddStunSpell(luaspell);
  2555. if (target->IsNPC())
  2556. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2557. }
  2558. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2559. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2560. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2561. ((Entity*)target)->AddRootSpell(luaspell);
  2562. if (target->IsNPC())
  2563. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2564. }
  2565. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2566. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2567. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2568. ((Entity*)target)->AddFearSpell(luaspell);
  2569. if (target->IsNPC())
  2570. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2571. }
  2572. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2573. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2574. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2575. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2576. }
  2577. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2578. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2579. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2580. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2581. }
  2582. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2583. ((Entity*)target)->AddSnareSpell(luaspell);
  2584. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2585. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2586. if (target->IsNPC())
  2587. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2588. }
  2589. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2590. ((Entity*)target)->AddFlightSpell(luaspell);
  2591. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2592. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2593. }
  2594. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2595. ((Entity*)target)->AddGlideSpell(luaspell);
  2596. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2597. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2598. }
  2599. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2600. ((Entity*)target)->AddSafefallSpell(luaspell);
  2601. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2602. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2603. }
  2604. else
  2605. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2606. }
  2607. else
  2608. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2609. }
  2610. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2611. }
  2612. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2613. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2614. ((Entity*)spawn)->AddMezSpell(luaspell);
  2615. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2616. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2617. }
  2618. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2619. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2620. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2621. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2622. }
  2623. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2624. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2625. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2626. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2627. }
  2628. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2629. ((Entity*)spawn)->AddStunSpell(luaspell);
  2630. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2631. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2632. }
  2633. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2634. ((Entity*)spawn)->AddRootSpell(luaspell);
  2635. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2636. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2637. }
  2638. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2639. ((Entity*)spawn)->AddFearSpell(luaspell);
  2640. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2641. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2642. }
  2643. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2644. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2645. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2646. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2647. }
  2648. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2649. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2650. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2651. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2652. }
  2653. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2654. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2655. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2656. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2657. }
  2658. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2659. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2660. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2661. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2662. }
  2663. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2664. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2665. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2666. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2667. }
  2668. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2669. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2670. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2671. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2672. }
  2673. else
  2674. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2675. }
  2676. else
  2677. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2678. return 0;
  2679. }
  2680. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2681. if (!lua_interface)
  2682. return 0;
  2683. Spawn* spawn = lua_interface->GetSpawn(state);
  2684. int8 type = lua_interface->GetInt8Value(state, 2);
  2685. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2686. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2687. if (spawn && spawn->IsEntity()) {
  2688. if (!only_remove_spawn && luaspell && luaspell->spell && luaspell->caster) {
  2689. ZoneServer* zone = luaspell->caster->GetZone();
  2690. Spawn* target = 0;
  2691. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2692. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2693. target = zone->GetSpawnByID(luaspell->targets[i]);
  2694. if (target) {
  2695. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2696. ((Entity*)target)->RemoveMezSpell(luaspell);
  2697. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2698. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2699. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2700. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2701. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2702. ((Entity*)target)->RemoveStunSpell(luaspell);
  2703. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2704. ((Entity*)target)->RemoveRootSpell(luaspell);
  2705. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2706. ((Entity*)target)->RemoveFearSpell(luaspell);
  2707. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2708. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2709. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2710. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2711. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2712. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2713. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2714. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2715. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2716. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2717. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2718. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2719. else
  2720. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2721. }
  2722. }
  2723. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2724. }
  2725. else if (only_remove_spawn) {
  2726. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2727. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2728. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2729. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2730. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2731. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2732. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2733. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2734. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2735. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2736. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2737. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2738. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2739. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2740. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2741. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2742. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2743. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2744. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2745. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2746. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2747. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2748. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2749. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2750. else
  2751. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2752. }
  2753. }
  2754. return 0;
  2755. }
  2756. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2757. if (!lua_interface)
  2758. return 0;
  2759. Spawn* spawn = lua_interface->GetSpawn(state);
  2760. int8 type = lua_interface->GetInt8Value(state, 2);
  2761. bool hasEffect = false;
  2762. if (!spawn)
  2763. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2764. else if (!spawn->IsEntity())
  2765. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2766. else if (type < CONTROL_MAX_EFFECTS)
  2767. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2768. else
  2769. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2770. lua_interface->SetBooleanValue(state, hasEffect);
  2771. return 1;
  2772. }
  2773. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2774. if (!lua_interface)
  2775. return 0;
  2776. Spawn* spawn = lua_interface->GetSpawn(state);
  2777. float distance = 0.0f;
  2778. if (!spawn)
  2779. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2780. else if (!spawn->IsNPC())
  2781. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2782. else
  2783. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2784. lua_interface->SetFloatValue(state, distance);
  2785. return 1;
  2786. }
  2787. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2788. if (!lua_interface)
  2789. return 0;
  2790. Spawn* spawn = lua_interface->GetSpawn(state);
  2791. float distance = 0.0f;
  2792. if (!spawn)
  2793. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2794. else if (!spawn->IsNPC())
  2795. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2796. else
  2797. distance = ((NPC*)spawn)->GetAggroRadius();
  2798. lua_interface->SetFloatValue(state, distance);
  2799. return 1;
  2800. }
  2801. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2802. if (!lua_interface)
  2803. return 0;
  2804. Spawn* spawn = lua_interface->GetSpawn(state);
  2805. float distance = lua_interface->GetFloatValue(state, 2);
  2806. bool override = lua_interface->GetBooleanValue(state, 3);
  2807. bool result = false;
  2808. lua_interface->ResetFunctionStack(state);
  2809. if (!spawn)
  2810. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2811. else if (!spawn->IsNPC())
  2812. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2813. else
  2814. {
  2815. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2816. result = true;
  2817. }
  2818. lua_interface->SetBooleanValue(state, result);
  2819. return 1;
  2820. }
  2821. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2822. if (!lua_interface)
  2823. return 0;
  2824. Spawn* spawn = lua_interface->GetSpawn(state);
  2825. int16 value = lua_interface->GetInt16Value(state, 2);
  2826. if (spawn && spawn->IsEntity()) {
  2827. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2828. if (spawn->IsPlayer())
  2829. ((Player*)spawn)->SetCharSheetChanged(true);
  2830. }
  2831. return 0;
  2832. }
  2833. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2834. if (!lua_interface)
  2835. return 0;
  2836. Spawn* spawn = lua_interface->GetSpawn(state);
  2837. int16 value = lua_interface->GetInt16Value(state, 2);
  2838. if (spawn && spawn->IsEntity()) {
  2839. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2840. if (spawn->IsPlayer())
  2841. ((Player*)spawn)->SetCharSheetChanged(true);
  2842. }
  2843. return 0;
  2844. }
  2845. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2846. if (!lua_interface)
  2847. return 0;
  2848. Spawn* spawn = lua_interface->GetSpawn(state);
  2849. int16 value = lua_interface->GetInt16Value(state, 2);
  2850. if (spawn && spawn->IsEntity()) {
  2851. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2852. if (spawn->IsPlayer())
  2853. ((Player*)spawn)->SetCharSheetChanged(true);
  2854. }
  2855. return 0;
  2856. }
  2857. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2858. if (!lua_interface)
  2859. return 0;
  2860. Spawn* spawn = lua_interface->GetSpawn(state);
  2861. int16 value = lua_interface->GetInt16Value(state, 2);
  2862. if (spawn && spawn->IsEntity()) {
  2863. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2864. if (spawn->IsPlayer())
  2865. ((Player*)spawn)->SetCharSheetChanged(true);
  2866. }
  2867. return 0;
  2868. }
  2869. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2870. if (!lua_interface)
  2871. return 0;
  2872. Spawn* spawn = lua_interface->GetSpawn(state);
  2873. int16 value = lua_interface->GetInt16Value(state, 2);
  2874. if (spawn && spawn->IsEntity()) {
  2875. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2876. if (spawn->IsPlayer())
  2877. ((Player*)spawn)->SetCharSheetChanged(true);
  2878. }
  2879. return 0;
  2880. }
  2881. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2882. if (!lua_interface)
  2883. return 0;
  2884. Spawn* spawn = lua_interface->GetSpawn(state);
  2885. int8 value = lua_interface->GetInt8Value(state, 2);
  2886. if (spawn && spawn->IsEntity()) {
  2887. ((Entity*)spawn)->SetDeity(value);
  2888. if (spawn->IsPlayer())
  2889. ((Player*)spawn)->SetCharSheetChanged(true);
  2890. }
  2891. lua_interface->ResetFunctionStack(state);
  2892. return 0;
  2893. }
  2894. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2895. if (!lua_interface)
  2896. return 0;
  2897. Spawn* spawn = lua_interface->GetSpawn(state);
  2898. if (spawn && spawn->IsEntity()) {
  2899. int8 deity = ((Entity*)spawn)->GetDeity();
  2900. lua_interface->SetInt32Value(state, deity);
  2901. return 1;
  2902. }
  2903. return 0;
  2904. }
  2905. int EQ2Emu_lua_SetInt(lua_State* state) {
  2906. if (!lua_interface)
  2907. return 0;
  2908. Spawn* spawn = lua_interface->GetSpawn(state);
  2909. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2910. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2911. if (spawn && spawn->IsEntity()) {
  2912. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_INT, value);
  2913. if (spawn->IsPlayer())
  2914. ((Player*)spawn)->SetCharSheetChanged(true);
  2915. }
  2916. return 0;
  2917. }
  2918. int EQ2Emu_lua_SetWis(lua_State* state) {
  2919. if (!lua_interface)
  2920. return 0;
  2921. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2922. Spawn* spawn = lua_interface->GetSpawn(state);
  2923. float value = lua_interface->GetFloatValue(state, 2);
  2924. if (spawn && spawn->IsEntity()) {
  2925. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_WIS, value);
  2926. if (spawn->IsPlayer())
  2927. ((Player*)spawn)->SetCharSheetChanged(true);
  2928. }
  2929. return 0;
  2930. }
  2931. int EQ2Emu_lua_SetSta(lua_State* state) {
  2932. if (!lua_interface)
  2933. return 0;
  2934. Spawn* spawn = lua_interface->GetSpawn(state);
  2935. float value = lua_interface->GetFloatValue(state, 2);
  2936. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2937. if (spawn && spawn->IsEntity()) {
  2938. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STA, value);
  2939. if (spawn->IsPlayer())
  2940. ((Player*)spawn)->SetCharSheetChanged(true);
  2941. }
  2942. return 0;
  2943. }
  2944. int EQ2Emu_lua_SetStr(lua_State* state) {
  2945. if (!lua_interface)
  2946. return 0;
  2947. Spawn* spawn = lua_interface->GetSpawn(state);
  2948. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2949. float value = lua_interface->GetFloatValue(state, 2);
  2950. if (spawn && spawn->IsEntity()) {
  2951. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_STR, value);
  2952. if (spawn->IsPlayer())
  2953. ((Player*)spawn)->SetCharSheetChanged(true);
  2954. }
  2955. return 0;
  2956. }
  2957. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2958. if (!lua_interface)
  2959. return 0;
  2960. Spawn* spawn = lua_interface->GetSpawn(state);
  2961. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2962. float value = lua_interface->GetFloatValue(state, 2);
  2963. if (spawn && spawn->IsEntity()) {
  2964. ((Entity*)spawn)->AddSpellBonus(luaspell, ITEM_STAT_AGI, value);
  2965. if (spawn->IsPlayer())
  2966. ((Player*)spawn)->SetCharSheetChanged(true);
  2967. }
  2968. return 0;
  2969. }
  2970. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2971. if (!lua_interface)
  2972. return 0;
  2973. Spawn* spawn = lua_interface->GetSpawn(state);
  2974. if (spawn) {
  2975. lua_interface->SetInt32Value(state, spawn->GetHP());
  2976. return 1;
  2977. }
  2978. return 0;
  2979. }
  2980. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2981. if (!lua_interface)
  2982. return 0;
  2983. Spawn* spawn = lua_interface->GetSpawn(state);
  2984. if (spawn) {
  2985. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2986. return 1;
  2987. }
  2988. return 0;
  2989. }
  2990. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2991. if (!lua_interface)
  2992. return 0;
  2993. Spawn* spawn = lua_interface->GetSpawn(state);
  2994. if (spawn) {
  2995. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2996. return 1;
  2997. }
  2998. return 0;
  2999. }
  3000. int EQ2Emu_lua_GetName(lua_State* state) {
  3001. if (!lua_interface)
  3002. return 0;
  3003. Spawn* spawn = lua_interface->GetSpawn(state);
  3004. if (spawn) {
  3005. lua_interface->SetStringValue(state, spawn->GetName());
  3006. return 1;
  3007. }
  3008. return 0;
  3009. }
  3010. int EQ2Emu_lua_GetLevel(lua_State* state) {
  3011. Spawn* spawn = lua_interface->GetSpawn(state);
  3012. if (spawn) {
  3013. lua_interface->SetInt32Value(state, spawn->GetLevel());
  3014. return 1;
  3015. }
  3016. return 0;
  3017. }
  3018. int EQ2Emu_lua_GetDifficulty(lua_State* state) {
  3019. Spawn* spawn = lua_interface->GetSpawn(state);
  3020. if (spawn) {
  3021. lua_interface->SetInt32Value(state, spawn->GetDifficulty());
  3022. return 1;
  3023. }
  3024. return 0;
  3025. }
  3026. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  3027. if (!lua_interface)
  3028. return 0;
  3029. Spawn* spawn = lua_interface->GetSpawn(state);
  3030. if (spawn) {
  3031. lua_interface->SetInt32Value(state, spawn->GetPower());
  3032. return 1;
  3033. }
  3034. return 0;
  3035. }
  3036. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  3037. if (!lua_interface)
  3038. return 0;
  3039. Spawn* spawn = lua_interface->GetSpawn(state);
  3040. if (spawn) {
  3041. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  3042. return 1;
  3043. }
  3044. return 0;
  3045. }
  3046. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  3047. if (!lua_interface)
  3048. return 0;
  3049. Spawn* spawn = lua_interface->GetSpawn(state);
  3050. if (spawn) {
  3051. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  3052. return 1;
  3053. }
  3054. return 0;
  3055. }
  3056. int EQ2Emu_lua_GetDistance(lua_State* state) {
  3057. if (!lua_interface)
  3058. return 0;
  3059. Spawn* spawn = lua_interface->GetSpawn(state);
  3060. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  3061. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  3062. if (spawn && spawn2) {
  3063. float distance = spawn->GetDistance(spawn2, false, include_radius);
  3064. lua_interface->SetFloatValue(state, distance);
  3065. return 1;
  3066. }
  3067. return 0;
  3068. }
  3069. int EQ2Emu_lua_GetX(lua_State* state) {
  3070. if (!lua_interface)
  3071. return 0;
  3072. Spawn* spawn = lua_interface->GetSpawn(state);
  3073. if (spawn) {
  3074. lua_interface->SetFloatValue(state, spawn->GetX());
  3075. return 1;
  3076. }
  3077. return 0;
  3078. }
  3079. int EQ2Emu_lua_GetY(lua_State* state) {
  3080. if (!lua_interface)
  3081. return 0;
  3082. Spawn* spawn = lua_interface->GetSpawn(state);
  3083. if (spawn) {
  3084. lua_interface->SetFloatValue(state, spawn->GetY());
  3085. return 1;
  3086. }
  3087. return 0;
  3088. }
  3089. int EQ2Emu_lua_GetZ(lua_State* state) {
  3090. if (!lua_interface)
  3091. return 0;
  3092. Spawn* spawn = lua_interface->GetSpawn(state);
  3093. if (spawn) {
  3094. lua_interface->SetFloatValue(state, spawn->GetZ());
  3095. return 1;
  3096. }
  3097. return 0;
  3098. }
  3099. int EQ2Emu_lua_GetHeading(lua_State* state) {
  3100. if (!lua_interface)
  3101. return 0;
  3102. Spawn* spawn = lua_interface->GetSpawn(state);
  3103. if (spawn) {
  3104. lua_interface->SetFloatValue(state, spawn->GetHeading());
  3105. return 1;
  3106. }
  3107. return 0;
  3108. }
  3109. int EQ2Emu_lua_GetModelType(lua_State* state) {
  3110. if (!lua_interface)
  3111. return 0;
  3112. Spawn* spawn = lua_interface->GetSpawn(state);
  3113. if (spawn) {
  3114. lua_interface->SetInt32Value(state, spawn->GetModelType());
  3115. return 1;
  3116. }
  3117. return 0;
  3118. }
  3119. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  3120. if (!lua_interface)
  3121. return 0;
  3122. Spawn* spawn = lua_interface->GetSpawn(state);
  3123. if (spawn) {
  3124. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  3125. return 1;
  3126. }
  3127. return 0;
  3128. }
  3129. int EQ2Emu_lua_HasMoved(lua_State* state) {
  3130. if (!lua_interface)
  3131. return 0;
  3132. Spawn* spawn = lua_interface->GetSpawn(state);
  3133. if (spawn && spawn->IsEntity()) {
  3134. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  3135. return 1;
  3136. }
  3137. return 0;
  3138. }
  3139. int EQ2Emu_lua_GetInt(lua_State* state) {
  3140. if (!lua_interface)
  3141. return 0;
  3142. Spawn* spawn = lua_interface->GetSpawn(state);
  3143. if (spawn && spawn->IsEntity()) {
  3144. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  3145. return 1;
  3146. }
  3147. return 0;
  3148. }
  3149. int EQ2Emu_lua_GetWis(lua_State* state) {
  3150. if (!lua_interface)
  3151. return 0;
  3152. Spawn* spawn = lua_interface->GetSpawn(state);
  3153. if (spawn && spawn->IsEntity()) {
  3154. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  3155. return 1;
  3156. }
  3157. return 0;
  3158. }
  3159. int EQ2Emu_lua_GetSta(lua_State* state) {
  3160. if (!lua_interface)
  3161. return 0;
  3162. Spawn* spawn = lua_interface->GetSpawn(state);
  3163. if (spawn && spawn->IsEntity()) {
  3164. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  3165. return 1;
  3166. }
  3167. return 0;
  3168. }
  3169. int EQ2Emu_lua_GetStr(lua_State* state) {
  3170. if (!lua_interface)
  3171. return 0;
  3172. Spawn* spawn = lua_interface->GetSpawn(state);
  3173. if (spawn && spawn->IsEntity()) {
  3174. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  3175. return 1;
  3176. }
  3177. return 0;
  3178. }
  3179. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3180. if (!lua_interface)
  3181. return 0;
  3182. Spawn* spawn = lua_interface->GetSpawn(state);
  3183. if (spawn && spawn->IsEntity()) {
  3184. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3185. return 1;
  3186. }
  3187. return 0;
  3188. }
  3189. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3190. if (!lua_interface)
  3191. return 0;
  3192. Spawn* spawn = lua_interface->GetSpawn(state);
  3193. if (spawn && spawn->IsEntity()) {
  3194. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3195. return 1;
  3196. }
  3197. return 0;
  3198. }
  3199. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3200. if (!lua_interface)
  3201. return 0;
  3202. Spawn* spawn = lua_interface->GetSpawn(state);
  3203. if (spawn && spawn->IsEntity()) {
  3204. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3205. return 1;
  3206. }
  3207. return 0;
  3208. }
  3209. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3210. if (!lua_interface)
  3211. return 0;
  3212. Spawn* spawn = lua_interface->GetSpawn(state);
  3213. if (spawn && spawn->IsEntity()) {
  3214. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3215. return 1;
  3216. }
  3217. return 0;
  3218. }
  3219. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3220. if (!lua_interface)
  3221. return 0;
  3222. Spawn* spawn = lua_interface->GetSpawn(state);
  3223. if (spawn && spawn->IsEntity()) {
  3224. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3225. return 1;
  3226. }
  3227. return 0;
  3228. }
  3229. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3230. if (!lua_interface)
  3231. return 0;
  3232. Spawn* spawn = lua_interface->GetSpawn(state);
  3233. if (spawn && spawn->IsEntity()) {
  3234. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3235. return 1;
  3236. }
  3237. return 0;
  3238. }
  3239. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3240. if (!lua_interface)
  3241. return 0;
  3242. Spawn* player = lua_interface->GetSpawn(state);
  3243. if (!player || !player->IsPlayer()) {
  3244. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3245. return 0;
  3246. }
  3247. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3248. if (quest_id <= 0) {
  3249. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3250. return 0;
  3251. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3252. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3253. return 0;
  3254. }
  3255. int32 step = lua_interface->GetInt32Value(state, 3);
  3256. if (step > 0) {
  3257. Client* client = ((Player*)player)->GetClient();
  3258. if (client)
  3259. client->AddPendingQuestUpdate(quest_id, step);
  3260. } else {
  3261. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3262. }
  3263. return 0;
  3264. }
  3265. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3266. Spawn* player = lua_interface->GetSpawn(state);
  3267. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3268. int32 step = lua_interface->GetInt32Value(state, 3);
  3269. int32 progress = lua_interface->GetInt32Value(state, 4);
  3270. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3271. Client* client = ((Player*)player)->GetClient();
  3272. if (client)
  3273. client->AddPendingQuestUpdate(quest_id, step, progress);
  3274. }
  3275. return 0;
  3276. }
  3277. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3278. if (!lua_interface)
  3279. return 0;
  3280. Spawn* player = lua_interface->GetSpawn(state);
  3281. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3282. if (player && player->IsPlayer() && quest_id > 0) {
  3283. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3284. return 1;
  3285. }
  3286. return 0;
  3287. }
  3288. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3289. if (!lua_interface)
  3290. return 0;
  3291. Spawn* player = lua_interface->GetSpawn(state);
  3292. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3293. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3294. if (player && player->IsPlayer() && quest_id > 0) {
  3295. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3296. return 1;
  3297. }
  3298. return 0;
  3299. }
  3300. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3301. if (!lua_interface)
  3302. return 0;
  3303. Spawn* player = lua_interface->GetSpawn(state);
  3304. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3305. if (player && player->IsPlayer() && quest_id > 0) {
  3306. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3307. return 1;
  3308. }
  3309. return 0;
  3310. }
  3311. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3312. if (!lua_interface)
  3313. return 0;
  3314. Quest* quest = lua_interface->GetQuest(state);
  3315. string name = lua_interface->GetStringValue(state, 2);
  3316. string type = lua_interface->GetStringValue(state, 3);
  3317. string zone = lua_interface->GetStringValue(state, 4);
  3318. int16 level = lua_interface->GetInt16Value(state, 5);
  3319. string description = lua_interface->GetStringValue(state, 6);
  3320. bool load = true;
  3321. if (!quest) {
  3322. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3323. load = false;
  3324. }
  3325. if (load && name.length() == 0) {
  3326. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3327. load = false;
  3328. }
  3329. if (load && type.length() == 0) {
  3330. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3331. load = false;
  3332. }
  3333. if (load && zone.length() == 0) {
  3334. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3335. load = false;
  3336. }
  3337. if (load && description.length() == 0) {
  3338. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3339. load = false;
  3340. }
  3341. if (load && level == 0) {
  3342. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3343. load = false;
  3344. }
  3345. if (load)
  3346. quest->RegisterQuest(name, type, zone, level, description);
  3347. return 0;
  3348. }
  3349. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3350. if (!lua_interface)
  3351. return 0;
  3352. Quest* quest = lua_interface->GetQuest(state);
  3353. if (quest) {
  3354. int8 level = lua_interface->GetInt16Value(state, 2);
  3355. quest->SetPrereqLevel(level);
  3356. }
  3357. return 0;
  3358. }
  3359. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3360. if (!lua_interface)
  3361. return 0;
  3362. Quest* quest = lua_interface->GetQuest(state);
  3363. if (quest) {
  3364. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3365. quest->AddPrereqQuest(quest_id);
  3366. }
  3367. return 0;
  3368. }
  3369. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3370. if (!lua_interface)
  3371. return 0;
  3372. Quest* quest = lua_interface->GetQuest(state);
  3373. if (quest) {
  3374. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3375. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3376. if (quantity == 0)
  3377. quantity = 1;
  3378. Item* master_item = master_item_list.GetItem(item_id);
  3379. if (master_item) {
  3380. Item* item = new Item(master_item);
  3381. item->details.count = quantity;
  3382. quest->AddPrereqItem(item);
  3383. }
  3384. }
  3385. return 0;
  3386. }
  3387. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3388. if (!lua_interface)
  3389. return 0;
  3390. Spawn* player = lua_interface->GetSpawn(state);
  3391. if(!player || !player->IsPlayer()) {
  3392. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3393. return 0;
  3394. }
  3395. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3396. if (quest_id > 0) {
  3397. lua_interface->SetBooleanValue(state, (((Player*)player)->HasActiveQuest(quest_id) > 0));
  3398. return 1;
  3399. } else {
  3400. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3401. }
  3402. return 0;
  3403. }
  3404. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3405. if (!lua_interface)
  3406. return 0;
  3407. Quest* quest = lua_interface->GetQuest(state);
  3408. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3409. lua_interface->ResetFunctionStack(state);
  3410. if (quest && spawn_id > 0)
  3411. quest->SetQuestReturnNPC(spawn_id);
  3412. return 0;
  3413. }
  3414. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3415. if (!lua_interface)
  3416. return 0;
  3417. Spawn* spawn = lua_interface->GetSpawn(state);
  3418. int32 time = lua_interface->GetInt32Value(state, 2);
  3419. string function = lua_interface->GetStringValue(state, 3);
  3420. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3421. Spawn* player = lua_interface->GetSpawn(state, 5);
  3422. lua_interface->ResetFunctionStack(state);
  3423. if (!spawn) {
  3424. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3425. return 0;
  3426. }
  3427. if (time <= 0) {
  3428. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3429. return 0;
  3430. }
  3431. if (function.length() == 0) {
  3432. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3433. return 0;
  3434. }
  3435. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3436. if ( time < 10)
  3437. time = 10;
  3438. timer->timer = Timer::GetCurrentTime2() + time;
  3439. timer->function = function;
  3440. timer->spawn = spawn->GetID();
  3441. timer->player = player ? player->GetID() : 0;
  3442. if (max_count == 0)
  3443. max_count = 1;
  3444. timer->max_count = max_count;
  3445. timer->current_count = 0;
  3446. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3447. return 0;
  3448. }
  3449. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3450. if (!lua_interface)
  3451. return 0;
  3452. Spawn* spawn = lua_interface->GetSpawn(state);
  3453. string function = lua_interface->GetStringValue(state, 2);
  3454. lua_interface->ResetFunctionStack(state);
  3455. if (!spawn) {
  3456. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3457. return 0;
  3458. }
  3459. if(!spawn->GetZone()) {
  3460. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3461. return 0;
  3462. }
  3463. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3464. return 0;
  3465. }
  3466. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3467. if (!lua_interface)
  3468. return 0;
  3469. Spawn* player = lua_interface->GetSpawn(state);
  3470. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3471. lua_interface->ResetFunctionStack(state);
  3472. if (player && player->IsPlayer() && quest_id > 0) {
  3473. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3474. return 1;
  3475. }
  3476. return 0;
  3477. }
  3478. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3479. if (!lua_interface)
  3480. return 0;
  3481. Spawn* player = lua_interface->GetSpawn(state);
  3482. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3483. lua_interface->ResetFunctionStack(state);
  3484. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3485. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3486. if (quest)
  3487. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3488. return 1;
  3489. }
  3490. return 0;
  3491. }
  3492. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3493. if (!lua_interface)
  3494. return 0;
  3495. Spawn* player = lua_interface->GetSpawn(state);
  3496. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3497. lua_interface->ResetFunctionStack(state);
  3498. if (player && player->IsPlayer() && quest_id > 0) {
  3499. lua_interface->SetBooleanValue(state, (((Player*)player)->HasQuestBeenCompleted(quest_id) != 0));
  3500. return 1;
  3501. }
  3502. return 0;
  3503. }
  3504. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3505. if (!lua_interface)
  3506. return 0;
  3507. Spawn* npc = lua_interface->GetSpawn(state);
  3508. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3509. lua_interface->ResetFunctionStack(state);
  3510. if (npc && !npc->IsPlayer() && quest_id > 0)
  3511. npc->AddProvidedQuest(quest_id);
  3512. return 0;
  3513. }
  3514. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3515. if (!lua_interface)
  3516. return 0;
  3517. Spawn* npc = lua_interface->GetSpawn(state);
  3518. Spawn* player = lua_interface->GetSpawn(state, 2);
  3519. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3520. bool forced = lua_interface->GetBooleanValue(state, 4);
  3521. lua_interface->ResetFunctionStack(state);
  3522. /* NPC is allowed to be null */
  3523. if (player && player->IsPlayer() && quest_id > 0) {
  3524. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3525. if (master_quest) {
  3526. Client* client = ((Player*)player)->GetClient();
  3527. if (!client) {
  3528. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3529. }
  3530. Quest* quest = new Quest(master_quest);
  3531. if (!quest) {
  3532. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3533. }
  3534. if (client && quest) {
  3535. if (npc)
  3536. quest->SetQuestGiver(npc->GetDatabaseID());
  3537. else
  3538. quest->SetQuestGiver(0);
  3539. client->AddPendingQuest(quest, forced);
  3540. }
  3541. }
  3542. else {
  3543. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3544. }
  3545. }
  3546. else {
  3547. 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);
  3548. }
  3549. return 0;
  3550. }
  3551. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3552. if (!lua_interface)
  3553. return 0;
  3554. Quest* quest = lua_interface->GetQuest(state);
  3555. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3556. lua_interface->ResetFunctionStack(state);
  3557. if (quest) {
  3558. quest->AddPrereqClass(class_id);
  3559. }
  3560. return 0;
  3561. }
  3562. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3563. if (!lua_interface)
  3564. return 0;
  3565. Quest* quest = lua_interface->GetQuest(state);
  3566. int8 race = lua_interface->GetInt8Value(state, 2);
  3567. lua_interface->ResetFunctionStack(state);
  3568. if (quest) {
  3569. quest->AddPrereqRace(race);
  3570. }
  3571. return 0;
  3572. }
  3573. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3574. if (!lua_interface)
  3575. return 0;
  3576. Quest* quest = lua_interface->GetQuest(state);
  3577. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3578. lua_interface->ResetFunctionStack(state);
  3579. if (quest) {
  3580. quest->AddPrereqModelType(model_type);
  3581. }
  3582. return 0;
  3583. }
  3584. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3585. if (!lua_interface)
  3586. return 0;
  3587. Quest* quest = lua_interface->GetQuest(state);
  3588. int8 level = lua_interface->GetInt8Value(state, 2);
  3589. lua_interface->ResetFunctionStack(state);
  3590. if (!quest) {
  3591. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3592. return 0;
  3593. }
  3594. quest->SetPrereqTSLevel(level);
  3595. return 0;
  3596. }
  3597. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3598. if (!lua_interface)
  3599. return 0;
  3600. Quest* quest = lua_interface->GetQuest(state);
  3601. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3602. lua_interface->ResetFunctionStack(state);
  3603. if (!quest) {
  3604. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3605. return 0;
  3606. }
  3607. quest->AddPrereqTradeskillClass(class_id);
  3608. return 0;
  3609. }
  3610. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3611. if (!lua_interface)
  3612. return 0;
  3613. Quest* quest = lua_interface->GetQuest(state);
  3614. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3615. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3616. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3617. lua_interface->ResetFunctionStack(state);
  3618. if (quest) {
  3619. quest->AddPrereqFaction(faction_id, min, max);
  3620. }
  3621. return 0;
  3622. }
  3623. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3624. if (!lua_interface)
  3625. return 0;
  3626. Quest* quest = lua_interface->GetQuest(state);
  3627. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3628. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3629. lua_interface->ResetFunctionStack(state);
  3630. if (quest) {
  3631. if (quantity == 0)
  3632. quantity = 1;
  3633. Item* master_item = master_item_list.GetItem(item_id);
  3634. if (master_item) {
  3635. Item* item = new Item(master_item);
  3636. item->details.count = quantity;
  3637. quest->AddSelectableRewardItem(item);
  3638. }
  3639. }
  3640. return 0;
  3641. }
  3642. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3643. if (!lua_interface)
  3644. return 0;
  3645. Quest* quest = lua_interface->GetQuest(state);
  3646. if (quest) {
  3647. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3648. vector<Item*>* items = quest->GetRewardItems();
  3649. if (items) {
  3650. vector<Item*>::iterator itr;
  3651. for (itr = items->begin(); itr != items->end(); itr++) {
  3652. if (*itr && (*itr)->details.item_id == item_id) {
  3653. lua_interface->SetBooleanValue(state, true);
  3654. return 1;
  3655. }
  3656. }
  3657. }
  3658. }
  3659. lua_interface->SetBooleanValue(state, false);
  3660. return 1;
  3661. }
  3662. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3663. if (!lua_interface)
  3664. return 0;
  3665. Quest* quest = lua_interface->GetQuest(state);
  3666. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3667. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3668. lua_interface->ResetFunctionStack(state);
  3669. if (quest) {
  3670. if (quantity == 0)
  3671. quantity = 1;
  3672. Item* master_item = master_item_list.GetItem(item_id);
  3673. if (master_item) {
  3674. Item* item = new Item(master_item);
  3675. item->details.count = quantity;
  3676. quest->AddRewardItem(item);
  3677. }
  3678. }
  3679. return 0;
  3680. }
  3681. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3682. if (!lua_interface)
  3683. return 0;
  3684. Quest* quest = lua_interface->GetQuest(state);
  3685. int32 copper = lua_interface->GetInt32Value(state, 2);
  3686. int32 silver = lua_interface->GetInt32Value(state, 3);
  3687. int32 gold = lua_interface->GetInt32Value(state, 4);
  3688. int32 plat = lua_interface->GetInt32Value(state, 5);
  3689. lua_interface->ResetFunctionStack(state);
  3690. if (quest) {
  3691. quest->AddRewardCoins(copper, silver, gold, plat);
  3692. }
  3693. return 0;
  3694. }
  3695. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3696. if (!lua_interface)
  3697. return 0;
  3698. Quest* quest = lua_interface->GetQuest(state);
  3699. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3700. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3701. lua_interface->ResetFunctionStack(state);
  3702. if (quest && faction_id > 0 && amount != 0)
  3703. quest->AddRewardFaction(faction_id, amount);
  3704. return 0;
  3705. }
  3706. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3707. if (!lua_interface)
  3708. return 0;
  3709. Quest* quest = lua_interface->GetQuest(state);
  3710. int32 status = lua_interface->GetInt32Value(state, 2);
  3711. lua_interface->ResetFunctionStack(state);
  3712. if (quest) {
  3713. quest->SetRewardStatus(status);
  3714. }
  3715. return 0;
  3716. }
  3717. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3718. if (!lua_interface)
  3719. return 0;
  3720. Quest* quest = lua_interface->GetQuest(state);
  3721. int32 status = lua_interface->GetInt32Value(state, 2);
  3722. lua_interface->ResetFunctionStack(state);
  3723. if (quest) {
  3724. quest->SetStatusTmpReward(status);
  3725. }
  3726. return 0;
  3727. }
  3728. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3729. if (!lua_interface)
  3730. return 0;
  3731. Quest* quest = lua_interface->GetQuest(state);
  3732. int64 coins = lua_interface->GetInt64Value(state, 2);
  3733. lua_interface->ResetFunctionStack(state);
  3734. if (quest) {
  3735. quest->SetCoinTmpReward(coins);
  3736. }
  3737. return 0;
  3738. }
  3739. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3740. if (!lua_interface)
  3741. return 0;
  3742. Quest* quest = lua_interface->GetQuest(state);
  3743. string comment = lua_interface->GetStringValue(state, 2);
  3744. lua_interface->ResetFunctionStack(state);
  3745. if (quest) {
  3746. quest->SetRewardComment(comment);
  3747. }
  3748. return 0;
  3749. }
  3750. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3751. if (!lua_interface)
  3752. return 0;
  3753. Quest* quest = lua_interface->GetQuest(state);
  3754. int32 exp = lua_interface->GetInt32Value(state, 2);
  3755. lua_interface->ResetFunctionStack(state);
  3756. if (quest) {
  3757. quest->SetRewardXP(exp);
  3758. }
  3759. return 0;
  3760. }
  3761. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3762. Quest* quest = lua_interface->GetQuest(state);
  3763. int32 step = lua_interface->GetInt32Value(state, 2);
  3764. string description = lua_interface->GetStringValue(state, 3);
  3765. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3766. float percentage = lua_interface->GetFloatValue(state, 5);
  3767. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3768. int16 icon = lua_interface->GetInt16Value(state, 7);
  3769. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3770. if (quest) {
  3771. const char* taskgroup = 0;
  3772. if (str_taskgroup.length() > 0)
  3773. taskgroup = str_taskgroup.c_str();
  3774. int32 id = 0;
  3775. vector<int32>* ids = 0;
  3776. int i = 0;
  3777. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3778. if (ids == 0)
  3779. ids = new vector<int32>;
  3780. ids->push_back(id);
  3781. i++;
  3782. }
  3783. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3784. if (quest_step && icon && quantity > 0)
  3785. quest_step->SetIcon(icon);
  3786. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3787. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3788. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3789. }
  3790. }
  3791. lua_interface->ResetFunctionStack(state);
  3792. return 0;
  3793. }
  3794. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3795. {
  3796. if (!lua_interface)
  3797. return 0;
  3798. Quest* quest = lua_interface->GetQuest(state);
  3799. int32 step = lua_interface->GetInt32Value(state, 2);
  3800. string description = lua_interface->GetStringValue(state, 3);
  3801. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3802. float percentage = lua_interface->GetFloatValue(state, 5);
  3803. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3804. int16 icon = lua_interface->GetInt16Value(state, 7);
  3805. if (quest) {
  3806. const char* taskgroup = 0;
  3807. if (str_taskgroup.length() > 0)
  3808. taskgroup = str_taskgroup.c_str();
  3809. int32 id = 0;
  3810. vector<int32>* ids = 0;
  3811. int i = 0;
  3812. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3813. if (ids == 0)
  3814. ids = new vector<int32>;
  3815. ids->push_back(id);
  3816. i++;
  3817. }
  3818. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3819. if (quest_step && icon > 0 && quantity > 0)
  3820. quest_step->SetIcon(icon);
  3821. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3822. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3823. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3824. }
  3825. safe_delete(ids);
  3826. }
  3827. lua_interface->ResetFunctionStack(state);
  3828. return 0;
  3829. }
  3830. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3831. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3832. }
  3833. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3834. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3835. }
  3836. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3837. if (!lua_interface)
  3838. return 0;
  3839. Quest* quest = lua_interface->GetQuest(state);
  3840. int32 step = lua_interface->GetInt32Value(state, 2);
  3841. string description = lua_interface->GetStringValue(state, 3);
  3842. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3843. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3844. int16 icon = lua_interface->GetInt16Value(state, 6);
  3845. if (quest) {
  3846. const char* taskgroup = 0;
  3847. if (str_taskgroup.length() > 0)
  3848. taskgroup = str_taskgroup.c_str();
  3849. int32 npc_id = 0;
  3850. vector<int32>* ids = 0;
  3851. int i = 0;
  3852. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3853. if (ids == 0)
  3854. ids = new vector<int32>;
  3855. ids->push_back(npc_id);
  3856. i++;
  3857. }
  3858. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3859. if (quest_step && icon > 0)
  3860. quest_step->SetIcon(icon);
  3861. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3862. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3863. if(client)
  3864. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3865. }
  3866. safe_delete(ids);
  3867. }
  3868. lua_interface->ResetFunctionStack(state);
  3869. return 0;
  3870. }
  3871. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3872. if (!lua_interface)
  3873. return 0;
  3874. Quest* quest = lua_interface->GetQuest(state);
  3875. int32 step = lua_interface->GetInt32Value(state, 2);
  3876. string description = lua_interface->GetStringValue(state, 3);
  3877. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3878. float percentage = lua_interface->GetFloatValue(state, 5);
  3879. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3880. int16 icon = lua_interface->GetInt16Value(state, 7);
  3881. if (quest) {
  3882. const char* taskgroup = 0;
  3883. if (str_taskgroup.length() > 0)
  3884. taskgroup = str_taskgroup.c_str();
  3885. int32 item_id = 0;
  3886. vector<int32>* ids = 0;
  3887. int i = 0;
  3888. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3889. if (ids == 0)
  3890. ids = new vector<int32>;
  3891. ids->push_back(item_id);
  3892. i++;
  3893. }
  3894. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3895. if (quest_step && icon > 0 && quantity > 0)
  3896. quest_step->SetIcon(icon);
  3897. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3898. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3899. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3900. }
  3901. safe_delete(ids);
  3902. }
  3903. lua_interface->ResetFunctionStack(state);
  3904. return 0;
  3905. }
  3906. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3907. if (!lua_interface)
  3908. return 0;
  3909. Quest* quest = lua_interface->GetQuest(state);
  3910. int32 step = lua_interface->GetInt32Value(state, 2);
  3911. string description = lua_interface->GetStringValue(state, 3);
  3912. float max_variation = lua_interface->GetFloatValue(state, 4);
  3913. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3914. int16 icon = lua_interface->GetInt16Value(state, 6);
  3915. if (quest) {
  3916. const char* taskgroup = 0;
  3917. if (str_taskgroup.length() > 0)
  3918. taskgroup = str_taskgroup.c_str();
  3919. vector<Location>* locations = 0;
  3920. int8 i = 7;
  3921. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3922. while (true) {
  3923. Location loc;
  3924. loc.x = lua_interface->GetFloatValue(state, i);
  3925. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3926. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3927. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3928. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3929. break;
  3930. if (locations == 0)
  3931. locations = new vector<Location>;
  3932. locations->push_back(loc);
  3933. i += 4;
  3934. }
  3935. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3936. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3937. if (quest_step && icon > 0)
  3938. quest_step->SetIcon(icon);
  3939. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3940. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3941. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3942. }
  3943. }
  3944. lua_interface->ResetFunctionStack(state);
  3945. return 0;
  3946. }
  3947. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3948. if (!lua_interface)
  3949. return 0;
  3950. Quest* quest = lua_interface->GetQuest(state);
  3951. int32 step = lua_interface->GetInt32Value(state, 2);
  3952. string description = lua_interface->GetStringValue(state, 3);
  3953. float max_variation = lua_interface->GetFloatValue(state, 4);
  3954. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3955. int16 icon = lua_interface->GetInt16Value(state, 6);
  3956. if (quest) {
  3957. const char* taskgroup = 0;
  3958. if (str_taskgroup.length() > 0)
  3959. taskgroup = str_taskgroup.c_str();
  3960. vector<Location>* locations = 0;
  3961. int8 i = 7;
  3962. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3963. while (true) {
  3964. Location loc;
  3965. loc.x = lua_interface->GetFloatValue(state, i);
  3966. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3967. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3968. loc.zone_id = 0;
  3969. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3970. break;
  3971. if (locations == 0)
  3972. locations = new vector<Location>;
  3973. locations->push_back(loc);
  3974. i += 3;
  3975. }
  3976. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3977. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  3978. if (quest_step && icon > 0)
  3979. quest_step->SetIcon(icon);
  3980. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  3981. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  3982. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3983. }
  3984. }
  3985. lua_interface->ResetFunctionStack(state);
  3986. return 0;
  3987. }
  3988. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3989. if (!lua_interface)
  3990. return 0;
  3991. Quest* quest = lua_interface->GetQuest(state);
  3992. int32 step = lua_interface->GetInt32Value(state, 2);
  3993. string description = lua_interface->GetStringValue(state, 3);
  3994. float max_variation = lua_interface->GetFloatValue(state, 4);
  3995. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3996. int16 icon = lua_interface->GetInt16Value(state, 6);
  3997. if (quest) {
  3998. const char* taskgroup = 0;
  3999. if (str_taskgroup.length() > 0)
  4000. taskgroup = str_taskgroup.c_str();
  4001. vector<Location>* locations = 0;
  4002. int i = 7;
  4003. while (true) {
  4004. Location loc;
  4005. loc.x = lua_interface->GetFloatValue(state, i);
  4006. loc.y = lua_interface->GetFloatValue(state, i + 1);
  4007. loc.z = lua_interface->GetFloatValue(state, i + 2);
  4008. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  4009. break;
  4010. if (locations == 0)
  4011. locations = new vector<Location>;
  4012. locations->push_back(loc);
  4013. i += 3;
  4014. }
  4015. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  4016. safe_delete(locations); // gets duplicated into new table in QuestStep constructor
  4017. if (quest_step && icon > 0)
  4018. quest_step->SetIcon(icon);
  4019. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4020. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4021. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4022. }
  4023. }
  4024. lua_interface->ResetFunctionStack(state);
  4025. return 0;
  4026. }
  4027. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  4028. Quest* quest = lua_interface->GetQuest(state);
  4029. int32 step = lua_interface->GetInt32Value(state, 2);
  4030. string description = lua_interface->GetStringValue(state, 3);
  4031. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4032. float percentage = lua_interface->GetFloatValue(state, 5);
  4033. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4034. int16 icon = lua_interface->GetInt16Value(state, 7);
  4035. if (quest) {
  4036. const char* taskgroup = 0;
  4037. if (str_taskgroup.length() > 0)
  4038. taskgroup = str_taskgroup.c_str();
  4039. int32 spell_id = 0;
  4040. vector<int32>* ids = 0;
  4041. int i = 0;
  4042. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4043. if (ids == 0)
  4044. ids = new vector<int32>;
  4045. ids->push_back(spell_id);
  4046. i++;
  4047. }
  4048. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4049. if (quest_step && icon > 0 && quantity > 0)
  4050. quest_step->SetIcon(icon);
  4051. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4052. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4053. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4054. }
  4055. safe_delete(ids);
  4056. }
  4057. lua_interface->ResetFunctionStack(state);
  4058. return 0;
  4059. }
  4060. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  4061. if (!lua_interface)
  4062. return 0;
  4063. Quest* quest = lua_interface->GetQuest(state);
  4064. int32 step = lua_interface->GetInt32Value(state, 2);
  4065. string description = lua_interface->GetStringValue(state, 3);
  4066. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4067. float percentage = lua_interface->GetFloatValue(state, 5);
  4068. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4069. int16 icon = lua_interface->GetInt16Value(state, 7);
  4070. if (quest) {
  4071. const char* taskgroup = 0;
  4072. if (str_taskgroup.length() > 0)
  4073. taskgroup = str_taskgroup.c_str();
  4074. int32 item_id = 0;
  4075. vector<int32>* ids = 0;
  4076. int i = 0;
  4077. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4078. if (ids == 0)
  4079. ids = new vector<int32>;
  4080. ids->push_back(item_id);
  4081. i++;
  4082. }
  4083. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4084. if (quest_step && icon > 0 && quantity > 0)
  4085. quest_step->SetIcon(icon);
  4086. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4087. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4088. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4089. }
  4090. safe_delete(ids);
  4091. }
  4092. lua_interface->ResetFunctionStack(state);
  4093. return 0;
  4094. }
  4095. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  4096. if (!lua_interface)
  4097. return 0;
  4098. Quest* quest = lua_interface->GetQuest(state);
  4099. int32 step = lua_interface->GetInt32Value(state, 2);
  4100. string description = lua_interface->GetStringValue(state, 3);
  4101. int32 quantity = lua_interface->GetInt32Value(state, 4);
  4102. float percentage = lua_interface->GetFloatValue(state, 5);
  4103. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  4104. int16 icon = lua_interface->GetInt16Value(state, 7);
  4105. if (quest) {
  4106. const char* taskgroup = 0;
  4107. if (str_taskgroup.length() > 0)
  4108. taskgroup = str_taskgroup.c_str();
  4109. int32 item_id = 0;
  4110. vector<int32>* ids = 0;
  4111. int i = 0;
  4112. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  4113. if (ids == 0)
  4114. ids = new vector<int32>;
  4115. ids->push_back(item_id);
  4116. i++;
  4117. }
  4118. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  4119. if (quest_step && icon > 0 && quantity > 0)
  4120. quest_step->SetIcon(icon);
  4121. if (quest->GetPlayer() && ((Player*)quest->GetPlayer())->GetClient()) {
  4122. Client* client = ((Player*)quest->GetPlayer())->GetClient();
  4123. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  4124. }
  4125. safe_delete(ids);
  4126. }
  4127. lua_interface->ResetFunctionStack(state);
  4128. return 0;
  4129. }
  4130. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  4131. if (!lua_interface)
  4132. return 0;
  4133. Quest* quest = lua_interface->GetQuest(state);
  4134. string action = lua_interface->GetStringValue(state, 2);
  4135. lua_interface->ResetFunctionStack(state);
  4136. if (quest) {
  4137. if (action.length() > 0)
  4138. quest->SetCompleteAction(action);
  4139. }
  4140. return 0;
  4141. }
  4142. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  4143. if (!lua_interface)
  4144. return 0;
  4145. Quest* quest = lua_interface->GetQuest(state);
  4146. int32 step = lua_interface->GetInt32Value(state, 2);
  4147. string action = lua_interface->GetStringValue(state, 3);
  4148. lua_interface->ResetFunctionStack(state);
  4149. if (quest) {
  4150. if (step > 0 && action.length() > 0)
  4151. quest->AddCompleteAction(step, action);
  4152. }
  4153. return 0;
  4154. }
  4155. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  4156. if (!lua_interface)
  4157. return 0;
  4158. Quest* quest = lua_interface->GetQuest(state);
  4159. int32 step = lua_interface->GetInt32Value(state, 2);
  4160. string action = lua_interface->GetStringValue(state, 3);
  4161. lua_interface->ResetFunctionStack(state);
  4162. if (quest) {
  4163. if (step > 0 && action.length() > 0)
  4164. quest->AddProgressAction(step, action);
  4165. }
  4166. return 0;
  4167. }
  4168. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  4169. if (!lua_interface)
  4170. return 0;
  4171. Quest* quest = lua_interface->GetQuest(state);
  4172. string description = lua_interface->GetStringValue(state, 2);
  4173. lua_interface->ResetFunctionStack(state);
  4174. if (quest && description.length() > 0)
  4175. quest->SetDescription(description);
  4176. return 0;
  4177. }
  4178. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  4179. if (!lua_interface)
  4180. return 0;
  4181. Quest* quest = lua_interface->GetQuest(state);
  4182. string description = lua_interface->GetStringValue(state, 2);
  4183. lua_interface->ResetFunctionStack(state);
  4184. if (quest && description.length() > 0)
  4185. quest->SetCompletedDescription(description);
  4186. return 0;
  4187. }
  4188. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(lua_State* state) {
  4189. if (!lua_interface)
  4190. return 0;
  4191. Quest* quest = lua_interface->GetQuest(state);
  4192. int32 step = lua_interface->GetInt32Value(state, 2);
  4193. string description = lua_interface->GetStringValue(state, 3);
  4194. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4195. lua_interface->ResetFunctionStack(state);
  4196. if (quest && step > 0 && description.length() > 0) {
  4197. quest->SetTaskGroupDescription(step, description, display_bullets);
  4198. }
  4199. return 0;
  4200. }
  4201. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4202. if (!lua_interface)
  4203. return 0;
  4204. Quest* quest = lua_interface->GetQuest(state);
  4205. int32 step = lua_interface->GetInt32Value(state, 2);
  4206. string description = lua_interface->GetStringValue(state, 3);
  4207. lua_interface->ResetFunctionStack(state);
  4208. if (quest && step > 0 && description.length() > 0) {
  4209. quest->SetStepDescription(step, description);
  4210. }
  4211. return 0;
  4212. }
  4213. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4214. Quest* quest = lua_interface->GetQuest(state);
  4215. string zone = lua_interface->GetStringValue(state, 2);
  4216. lua_interface->ResetFunctionStack(state);
  4217. if (quest && zone.length() > 0)
  4218. quest->SetZone(zone);
  4219. return 0;
  4220. }
  4221. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4222. if (!lua_interface)
  4223. return 0;
  4224. Quest* quest = lua_interface->GetQuest(state);
  4225. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4226. lua_interface->ResetFunctionStack(state);
  4227. if (quest && spawn) {
  4228. if (spawn->IsPlayer()) {
  4229. Client* client = ((Player*)spawn)->GetClient();
  4230. if (client) {
  4231. client->AddPendingQuestReward(quest);
  4232. }
  4233. }
  4234. }
  4235. return 0;
  4236. }
  4237. int EQ2Emu_lua_Harvest(lua_State* state) {
  4238. if (!lua_interface)
  4239. return 0;
  4240. Spawn* player = lua_interface->GetSpawn(state);
  4241. Spawn* node = lua_interface->GetSpawn(state, 2);
  4242. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4243. Client* client = ((Player*)player)->GetClient();
  4244. if (client) {
  4245. ((GroundSpawn*)node)->ProcessHarvest(client);
  4246. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4247. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4248. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4249. }
  4250. }
  4251. }
  4252. else if (player && player->IsPlayer()) {
  4253. Client* client = ((Player*)player)->GetClient();
  4254. if (client)
  4255. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4256. }
  4257. lua_interface->ResetFunctionStack(state);
  4258. return 0;
  4259. }
  4260. int EQ2Emu_lua_Bind(lua_State* state) {
  4261. if (!lua_interface)
  4262. return 0;
  4263. Spawn* spawn = lua_interface->GetSpawn(state);
  4264. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4265. float x = lua_interface->GetFloatValue(state, 3);
  4266. float y = lua_interface->GetFloatValue(state, 4);
  4267. float z = lua_interface->GetFloatValue(state, 5);
  4268. float h = lua_interface->GetFloatValue(state, 6);
  4269. lua_interface->ResetFunctionStack(state);
  4270. if (!spawn) {
  4271. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4272. return 0;
  4273. }
  4274. if (!spawn->IsPlayer()) {
  4275. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4276. return 0;
  4277. }
  4278. if (zone_id == 0) {
  4279. Client* client = ((Player*)spawn)->GetClient();
  4280. if (!client) {
  4281. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4282. return 0;
  4283. }
  4284. if (!client->Bind())
  4285. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4286. }
  4287. else {
  4288. Player* player = (Player*)spawn;
  4289. player->GetPlayerInfo()->SetBindZone(zone_id);
  4290. player->GetPlayerInfo()->SetBindX(x);
  4291. player->GetPlayerInfo()->SetBindY(y);
  4292. player->GetPlayerInfo()->SetBindZ(z);
  4293. player->GetPlayerInfo()->SetBindHeading(h);
  4294. }
  4295. return 0;
  4296. }
  4297. int EQ2Emu_lua_Gate(lua_State* state) {
  4298. if (!lua_interface)
  4299. return 0;
  4300. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4301. Spawn* spawn = lua_interface->GetSpawn(state);
  4302. lua_interface->ResetFunctionStack(state);
  4303. if (spawn) {
  4304. if (spawn->IsPlayer()) {
  4305. Client* client = ((Player*)spawn)->GetClient();
  4306. if (client) {
  4307. if (!client->Gate((spell != nullptr) ? true : false))
  4308. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4309. }
  4310. }
  4311. }
  4312. return 0;
  4313. }
  4314. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4315. if (!lua_interface)
  4316. return 0;
  4317. bool ret = false;
  4318. Spawn* spawn = lua_interface->GetSpawn(state);
  4319. lua_interface->ResetFunctionStack(state);
  4320. if (spawn) {
  4321. if (spawn->IsPlayer()) {
  4322. Client* client = ((Player*)spawn)->GetClient();
  4323. if (client)
  4324. ret = client->BindAllowed();
  4325. }
  4326. }
  4327. lua_interface->SetBooleanValue(state, ret);
  4328. return 1;
  4329. }
  4330. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4331. if (!lua_interface)
  4332. return 0;
  4333. bool ret = false;
  4334. Spawn* spawn = lua_interface->GetSpawn(state);
  4335. lua_interface->ResetFunctionStack(state);
  4336. if (spawn) {
  4337. if (spawn->IsPlayer()) {
  4338. Client* client = ((Player*)spawn)->GetClient();
  4339. ZoneServer* zone = lua_interface->GetZone(state);
  4340. if (client && zone){
  4341. ret = zone->GetCanGate();
  4342. }
  4343. }
  4344. }
  4345. lua_interface->SetBooleanValue(state, ret);
  4346. return 1;
  4347. }
  4348. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4349. Spawn* spawn = lua_interface->GetSpawn(state);
  4350. lua_interface->ResetFunctionStack(state);
  4351. if (spawn) {
  4352. lua_interface->SetBooleanValue(state, spawn->Alive());
  4353. return 1;
  4354. }
  4355. return 0;
  4356. }
  4357. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4358. if (!lua_interface)
  4359. return 0;
  4360. Spawn* spawn = lua_interface->GetSpawn(state);
  4361. lua_interface->ResetFunctionStack(state);
  4362. if (spawn && spawn->IsEntity()) {
  4363. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4364. return 1;
  4365. }
  4366. return 0;
  4367. }
  4368. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4369. Spawn* spawn = lua_interface->GetSpawn(state);
  4370. string message = lua_interface->GetStringValue(state, 2);
  4371. string color_str = lua_interface->GetStringValue(state, 3);
  4372. lua_interface->ResetFunctionStack(state);
  4373. int8 color = CHANNEL_NARRATIVE;
  4374. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4375. Client* client = ((Player*)spawn)->GetClient();
  4376. if (client) {
  4377. if (color_str.length() > 0) {
  4378. // leave for backwards compat, but all future should just use the number
  4379. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4380. color = CHANNEL_COLOR_RED;
  4381. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4382. color = CHANNEL_COLOR_YELLOW;
  4383. else
  4384. {
  4385. // use a number to specify the channel as per Commands/Commands.h defines
  4386. color = (int8)atoul(color_str.c_str());
  4387. }
  4388. }
  4389. client->SimpleMessage(color, message.c_str());
  4390. }
  4391. }
  4392. return 0;
  4393. }
  4394. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4395. Spawn* spawn = lua_interface->GetSpawn(state);
  4396. string message = lua_interface->GetStringValue(state, 2);
  4397. int8 red = lua_interface->GetInt8Value(state, 3);
  4398. int8 green = lua_interface->GetInt8Value(state, 4);
  4399. int8 blue = lua_interface->GetInt8Value(state, 5);
  4400. lua_interface->ResetFunctionStack(state);
  4401. if (!spawn) {
  4402. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4403. return 0;
  4404. }
  4405. if (!spawn->IsPlayer()) {
  4406. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not a player.", lua_interface->GetScriptName(state));
  4407. return 0;
  4408. }
  4409. int32 words = ::CountWordsInString(message.c_str());
  4410. if (words < 5)
  4411. words = 5;
  4412. Client* client = ((Player*)spawn)->GetClient();
  4413. if (client)
  4414. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4415. return 0;
  4416. }
  4417. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4418. Spawn* spawn = lua_interface->GetSpawn(state);
  4419. int8 param = lua_interface->GetInt8Value(state, 2);
  4420. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4421. int8 value = lua_interface->GetInt8Value(state, 4);
  4422. lua_interface->ResetFunctionStack(state);
  4423. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4424. Client* client = ((Player*)spawn)->GetClient();
  4425. if (client) {
  4426. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4427. switch (param) {
  4428. case 1: {
  4429. packet->setDataByName("parameter1", param_value);
  4430. break;
  4431. }
  4432. case 2: {
  4433. packet->setDataByName("parameter2", param_value);
  4434. break;
  4435. }
  4436. case 3: {
  4437. packet->setDataByName("parameter3", param_value);
  4438. break;
  4439. }
  4440. case 4: {
  4441. packet->setDataByName("parameter4", param_value);
  4442. break;
  4443. }
  4444. case 5: {
  4445. packet->setDataByName("parameter5", param_value);
  4446. break;
  4447. }
  4448. }
  4449. packet->setDataByName("value", value);
  4450. client->QueuePacket(packet->serialize());
  4451. safe_delete(packet);
  4452. }
  4453. }
  4454. return 0;
  4455. }
  4456. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4457. Spawn* spawn = lua_interface->GetSpawn(state);
  4458. lua_interface->ResetFunctionStack(state);
  4459. if (spawn && spawn->IsPlayer()) {
  4460. if (((Player*)spawn)->GetIsTracking())
  4461. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4462. else
  4463. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4464. }
  4465. return 0;
  4466. }
  4467. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4468. Spawn* player = lua_interface->GetSpawn(state);
  4469. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4470. string name = lua_interface->GetStringValue(state, 3);
  4471. float distance = lua_interface->GetFloatValue(state, 4);
  4472. string command = lua_interface->GetStringValue(state, 5);
  4473. string error_text = lua_interface->GetStringValue(state, 6);
  4474. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4475. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4476. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4477. lua_interface->ResetFunctionStack(state);
  4478. if (spawn) {
  4479. if (distance == 0)
  4480. distance = 10.0f;
  4481. if (command.length() == 0)
  4482. command = name;
  4483. if (command.length() < 1 && name.length() < 1)
  4484. {
  4485. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4486. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4487. spawn->RemovePrimaryCommands();
  4488. }
  4489. else
  4490. {
  4491. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4492. }
  4493. }
  4494. return 0;
  4495. }
  4496. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4497. if (!lua_interface)
  4498. return 0;
  4499. Spawn* player = lua_interface->GetSpawn(state);
  4500. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4501. int16 tier = lua_interface->GetInt16Value(state, 3);
  4502. lua_interface->ResetFunctionStack(state);
  4503. if (player && player->IsPlayer()) {
  4504. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4505. return 1;
  4506. }
  4507. return 0;
  4508. }
  4509. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4510. if (!lua_interface)
  4511. return 0;
  4512. Spawn* player = lua_interface->GetSpawn(state);
  4513. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4514. int16 tier = lua_interface->GetInt16Value(state, 3);
  4515. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4516. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4517. bool add_to_hotbar = true;
  4518. if (num_args > 4) {
  4519. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4520. }
  4521. lua_interface->ResetFunctionStack(state);
  4522. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4523. if (player && spell && player->IsPlayer()) {
  4524. Client* client = player->GetClient();
  4525. if (client) {
  4526. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4527. {
  4528. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4529. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4530. client->GetPlayer()->UnlockSpell(spell);
  4531. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4532. }
  4533. else
  4534. {
  4535. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4536. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4537. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4538. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4539. client->GetPlayer()->UnlockSpell(spell);
  4540. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4541. }
  4542. //if (client ) {
  4543. // ((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);
  4544. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4545. if (outapp)
  4546. client->QueuePacket(outapp);
  4547. }
  4548. }
  4549. return 0;
  4550. }
  4551. int EQ2Emu_lua_DeleteSpellBook(lua_State* state) {
  4552. if (!lua_interface)
  4553. return 0;
  4554. Spawn* player = lua_interface->GetSpawn(state);
  4555. int8 type_selection = lua_interface->GetInt8Value(state, 2);
  4556. lua_interface->ResetFunctionStack(state);
  4557. if (player && player->IsPlayer()) {
  4558. Client* client = player->GetClient();
  4559. if (client) {
  4560. ((Player*)player)->DeleteSpellBook(type_selection);
  4561. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4562. if (outapp)
  4563. client->QueuePacket(outapp);
  4564. }
  4565. }
  4566. return 0;
  4567. }
  4568. int EQ2Emu_lua_SendNewAdventureSpells(lua_State* state) {
  4569. if (!lua_interface)
  4570. return 0;
  4571. Spawn* player = lua_interface->GetSpawn(state);
  4572. lua_interface->ResetFunctionStack(state);
  4573. if (player && player->IsPlayer()) {
  4574. Client* client = player->GetClient();
  4575. if (client) {
  4576. client->SendNewAdventureSpells();
  4577. }
  4578. }
  4579. return 0;
  4580. }
  4581. int EQ2Emu_lua_SendNewTradeskillSpells(lua_State* state) {
  4582. if (!lua_interface)
  4583. return 0;
  4584. Spawn* player = lua_interface->GetSpawn(state);
  4585. lua_interface->ResetFunctionStack(state);
  4586. if (player && player->IsPlayer()) {
  4587. Client* client = player->GetClient();
  4588. if (client) {
  4589. client->SendNewTradeskillSpells();
  4590. }
  4591. }
  4592. return 0;
  4593. }
  4594. int EQ2Emu_lua_RemoveSpellBookEntry(lua_State* state) {
  4595. if (!lua_interface)
  4596. return 0;
  4597. Spawn* player = lua_interface->GetSpawn(state);
  4598. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4599. lua_interface->ResetFunctionStack(state);
  4600. if (player && player->IsPlayer()) {
  4601. SpellBookEntry* sbe = ((Player*)player)->GetSpellBookSpell(spellid);
  4602. Client* client = player->GetClient();
  4603. if (sbe && client) {
  4604. ((Player*)player)->RemoveSpellBookEntry(spellid);
  4605. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4606. if (outapp)
  4607. client->QueuePacket(outapp);
  4608. }
  4609. }
  4610. return 0;
  4611. }
  4612. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4613. if (!lua_interface)
  4614. return 0;
  4615. Spawn* player = lua_interface->GetSpawn(state);
  4616. lua_interface->ResetFunctionStack(state);
  4617. if (player && player->IsPlayer()) {
  4618. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4619. return 1;
  4620. }
  4621. return 0;
  4622. }
  4623. int EQ2Emu_lua_Attack(lua_State* state) {
  4624. if (lua_interface) {
  4625. Spawn* npc = lua_interface->GetSpawn(state);
  4626. Spawn* player = lua_interface->GetSpawn(state, 2);
  4627. lua_interface->ResetFunctionStack(state);
  4628. if (npc && player && npc->IsNPC() && player->IsEntity())
  4629. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4630. }
  4631. return 0;
  4632. }
  4633. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4634. if (lua_interface) {
  4635. Spawn* target = lua_interface->GetSpawn(state);
  4636. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4637. lua_interface->ResetFunctionStack(state);
  4638. if (target && target->GetZone())
  4639. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4640. }
  4641. return 0;
  4642. }
  4643. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4644. Spawn* player;
  4645. if (lua_interface) {
  4646. player = lua_interface->GetSpawn(state);
  4647. lua_interface->ResetFunctionStack(state);
  4648. if (player && player->IsPlayer()) {
  4649. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4650. return 1;
  4651. }
  4652. }
  4653. return 0;
  4654. }
  4655. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4656. Spawn* player;
  4657. Client* client;
  4658. if (lua_interface) {
  4659. player = lua_interface->GetSpawn(state);
  4660. lua_interface->ResetFunctionStack(state);
  4661. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4662. if ((client = ((Player*)player)->GetClient()))
  4663. client->HandInCollections();
  4664. }
  4665. return 0;
  4666. }
  4667. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4668. Spawn* widget;
  4669. if (lua_interface) {
  4670. widget = lua_interface->GetSpawn(state);
  4671. lua_interface->ResetFunctionStack(state);
  4672. if (widget && widget->IsWidget())
  4673. ((Widget*)widget)->HandleUse(nullptr, "");
  4674. }
  4675. return 0;
  4676. }
  4677. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4678. Spawn* spawn = 0;
  4679. int32 primary_list = 0;
  4680. int32 secondary_list = 0;
  4681. if (lua_interface) {
  4682. spawn = lua_interface->GetSpawn(state);
  4683. primary_list = lua_interface->GetInt32Value(state, 2);
  4684. secondary_list = lua_interface->GetInt32Value(state, 3);
  4685. lua_interface->ResetFunctionStack(state);
  4686. if (!spawn->IsNPC()) {
  4687. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4688. return 0;
  4689. }
  4690. NPC* npc = (NPC*)spawn;
  4691. npc->SetPrimarySpellList(primary_list);
  4692. npc->SetSecondarySpellList(secondary_list);
  4693. npc->SetSpells(world.GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4694. }
  4695. return 0;
  4696. }
  4697. int EQ2Emu_lua_GetPet(lua_State* state) {
  4698. if (!lua_interface)
  4699. return 0;
  4700. Spawn* spawn = lua_interface->GetSpawn(state);
  4701. lua_interface->ResetFunctionStack(state);
  4702. if (spawn) {
  4703. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4704. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4705. return 1;
  4706. }
  4707. }
  4708. return 0;
  4709. }
  4710. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4711. if (!lua_interface)
  4712. return 0;
  4713. Spawn* spawn = lua_interface->GetSpawn(state);
  4714. lua_interface->ResetFunctionStack(state);
  4715. if (spawn) {
  4716. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4717. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4718. return 1;
  4719. }
  4720. }
  4721. return 0;
  4722. }
  4723. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4724. if (!lua_interface)
  4725. return 0;
  4726. Spawn* spawn = lua_interface->GetSpawn(state);
  4727. lua_interface->ResetFunctionStack(state);
  4728. if (spawn) {
  4729. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4730. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4731. return 1;
  4732. }
  4733. }
  4734. return 0;
  4735. }
  4736. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4737. if (!lua_interface)
  4738. return 0;
  4739. Spawn* spawn = lua_interface->GetSpawn(state);
  4740. lua_interface->ResetFunctionStack(state);
  4741. if (spawn) {
  4742. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4743. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4744. return 1;
  4745. }
  4746. }
  4747. return 0;
  4748. }
  4749. int EQ2Emu_lua_Charm(lua_State* state) {
  4750. if (!lua_interface)
  4751. return 0;
  4752. Spawn* owner = lua_interface->GetSpawn(state);
  4753. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4754. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4755. lua_interface->ResetFunctionStack(state);
  4756. if (!luaspell) {
  4757. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4758. return 0;
  4759. }
  4760. if(luaspell->resisted) {
  4761. return 0;
  4762. }
  4763. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4764. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4765. pet->SetPet(true);
  4766. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4767. ((NPC*)pet)->SetOwner((Entity*)owner);
  4768. // If owner is player and player does not have a summoned pet set the players charsheet
  4769. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4770. Player* player = (Player*)owner;
  4771. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4772. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4773. player->GetInfoStruct()->set_pet_movement(2);
  4774. player->GetInfoStruct()->set_pet_behavior(3);
  4775. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4776. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4777. // Make sure the values get sent to the client
  4778. player->SetCharSheetChanged(true);
  4779. }
  4780. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4781. pet->SetSpawnScript("");
  4782. // Set faction to the same as the owner
  4783. pet->SetFactionID(owner->GetFactionID());
  4784. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4785. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4786. // Clear hate list
  4787. ((NPC*)pet)->Brain()->ClearHate();
  4788. // Set the brain to a pet brain
  4789. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4790. }
  4791. return 0;
  4792. }
  4793. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4794. if (!lua_interface)
  4795. return 0;
  4796. Spawn* spawn = lua_interface->GetSpawn(state);
  4797. lua_interface->ResetFunctionStack(state);
  4798. if (!spawn) {
  4799. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4800. return 0;
  4801. }
  4802. vector<Spawn*> groupMembers;
  4803. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4804. groupMembers = *spawn->GetSpawnGroup();
  4805. }
  4806. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4807. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4808. deque<GroupMemberInfo*>::iterator itr;
  4809. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4810. if (group)
  4811. {
  4812. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4813. deque<GroupMemberInfo*>* members = group->GetMembers();
  4814. GroupMemberInfo* info = 0;
  4815. for (itr = members->begin(); itr != members->end(); itr++) {
  4816. info = *itr;
  4817. if (info->client)
  4818. groupMembers.push_back(info->client->GetPlayer());
  4819. }
  4820. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4821. }
  4822. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4823. }
  4824. else
  4825. return 0;
  4826. lua_createtable(state, groupMembers.size(), 0);
  4827. int newTable = lua_gettop(state);
  4828. for (int32 i = 0; i < groupMembers.size(); i++) {
  4829. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4830. lua_rawseti(state, newTable, i + 1);
  4831. }
  4832. return 1;
  4833. }
  4834. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4835. if (!lua_interface)
  4836. return 0;
  4837. lua_interface->ResetFunctionStack(state);
  4838. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4839. lua_interface->SetOptionWindowValue(state, option_window);
  4840. return 1;
  4841. }
  4842. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4843. if (!lua_interface)
  4844. return 0;
  4845. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4846. if (option_window) {
  4847. OptionWindowOption option_window_option;
  4848. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4849. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4850. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4851. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4852. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4853. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4854. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4855. option_window->push_back(option_window_option);
  4856. }
  4857. lua_interface->ResetFunctionStack(state);
  4858. return 0;
  4859. }
  4860. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4861. if (!lua_interface)
  4862. return 0;
  4863. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4864. Spawn* player = lua_interface->GetSpawn(state, 2);
  4865. string window_title = lua_interface->GetStringValue(state, 3);
  4866. string cancel_command = lua_interface->GetStringValue(state, 4);
  4867. lua_interface->ResetFunctionStack(state);
  4868. if (!player->IsPlayer()) {
  4869. lua_interface->LogError("%s: LUA SendOptionWindow command error: spawn is not a player", lua_interface->GetScriptName(state));
  4870. return 0;
  4871. }
  4872. Client* client = ((Player*)player)->GetClient();
  4873. if (option_window && window_title.length() > 0 && client) {
  4874. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4875. if (!packet)
  4876. return 0;
  4877. packet->setDataByName("title_text", window_title.c_str());
  4878. if (cancel_command.length() > 0)
  4879. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4880. packet->setArrayLengthByName("num_selections", option_window->size());
  4881. vector<OptionWindowOption>::iterator itr;
  4882. int8 i = 0;
  4883. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4884. OptionWindowOption opt = *itr;
  4885. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4886. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4887. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4888. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4889. if (opt.optionCommand.length() > 0)
  4890. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4891. if (opt.optionConfirmTitle.length() > 0)
  4892. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4893. i++;
  4894. }
  4895. client->QueuePacket(packet->serialize());
  4896. lua_interface->SetLuaUserDataStale(option_window);
  4897. safe_delete(option_window);
  4898. safe_delete(packet);
  4899. }
  4900. return 0;
  4901. }
  4902. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4903. if (!lua_interface)
  4904. return 0;
  4905. Spawn* spawn = lua_interface->GetSpawn(state);
  4906. lua_interface->ResetFunctionStack(state);
  4907. if (spawn) {
  4908. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4909. return 1;
  4910. }
  4911. else
  4912. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4913. return 0;
  4914. }
  4915. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4916. if (!lua_interface)
  4917. return 0;
  4918. Spawn* spawn = lua_interface->GetSpawn(state);
  4919. lua_interface->ResetFunctionStack(state);
  4920. if (spawn) {
  4921. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4922. return 1;
  4923. }
  4924. else
  4925. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4926. return 0;
  4927. }
  4928. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4929. if (!lua_interface)
  4930. return 0;
  4931. Spawn* spawn = lua_interface->GetSpawn(state);
  4932. lua_interface->ResetFunctionStack(state);
  4933. if (spawn) {
  4934. int8 class_id = spawn->GetTradeskillClass();
  4935. // Need to add 42 for the offset in the array
  4936. class_id += 44;
  4937. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4938. return 1;
  4939. }
  4940. else
  4941. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4942. return 0;
  4943. }
  4944. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4945. if (!lua_interface)
  4946. return 0;
  4947. Spawn* spawn = lua_interface->GetSpawn(state);
  4948. int16 level = lua_interface->GetInt8Value(state, 2);
  4949. lua_interface->ResetFunctionStack(state);
  4950. if (spawn) {
  4951. if (spawn->IsPlayer() && ((Player*)spawn)->GetClient())
  4952. ((Player*)spawn)->GetClient()->ChangeTSLevel(spawn->GetTSLevel(), level);
  4953. else
  4954. spawn->SetTSLevel(level);
  4955. }
  4956. else
  4957. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4958. return 0;
  4959. }
  4960. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4961. if (!lua_interface)
  4962. return 0;
  4963. Spawn* spawn = lua_interface->GetSpawn(state);
  4964. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4965. lua_interface->ResetFunctionStack(state);
  4966. if (spawn) {
  4967. spawn->SetAttackable(attackable);
  4968. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4969. }
  4970. return 0;
  4971. }
  4972. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4973. // Check to see if we have a valid lua_interface
  4974. if (!lua_interface)
  4975. return 0;
  4976. // Get the spawn that is getting the pet
  4977. Spawn* spawn = lua_interface->GetSpawn(state);
  4978. // Get the DB ID of the pet
  4979. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4980. // The max level the pet can gain
  4981. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4982. // Get the spell that this command was called from
  4983. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4984. lua_interface->ResetFunctionStack(state);
  4985. // Check to make sure the spawn pointer is valid
  4986. if (!spawn) {
  4987. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4988. return 0;
  4989. }
  4990. // Check to make sure the spawn is an entity
  4991. if (!spawn->IsEntity()) {
  4992. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4993. return 0;
  4994. }
  4995. // Check to make sure the spawn doesn't already have a pet of this type
  4996. if (((Entity*)spawn)->GetPet()) {
  4997. if (spawn->IsPlayer()) {
  4998. Client* client = ((Player*)spawn)->GetClient();
  4999. if (client)
  5000. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  5001. }
  5002. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5003. return 0;
  5004. }
  5005. // Check to see if the DB ID for the pet is set
  5006. if (pet_id == 0) {
  5007. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5008. return 0;
  5009. }
  5010. // Check to see if the pointer to the spell is valid
  5011. if (!luaspell) {
  5012. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5013. return 0;
  5014. }
  5015. if(luaspell->resisted) {
  5016. return 0;
  5017. }
  5018. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  5019. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5020. if (!pet) {
  5021. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5022. return 0;
  5023. }
  5024. // Check to make sure the pet is an npc
  5025. if (!pet->IsNPC()) {
  5026. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  5027. return 0;
  5028. }
  5029. // Spawn the pet at the same location as the owner
  5030. pet->SetX(spawn->GetX());
  5031. pet->SetY(spawn->GetY());
  5032. pet->SetZ(spawn->GetZ());
  5033. pet->SetLocation(spawn->GetLocation());
  5034. pet->SetHeading(spawn->GetHeading());
  5035. std::string petName = std::string("");
  5036. if(spawn->IsEntity()) {
  5037. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  5038. }
  5039. if(petName.size() < 1) {
  5040. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5041. petName = spawn->GetZone()->pet_names.at(rand_index);
  5042. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  5043. }
  5044. // If player set various values for the char sheet (pet window)
  5045. if (spawn->IsPlayer()) {
  5046. Player* player = (Player*)spawn;
  5047. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  5048. player->GetInfoStruct()->set_pet_name(petName);
  5049. player->GetInfoStruct()->set_pet_movement(2);
  5050. player->GetInfoStruct()->set_pet_behavior(3);
  5051. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  5052. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  5053. // Make sure the values get sent to the client
  5054. player->SetCharSheetChanged(true);
  5055. }
  5056. // Set the pets name
  5057. pet->SetName(petName.c_str());
  5058. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  5059. if (max_level > 0)
  5060. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  5061. else
  5062. pet->SetLevel(spawn->GetLevel());
  5063. // Set the max level this pet can reach
  5064. ((NPC*)pet)->SetMaxPetLevel(max_level);
  5065. ((NPC*)pet)->UpdateWeapons();
  5066. // Set the faction of the pet to the same faction as the owner
  5067. pet->SetFactionID(spawn->GetFactionID());
  5068. // Set the spawn as a pet
  5069. pet->SetPet(true);
  5070. // Give a pointer of the owner to the pet
  5071. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5072. // Give a pointer of the pet to the owner
  5073. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  5074. // Set the pet type
  5075. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  5076. // Set the spell id used to create this pet
  5077. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5078. // Set the spell tier used to create this pet
  5079. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5080. // Set the pets spawn type to 6
  5081. pet->SetSpawnType(6);
  5082. // Set the pets brain
  5083. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  5084. // Check to see if the pet has a subtitle
  5085. if (strlen(pet->GetSubTitle()) > 0) {
  5086. // Add the players name to the front of the sub title
  5087. string pet_subtitle;
  5088. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5089. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5090. // Set the pets subtitle to the new one
  5091. pet->SetSubTitle(pet_subtitle.c_str());
  5092. }
  5093. // Add the "Pet Options" entity command to the pet
  5094. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5095. const char* spawn_script = world.GetSpawnScript(pet_id);
  5096. bool runScript = false;
  5097. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  5098. runScript = true;
  5099. pet->SetSpawnScript(string(spawn_script));
  5100. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_PRESPAWN);
  5101. }
  5102. spawn->GetZone()->AddSpawn(pet);
  5103. if(runScript){
  5104. spawn->GetZone()->CallSpawnScript(pet, SPAWN_SCRIPT_SPAWN);
  5105. }
  5106. // Set the pet as the return value for this function
  5107. lua_interface->SetSpawnValue(state, pet);
  5108. return 1;
  5109. }
  5110. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  5111. if (!lua_interface)
  5112. return 0;
  5113. Spawn* spawn = lua_interface->GetSpawn(state);
  5114. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5115. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5116. lua_interface->ResetFunctionStack(state);
  5117. if (!spawn) {
  5118. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5119. return 0;
  5120. }
  5121. if (!spawn->IsEntity()) {
  5122. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5123. return 0;
  5124. }
  5125. if (((Entity*)spawn)->GetDeityPet()) {
  5126. if (spawn->IsPlayer()) {
  5127. Client* client = ((Player*)spawn)->GetClient();
  5128. if (client)
  5129. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  5130. }
  5131. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5132. return 0;
  5133. }
  5134. if (pet_id == 0) {
  5135. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5136. return 0;
  5137. }
  5138. if (!luaspell) {
  5139. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5140. return 0;
  5141. }
  5142. if(luaspell->resisted) {
  5143. return 0;
  5144. }
  5145. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5146. if (!pet) {
  5147. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5148. return 0;
  5149. }
  5150. if (!pet->IsNPC()) {
  5151. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5152. return 0;
  5153. }
  5154. pet->SetX(spawn->GetX());
  5155. pet->SetY(spawn->GetY());
  5156. pet->SetZ(spawn->GetZ());
  5157. pet->SetLocation(spawn->GetLocation());
  5158. pet->SetHeading(spawn->GetHeading());
  5159. spawn->GetZone()->AddSpawn(pet);
  5160. string random_pet_name;
  5161. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5162. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5163. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5164. pet->SetName(random_pet_name.c_str());
  5165. pet->SetLevel(spawn->GetLevel());
  5166. pet->SetFactionID(spawn->GetFactionID());
  5167. pet->SetPet(true);
  5168. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  5169. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5170. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  5171. pet->SetSpawnType(6);
  5172. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5173. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5174. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5175. if (strlen(pet->GetSubTitle()) > 0) {
  5176. string pet_subtitle;
  5177. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5178. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5179. pet->SetSubTitle(pet_subtitle.c_str());
  5180. }
  5181. // deity and cosmetic pets are not attackable
  5182. pet->SetAttackable(false);
  5183. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5184. lua_interface->SetSpawnValue(state, pet);
  5185. return 1;
  5186. }
  5187. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  5188. if (!lua_interface)
  5189. return 0;
  5190. Spawn* spawn = lua_interface->GetSpawn(state);
  5191. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  5192. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  5193. lua_interface->ResetFunctionStack(state);
  5194. if (!spawn) {
  5195. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  5196. return 0;
  5197. }
  5198. if (!spawn->IsEntity()) {
  5199. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  5200. return 0;
  5201. }
  5202. if (((Entity*)spawn)->GetCosmeticPet()) {
  5203. if (spawn->IsPlayer()) {
  5204. Client* client = ((Player*)spawn)->GetClient();
  5205. if (client)
  5206. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  5207. }
  5208. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  5209. return 0;
  5210. }
  5211. if (pet_id == 0) {
  5212. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  5213. return 0;
  5214. }
  5215. if (!luaspell) {
  5216. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  5217. return 0;
  5218. }
  5219. if(luaspell->resisted) {
  5220. return 0;
  5221. }
  5222. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  5223. if (!pet) {
  5224. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  5225. return 0;
  5226. }
  5227. if (!pet->IsNPC()) {
  5228. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  5229. return 0;
  5230. }
  5231. pet->SetX(spawn->GetX());
  5232. pet->SetY(spawn->GetY());
  5233. pet->SetZ(spawn->GetZ());
  5234. pet->SetLocation(spawn->GetLocation());
  5235. pet->SetHeading(spawn->GetHeading());
  5236. spawn->GetZone()->AddSpawn(pet);
  5237. string random_pet_name;
  5238. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  5239. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  5240. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  5241. pet->SetName(random_pet_name.c_str());
  5242. pet->SetLevel(spawn->GetLevel());
  5243. pet->SetFactionID(spawn->GetFactionID());
  5244. pet->SetPet(true);
  5245. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  5246. ((NPC*)pet)->SetOwner((Entity*)spawn);
  5247. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  5248. pet->SetSpawnType(6);
  5249. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  5250. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  5251. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  5252. if (strlen(pet->GetSubTitle()) > 0) {
  5253. string pet_subtitle;
  5254. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  5255. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  5256. pet->SetSubTitle(pet_subtitle.c_str());
  5257. }
  5258. pet->SetAttackable(false);
  5259. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5260. lua_interface->SetSpawnValue(state, pet);
  5261. return 1;
  5262. }
  5263. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5264. if (!lua_interface)
  5265. return 0;
  5266. Spawn* spawn = lua_interface->GetSpawn(state);
  5267. lua_interface->ResetFunctionStack(state);
  5268. if (!spawn) {
  5269. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5270. return 0;
  5271. }
  5272. if (!spawn->IsPet()) {
  5273. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5274. return 0;
  5275. }
  5276. if (!((NPC*)spawn)->IsDismissing() && ((NPC*)spawn)->GetOwner())
  5277. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5278. return 0;
  5279. }
  5280. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5281. if (!lua_interface)
  5282. return 0;
  5283. Quest* quest = lua_interface->GetQuest(state);
  5284. if (!quest) {
  5285. 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));
  5286. lua_interface->ResetFunctionStack(state);
  5287. return 0;
  5288. }
  5289. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5290. lua_interface->ResetFunctionStack(state);
  5291. if (feather_color > 0)
  5292. quest->SetFeatherColor(feather_color);
  5293. return 0;
  5294. }
  5295. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5296. if (!lua_interface)
  5297. return 0;
  5298. Spawn* spawn = lua_interface->GetSpawn(state);
  5299. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5300. lua_interface->ResetFunctionStack(state);
  5301. if (!spawn) {
  5302. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5303. return 0;
  5304. }
  5305. if (!spawn2) {
  5306. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5307. return 0;
  5308. }
  5309. spawn->RemoveSpawnAccess(spawn2);
  5310. return 0;
  5311. }
  5312. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5313. if (!lua_interface)
  5314. return 0;
  5315. ZoneServer* zone = lua_interface->GetZone(state);
  5316. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5317. lua_interface->ResetFunctionStack(state);
  5318. if (!zone) {
  5319. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5320. return 0;
  5321. }
  5322. if (location_id == 0) {
  5323. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5324. return 0;
  5325. }
  5326. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5327. if (!location) {
  5328. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5329. return 0;
  5330. }
  5331. Spawn* spawn = 0;
  5332. if (location->entities[0]) {
  5333. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5334. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5335. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5336. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5337. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5338. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5339. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5340. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5341. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5342. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5343. if(spawn && spawn->IsOmittedByDBFlag())
  5344. {
  5345. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5346. safe_delete(spawn);
  5347. spawn = 0;
  5348. return 0;
  5349. }
  5350. if (spawn) {
  5351. const char* script = 0;
  5352. for (int x = 0; x < 3; x++) {
  5353. switch (x) {
  5354. case 0:
  5355. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5356. break;
  5357. case 1:
  5358. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5359. break;
  5360. case 2:
  5361. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5362. break;
  5363. }
  5364. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5365. spawn->SetSpawnScript(string(script));
  5366. break;
  5367. }
  5368. }
  5369. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5370. lua_interface->SetSpawnValue(state, spawn);
  5371. return 1;
  5372. }
  5373. else {
  5374. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5375. safe_delete(spawn);
  5376. }
  5377. }
  5378. return 0;
  5379. }
  5380. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5381. if (!lua_interface)
  5382. return 0;
  5383. Spawn* caster = lua_interface->GetSpawn(state);
  5384. Spawn* target = lua_interface->GetSpawn(state, 2);
  5385. int32 id = lua_interface->GetInt32Value(state, 3);
  5386. string command = lua_interface->GetStringValue(state, 4);
  5387. lua_interface->ResetFunctionStack(state);
  5388. if (!caster) {
  5389. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5390. return 0;
  5391. }
  5392. if (!target) {
  5393. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5394. return 0;
  5395. }
  5396. if (!caster->IsPlayer()) {
  5397. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5398. return 0;
  5399. }
  5400. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5401. if (!entity_command) {
  5402. 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());
  5403. return 0;
  5404. }
  5405. Client* client = ((Player*)caster)->GetClient();
  5406. if (!client) {
  5407. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5408. return 0;
  5409. }
  5410. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5411. return 0;
  5412. }
  5413. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5414. if (!lua_interface)
  5415. return 0;
  5416. Spawn* spawn = lua_interface->GetSpawn(state);
  5417. lua_interface->ResetFunctionStack(state);
  5418. if (!spawn) {
  5419. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5420. return 0;
  5421. }
  5422. if (!spawn->IsNPC()) {
  5423. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5424. return 0;
  5425. }
  5426. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5427. return 0;
  5428. }
  5429. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5430. if (!lua_interface)
  5431. return 0;
  5432. Spawn* spawn = lua_interface->GetSpawn(state);
  5433. int16 tick = lua_interface->GetInt16Value(state, 2);
  5434. lua_interface->ResetFunctionStack(state);
  5435. if (!spawn) {
  5436. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5437. return 0;
  5438. }
  5439. if (!spawn->IsNPC()) {
  5440. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5441. return 0;
  5442. }
  5443. if (tick < 20) {
  5444. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5445. return 0;
  5446. }
  5447. ((NPC*)spawn)->Brain()->SetTick(tick);
  5448. return 0;
  5449. }
  5450. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5451. if (!lua_interface)
  5452. return 0;
  5453. Spawn* spawn = lua_interface->GetSpawn(state);
  5454. Spawn* target = lua_interface->GetSpawn(state, 2);
  5455. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5456. lua_interface->ResetFunctionStack(state);
  5457. if (!spawn) {
  5458. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5459. return 0;
  5460. }
  5461. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5462. spawn->SetFollowTarget(target, follow_distance);
  5463. return 0;
  5464. }
  5465. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5466. if (!lua_interface)
  5467. return 0;
  5468. Spawn* spawn = lua_interface->GetSpawn(state);
  5469. lua_interface->ResetFunctionStack(state);
  5470. if (!spawn) {
  5471. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5472. return 0;
  5473. }
  5474. Spawn* target = spawn->GetFollowTarget();
  5475. if (target) {
  5476. lua_interface->SetSpawnValue(state, target);
  5477. return 1;
  5478. }
  5479. return 0;
  5480. }
  5481. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5482. if (!lua_interface)
  5483. return 0;
  5484. Spawn* spawn = lua_interface->GetSpawn(state);
  5485. lua_interface->ResetFunctionStack(state);
  5486. if (!spawn) {
  5487. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5488. return 0;
  5489. }
  5490. if (spawn->following)
  5491. spawn->following = false;
  5492. else
  5493. spawn->following = true;
  5494. return 0;
  5495. }
  5496. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5497. if (!lua_interface)
  5498. return 0;
  5499. Spawn* spawn = lua_interface->GetSpawn(state);
  5500. lua_interface->ResetFunctionStack(state);
  5501. if (!spawn) {
  5502. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5503. return 0;
  5504. }
  5505. lua_interface->SetBooleanValue(state, spawn->following);
  5506. return 1;
  5507. }
  5508. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5509. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5510. // I will attempt to explain how this function works for future refrence
  5511. // Fist lets make sure lua_interface is valid, if not return out
  5512. if (!lua_interface)
  5513. return 0;
  5514. // Next we grab the first 2 params same as we usually would
  5515. Spawn* spawn = lua_interface->GetSpawn(state);
  5516. string var = lua_interface->GetStringValue(state, 2);
  5517. // 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
  5518. // 1 = Spawn
  5519. // 2 = Zone
  5520. // 3 = Item
  5521. // 4 = Quest
  5522. // 5 = String
  5523. // 6 = nil (null)
  5524. int8 dataType = 0;
  5525. // Define pointers for each potential type
  5526. Spawn* spawnVal = 0;
  5527. ZoneServer* zone = 0;
  5528. Item* item = 0;
  5529. Quest* quest = 0;
  5530. string val;
  5531. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5532. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5533. // options window are also light user data be we do not handle those.
  5534. // We check with lua_islightuserdata(lua_State*, index)
  5535. if (lua_islightuserdata(state, 3)) {
  5536. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5537. // and convert it to LUAUserData*
  5538. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5539. // Check to make sure the data we got is valid, if not give an error
  5540. if (!data || !data->IsCorrectlyInitialized()) {
  5541. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5542. }
  5543. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5544. else if (data->IsSpawn()) {
  5545. spawnVal = data->spawn;
  5546. dataType = 1;
  5547. }
  5548. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5549. else if (data->IsZone()) {
  5550. zone = data->zone;
  5551. dataType = 2;
  5552. }
  5553. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5554. else if (data->IsItem()) {
  5555. item = data->item;
  5556. dataType = 3;
  5557. }
  5558. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5559. else if (data->IsQuest()) {
  5560. quest = data->quest;
  5561. dataType = 4;
  5562. }
  5563. }
  5564. // Wasn't light user data, check if it is nil(null)
  5565. else if (lua_isnil(state, 3)) {
  5566. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5567. dataType = 6;
  5568. }
  5569. // Wasn't light user data or nil (null), must be a string
  5570. else {
  5571. // Set the string and dataType variable
  5572. val = lua_interface->GetStringValue(state, 3);
  5573. dataType = 5;
  5574. }
  5575. lua_interface->ResetFunctionStack(state);
  5576. // We now have all the params, lets check to make sure they are valid
  5577. if (!spawn) {
  5578. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5579. return 0;
  5580. }
  5581. if (var.length() == 0) {
  5582. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5583. return 0;
  5584. }
  5585. if (dataType == 0) {
  5586. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5587. return 0;
  5588. }
  5589. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5590. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5591. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5592. switch (dataType) {
  5593. case 1:
  5594. // 1 = Spawn
  5595. spawn->AddTempVariable(var, spawnVal);
  5596. break;
  5597. case 2:
  5598. // 2 = Zone
  5599. spawn->AddTempVariable(var, zone);
  5600. break;
  5601. case 3:
  5602. // 3 = Item
  5603. spawn->AddTempVariable(var, item);
  5604. break;
  5605. case 4:
  5606. // 4 = Quest
  5607. spawn->AddTempVariable(var, quest);
  5608. break;
  5609. case 5:
  5610. // 5 = String
  5611. spawn->AddTempVariable(var, val);
  5612. break;
  5613. case 6:
  5614. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5615. spawn->DeleteTempVariable(var);
  5616. break;
  5617. }
  5618. // And we are done so return out
  5619. return 0;
  5620. }
  5621. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5622. if (!lua_interface)
  5623. return 0;
  5624. Spawn* spawn = lua_interface->GetSpawn(state);
  5625. string var = lua_interface->GetStringValue(state, 2);
  5626. lua_interface->ResetFunctionStack(state);
  5627. if (!spawn) {
  5628. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5629. return 0;
  5630. }
  5631. if (var.length() == 0) {
  5632. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5633. return 0;
  5634. }
  5635. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5636. int8 type = spawn->GetTempVariableType(var);
  5637. Spawn* spawn2 = 0;
  5638. ZoneServer* zone = 0;
  5639. Item* item = 0;
  5640. Quest* quest = 0;
  5641. // Set the lua function return value based on the type of data the variable contains
  5642. switch (type) {
  5643. case 1:
  5644. spawn2 = spawn->GetTempVariableSpawn(var);
  5645. if (!spawn2)
  5646. return 0;
  5647. lua_interface->SetSpawnValue(state, spawn2);
  5648. break;
  5649. case 2:
  5650. zone = spawn->GetTempVariableZone(var);
  5651. if (!zone)
  5652. return 0;
  5653. lua_interface->SetZoneValue(state, zone);
  5654. break;
  5655. case 3:
  5656. item = spawn->GetTempVariableItem(var);
  5657. if (!item)
  5658. return 0;
  5659. lua_interface->SetItemValue(state, item);
  5660. break;
  5661. case 4:
  5662. quest = spawn->GetTempVariableQuest(var);
  5663. if (!quest)
  5664. return 0;
  5665. lua_interface->SetQuestValue(state, quest);
  5666. break;
  5667. case 5:
  5668. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5669. break;
  5670. default:
  5671. // Not a valid type then the variable was not set so return out
  5672. return 0;
  5673. }
  5674. // Return value was set so return out
  5675. return 1;
  5676. }
  5677. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5678. {
  5679. if (!lua_interface)
  5680. return 0;
  5681. Quest* quest = lua_interface->GetQuest(state);
  5682. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5683. string description = lua_interface->GetStringValue(state, 3);
  5684. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5685. if (!quest) {
  5686. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5687. lua_interface->ResetFunctionStack(state);
  5688. lua_interface->SetBooleanValue(state, false);
  5689. return 1;
  5690. }
  5691. if (!spawn) {
  5692. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5693. lua_interface->ResetFunctionStack(state);
  5694. lua_interface->SetBooleanValue(state, false);
  5695. return 1;
  5696. }
  5697. if (!spawn->IsPlayer()) {
  5698. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5699. lua_interface->ResetFunctionStack(state);
  5700. lua_interface->SetBooleanValue(state, false);
  5701. return 1;
  5702. }
  5703. if (item_id == 0) {
  5704. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5705. lua_interface->ResetFunctionStack(state);
  5706. lua_interface->SetBooleanValue(state, false);
  5707. return 1;
  5708. }
  5709. Client* client = ((Player*)spawn)->GetClient();
  5710. if (!client) {
  5711. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given player spawn", lua_interface->GetScriptName(state));
  5712. lua_interface->ResetFunctionStack(state);
  5713. lua_interface->SetBooleanValue(state, false);
  5714. return 1;
  5715. }
  5716. Item* item = master_item_list.GetItem(item_id);
  5717. if (!item) {
  5718. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5719. lua_interface->ResetFunctionStack(state);
  5720. lua_interface->SetBooleanValue(state, false);
  5721. return 1;
  5722. }
  5723. Item* firstItem = new Item(item);
  5724. quest->AddTmpRewardItem(firstItem);
  5725. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5726. bool itemsAddedSuccessfully = true;
  5727. if(num_args > 4)
  5728. {
  5729. for(int8 n=5;n<num_args+1;n++)
  5730. {
  5731. int32 new_item = lua_interface->GetInt32Value(state, n);
  5732. Item* tmpItem = master_item_list.GetItem(new_item);
  5733. if(tmpItem)
  5734. {
  5735. Item* newTmpItem = new Item(tmpItem);
  5736. quest->AddTmpRewardItem(newTmpItem);
  5737. }
  5738. else
  5739. itemsAddedSuccessfully = false;
  5740. }
  5741. }
  5742. client->AddPendingQuestReward(quest, true, true, description); // queue for display
  5743. lua_interface->ResetFunctionStack(state);
  5744. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5745. return 1;
  5746. }
  5747. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5748. if (!lua_interface)
  5749. return 0;
  5750. Quest* quest = lua_interface->GetQuest(state);
  5751. lua_interface->ResetFunctionStack(state);
  5752. if (!quest) {
  5753. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5754. return 0;
  5755. }
  5756. quest->SetRepeatable(true);
  5757. return 0;
  5758. }
  5759. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5760. if (!lua_interface)
  5761. return 0;
  5762. Spawn* spawn = lua_interface->GetSpawn(state);
  5763. lua_interface->ResetFunctionStack(state);
  5764. if (!spawn) {
  5765. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5766. return 0;
  5767. }
  5768. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5769. string ret = classes.GetClassNameCase(base_class);
  5770. if (ret.length() > 0) {
  5771. lua_interface->SetStringValue(state, ret.c_str());
  5772. return 1;
  5773. }
  5774. return 0;
  5775. }
  5776. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5777. if (!lua_interface)
  5778. return 0;
  5779. Spawn* player = lua_interface->GetSpawn(state);
  5780. lua_interface->ResetFunctionStack(state);
  5781. if (player && player->IsPlayer()) {
  5782. Client* client = player->GetClient();
  5783. if (client)
  5784. client->SendWaypoints();
  5785. }
  5786. return 0;
  5787. }
  5788. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5789. if (!lua_interface)
  5790. return 0;
  5791. Spawn* player = lua_interface->GetSpawn(state);
  5792. string name = lua_interface->GetStringValue(state, 2);
  5793. int32 type = lua_interface->GetInt32Value(state, 3);
  5794. lua_interface->ResetFunctionStack(state);
  5795. if (type == 0)
  5796. type = 2;
  5797. if (name.length() > 0) {
  5798. if (player && player->IsPlayer()) {
  5799. Client* client = player->GetClient();
  5800. if (client)
  5801. client->AddWaypoint(name, type);
  5802. }
  5803. }
  5804. return 0;
  5805. }
  5806. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5807. if (!lua_interface)
  5808. return 0;
  5809. Spawn* player = lua_interface->GetSpawn(state);
  5810. string name = lua_interface->GetStringValue(state, 2);
  5811. lua_interface->ResetFunctionStack(state);
  5812. if (name.length() > 0) {
  5813. if (player && player->IsPlayer()) {
  5814. Client* client = player->GetClient();
  5815. if (client)
  5816. client->RemoveWaypoint(name);
  5817. }
  5818. }
  5819. return 0;
  5820. }
  5821. int EQ2Emu_lua_AddWard(lua_State* state) {
  5822. if (!lua_interface)
  5823. return 0;
  5824. int32 damage = lua_interface->GetInt32Value(state);
  5825. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5826. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5827. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5828. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5829. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5830. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5831. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5832. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5833. lua_interface->ResetFunctionStack(state);
  5834. if(!spell || spell->resisted) {
  5835. return 0;
  5836. }
  5837. bool ward_was_added = false;
  5838. ZoneServer* zone = spell->caster->GetZone();
  5839. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5840. for (int32 i = 0; i < spell->targets.size(); i++) {
  5841. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5842. if (!target)
  5843. continue;
  5844. if (target->IsEntity()) {
  5845. // If the ward is already active remove it
  5846. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5847. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5848. // Create new ward info
  5849. WardInfo* ward = new WardInfo;
  5850. ward->Spell = spell;
  5851. ward->BaseDamage = damage;
  5852. ward->DamageLeft = damage;
  5853. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5854. ward->keepWard = keepWard;
  5855. ward->WardType = wardType;
  5856. if (damageAbsorptionPercent > 100)
  5857. damageAbsorptionPercent = 100;
  5858. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5859. if (damageAbsorptionMaxHealthPercent > 100)
  5860. damageAbsorptionMaxHealthPercent = 100;
  5861. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5862. ward->RedirectDamagePercent = redirectDamagePercent;
  5863. ward->LastRedirectDamage = 0;
  5864. ward->LastAbsorbedDamage = 0;
  5865. ward->HitCount = 0;
  5866. spell->num_triggers = maxHitCount;
  5867. spell->had_triggers = true;
  5868. spell->cancel_after_all_triggers = false;
  5869. ward->MaxHitCount = maxHitCount;
  5870. ward->RoundTriggered = false;
  5871. if (wardType == WARD_TYPE_MAGICAL)
  5872. ward->DamageType = damageTypes;
  5873. // Add the ward to the entity
  5874. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5875. ward_was_added = true;
  5876. }
  5877. }
  5878. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5879. if (ward_was_added && spell->caster->IsPlayer()) {
  5880. spell->had_dmg_remaining = true;
  5881. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, damage, 1);
  5882. }
  5883. return 0;
  5884. }
  5885. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5886. if (!lua_interface)
  5887. return 0;
  5888. int32 amount = lua_interface->GetInt32Value(state);
  5889. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5890. lua_interface->ResetFunctionStack(state);
  5891. WardInfo* ward = 0;
  5892. if(!spell || spell->resisted) {
  5893. return 0;
  5894. }
  5895. ZoneServer* zone = spell->caster->GetZone();
  5896. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5897. if (spell->targets.size() > 0 && zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5898. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5899. ward = target->GetWard(spell->spell->GetSpellID());
  5900. if (target && ward) {
  5901. ward->DamageLeft += amount;
  5902. if (ward->DamageLeft > ward->BaseDamage)
  5903. ward->DamageLeft = ward->BaseDamage;
  5904. for (int32 i = 0; i < spell->targets.size(); i++) {
  5905. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5906. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5907. }
  5908. }
  5909. }
  5910. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5911. if (ward && spell->caster->IsPlayer())
  5912. ClientPacketFunctions::SendMaintainedExamineUpdate(((Player*)spell->caster)->GetClient(), spell->slot_pos, ward->DamageLeft, 1);
  5913. return 0;
  5914. }
  5915. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5916. if (!lua_interface)
  5917. return 0;
  5918. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5919. lua_interface->ResetFunctionStack(state);
  5920. if (!spell) {
  5921. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5922. return 0;
  5923. }
  5924. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5925. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5926. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5927. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5928. if (ward) {
  5929. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5930. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5931. return 1;
  5932. }
  5933. }
  5934. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5935. return 0;
  5936. }
  5937. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5938. if (!lua_interface)
  5939. return 0;
  5940. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5941. if (!spell) {
  5942. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5943. lua_interface->ResetFunctionStack(state);
  5944. return 0;
  5945. }
  5946. string type = lua_interface->GetStringValue(state, 2);
  5947. lua_interface->ResetFunctionStack(state);
  5948. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5949. if (spell->caster && spell->caster->GetZone() && spell->targets.size() > 0 && spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5950. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5951. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5952. if (ward) {
  5953. if (boost::iequals(type, "damageleft"))
  5954. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5955. else if (boost::iequals(type, "basedamage"))
  5956. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5957. else if (boost::iequals(type, "keepward"))
  5958. lua_interface->SetBooleanValue(state, ward->keepWard);
  5959. else if (boost::iequals(type, "wardtype"))
  5960. lua_interface->SetInt32Value(state, ward->WardType);
  5961. else if (boost::iequals(type, "dmgabsorptionpct"))
  5962. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5963. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5964. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5965. else if (boost::iequals(type, "redirectdamagepercent"))
  5966. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5967. else if (boost::iequals(type, "lastredirectdamage"))
  5968. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5969. else if (boost::iequals(type, "lastabsorbeddamage"))
  5970. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5971. else if (boost::iequals(type, "hitcount"))
  5972. lua_interface->SetInt32Value(state, ward->HitCount);
  5973. else if (boost::iequals(type, "maxhitcount"))
  5974. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5975. else
  5976. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5977. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5978. return 1;
  5979. }
  5980. }
  5981. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5982. return 0;
  5983. }
  5984. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5985. if (!lua_interface)
  5986. return 0;
  5987. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5988. lua_interface->ResetFunctionStack(state);
  5989. if(!spell) {
  5990. return 0;
  5991. }
  5992. ZoneServer* zone = spell->caster->GetZone();
  5993. Spawn* target = 0;
  5994. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5995. for (int32 i = 0; i < spell->targets.size(); i++) {
  5996. target = zone->GetSpawnByID(spell->targets.at(i));
  5997. if (target && target->IsEntity()) {
  5998. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5999. }
  6000. }
  6001. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6002. return 0;
  6003. }
  6004. int EQ2Emu_lua_Interrupt(lua_State* state)
  6005. {
  6006. if (!lua_interface)
  6007. return 0;
  6008. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  6009. Spawn* target = lua_interface->GetSpawn(state, 2);
  6010. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6011. lua_interface->ResetFunctionStack(state);
  6012. if (!caster)
  6013. {
  6014. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  6015. return 0;
  6016. }
  6017. if (!target)
  6018. {
  6019. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  6020. return 0;
  6021. }
  6022. if (!spell) {
  6023. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  6024. return 0;
  6025. }
  6026. if (!target->IsEntity() && !spell)
  6027. {
  6028. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  6029. return 0;
  6030. }
  6031. if (!target && spell) {
  6032. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6033. for (int8 i = 0; i < spell->targets.size(); i++) {
  6034. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  6035. if (!target || !target->IsEntity())
  6036. continue;
  6037. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  6038. }
  6039. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6040. }
  6041. else
  6042. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  6043. return 0;
  6044. }
  6045. int EQ2Emu_lua_Stealth(lua_State* state) {
  6046. if (!lua_interface)
  6047. return 0;
  6048. int8 type = lua_interface->GetInt8Value(state);
  6049. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  6050. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  6051. lua_interface->ResetFunctionStack(state);
  6052. if (!spell) {
  6053. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  6054. return 0;
  6055. }
  6056. ZoneServer* zone = spell->caster->GetZone();
  6057. if (spawn) {
  6058. if (spawn->IsEntity()) {
  6059. if (type == 1) {
  6060. ((Entity*)spawn)->AddStealthSpell(spell);
  6061. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  6062. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  6063. }
  6064. else if (type == 2) {
  6065. ((Entity*)spawn)->AddInvisSpell(spell);
  6066. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  6067. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  6068. }
  6069. return 0;
  6070. }
  6071. else {
  6072. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  6073. return 0;
  6074. }
  6075. }
  6076. else {
  6077. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  6078. for (int32 i = 0; i < spell->targets.size(); i++) {
  6079. spawn = zone->GetSpawnByID(spell->targets.at(i));
  6080. if (!spawn || !spawn->IsEntity())
  6081. continue;
  6082. if (type == 1) {
  6083. ((Entity*)spawn)->AddStealthSpell(spell);
  6084. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  6085. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  6086. }
  6087. else if (type == 2) {
  6088. ((Entity*)spawn)->AddInvisSpell(spell);
  6089. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  6090. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  6091. }
  6092. else {
  6093. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  6094. break;
  6095. }
  6096. }
  6097. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  6098. }
  6099. return 0;
  6100. }
  6101. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  6102. if (!lua_interface)
  6103. return 0;
  6104. Spawn* spawn = lua_interface->GetSpawn(state);
  6105. lua_interface->ResetFunctionStack(state);
  6106. if (!spawn) {
  6107. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6108. return 0;
  6109. }
  6110. if (spawn->IsEntity()) {
  6111. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  6112. return 1;
  6113. }
  6114. else
  6115. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  6116. return 0;
  6117. }
  6118. int EQ2Emu_lua_IsInvis(lua_State* state) {
  6119. if (!lua_interface)
  6120. return 0;
  6121. Spawn* spawn = lua_interface->GetSpawn(state);
  6122. lua_interface->ResetFunctionStack(state);
  6123. if (!spawn) {
  6124. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  6125. return 0;
  6126. }
  6127. if (spawn->IsEntity()) {
  6128. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  6129. return 1;
  6130. }
  6131. else
  6132. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  6133. return 0;
  6134. }
  6135. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  6136. if (!lua_interface)
  6137. return 0;
  6138. Spawn* player = lua_interface->GetSpawn(state);
  6139. int32 item_id = lua_interface->GetInt32Value(state, 2);
  6140. lua_interface->ResetFunctionStack(state);
  6141. if (!player->IsPlayer()) {
  6142. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  6143. return 0;
  6144. }
  6145. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  6146. return 1;
  6147. }
  6148. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  6149. if (!lua_interface)
  6150. return 0;
  6151. Spawn* spawn = lua_interface->GetSpawn(state);
  6152. int8 slot = lua_interface->GetInt8Value(state, 2);
  6153. lua_interface->ResetFunctionStack(state);
  6154. if (!spawn) {
  6155. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6156. return 0;
  6157. }
  6158. if (!spawn->IsEntity()) {
  6159. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6160. return 0;
  6161. }
  6162. Item* item = ((Entity*)spawn)->GetEquipmentList()->GetItem(slot);
  6163. if (!item) {
  6164. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  6165. return 0;
  6166. }
  6167. lua_interface->SetItemValue(state, item);
  6168. return 1;
  6169. }
  6170. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  6171. if (!lua_interface)
  6172. return 0;
  6173. Spawn* player = lua_interface->GetSpawn(state);
  6174. int32 id = lua_interface->GetInt32Value(state, 2);
  6175. lua_interface->ResetFunctionStack(state);
  6176. if (!player) {
  6177. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6178. return 0;
  6179. }
  6180. if (!player->IsPlayer()) {
  6181. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6182. return 0;
  6183. }
  6184. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  6185. if (!item) {
  6186. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  6187. return 0;
  6188. }
  6189. lua_interface->SetItemValue(state, item);
  6190. return 1;
  6191. }
  6192. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  6193. if (!lua_interface)
  6194. return 0;
  6195. Spawn* spawn = lua_interface->GetSpawn(state);
  6196. int8 slot = lua_interface->GetInt8Value(state, 2);
  6197. int32 item_id = lua_interface->GetInt32Value(state, 3);
  6198. lua_interface->ResetFunctionStack(state);
  6199. if (!spawn) {
  6200. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6201. return 0;
  6202. }
  6203. if (!spawn->IsEntity()) {
  6204. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6205. return 0;
  6206. }
  6207. Item* item = master_item_list.GetItem(item_id);
  6208. if (!item) {
  6209. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  6210. return 0;
  6211. }
  6212. Item* copy = new Item(item);
  6213. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  6214. if(result)
  6215. {
  6216. ((Entity*)spawn)->SetEquipment(copy, slot);
  6217. spawn->vis_changed = true;
  6218. if(spawn->IsPlayer())
  6219. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6220. }
  6221. else
  6222. {
  6223. safe_delete(copy);
  6224. }
  6225. lua_interface->SetBooleanValue(state, result);
  6226. return 1;
  6227. }
  6228. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  6229. if (!lua_interface)
  6230. return 0;
  6231. Spawn* spawn = lua_interface->GetSpawn(state);
  6232. int8 slot = lua_interface->GetInt8Value(state, 2);
  6233. Item* item = lua_interface->GetItem(state, 3);
  6234. lua_interface->ResetFunctionStack(state);
  6235. if (!spawn) {
  6236. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  6237. return 0;
  6238. }
  6239. if (!spawn->IsEntity()) {
  6240. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6241. return 0;
  6242. }
  6243. if (!item) {
  6244. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  6245. return 0;
  6246. }
  6247. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  6248. if(result)
  6249. {
  6250. ((Entity*)spawn)->SetEquipment(item, slot);
  6251. spawn->vis_changed = true;
  6252. if(spawn->IsPlayer())
  6253. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6254. }
  6255. lua_interface->SetBooleanValue(state, result);
  6256. return 1;
  6257. }
  6258. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  6259. if (!lua_interface)
  6260. return 0;
  6261. Spawn* spawn = lua_interface->GetSpawn(state);
  6262. int8 slot = lua_interface->GetInt8Value(state, 2);
  6263. 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
  6264. lua_interface->ResetFunctionStack(state);
  6265. if (!spawn) {
  6266. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  6267. return 0;
  6268. }
  6269. if (!spawn->IsEntity()) {
  6270. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6271. return 0;
  6272. }
  6273. if(slot >= NUM_SLOTS) {
  6274. lua_interface->LogError("%s: LUA UnequipSlot command error: wrong slot id given %u, max %u", lua_interface->GetScriptName(state), slot, NUM_SLOTS);
  6275. return 0;
  6276. }
  6277. if(spawn->IsPlayer() && ((Player*)spawn)->GetClient()) {
  6278. Item* item = ((Player*)spawn)->GetEquipmentList()->GetItem(slot);
  6279. if(item) {
  6280. item->save_needed = true;
  6281. if(no_delete_item) {
  6282. database.DeleteItem(((Player*)spawn)->GetClient()->GetCharacterID(), item, 0);
  6283. ((Player*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6284. }
  6285. else{
  6286. Client* client = ((Player*)spawn)->GetClient();
  6287. client->UnequipItem(item->details.index);
  6288. }
  6289. }
  6290. }
  6291. else
  6292. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  6293. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  6294. spawn->vis_changed = true;
  6295. if(spawn->IsPlayer())
  6296. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  6297. lua_interface->SetBooleanValue(state, true);
  6298. return 1;
  6299. }
  6300. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  6301. if (!lua_interface)
  6302. return 0;
  6303. Spawn* spawn = lua_interface->GetSpawn(state);
  6304. int8 slot = lua_interface->GetInt8Value(state, 2);
  6305. int16 type = lua_interface->GetInt16Value(state, 3);
  6306. int8 r = lua_interface->GetInt8Value(state, 4);
  6307. int8 g = lua_interface->GetInt8Value(state, 5);
  6308. int8 b = lua_interface->GetInt8Value(state, 6);
  6309. int8 h_r = lua_interface->GetInt8Value(state, 7);
  6310. int8 h_g = lua_interface->GetInt8Value(state, 8);
  6311. int8 h_b = lua_interface->GetInt8Value(state, 9);
  6312. lua_interface->ResetFunctionStack(state);
  6313. if (!spawn) {
  6314. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  6315. return 0;
  6316. }
  6317. if (!spawn->IsEntity()) {
  6318. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6319. return 0;
  6320. }
  6321. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6322. spawn->vis_changed = true;
  6323. lua_interface->SetBooleanValue(state, true);
  6324. return 1;
  6325. }
  6326. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6327. if (!lua_interface)
  6328. return 0;
  6329. Spawn* player = lua_interface->GetSpawn(state);
  6330. int32 id = lua_interface->GetInt32Value(state, 2);
  6331. int8 count = lua_interface->GetInt8Value(state, 3);
  6332. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6333. lua_interface->ResetFunctionStack(state);
  6334. if (!player) {
  6335. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6336. return 0;
  6337. }
  6338. if (!player->IsPlayer()) {
  6339. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6340. return 0;
  6341. }
  6342. if (!count)
  6343. count = 1;
  6344. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6345. if (!item) {
  6346. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6347. return 0;
  6348. }
  6349. lua_interface->SetItemValue(state, item);
  6350. return 1;
  6351. }
  6352. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6353. if (!lua_interface)
  6354. return 0;
  6355. Spawn* spawn = lua_interface->GetSpawn(state);
  6356. int32 anim = lua_interface->GetInt32Value(state, 2);
  6357. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6358. int8 type = lua_interface->GetInt8Value(state, 4);
  6359. lua_interface->ResetFunctionStack(state);
  6360. if (!spawn) {
  6361. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6362. return 0;
  6363. }
  6364. if (spawn2) {
  6365. if (spawn2->IsPlayer()) {
  6366. if (type != 1 && type != 2)
  6367. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6368. else
  6369. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6370. return 0;
  6371. }
  6372. else {
  6373. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6374. return 0;
  6375. }
  6376. }
  6377. else
  6378. spawn->GetZone()->PlayAnimation(spawn, anim);
  6379. return 0;
  6380. }
  6381. int EQ2Emu_lua_IsPet(lua_State* state) {
  6382. if (!lua_interface)
  6383. return 0;
  6384. Spawn* spawn = lua_interface->GetSpawn(state);
  6385. lua_interface->ResetFunctionStack(state);
  6386. if (!spawn) {
  6387. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6388. return 0;
  6389. }
  6390. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6391. return 1;
  6392. }
  6393. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6394. if (!lua_interface)
  6395. return 0;
  6396. Spawn* spawn = lua_interface->GetSpawn(state);
  6397. lua_interface->ResetFunctionStack(state);
  6398. if (!spawn) {
  6399. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6400. return 0;
  6401. }
  6402. if (!spawn->IsNPC()) {
  6403. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6404. return 0;
  6405. }
  6406. if (((NPC*)spawn)->GetOwner()) {
  6407. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6408. return 1;
  6409. }
  6410. return 0;
  6411. }
  6412. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6413. if (!lua_interface)
  6414. return 0;
  6415. Spawn* spawn = lua_interface->GetSpawn(state);
  6416. Spawn* target = lua_interface->GetSpawn(state, 2);
  6417. lua_interface->ResetFunctionStack(state);
  6418. if (!spawn) {
  6419. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6420. return 0;
  6421. }
  6422. if (!spawn) {
  6423. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6424. return 0;
  6425. }
  6426. spawn->SetTarget(target);
  6427. return 0;
  6428. }
  6429. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6430. if (!lua_interface)
  6431. return 0;
  6432. Spawn* spawn = lua_interface->GetSpawn(state);
  6433. bool val = lua_interface->GetBooleanValue(state, 2);
  6434. lua_interface->ResetFunctionStack(state);
  6435. if (!spawn) {
  6436. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6437. return 0;
  6438. }
  6439. if (!spawn->IsEntity()) {
  6440. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6441. return 0;
  6442. }
  6443. ((Entity*)spawn)->InCombat(val);
  6444. if (val) {
  6445. spawn->ClearRunningLocations();
  6446. spawn->CalculateRunningLocation(true);
  6447. }
  6448. return 0;
  6449. }
  6450. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6451. if (!lua_interface)
  6452. return 0;
  6453. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6454. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6455. lua_interface->ResetFunctionStack(state);
  6456. if (!spawn1) {
  6457. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6458. return 0;
  6459. }
  6460. if (!spawn2) {
  6461. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6462. return 0;
  6463. }
  6464. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6465. return 1;
  6466. }
  6467. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6468. if (!lua_interface)
  6469. return 0;
  6470. Spawn* spawn = lua_interface->GetSpawn(state);
  6471. lua_interface->ResetFunctionStack(state);
  6472. if (!spawn) {
  6473. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6474. return 0;
  6475. }
  6476. if (!spawn->IsNPC()) {
  6477. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6478. return 0;
  6479. }
  6480. ((NPC*)spawn)->ClearRunback();
  6481. return 0;
  6482. }
  6483. int EQ2Emu_lua_Runback(lua_State* state) {
  6484. if (!lua_interface)
  6485. return 0;
  6486. Spawn* spawn = lua_interface->GetSpawn(state);
  6487. lua_interface->ResetFunctionStack(state);
  6488. if (!spawn) {
  6489. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6490. return 0;
  6491. }
  6492. if (!spawn->IsNPC()) {
  6493. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6494. return 0;
  6495. }
  6496. ((NPC*)spawn)->Runback();
  6497. return 0;
  6498. }
  6499. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6500. if (!lua_interface)
  6501. return 0;
  6502. Spawn* spawn = lua_interface->GetSpawn(state);
  6503. lua_interface->ResetFunctionStack(state);
  6504. if (!spawn) {
  6505. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6506. return 0;
  6507. }
  6508. if (!spawn->IsNPC()) {
  6509. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6510. return 0;
  6511. }
  6512. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6513. return 1;
  6514. }
  6515. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6516. if (!lua_interface)
  6517. return 0;
  6518. Spawn* spawn = lua_interface->GetSpawn(state);
  6519. lua_interface->ResetFunctionStack(state);
  6520. if (!spawn) {
  6521. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6522. return 0;
  6523. }
  6524. if (!spawn->IsEntity()) {
  6525. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6526. return 0;
  6527. }
  6528. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6529. return 1;
  6530. }
  6531. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6532. if (!lua_interface)
  6533. return 0;
  6534. Spawn* spawn = lua_interface->GetSpawn(state);
  6535. lua_interface->ResetFunctionStack(state);
  6536. if (!spawn) {
  6537. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6538. return 0;
  6539. }
  6540. if (!spawn->IsEntity()) {
  6541. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6542. return 0;
  6543. }
  6544. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6545. return 1;
  6546. }
  6547. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6548. if (!lua_interface)
  6549. return 0;
  6550. Spawn* spawn = lua_interface->GetSpawn(state);
  6551. lua_interface->ResetFunctionStack(state);
  6552. if (!spawn) {
  6553. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6554. return 0;
  6555. }
  6556. if (!spawn->IsEntity()) {
  6557. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6558. return 0;
  6559. }
  6560. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6561. return 1;
  6562. }
  6563. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6564. if (!lua_interface)
  6565. return 0;
  6566. Spawn* spawn = lua_interface->GetSpawn(state);
  6567. lua_interface->ResetFunctionStack(state);
  6568. if (!spawn) {
  6569. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6570. return 0;
  6571. }
  6572. if (!spawn->IsEntity()) {
  6573. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6574. return 0;
  6575. }
  6576. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6577. return 1;
  6578. }
  6579. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6580. if (!lua_interface)
  6581. return 0;
  6582. Spawn* spawn = lua_interface->GetSpawn(state);
  6583. Spawn* target = lua_interface->GetSpawn(state, 2);
  6584. float distance = lua_interface->GetFloatValue(state, 3);
  6585. lua_interface->ResetFunctionStack(state);
  6586. if (!spawn) {
  6587. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6588. return 0;
  6589. }
  6590. if (!target) {
  6591. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6592. return 0;
  6593. }
  6594. if (!spawn->IsNPC()) {
  6595. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6596. return 0;
  6597. }
  6598. if (!target->IsEntity()) {
  6599. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6600. return 0;
  6601. }
  6602. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6603. return 1;
  6604. }
  6605. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6606. if (!lua_interface)
  6607. return 0;
  6608. Spawn* spawn = lua_interface->GetSpawn(state);
  6609. Spawn* target = lua_interface->GetSpawn(state, 2);
  6610. float distance = lua_interface->GetFloatValue(state, 3);
  6611. lua_interface->ResetFunctionStack(state);
  6612. if (!spawn) {
  6613. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6614. return 0;
  6615. }
  6616. if (!target) {
  6617. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6618. return 0;
  6619. }
  6620. if (!spawn->IsNPC()) {
  6621. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6622. return 0;
  6623. }
  6624. if (!target->IsEntity()) {
  6625. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6626. return 0;
  6627. }
  6628. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6629. return 0;
  6630. }
  6631. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6632. if (!lua_interface)
  6633. return 0;
  6634. Spawn* spawn = lua_interface->GetSpawn(state);
  6635. lua_interface->ResetFunctionStack(state);
  6636. if (!spawn) {
  6637. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6638. return 0;
  6639. }
  6640. if (!spawn->IsNPC()) {
  6641. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6642. return 0;
  6643. }
  6644. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6645. return 1;
  6646. }
  6647. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6648. if (!lua_interface)
  6649. return 0;
  6650. Spawn* spawn = lua_interface->GetSpawn(state);
  6651. lua_interface->ResetFunctionStack(state);
  6652. if (!spawn) {
  6653. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6654. return 0;
  6655. }
  6656. if (!spawn->IsNPC()) {
  6657. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6658. return 0;
  6659. }
  6660. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6661. return 1;
  6662. }
  6663. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6664. if (!lua_interface)
  6665. return 0;
  6666. Spawn* spawn = lua_interface->GetSpawn(state);
  6667. lua_interface->ResetFunctionStack(state);
  6668. if (!spawn) {
  6669. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6670. return 0;
  6671. }
  6672. if (!spawn->IsNPC()) {
  6673. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6674. return 0;
  6675. }
  6676. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6677. if (hated) {
  6678. lua_interface->SetSpawnValue(state, hated);
  6679. return 1;
  6680. }
  6681. return 0;
  6682. }
  6683. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6684. if (!lua_interface)
  6685. return 0;
  6686. Spawn* spawn = lua_interface->GetSpawn(state);
  6687. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6688. lua_interface->ResetFunctionStack(state);
  6689. if (!spawn) {
  6690. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6691. return 0;
  6692. }
  6693. if (!spawn->IsNPC()) {
  6694. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6695. return 0;
  6696. }
  6697. if (!hated) {
  6698. ((NPC*)spawn)->Brain()->ClearHate();
  6699. return 0;
  6700. }
  6701. else
  6702. {
  6703. if (!hated->IsEntity()) {
  6704. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6705. return 0;
  6706. }
  6707. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6708. return 0;
  6709. }
  6710. return 0;
  6711. }
  6712. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6713. if (!lua_interface)
  6714. return 0;
  6715. Spawn* spawn = lua_interface->GetSpawn(state);
  6716. lua_interface->ResetFunctionStack(state);
  6717. if (!spawn) {
  6718. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6719. return 0;
  6720. }
  6721. if (!spawn->IsNPC()) {
  6722. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6723. return 0;
  6724. }
  6725. ((NPC*)spawn)->Brain()->ClearEncounter();
  6726. return 0;
  6727. }
  6728. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6729. if (!lua_interface)
  6730. return 0;
  6731. Spawn* spawn = lua_interface->GetSpawn(state);
  6732. lua_interface->ResetFunctionStack(state);
  6733. if (!spawn) {
  6734. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6735. return 0;
  6736. }
  6737. if (!spawn->IsNPC()) {
  6738. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6739. return 0;
  6740. }
  6741. // Temp list to store hate list
  6742. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6743. if (encounterList->size() == 0) {
  6744. safe_delete(encounterList);
  6745. return 0;
  6746. }
  6747. lua_createtable(state, encounterList->size(), 0);
  6748. int newTable = lua_gettop(state);
  6749. for (int32 i = 0; i < encounterList->size(); i++) {
  6750. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6751. if (temp)
  6752. lua_interface->SetSpawnValue(state, temp);
  6753. lua_rawseti(state, newTable, i + 1);
  6754. }
  6755. safe_delete(encounterList);
  6756. return 1;
  6757. }
  6758. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6759. if (!lua_interface)
  6760. return 0;
  6761. Spawn* spawn = lua_interface->GetSpawn(state);
  6762. lua_interface->ResetFunctionStack(state);
  6763. if (!spawn) {
  6764. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6765. return 0;
  6766. }
  6767. if (!spawn->IsNPC()) {
  6768. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6769. return 0;
  6770. }
  6771. // Temp list to store hate list
  6772. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6773. if (hateList->size() == 0) {
  6774. safe_delete(hateList);
  6775. return 0;
  6776. }
  6777. lua_createtable(state, hateList->size(), 0);
  6778. int newTable = lua_gettop(state);
  6779. for (int32 i = 0; i < hateList->size(); i++) {
  6780. lua_interface->SetSpawnValue(state, hateList->at(i));
  6781. lua_rawseti(state, newTable, i + 1);
  6782. }
  6783. safe_delete(hateList);
  6784. return 1;
  6785. }
  6786. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6787. if (!lua_interface)
  6788. return 0;
  6789. Spawn* spawn = lua_interface->GetSpawn(state);
  6790. lua_interface->ResetFunctionStack(state);
  6791. if (!spawn) {
  6792. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6793. return 0;
  6794. }
  6795. if (spawn->IsPlayer()) {
  6796. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6797. lua_interface->SetBooleanValue(state, true);
  6798. else
  6799. lua_interface->SetBooleanValue(state, false);
  6800. return 1;
  6801. }
  6802. else {
  6803. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6804. return 1;
  6805. }
  6806. }
  6807. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6808. if (!lua_interface)
  6809. return 0;
  6810. Quest* quest = lua_interface->GetQuest(state);
  6811. lua_interface->ResetFunctionStack(state);
  6812. if (!quest) {
  6813. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6814. return 0;
  6815. }
  6816. quest->SetCompletedFlag(true);
  6817. return 0;
  6818. }
  6819. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6820. if (!lua_interface)
  6821. return 0;
  6822. Spawn* spawn = lua_interface->GetSpawn(state);
  6823. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6824. int8 tier = lua_interface->GetInt8Value(state, 3);
  6825. lua_interface->ResetFunctionStack(state);
  6826. if (!spawn) {
  6827. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6828. return 0;
  6829. }
  6830. if (!spawn->IsEntity()) {
  6831. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6832. return 0;
  6833. }
  6834. if (spellID == 0) {
  6835. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6836. return 0;
  6837. }
  6838. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6839. if (effect) {
  6840. if (tier > 0) {
  6841. // If a tier was passed chec to see if it is the same as the effect
  6842. if (tier == effect->tier)
  6843. lua_interface->SetBooleanValue(state, true);
  6844. else
  6845. lua_interface->SetBooleanValue(state, false);
  6846. return 1;
  6847. }
  6848. else {
  6849. // Have an effect but no tier was passed so return true
  6850. lua_interface->SetBooleanValue(state, true);
  6851. }
  6852. return 1;
  6853. }
  6854. // no effect so return false
  6855. lua_interface->SetBooleanValue(state, false);
  6856. return 1;
  6857. }
  6858. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6859. if (!lua_interface)
  6860. return 0;
  6861. Spawn* spawn = lua_interface->GetSpawn(state);
  6862. int32 id = lua_interface->GetInt32Value(state, 2);
  6863. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6864. lua_interface->ResetFunctionStack(state);
  6865. Spawn* spawn2 = 0;
  6866. vector<Spawn*> list;
  6867. if (!spawn) {
  6868. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6869. return 0;
  6870. }
  6871. //If zone not provided, use spawn's zone
  6872. if (!zone)
  6873. zone = spawn->GetZone();
  6874. list = zone->GetSpawnsByID(id);
  6875. if (list.size() == 0) {
  6876. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6877. return 0;
  6878. }
  6879. vector<Spawn*>::iterator itr = list.begin();
  6880. for (int8 i = 0; i < list.size(); i++) {
  6881. spawn2 = itr[i];
  6882. if (spawn2)
  6883. spawn2->AddAllowAccessSpawn(spawn);
  6884. }
  6885. return 0;
  6886. }
  6887. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6888. if (!lua_interface)
  6889. return 0;
  6890. Spawn* spawn = lua_interface->GetSpawn(state);
  6891. int32 id = lua_interface->GetInt32Value(state, 2);
  6892. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6893. lua_interface->ResetFunctionStack(state);
  6894. Spawn* spawn2 = 0;
  6895. if (!spawn) {
  6896. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6897. return 0;
  6898. }
  6899. //If zone not provided, use spawn's zone
  6900. if (!zone)
  6901. zone = spawn->GetZone();
  6902. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6903. vector<Spawn*>::iterator itr = list.begin();
  6904. if (list.size() == 0) {
  6905. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6906. return 0;
  6907. }
  6908. for (int8 i = 0; i < list.size(); i++) {
  6909. spawn2 = itr[i];
  6910. if (spawn2)
  6911. spawn2->RemoveSpawnAccess(spawn);
  6912. }
  6913. return 0;
  6914. }
  6915. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6916. if (!lua_interface)
  6917. return 0;
  6918. Quest* quest = lua_interface->GetQuest(state);
  6919. lua_interface->ResetFunctionStack(state);
  6920. if (!quest) {
  6921. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6922. return 0;
  6923. }
  6924. quest->SetYellowName(true);
  6925. return 0;
  6926. }
  6927. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6928. if (!lua_interface)
  6929. return 0;
  6930. Spawn* spawn = lua_interface->GetSpawn(state);
  6931. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6932. lua_interface->ResetFunctionStack(state);
  6933. if (!spawn) {
  6934. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6935. return 0;
  6936. }
  6937. if (!spawn->IsPlayer()) {
  6938. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6939. return 0;
  6940. }
  6941. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6942. return 1;
  6943. }
  6944. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6945. if (!lua_interface)
  6946. return 0;
  6947. Spawn* spawn = lua_interface->GetSpawn(state);
  6948. lua_interface->ResetFunctionStack(state);
  6949. if (!spawn) {
  6950. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6951. return 0;
  6952. }
  6953. if (!spawn->IsPlayer()) {
  6954. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6955. return 0;
  6956. }
  6957. ZoneServer* zone = spawn->GetZone();
  6958. if (!zone) {
  6959. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6960. return 0;
  6961. }
  6962. Instance_Type iType = zone->GetInstanceType();
  6963. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6964. iType == GROUP_LOCKOUT_INSTANCE ||
  6965. iType == RAID_LOCKOUT_INSTANCE ||
  6966. iType == SOLO_PERSIST_INSTANCE ||
  6967. iType == GROUP_PERSIST_INSTANCE ||
  6968. iType == RAID_PERSIST_INSTANCE) {
  6969. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6970. if (data) {
  6971. // Check to see if the timer has already been set, if it has return out.
  6972. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6973. return 0;
  6974. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6975. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6976. if(spawn->IsPlayer()) {
  6977. Client* client = ((Player*)spawn)->GetClient();
  6978. if (client) {
  6979. string time_msg = "";
  6980. int32 time = data->success_lockout_time;
  6981. int16 hour;
  6982. int8 min;
  6983. int8 sec;
  6984. hour = time / 3600;
  6985. time = time % 3600;
  6986. min = time / 60;
  6987. time = time % 60;
  6988. sec = time;
  6989. if (hour > 0) {
  6990. char temp[10];
  6991. sprintf(temp, " %i", hour);
  6992. time_msg.append(temp);
  6993. time_msg.append(" hour");
  6994. time_msg.append((hour > 1) ? "s" : "");
  6995. }
  6996. if (min > 0) {
  6997. char temp[5];
  6998. sprintf(temp, " %i", min);
  6999. time_msg.append(temp);
  7000. time_msg.append(" minute");
  7001. time_msg.append((min > 1) ? "s" : "");
  7002. }
  7003. // Only add seconds if minutes and hours are 0
  7004. if (hour == 0 && min == 0 && sec > 0) {
  7005. char temp[5];
  7006. sprintf(temp, " %i", sec);
  7007. time_msg.append(temp);
  7008. time_msg.append(" second");
  7009. time_msg.append((sec > 1) ? "s" : "");
  7010. }
  7011. 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());
  7012. }
  7013. else {
  7014. lua_interface->LogError("LUA SetSuccessTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7015. }
  7016. }
  7017. }
  7018. else
  7019. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7020. }
  7021. else
  7022. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  7023. return 0;
  7024. }
  7025. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  7026. if (!lua_interface)
  7027. return 0;
  7028. Spawn* spawn = lua_interface->GetSpawn(state);
  7029. lua_interface->ResetFunctionStack(state);
  7030. if (!spawn) {
  7031. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7032. return 0;
  7033. }
  7034. if (!spawn->IsPlayer()) {
  7035. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  7036. return 0;
  7037. }
  7038. ZoneServer* zone = spawn->GetZone();
  7039. if (!zone) {
  7040. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  7041. return 0;
  7042. }
  7043. Instance_Type iType = zone->GetInstanceType();
  7044. if (iType == SOLO_LOCKOUT_INSTANCE ||
  7045. iType == GROUP_LOCKOUT_INSTANCE ||
  7046. iType == RAID_LOCKOUT_INSTANCE ||
  7047. iType == SOLO_PERSIST_INSTANCE ||
  7048. iType == GROUP_PERSIST_INSTANCE ||
  7049. iType == RAID_PERSIST_INSTANCE) {
  7050. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  7051. if (data) {
  7052. // Check to see if the timer has already been set, if it has return out.
  7053. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  7054. return 0;
  7055. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  7056. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  7057. if(spawn->IsPlayer()) {
  7058. Client* client = ((Player*)spawn)->GetClient();
  7059. if (client) {
  7060. string time_msg = "";
  7061. int32 time = data->failure_lockout_time;
  7062. int16 hour;
  7063. int8 min;
  7064. int8 sec;
  7065. hour = time / 3600;
  7066. time = time % 3600;
  7067. min = time / 60;
  7068. time = time % 60;
  7069. sec = time;
  7070. if (hour > 0) {
  7071. char temp[10];
  7072. sprintf(temp, " %i", hour);
  7073. time_msg.append(temp);
  7074. time_msg.append(" hour");
  7075. time_msg.append((hour > 1) ? "s" : "");
  7076. }
  7077. if (min > 0) {
  7078. char temp[5];
  7079. sprintf(temp, " %i", min);
  7080. time_msg.append(temp);
  7081. time_msg.append(" minute");
  7082. time_msg.append((min > 1) ? "s" : "");
  7083. }
  7084. // Only add seconds if minutes and hours are 0
  7085. if (hour == 0 && min == 0 && sec > 0) {
  7086. char temp[5];
  7087. sprintf(temp, " %i", sec);
  7088. time_msg.append(temp);
  7089. time_msg.append(" second");
  7090. time_msg.append((sec > 1) ? "s" : "");
  7091. }
  7092. 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());
  7093. }
  7094. }
  7095. else {
  7096. lua_interface->LogError("LUA SetFailureTimer command error: instance id %u client missing for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7097. }
  7098. }
  7099. else
  7100. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  7101. }
  7102. else
  7103. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  7104. return 0;
  7105. }
  7106. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  7107. if (!lua_interface)
  7108. return 0;
  7109. Spawn* spawn = lua_interface->GetSpawn(state);
  7110. lua_interface->ResetFunctionStack(state);
  7111. if (!spawn) {
  7112. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  7113. return 0;
  7114. }
  7115. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  7116. return 1;
  7117. }
  7118. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  7119. if (!lua_interface)
  7120. return 0;
  7121. Spawn* player = lua_interface->GetSpawn(state);
  7122. Spawn* ground = lua_interface->GetSpawn(state, 2);
  7123. if (!player) {
  7124. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7125. lua_interface->ResetFunctionStack(state);
  7126. return 0;
  7127. }
  7128. if (!player->IsPlayer()) {
  7129. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  7130. lua_interface->ResetFunctionStack(state);
  7131. return 0;
  7132. }
  7133. if (!ground) {
  7134. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  7135. lua_interface->ResetFunctionStack(state);
  7136. return 0;
  7137. }
  7138. if (!ground->IsGroundSpawn()) {
  7139. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  7140. lua_interface->ResetFunctionStack(state);
  7141. return 0;
  7142. }
  7143. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7144. if (!groundspawn_entries) {
  7145. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  7146. lua_interface->ResetFunctionStack(state);
  7147. return 0;
  7148. }
  7149. Skill* skill = 0;
  7150. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  7151. if (collection_skill == "Collecting")
  7152. skill = ((Player*)player)->GetSkillByName("Gathering");
  7153. else
  7154. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  7155. if (!skill) {
  7156. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  7157. lua_interface->ResetFunctionStack(state);
  7158. return 0;
  7159. }
  7160. vector<GroundSpawnEntry*>::iterator itr;
  7161. GroundSpawnEntry* entry = 0;
  7162. bool can_harvest = false;
  7163. sint32 min_skill = -1;
  7164. int16 totalSkill = skill->current_val;
  7165. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  7166. if(skillID != 0xFFFFFFFF)
  7167. {
  7168. ((Entity*)player)->MStats.lock();
  7169. totalSkill += ((Entity*)player)->stats[skillID];
  7170. ((Entity*)player)->MStats.unlock();
  7171. }
  7172. // first, iterate through groundspawn_entries, discard tables player cannot use
  7173. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  7174. {
  7175. entry = *itr;
  7176. if (min_skill == -1 || entry->min_skill_level < min_skill)
  7177. min_skill = entry->min_skill_level;
  7178. // if player lacks skill, skip table
  7179. if (entry->min_skill_level > totalSkill)
  7180. continue;
  7181. // if bonus, but player lacks level, skip table
  7182. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  7183. continue;
  7184. can_harvest = true;
  7185. break;
  7186. }
  7187. lua_interface->SetBooleanValue(state, can_harvest);
  7188. // If false, send the message to the client
  7189. if (!can_harvest) {
  7190. Client* client = ((Player*)player)->GetClient();
  7191. if (client) {
  7192. string msg = "You do not have enough skill to ";
  7193. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  7194. msg.append("gather");
  7195. else if (collection_skill == "Mining")
  7196. msg.append("mine");
  7197. else if (collection_skill == "Trapping")
  7198. msg.append("trap");
  7199. else if (collection_skill == "Foresting")
  7200. msg.append("forest");
  7201. else if (collection_skill == "Fishing")
  7202. msg.append("catch");
  7203. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  7204. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  7205. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  7206. }
  7207. }
  7208. lua_interface->ResetFunctionStack(state);
  7209. return 1;
  7210. }
  7211. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  7212. if (!lua_interface)
  7213. return 0;
  7214. Spawn* player = lua_interface->GetSpawn(state);
  7215. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  7216. lua_interface->ResetFunctionStack(state);
  7217. if (!player) {
  7218. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  7219. return 0;
  7220. }
  7221. if (!player->IsPlayer()) {
  7222. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  7223. return 0;
  7224. }
  7225. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  7226. lua_interface->SetBooleanValue(state, ret);
  7227. return 1;
  7228. }
  7229. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  7230. // Check to see if we have a valid lua_interface
  7231. if (!lua_interface)
  7232. return 0;
  7233. // Get the spawn that is getting the pet
  7234. Spawn* spawn = lua_interface->GetSpawn(state);
  7235. Spawn* target = lua_interface->GetSpawn(state, 2);
  7236. // Get the DB ID of the pet
  7237. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  7238. float x = lua_interface->GetFloatValue(state, 4);
  7239. float y = lua_interface->GetFloatValue(state, 5);
  7240. float z = lua_interface->GetFloatValue(state, 6);
  7241. // Get the spell that this command was called from
  7242. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7243. lua_interface->ResetFunctionStack(state);
  7244. // Check to make sure the spawn pointer is valid
  7245. if (!spawn) {
  7246. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  7247. return 0;
  7248. }
  7249. // Check to make sure the spawn is an entity
  7250. if (!spawn->IsEntity()) {
  7251. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  7252. return 0;
  7253. }
  7254. if (!target) {
  7255. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  7256. return 0;
  7257. }
  7258. if (!target->IsEntity()) {
  7259. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  7260. return 0;
  7261. }
  7262. // Check to see if the DB ID for the pet is set
  7263. if (pet_id == 0) {
  7264. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  7265. return 0;
  7266. }
  7267. // Check to see if the pointer to the spell is valid
  7268. if (!luaspell) {
  7269. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  7270. return 0;
  7271. }
  7272. if(luaspell->resisted) {
  7273. return 0;
  7274. }
  7275. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  7276. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  7277. if (!pet) {
  7278. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  7279. return 0;
  7280. }
  7281. // Check to make sure the pet is an npc
  7282. if (!pet->IsNPC()) {
  7283. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  7284. return 0;
  7285. }
  7286. if (x == 0)
  7287. x = spawn->GetX();
  7288. if (y == 0)
  7289. y = spawn->GetY();
  7290. if (z == 0)
  7291. z = spawn->GetZ();
  7292. // Spawn the pet at the same location as the owner
  7293. pet->SetX(x);
  7294. pet->SetY(y);
  7295. pet->SetZ(z);
  7296. pet->SetLocation(spawn->GetLocation());
  7297. pet->SetHeading(spawn->GetHeading());
  7298. spawn->GetZone()->AddSpawn(pet);
  7299. const char* spawn_script = world.GetSpawnScript(pet_id);
  7300. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  7301. spawn->SetSpawnScript(string(spawn_script));
  7302. spawn->GetZone()->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  7303. }
  7304. std::string petName = std::string("");
  7305. if(spawn->IsEntity()) {
  7306. petName = ((Entity*)spawn)->GetInfoStruct()->get_pet_name();
  7307. }
  7308. if(petName.size() < 1) {
  7309. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  7310. petName = spawn->GetZone()->pet_names.at(rand_index);
  7311. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", petName.c_str(), rand_index);
  7312. }
  7313. // Set the pets name
  7314. pet->SetName(petName.c_str());
  7315. // Set the level of the pet to the owners level
  7316. pet->SetLevel(spawn->GetLevel());
  7317. // Set the faction of the pet to the same faction as the owner
  7318. pet->SetFactionID(spawn->GetFactionID());
  7319. // Set the spawn as a pet
  7320. pet->SetPet(true);
  7321. // Give a pointer of the owner to the pet
  7322. ((NPC*)pet)->SetOwner((Entity*)spawn);
  7323. // Set the pet type
  7324. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  7325. // Set the spell id used to create this pet
  7326. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  7327. // Set the spell tier used to create this pet
  7328. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  7329. // Set the pets spawn type to 6
  7330. pet->SetSpawnType(6);
  7331. // Set the pets brain
  7332. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  7333. // Check to see if the pet has a subtitle
  7334. if (strlen(pet->GetSubTitle()) > 0) {
  7335. // Add the players name to the front of the sub title
  7336. string pet_subtitle;
  7337. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  7338. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  7339. // Set the pets subtitle to the new one
  7340. pet->SetSubTitle(pet_subtitle.c_str());
  7341. }
  7342. // Set the pet as the return value for this function
  7343. lua_interface->SetSpawnValue(state, pet);
  7344. return 1;
  7345. }
  7346. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  7347. if (!lua_interface)
  7348. return 0;
  7349. Spawn* spawn = lua_interface->GetSpawn(state);
  7350. Spawn* player = lua_interface->GetSpawn(state, 2);
  7351. float max_distance = lua_interface->GetFloatValue(state, 3);
  7352. string type = lua_interface->GetStringValue(state, 4);
  7353. lua_interface->ResetFunctionStack(state);
  7354. if (!spawn || (spawn && spawn->IsPlayer())) {
  7355. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  7356. return 0;
  7357. }
  7358. if (!player || !player->IsPlayer()) {
  7359. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  7360. return 0;
  7361. }
  7362. Client* client = ((Player*)player)->GetClient();
  7363. if (!client) {
  7364. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  7365. return 0;
  7366. }
  7367. //Set max_distance to default if not set or not proper value
  7368. if (max_distance <= 0)
  7369. max_distance = 500;
  7370. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  7371. if (packet) {
  7372. float unknown2_3 = 0;
  7373. int8 placement_mode = 0;
  7374. if (type == "wall") {
  7375. placement_mode = 2;
  7376. unknown2_3 = 150;
  7377. }
  7378. else if (type == "ceiling")
  7379. placement_mode = 1;
  7380. packet->setDataByName("placement_mode", placement_mode);
  7381. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7382. packet->setDataByName("model_type", spawn->GetModelType());
  7383. packet->setDataByName("unknown", 1); //size
  7384. packet->setDataByName("unknown2", 1); //size 2
  7385. packet->setDataByName("unknown2", .5, 1); //size 3
  7386. packet->setDataByName("unknown2", 3, 2);
  7387. packet->setDataByName("unknown2", unknown2_3, 3);
  7388. packet->setDataByName("max_distance", max_distance);
  7389. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7390. client->QueuePacket(packet->serialize());
  7391. safe_delete(packet);
  7392. }
  7393. return 0;
  7394. }
  7395. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7396. if (!lua_interface)
  7397. return 0;
  7398. Item* item = lua_interface->GetItem(state);
  7399. lua_interface->ResetFunctionStack(state);
  7400. if (!item) {
  7401. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7402. return 0;
  7403. }
  7404. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7405. return 1;
  7406. }
  7407. int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
  7408. if (!lua_interface)
  7409. return 0;
  7410. Item* item = lua_interface->GetItem(state);
  7411. lua_interface->ResetFunctionStack(state);
  7412. if (!item) {
  7413. lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7414. return 0;
  7415. }
  7416. lua_interface->SetInt32Value(state, item->effect_type);
  7417. return 1;
  7418. }
  7419. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7420. if (!lua_interface)
  7421. return 0;
  7422. Spawn* spawn = lua_interface->GetSpawn(state);
  7423. lua_interface->ResetFunctionStack(state);
  7424. if (!spawn) {
  7425. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7426. return 0;
  7427. }
  7428. if (spawn->GetZone())
  7429. spawn->GetZone()->AddTransportSpawn(spawn);
  7430. return 0;
  7431. }
  7432. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7433. if (!lua_interface)
  7434. return 0;
  7435. Spawn* spawn = lua_interface->GetSpawn(state);
  7436. lua_interface->ResetFunctionStack(state);
  7437. if (!spawn) {
  7438. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7439. return 0;
  7440. }
  7441. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7442. return 1;
  7443. }
  7444. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7445. if (!lua_interface)
  7446. return 0;
  7447. Skill* skill = lua_interface->GetSkill(state);
  7448. lua_interface->ResetFunctionStack(state);
  7449. if (!skill) {
  7450. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7451. return 0;
  7452. }
  7453. lua_interface->SetInt32Value(state, skill->current_val);
  7454. return 1;
  7455. }
  7456. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7457. if (!lua_interface)
  7458. return 0;
  7459. Skill* skill = lua_interface->GetSkill(state);
  7460. lua_interface->ResetFunctionStack(state);
  7461. if (!skill) {
  7462. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7463. return 0;
  7464. }
  7465. lua_interface->SetInt32Value(state, skill->max_val);
  7466. return 1;
  7467. }
  7468. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7469. if (!lua_interface)
  7470. return 0;
  7471. Skill* skill = lua_interface->GetSkill(state);
  7472. lua_interface->ResetFunctionStack(state);
  7473. if (!skill) {
  7474. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7475. return 0;
  7476. }
  7477. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7478. return 1;
  7479. }
  7480. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7481. if (!lua_interface)
  7482. return 0;
  7483. Skill* skill = lua_interface->GetSkill(state);
  7484. int16 value = lua_interface->GetInt16Value(state, 2);
  7485. lua_interface->ResetFunctionStack(state);
  7486. if (!skill) {
  7487. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7488. return 0;
  7489. }
  7490. skill->max_val = value;
  7491. if (skill->max_val < skill->current_val)
  7492. skill->current_val = skill->max_val;
  7493. return 0;
  7494. }
  7495. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7496. if (!lua_interface)
  7497. return 0;
  7498. Skill* skill = lua_interface->GetSkill(state);
  7499. int16 value = lua_interface->GetInt16Value(state, 2);
  7500. lua_interface->ResetFunctionStack(state);
  7501. if (!skill) {
  7502. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7503. return 0;
  7504. }
  7505. if (value > skill->max_val)
  7506. skill->current_val = skill->max_val;
  7507. else
  7508. skill->current_val = value;
  7509. return 0;
  7510. }
  7511. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7512. if (!lua_interface)
  7513. return 0;
  7514. Spawn* player = lua_interface->GetSpawn(state);
  7515. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7516. lua_interface->ResetFunctionStack(state);
  7517. if (skill_id > 0 && player && player->IsPlayer()) {
  7518. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7519. return 1;
  7520. }
  7521. return 0;
  7522. }
  7523. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7524. if (!lua_interface)
  7525. return 0;
  7526. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7527. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7528. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7529. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7530. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7531. lua_interface->ResetFunctionStack(state);
  7532. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7533. if (player_spawn && player_spawn->IsPlayer()) {
  7534. Player* player = (Player*)player_spawn;
  7535. bool added = false;
  7536. if (!player->skill_list.HasSkill(skill_id)) {
  7537. player->AddSkill(skill_id, current_val, max_val, true);
  7538. added = true;
  7539. }
  7540. 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
  7541. Client* client = player->GetClient();
  7542. if (client) {
  7543. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7544. if (packet)
  7545. client->QueuePacket(packet);
  7546. }
  7547. }
  7548. if (added) {
  7549. lua_interface->SetBooleanValue(state, true);
  7550. return 1;
  7551. }
  7552. }
  7553. else {
  7554. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7555. }
  7556. }
  7557. else {
  7558. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7559. }
  7560. lua_interface->SetBooleanValue(state, false);
  7561. return 1;
  7562. }
  7563. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7564. if (!lua_interface)
  7565. return 0;
  7566. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7567. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7568. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7569. lua_interface->ResetFunctionStack(state);
  7570. if (skill_id > 0) {
  7571. if (player_spawn && player_spawn->IsPlayer()) {
  7572. Player* player = (Player*)player_spawn;
  7573. if (player->skill_list.HasSkill(skill_id)) {
  7574. player->RemovePlayerSkill(skill_id, true);
  7575. if (!more_to_remove) {
  7576. Client* client = player->GetClient();
  7577. if (client) {
  7578. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7579. if (packet)
  7580. client->QueuePacket(packet);
  7581. }
  7582. }
  7583. }
  7584. }
  7585. else {
  7586. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7587. }
  7588. }
  7589. else {
  7590. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7591. }
  7592. return 0;
  7593. }
  7594. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7595. if (!lua_interface)
  7596. return 0;
  7597. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7598. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7599. int16 amount = lua_interface->GetInt8Value(state, 3);
  7600. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7601. lua_interface->ResetFunctionStack(state);
  7602. if (amount > 0 && skill_type < 100) {
  7603. if (player_spawn && player_spawn->IsPlayer()) {
  7604. Player* player = (Player*)player_spawn;
  7605. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7606. if (!more_to_increase) {
  7607. Client* client = player->GetClient();
  7608. if (client) {
  7609. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7610. if (packet)
  7611. client->QueuePacket(packet);
  7612. }
  7613. }
  7614. }
  7615. else {
  7616. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7617. }
  7618. }
  7619. else {
  7620. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7621. }
  7622. return 0;
  7623. }
  7624. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7625. if (!lua_interface)
  7626. return 0;
  7627. Spawn* spawn = lua_interface->GetSpawn(state);
  7628. string name = lua_interface->GetStringValue(state, 2);
  7629. lua_interface->ResetFunctionStack(state);
  7630. if (!spawn) {
  7631. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7632. return 0;
  7633. }
  7634. if (!spawn->IsEntity()) {
  7635. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7636. return 0;
  7637. }
  7638. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7639. if (skill) {
  7640. lua_interface->SetSkillValue(state, skill);
  7641. return 1;
  7642. }
  7643. return 0;
  7644. }
  7645. int EQ2Emu_lua_AddProc(lua_State* state) {
  7646. if (!lua_interface)
  7647. return 0;
  7648. Spawn* spawn = lua_interface->GetSpawn(state);
  7649. int8 type = lua_interface->GetInt8Value(state, 2);
  7650. float chance = lua_interface->GetFloatValue(state, 3);
  7651. Item* item = lua_interface->GetItem(state, 4);
  7652. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7653. LuaSpell* spell = 0;
  7654. if (!spawn && (!spell || !use_all_spelltargets)) {
  7655. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7656. return 0;
  7657. }
  7658. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7659. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7660. return 0;
  7661. }
  7662. if (!item)
  7663. spell = lua_interface->GetCurrentSpell(state);
  7664. if (!item && !spell) {
  7665. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7666. return 0;
  7667. }
  7668. if(spell && spell->resisted) {
  7669. return 0;
  7670. }
  7671. if (spell && spell->caster && spell->caster->GetZone() && use_all_spelltargets) {
  7672. Spawn* target;
  7673. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7674. for (int8 i = 0; i < spell->targets.size(); i++) {
  7675. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7676. if (!target || !target->IsEntity())
  7677. continue;
  7678. ((Entity*)target)->AddProc(type, chance, item, spell);
  7679. }
  7680. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7681. }
  7682. else
  7683. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7684. return 0;
  7685. }
  7686. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7687. if (!lua_interface)
  7688. return 0;
  7689. Spawn* spawn = lua_interface->GetSpawn(state);
  7690. Item* item = lua_interface->GetItem(state, 2);
  7691. LuaSpell* spell = 0;
  7692. if (!spawn) {
  7693. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7694. lua_interface->ResetFunctionStack(state);
  7695. return 0;
  7696. }
  7697. if (!spawn->IsEntity()) {
  7698. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7699. lua_interface->ResetFunctionStack(state);
  7700. return 0;
  7701. }
  7702. if (!item)
  7703. spell = lua_interface->GetCurrentSpell(state);
  7704. lua_interface->ResetFunctionStack(state);
  7705. if (!item && !spell) {
  7706. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7707. return 0;
  7708. }
  7709. if (spell && spell->caster && spell->caster->GetZone()) {
  7710. Spawn* target;
  7711. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7712. for (int8 i = 0; i < spell->targets.size(); i++) {
  7713. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7714. if (!target || !target->IsEntity())
  7715. continue;
  7716. ((Entity*)target)->RemoveProc(item, spell);
  7717. }
  7718. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7719. spell->caster->RemoveProc(item, spell);
  7720. }
  7721. else
  7722. ((Entity*)spawn)->RemoveProc(item, spell);
  7723. return 0;
  7724. }
  7725. int EQ2Emu_lua_Knockback(lua_State* state) {
  7726. if (!lua_interface)
  7727. return 0;
  7728. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7729. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7730. int32 duration = lua_interface->GetInt32Value(state, 3);
  7731. float vertical = lua_interface->GetFloatValue(state, 4);
  7732. float horizontal = lua_interface->GetFloatValue(state, 5);
  7733. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7734. lua_interface->ResetFunctionStack(state);
  7735. if (!target_spawn) {
  7736. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7737. return 0;
  7738. }
  7739. if (!spawn) {
  7740. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7741. return 0;
  7742. }
  7743. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7744. Client* client = ((Player*)spawn)->GetClient();
  7745. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7746. if (packet) {
  7747. packet->setDataByName("target_x", target_spawn->GetX());
  7748. packet->setDataByName("target_y", target_spawn->GetY());
  7749. packet->setDataByName("target_z", target_spawn->GetZ());
  7750. packet->setDataByName("vertical_movement", vertical);
  7751. packet->setDataByName("horizontal_movement", horizontal);
  7752. if (use_heading)
  7753. packet->setDataByName("use_player_heading", 1);
  7754. client->QueuePacket(packet->serialize());
  7755. }
  7756. safe_delete(packet);
  7757. }
  7758. return 0;
  7759. }
  7760. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7761. if (!lua_interface)
  7762. return 0;
  7763. Spawn* spawn = lua_interface->GetSpawn(state);
  7764. lua_interface->ResetFunctionStack(state);
  7765. if (!spawn) {
  7766. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7767. return 0;
  7768. }
  7769. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7770. return 1;
  7771. }
  7772. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7773. if (!lua_interface)
  7774. return 0;
  7775. Spawn* caster = lua_interface->GetSpawn(state);
  7776. Spawn* target = lua_interface->GetSpawn(state, 2);
  7777. string name = lua_interface->GetStringValue(state, 3);
  7778. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7779. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7780. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7781. string success_msg = lua_interface->GetStringValue(state, 7);
  7782. string effect_msg = lua_interface->GetStringValue(state, 8);
  7783. lua_interface->ResetFunctionStack(state);
  7784. if (!caster) {
  7785. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7786. return 0;
  7787. }
  7788. if (!caster->IsEntity()) {
  7789. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7790. return 0;
  7791. }
  7792. if (!target) {
  7793. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7794. return 0;
  7795. }
  7796. if (!target->IsEntity()) {
  7797. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7798. return 0;
  7799. }
  7800. if (name.length() == 0) {
  7801. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7802. return 0;
  7803. }
  7804. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7805. return 0;
  7806. }
  7807. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7808. if (!lua_interface)
  7809. return 0;
  7810. string name = lua_interface->GetStringValue(state);
  7811. lua_interface->ResetFunctionStack(state);
  7812. if (name.length() == 0) {
  7813. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7814. return 0;
  7815. }
  7816. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7817. if (!skill) {
  7818. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7819. return 0;
  7820. }
  7821. lua_interface->SetInt32Value(state, skill->skill_id);
  7822. return 1;
  7823. }
  7824. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7825. if (!lua_interface)
  7826. return 0;
  7827. Spawn* spawn = lua_interface->GetSpawn(state);
  7828. lua_interface->ResetFunctionStack(state);
  7829. if (!spawn) {
  7830. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7831. return 0;
  7832. }
  7833. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7834. return 1;
  7835. }
  7836. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7837. if (!lua_interface)
  7838. return 0;
  7839. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7840. lua_interface->ResetFunctionStack(state);
  7841. if (!luaspell) {
  7842. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7843. return 0;
  7844. }
  7845. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7846. return 1;
  7847. }
  7848. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7849. if (!lua_interface)
  7850. return 0;
  7851. Spawn* spawn = lua_interface->GetSpawn(state);
  7852. Spawn* target = lua_interface->GetSpawn(state, 2);
  7853. lua_interface->ResetFunctionStack(state);
  7854. if (!spawn) {
  7855. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7856. return 0;
  7857. }
  7858. if (!spawn->IsEntity()) {
  7859. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7860. return 0;
  7861. }
  7862. if (!target) {
  7863. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7864. return 0;
  7865. }
  7866. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7867. return 1;
  7868. }
  7869. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7870. if (!lua_interface)
  7871. return 0;
  7872. Spawn* spawn = lua_interface->GetSpawn(state);
  7873. Spawn* target = lua_interface->GetSpawn(state, 2);
  7874. lua_interface->ResetFunctionStack(state);
  7875. if (!spawn) {
  7876. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7877. return 0;
  7878. }
  7879. if (!spawn->IsEntity()) {
  7880. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7881. return 0;
  7882. }
  7883. if (!target) {
  7884. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7885. return 0;
  7886. }
  7887. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7888. return 1;
  7889. }
  7890. int EQ2Emu_lua_InFront(lua_State* state) {
  7891. if (!lua_interface)
  7892. return 0;
  7893. Spawn* spawn = lua_interface->GetSpawn(state);
  7894. Spawn* target = lua_interface->GetSpawn(state, 2);
  7895. lua_interface->ResetFunctionStack(state);
  7896. if (!spawn) {
  7897. lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7898. return 0;
  7899. }
  7900. if (!spawn->IsEntity()) {
  7901. lua_interface->LogError("%s: LUA InFrontSpawn command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7902. return 0;
  7903. }
  7904. if (!target) {
  7905. lua_interface->LogError("%s: LUA InFrontSpawn command error: target is not valid", lua_interface->GetScriptName(state));
  7906. return 0;
  7907. }
  7908. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->InFrontSpawn(target, spawn->GetX(), spawn->GetZ()));
  7909. return 1;
  7910. }
  7911. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7912. if (!lua_interface)
  7913. return 0;
  7914. Item* item = lua_interface->GetItem(state);
  7915. lua_interface->ResetFunctionStack(state);
  7916. if (!item) {
  7917. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7918. return 0;
  7919. }
  7920. lua_interface->SetInt32Value(state, item->details.count);
  7921. return 1;
  7922. }
  7923. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7924. if (!lua_interface)
  7925. return 0;
  7926. Item* item = lua_interface->GetItem(state);
  7927. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7928. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7929. lua_interface->ResetFunctionStack(state);
  7930. if (!item) {
  7931. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7932. return 0;
  7933. }
  7934. if (!owner) {
  7935. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7936. return 0;
  7937. }
  7938. if (!owner->IsPlayer()) {
  7939. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7940. return 0;
  7941. }
  7942. if (item->stack_count < new_count) {
  7943. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7944. return 0;
  7945. }
  7946. if (new_count > 0) {
  7947. item->details.count = new_count;
  7948. item->save_needed = true;
  7949. }
  7950. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7951. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7952. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7953. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7954. else
  7955. {
  7956. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7957. return 0;
  7958. }
  7959. Client* client = ((Player*)owner)->GetClient();
  7960. if (!client)
  7961. return 0;
  7962. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7963. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7964. if (app)
  7965. client->QueuePacket(app);
  7966. return 0;
  7967. }
  7968. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7969. if (!lua_interface)
  7970. return 0;
  7971. int32 time = lua_interface->GetInt32Value(state);
  7972. string function = lua_interface->GetStringValue(state, 2);
  7973. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7974. Spawn* target = lua_interface->GetSpawn(state, 4);
  7975. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7976. lua_interface->ResetFunctionStack(state);
  7977. if (time == 0) {
  7978. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7979. return 0;
  7980. }
  7981. if (function.length() == 0) {
  7982. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7983. return 0;
  7984. }
  7985. if (!spell || (!spell->caster || !spell->caster->GetZone())) {
  7986. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7987. return 0;
  7988. }
  7989. SpellScriptTimer* timer = new SpellScriptTimer;
  7990. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7991. #ifdef WIN32
  7992. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7993. #else
  7994. bzero(timer, sizeof(SpellScriptTimer));
  7995. #endif*/
  7996. timer->caster = 0;
  7997. timer->deleteWhenDone = false;
  7998. timer->target = 0;
  7999. timer->time = Timer::GetCurrentTime2() + time;
  8000. timer->customFunction = function;
  8001. timer->spell = spell;
  8002. if (caster)
  8003. timer->caster = caster->GetID();
  8004. if (target)
  8005. timer->target = target->GetID();
  8006. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  8007. return 0;
  8008. }
  8009. int EQ2Emu_lua_Resurrect(lua_State* state) {
  8010. if (!lua_interface)
  8011. return 0;
  8012. float hp_perc = lua_interface->GetFloatValue(state);
  8013. float power_perc = lua_interface->GetFloatValue(state, 2);
  8014. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  8015. Spawn* target = lua_interface->GetSpawn(state, 4);
  8016. string heal_name = lua_interface->GetStringValue(state, 5);
  8017. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  8018. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  8019. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8020. lua_interface->ResetFunctionStack(state);
  8021. if (!spell) {
  8022. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  8023. return 0;
  8024. }
  8025. Entity* caster = spell->caster;
  8026. if (!caster) {
  8027. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  8028. return 0;
  8029. }
  8030. Client* client = 0;
  8031. PendingResurrection* rez = 0;
  8032. ZoneServer* zone = spell->caster->GetZone();
  8033. if (!target) {
  8034. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8035. if (spell->targets.size() > 0) {
  8036. vector<int32> spell_targets = spell->targets;
  8037. for (int8 i = 0; i < spell_targets.size(); i++) {
  8038. target = zone->GetSpawnByID(spell_targets.at(i));
  8039. if (!target)
  8040. continue;
  8041. if (!target->IsPlayer())
  8042. continue;
  8043. client = ((Player*)target)->GetClient();
  8044. if (!client)
  8045. continue;
  8046. rez = client->GetCurrentRez();
  8047. if (rez->active)
  8048. continue;
  8049. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  8050. rez->active = true;
  8051. rez->caster = caster;
  8052. rez->expire_timer = new Timer;
  8053. int32 duration = spell->spell->GetSpellDuration();
  8054. rez->expire_timer->Start(duration * 100);
  8055. rez->hp_perc = hp_perc;
  8056. rez->mp_perc = power_perc;
  8057. rez->range = spell->spell->GetSpellData()->range;
  8058. rez->spell_name = spell->spell->GetName();
  8059. if (heal_name.length() > 0)
  8060. rez->heal_name = heal_name;
  8061. else
  8062. rez->heal_name = rez->spell_name;
  8063. rez->no_calcs = no_calcs;
  8064. rez->crit_mod = crit_mod;
  8065. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  8066. if (send_window)
  8067. client->SendResurrectionWindow();
  8068. else {
  8069. target->GetZone()->ResurrectSpawn(target, client);
  8070. rez->should_delete = true;
  8071. }
  8072. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  8073. }
  8074. }
  8075. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8076. }
  8077. else {
  8078. if(!target->IsPlayer())
  8079. return 0;
  8080. client = ((Player*)target)->GetClient();
  8081. if (!client)
  8082. return 0;
  8083. rez = client->GetCurrentRez();
  8084. if (rez->active)
  8085. return 0;
  8086. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  8087. rez->active = true;
  8088. rez->caster = caster;
  8089. rez->expire_timer = new Timer;
  8090. int32 duration = spell->spell->GetSpellDuration();
  8091. rez->expire_timer->Start(duration * 100);
  8092. rez->hp_perc = hp_perc;
  8093. rez->mp_perc = power_perc;
  8094. rez->range = spell->spell->GetSpellData()->range;
  8095. rez->spell_name = spell->spell->GetName();
  8096. if (heal_name.length() > 0)
  8097. rez->heal_name = heal_name;
  8098. else
  8099. rez->heal_name = rez->spell_name;
  8100. rez->no_calcs = no_calcs;
  8101. rez->crit_mod = crit_mod;
  8102. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  8103. if (send_window)
  8104. client->SendResurrectionWindow();
  8105. else {
  8106. target->GetZone()->ResurrectSpawn(target, client);
  8107. rez->should_delete = true;
  8108. }
  8109. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  8110. }
  8111. return 0;
  8112. }
  8113. int EQ2Emu_lua_SetVision(lua_State* state) {
  8114. if (!lua_interface)
  8115. return 0;
  8116. Spawn* spawn = lua_interface->GetSpawn(state);
  8117. int32 vision = lua_interface->GetInt32Value(state, 2);
  8118. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8119. lua_interface->ResetFunctionStack(state);
  8120. if (!spawn) {
  8121. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8122. return 0;
  8123. }
  8124. if (!spawn->IsEntity()) {
  8125. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8126. return 0;
  8127. }
  8128. if (spell && spell->targets.size() > 0) {
  8129. ZoneServer* zone = spell->caster->GetZone();
  8130. for (int8 i = 0; i < spell->targets.size(); i++) {
  8131. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8132. if (target && target->IsEntity()) {
  8133. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  8134. if (target->IsPlayer())
  8135. ((Player*)target)->SetCharSheetChanged(true);
  8136. }
  8137. }
  8138. }
  8139. else {
  8140. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  8141. if (spawn->IsPlayer())
  8142. ((Player*)spawn)->SetCharSheetChanged(true);
  8143. }
  8144. return 0;
  8145. }
  8146. int EQ2Emu_lua_BlurVision(lua_State* state) {
  8147. if (!lua_interface)
  8148. return 0;
  8149. Spawn* spawn = lua_interface->GetSpawn(state);
  8150. float intensity = lua_interface->GetFloatValue(state, 2);
  8151. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8152. lua_interface->ResetFunctionStack(state);
  8153. if (!spawn) {
  8154. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  8155. return 0;
  8156. }
  8157. if (!spawn->IsEntity()) {
  8158. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  8159. return 0;
  8160. }
  8161. if (spell && spell->targets.size() > 0) {
  8162. ZoneServer* zone = spell->caster->GetZone();
  8163. for (int8 i = 0; i < spell->targets.size(); i++) {
  8164. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8165. if (target && target->IsEntity()) {
  8166. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  8167. if (target->IsPlayer())
  8168. ((Player*)target)->SetCharSheetChanged(true);
  8169. }
  8170. }
  8171. }
  8172. else {
  8173. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  8174. if (spawn->IsPlayer())
  8175. ((Player*)spawn)->SetCharSheetChanged(true);
  8176. }
  8177. return 0;
  8178. }
  8179. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  8180. if (!lua_interface)
  8181. return 0;
  8182. Spawn* spawn = lua_interface->GetSpawn(state);
  8183. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  8184. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8185. lua_interface->ResetFunctionStack(state);
  8186. if (!spawn) {
  8187. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  8188. return 0;
  8189. }
  8190. if (!spawn->IsEntity()) {
  8191. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  8192. return 0;
  8193. }
  8194. if (spell && spell->targets.size() > 0) {
  8195. ZoneServer* zone = spell->caster->GetZone();
  8196. for (int8 i = 0; i < spell->targets.size(); i++) {
  8197. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8198. if (target && target->IsEntity()) {
  8199. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8200. if (target->IsPlayer())
  8201. ((Player*)target)->SetCharSheetChanged(true);
  8202. }
  8203. }
  8204. }
  8205. else {
  8206. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  8207. if (spawn->IsPlayer())
  8208. ((Player*)spawn)->SetCharSheetChanged(true);
  8209. }
  8210. return 0;
  8211. }
  8212. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  8213. if (!lua_interface)
  8214. return 0;
  8215. Item* item = lua_interface->GetItem(state);
  8216. int8 type = lua_interface->GetInt32Value(state, 2);
  8217. lua_interface->ResetFunctionStack(state);
  8218. if (!item) {
  8219. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  8220. return 0;
  8221. }
  8222. if (type == 1)
  8223. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  8224. else if (type == 2)
  8225. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  8226. return 1;
  8227. }
  8228. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  8229. if (!lua_interface)
  8230. return 0;
  8231. Spawn* target = lua_interface->GetSpawn(state);
  8232. float val = lua_interface->GetFloatValue(state, 2);
  8233. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8234. lua_interface->ResetFunctionStack(state);
  8235. // Added from Gangrenous post
  8236. if (spell && spell->resisted)
  8237. return 0;
  8238. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  8239. if (val > 1.0f)
  8240. val = 1.0f - (val / 100.0f);
  8241. if (spell && spell->spell && spell->targets.size() > 0) {
  8242. ZoneServer* zone = spell->caster->GetZone();
  8243. for (int32 i = 0; i != spell->targets.size(); i++) {
  8244. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  8245. if (spawn && spawn->IsEntity()) {
  8246. ((Entity*)spawn)->SetSpeedMultiplier(val);
  8247. if (spawn->IsPlayer())
  8248. ((Player*)spawn)->SetCharSheetChanged(true);
  8249. }
  8250. }
  8251. }
  8252. else {
  8253. if (target && target->IsEntity()) {
  8254. ((Entity*)target)->SetSpeedMultiplier(val);
  8255. if (target->IsPlayer())
  8256. ((Player*)target)->SetCharSheetChanged(true);
  8257. }
  8258. }
  8259. return 0;
  8260. }
  8261. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  8262. if (!lua_interface)
  8263. return 0;
  8264. Spawn* spawn = lua_interface->GetSpawn(state);
  8265. int16 model = lua_interface->GetInt16Value(state, 2);
  8266. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8267. lua_interface->ResetFunctionStack(state);
  8268. if (spell && spell->spell && spell->targets.size() > 0) {
  8269. ZoneServer* zone = spell->caster->GetZone();
  8270. for (int32 i = 0; i < spell->targets.size(); i++) {
  8271. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8272. if (target)
  8273. target->SetIllusionModel(model);
  8274. }
  8275. }
  8276. else {
  8277. if (!spawn) {
  8278. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8279. return 0;
  8280. }
  8281. spawn->SetIllusionModel(model);
  8282. }
  8283. return 0;
  8284. }
  8285. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  8286. if (!lua_interface)
  8287. return 0;
  8288. Spawn* spawn = lua_interface->GetSpawn(state);
  8289. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8290. lua_interface->ResetFunctionStack(state);
  8291. if (spell && spell->spell && spell->targets.size() > 0) {
  8292. ZoneServer* zone = spell->caster->GetZone();
  8293. for (int32 i = 0; i < spell->targets.size(); i++) {
  8294. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  8295. if (target)
  8296. target->SetIllusionModel(0);
  8297. }
  8298. }
  8299. else {
  8300. if (!spawn) {
  8301. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  8302. return 0;
  8303. }
  8304. spawn->SetIllusionModel(0);
  8305. }
  8306. return 0;
  8307. }
  8308. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  8309. if (!lua_interface)
  8310. return 0;
  8311. Spawn* caster = lua_interface->GetSpawn(state);
  8312. Spawn* target = lua_interface->GetSpawn(state, 2);
  8313. float chance = lua_interface->GetFloatValue(state, 3);
  8314. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8315. lua_interface->ResetFunctionStack(state);
  8316. if (!caster) {
  8317. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  8318. return 0;
  8319. }
  8320. if (!caster->IsEntity()) {
  8321. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  8322. return 0;
  8323. }
  8324. if (!target) {
  8325. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  8326. return 0;
  8327. }
  8328. if (!target->IsEntity()) {
  8329. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  8330. return 0;
  8331. }
  8332. if (chance <= 0) {
  8333. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  8334. return 0;
  8335. }
  8336. if (!spell) {
  8337. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8338. return 0;
  8339. }
  8340. if(spell->resisted) {
  8341. return 0;
  8342. }
  8343. if (((Entity*)caster)->GetThreatTransfer()) {
  8344. return 0;
  8345. }
  8346. ThreatTransfer* transfer = new ThreatTransfer;
  8347. transfer->Target = target->GetID();
  8348. transfer->Amount = chance;
  8349. transfer->Spell = spell;
  8350. ((Entity*)caster)->SetThreatTransfer(transfer);
  8351. return 0;
  8352. }
  8353. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  8354. if (!lua_interface)
  8355. return 0;
  8356. Spawn* spawn = lua_interface->GetSpawn(state);
  8357. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8358. lua_interface->ResetFunctionStack(state);
  8359. if (!spawn) {
  8360. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  8361. return 0;
  8362. }
  8363. if (!spell) {
  8364. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8365. return 0;
  8366. }
  8367. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  8368. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  8369. if(transfer && transfer->Spell != spell) {
  8370. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  8371. return 0;
  8372. }
  8373. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  8374. }
  8375. return 0;
  8376. }
  8377. int EQ2Emu_lua_CureByType(lua_State* state) {
  8378. if (!lua_interface)
  8379. return 0;
  8380. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8381. int8 cure_count = lua_interface->GetInt8Value(state);
  8382. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8383. string cure_name = lua_interface->GetStringValue(state, 3);
  8384. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8385. Spawn* target = lua_interface->GetSpawn(state, 5);
  8386. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  8387. lua_interface->ResetFunctionStack(state);
  8388. if(spell && spell->resisted) {
  8389. return 0;
  8390. }
  8391. if (target) {
  8392. if (!target->IsEntity()) {
  8393. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8394. return 0;
  8395. }
  8396. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8397. std::string alternate_name = "item";
  8398. if(spell)
  8399. alternate_name = std::string(spell->spell->GetName());
  8400. if(!caster && spell)
  8401. caster = (Spawn*)spell->caster;
  8402. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  8403. }
  8404. }
  8405. else {
  8406. ZoneServer* zone = spell->caster->GetZone();
  8407. vector<int32> targets = spell->targets;
  8408. vector<Entity*> targets_to_cure;
  8409. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8410. for (int8 i = 0; i < targets.size(); i++) {
  8411. target = zone->GetSpawnByID(targets.at(i));
  8412. if (!target || !target->IsEntity())
  8413. continue;
  8414. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  8415. targets_to_cure.push_back((Entity*)target);
  8416. }
  8417. }
  8418. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8419. vector<Entity*>::iterator itr;
  8420. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  8421. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8422. }
  8423. }
  8424. return 0;
  8425. }
  8426. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  8427. if (!lua_interface)
  8428. return 0;
  8429. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8430. if (!spell) {
  8431. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  8432. lua_interface->ResetFunctionStack(state);
  8433. return 0;
  8434. }
  8435. if(spell->resisted) {
  8436. lua_interface->ResetFunctionStack(state);
  8437. return 0;
  8438. }
  8439. int8 cure_count = lua_interface->GetInt8Value(state);
  8440. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8441. string cure_name = lua_interface->GetStringValue(state, 3);
  8442. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8443. Spawn* target = lua_interface->GetSpawn(state, 5);
  8444. lua_interface->ResetFunctionStack(state);
  8445. if (target) {
  8446. if (!target->IsEntity()) {
  8447. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8448. return 0;
  8449. }
  8450. if (((Entity*)target)->GetDetCount() > 0)
  8451. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8452. }
  8453. else {
  8454. ZoneServer* zone = spell->caster->GetZone();
  8455. vector<int32> targets = spell->targets;
  8456. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8457. for (int8 i = 0; i < targets.size(); i++) {
  8458. target = zone->GetSpawnByID(targets.at(i));
  8459. if (!target || !target->IsEntity())
  8460. continue;
  8461. if (((Entity*)target)->GetDetCount() > 0)
  8462. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8463. }
  8464. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8465. }
  8466. return 0;
  8467. }
  8468. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8469. if (!lua_interface)
  8470. return 0;
  8471. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8472. lua_interface->ResetFunctionStack(state);
  8473. if (!spell) {
  8474. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8475. return 0;
  8476. }
  8477. if (!spell->caster) {
  8478. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8479. return 0;
  8480. }
  8481. if (!spell->caster->GetZone()) {
  8482. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8483. return 0;
  8484. }
  8485. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8486. return 0;
  8487. }
  8488. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8489. if (!lua_interface)
  8490. return 0;
  8491. Spawn* spawn = lua_interface->GetSpawn(state);
  8492. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8493. lua_interface->ResetFunctionStack(state);
  8494. if (!spell) {
  8495. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8496. return 0;
  8497. }
  8498. if (spawn && spawn->IsEntity())
  8499. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8500. else {
  8501. ZoneServer* zone = spell->caster->GetZone();
  8502. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8503. for (int32 i = 0; i < spell->targets.size(); i++) {
  8504. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8505. if (!spawn || !spawn->IsEntity())
  8506. continue;
  8507. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8508. }
  8509. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8510. }
  8511. return 0;
  8512. }
  8513. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8514. if (!lua_interface)
  8515. return 0;
  8516. Spawn* spawn = lua_interface->GetSpawn(state);
  8517. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8518. lua_interface->ResetFunctionStack(state);
  8519. if (!spell) {
  8520. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8521. return 0;
  8522. }
  8523. if (spawn && spawn->IsEntity())
  8524. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8525. else {
  8526. ZoneServer* zone = spell->caster->GetZone();
  8527. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8528. for (int32 i = 0; i < spell->targets.size(); i++) {
  8529. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8530. if (!spawn || !spawn->IsEntity())
  8531. continue;
  8532. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8533. }
  8534. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8535. }
  8536. return 0;
  8537. }
  8538. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8539. if (!lua_interface)
  8540. return 0;
  8541. Spawn* caster = lua_interface->GetSpawn(state);
  8542. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8543. lua_interface->ResetFunctionStack(state);
  8544. if (!caster) {
  8545. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8546. return 0;
  8547. }
  8548. if (!caster->IsPlayer()) {
  8549. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8550. return 0;
  8551. }
  8552. Spawn* target = caster->GetTarget();
  8553. if (!target) {
  8554. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8555. return 0;
  8556. }
  8557. Client* client = ((Player*)caster)->GetClient();
  8558. if (!client) {
  8559. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8560. return 0;
  8561. }
  8562. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8563. if (ho) {
  8564. ho->SetTarget(target->GetID());
  8565. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8566. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8567. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8568. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8569. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8570. deque<GroupMemberInfo*>::iterator itr;
  8571. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8572. if (group)
  8573. {
  8574. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8575. deque<GroupMemberInfo*>* members = group->GetMembers();
  8576. for (itr = members->begin(); itr != members->end(); itr++) {
  8577. if ((*itr)->client)
  8578. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8579. }
  8580. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8581. }
  8582. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8583. }
  8584. else
  8585. safe_delete(ho);
  8586. }
  8587. else {
  8588. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8589. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8590. }
  8591. else
  8592. safe_delete(ho);
  8593. }
  8594. }
  8595. return 0;
  8596. }
  8597. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8598. if (!lua_interface)
  8599. return 0;
  8600. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8601. if (!spell) {
  8602. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8603. return 0;
  8604. }
  8605. int16 triggerCount = lua_interface->GetInt16Value(state);
  8606. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8607. if (!triggerCount) {
  8608. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8609. return 0;
  8610. }
  8611. spell->num_triggers = triggerCount;
  8612. spell->had_triggers = true;
  8613. spell->cancel_after_all_triggers = cancel_after_triggers;
  8614. return 0;
  8615. }
  8616. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8617. if (!lua_interface)
  8618. return 0;
  8619. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8620. lua_interface->ResetFunctionStack(state);
  8621. if (!spell) {
  8622. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8623. return 0;
  8624. }
  8625. lua_interface->SetInt32Value(state, spell->num_triggers);
  8626. return 1;
  8627. }
  8628. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8629. if (!lua_interface)
  8630. return 0;
  8631. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8632. if (!spell) {
  8633. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8634. lua_interface->ResetFunctionStack(state);
  8635. return 0;
  8636. }
  8637. if (!spell->caster || !spell->caster->GetZone()) {
  8638. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: caster / caster zone must be set!", lua_interface->GetScriptName(state));
  8639. lua_interface->ResetFunctionStack(state);
  8640. return 0;
  8641. }
  8642. int16 remove_count = lua_interface->GetInt16Value(state);
  8643. lua_interface->ResetFunctionStack(state);
  8644. if (!remove_count)
  8645. remove_count = 1;
  8646. if (remove_count >= spell->num_triggers) {
  8647. spell->num_triggers = 0;
  8648. if (spell->cancel_after_all_triggers)
  8649. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8650. }
  8651. else {
  8652. spell->num_triggers -= remove_count;
  8653. Client* client = spell->caster->IsPlayer() ? ((Player*)spell->caster)->GetClient() : nullptr;
  8654. ClientPacketFunctions::SendMaintainedExamineUpdate(client, spell->slot_pos, spell->num_triggers, 0);
  8655. }
  8656. return 0;
  8657. }
  8658. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8659. if (!lua_interface)
  8660. return 0;
  8661. Spawn* spawn = lua_interface->GetSpawn(state);
  8662. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8663. lua_interface->ResetFunctionStack(state);
  8664. if (!spawn) {
  8665. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8666. return 0;
  8667. }
  8668. if (!copy_spawn) {
  8669. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8670. return 0;
  8671. }
  8672. spawn->CopySpawnAppearance(copy_spawn);
  8673. return 0;
  8674. }
  8675. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8676. Spawn* spawn = lua_interface->GetSpawn(state);
  8677. int8 type = lua_interface->GetInt8Value(state, 2);
  8678. lua_interface->ResetFunctionStack(state);
  8679. if (!spawn) {
  8680. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8681. return 0;
  8682. }
  8683. else if (!spawn->IsEntity()) {
  8684. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8685. return 0;
  8686. }
  8687. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8688. return 1;
  8689. }
  8690. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8691. if (!lua_interface)
  8692. return 0;
  8693. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8694. int8 type = lua_interface->GetInt8Value(state);
  8695. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8696. lua_interface->ResetFunctionStack(state);
  8697. if (!spell) {
  8698. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8699. return 0;
  8700. }
  8701. if(spell->resisted) {
  8702. return 0;
  8703. }
  8704. if (spawn) {
  8705. if (!spawn->IsEntity()) {
  8706. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8707. return 0;
  8708. }
  8709. Entity* entity = ((Entity*)spawn);
  8710. entity->AddImmunity(spell, type);
  8711. }
  8712. else if(spell->caster && spell->caster->GetZone()) {
  8713. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8714. for (int8 i = 0; i < spell->targets.size(); i++) {
  8715. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8716. if (!spawn || !spawn->IsEntity())
  8717. continue;
  8718. Entity* entity = ((Entity*)spawn);
  8719. entity->AddImmunity(spell, type);
  8720. }
  8721. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8722. }
  8723. return 0;
  8724. }
  8725. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8726. if (!lua_interface)
  8727. return 0;
  8728. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8729. int8 type = lua_interface->GetInt8Value(state);
  8730. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8731. lua_interface->ResetFunctionStack(state);
  8732. if (!spell) {
  8733. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8734. return 0;
  8735. }
  8736. if (spawn) {
  8737. if (!spawn->IsEntity()) {
  8738. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8739. return 0;
  8740. }
  8741. Entity* entity = ((Entity*)spawn);
  8742. entity->RemoveImmunity(spell, type);
  8743. }
  8744. else if(spell->caster && spell->caster->GetZone()) {
  8745. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8746. for (int8 i = 0; i < spell->targets.size(); i++) {
  8747. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8748. if (!spawn || !spawn->IsEntity())
  8749. continue;
  8750. Entity* entity = ((Entity*)spawn);
  8751. entity->RemoveImmunity(spell, type);
  8752. }
  8753. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8754. }
  8755. return 0;
  8756. }
  8757. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8758. if (!lua_interface)
  8759. return 0;
  8760. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8761. if (!spell) {
  8762. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8763. lua_interface->ResetFunctionStack(state);
  8764. return 0;
  8765. }
  8766. if(spell->resisted) {
  8767. lua_interface->ResetFunctionStack(state);
  8768. return 0;
  8769. }
  8770. float snare = lua_interface->GetFloatValue(state);
  8771. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8772. lua_interface->ResetFunctionStack(state);
  8773. // convert the val to the speed multipler value (100 - val)
  8774. float val = 100.0 - snare;
  8775. val /= 100.0;
  8776. if (spawn) {
  8777. if (!spawn->IsEntity()) {
  8778. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8779. return 0;
  8780. }
  8781. ((Entity*)spawn)->SetSnareValue(spell, val);
  8782. }
  8783. else if(spell->caster && spell->caster->GetZone()) {
  8784. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8785. for (int8 i = 0; i < spell->targets.size(); i++) {
  8786. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8787. if (!spawn || !spawn->IsEntity())
  8788. continue;
  8789. ((Entity*)spawn)->SetSnareValue(spell, val);
  8790. }
  8791. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8792. }
  8793. return 0;
  8794. }
  8795. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8796. if (!lua_interface)
  8797. return 0;
  8798. Spawn* spawn = lua_interface->GetSpawn(state);
  8799. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8800. lua_interface->ResetFunctionStack(state);
  8801. if (!spawn) {
  8802. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8803. return 0;
  8804. }
  8805. if (race_id == 0) {
  8806. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8807. return 0;
  8808. }
  8809. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8810. return 1;
  8811. }
  8812. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8813. if (!lua_interface)
  8814. return 0;
  8815. Spawn* spawn = lua_interface->GetSpawn(state);
  8816. lua_interface->ResetFunctionStack(state);
  8817. if (!spawn) {
  8818. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8819. return 0;
  8820. }
  8821. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8822. return 1;
  8823. }
  8824. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8825. if (!lua_interface)
  8826. return 0;
  8827. Spawn* spawn = lua_interface->GetSpawn(state);
  8828. lua_interface->ResetFunctionStack(state);
  8829. if (!spawn) {
  8830. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8831. return 0;
  8832. }
  8833. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8834. return 1;
  8835. }
  8836. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8837. if (!lua_interface)
  8838. return 0;
  8839. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8840. lua_interface->ResetFunctionStack(state);
  8841. if (!spell) {
  8842. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8843. return 0;
  8844. }
  8845. lua_interface->SetStringValue(state, spell->spell->GetName());
  8846. return 1;
  8847. }
  8848. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8849. if (!lua_interface)
  8850. return 0;
  8851. Quest* quest = lua_interface->GetQuest(state);
  8852. lua_interface->ResetFunctionStack(state);
  8853. if (!quest) {
  8854. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8855. return 0;
  8856. }
  8857. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8858. return 1;
  8859. }
  8860. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8861. if (!lua_interface)
  8862. return 0;
  8863. Quest* quest = lua_interface->GetQuest(state);
  8864. int32 flags = lua_interface->GetInt32Value(state, 2);
  8865. lua_interface->ResetFunctionStack(state);
  8866. if (!quest) {
  8867. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8868. return 0;
  8869. }
  8870. quest->SetQuestFlags(flags);
  8871. return 0;
  8872. }
  8873. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8874. if (!lua_interface)
  8875. return 0;
  8876. Quest* quest = lua_interface->GetQuest(state);
  8877. Spawn* player = lua_interface->GetSpawn(state, 2);
  8878. int32 step = lua_interface->GetInt32Value(state, 3);
  8879. int32 duration = lua_interface->GetInt32Value(state, 4);
  8880. string action = lua_interface->GetStringValue(state, 5);
  8881. lua_interface->ResetFunctionStack(state);
  8882. if (!quest) {
  8883. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8884. return 0;
  8885. }
  8886. if (!player) {
  8887. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8888. return 0;
  8889. }
  8890. if (!player->IsPlayer()) {
  8891. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8892. return 0;
  8893. }
  8894. if (step == 0) {
  8895. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8896. return 0;
  8897. }
  8898. if (duration == 0) {
  8899. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8900. return 0;
  8901. }
  8902. if (action.length() == 0) {
  8903. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8904. return 0;
  8905. }
  8906. Client* client = ((Player*)player)->GetClient();
  8907. if (!client) {
  8908. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8909. return 0;
  8910. }
  8911. quest->SetTimerStep(step);
  8912. quest->AddFailedAction(step, action);
  8913. quest->SetStepTimer(duration);
  8914. client->AddQuestTimer(quest->GetQuestID());
  8915. return 0;
  8916. }
  8917. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8918. if (!lua_interface)
  8919. return 0;
  8920. Quest* quest = lua_interface->GetQuest(state);
  8921. Spawn* player = lua_interface->GetSpawn(state, 2);
  8922. lua_interface->ResetFunctionStack(state);
  8923. if (!quest) {
  8924. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8925. return 0;
  8926. }
  8927. if (!player) {
  8928. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8929. return 0;
  8930. }
  8931. if (!player->IsPlayer()) {
  8932. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8933. return 0;
  8934. }
  8935. Client* client = ((Player*)player)->GetClient();
  8936. if (!client) {
  8937. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8938. return 0;
  8939. }
  8940. quest->SetTimerStep(0);
  8941. quest->SetStepTimer(0);
  8942. client->RemoveQuestTimer(quest->GetQuestID());
  8943. return 0;
  8944. }
  8945. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8946. if (!lua_interface)
  8947. return 0;
  8948. Spawn* player = lua_interface->GetSpawn(state);
  8949. Quest* quest = lua_interface->GetQuest(state, 2);
  8950. int32 step = lua_interface->GetInt32Value(state, 3);
  8951. lua_interface->ResetFunctionStack(state);
  8952. if (!player) {
  8953. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8954. return 0;
  8955. }
  8956. if (!player->IsPlayer()) {
  8957. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8958. return 0;
  8959. }
  8960. if (!quest) {
  8961. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8962. return 0;
  8963. }
  8964. if (step == 0) {
  8965. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8966. return 0;
  8967. }
  8968. Client* client = ((Player*)player)->GetClient();
  8969. if (!client) {
  8970. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8971. return 0;
  8972. }
  8973. if (quest->RemoveQuestStep(step, client)) {
  8974. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8975. client->GetCurrentZone()->SendQuestUpdates(client);
  8976. }
  8977. else
  8978. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8979. return 0;
  8980. }
  8981. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8982. if (!lua_interface)
  8983. return 0;
  8984. Quest* quest = lua_interface->GetQuest(state, 1);
  8985. int32 step = lua_interface->GetInt32Value(state, 2);
  8986. string desc = lua_interface->GetStringValue(state, 3);
  8987. string task_group = lua_interface->GetStringValue(state, 4);
  8988. lua_interface->ResetFunctionStack(state);
  8989. if (!quest) {
  8990. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8991. return 0;
  8992. }
  8993. if (step == 0) {
  8994. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8995. return 0;
  8996. }
  8997. QuestStep* quest_step = quest->GetQuestStep(step);
  8998. if (!quest_step) {
  8999. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  9000. return 0;
  9001. }
  9002. quest_step->SetStepProgress(0);
  9003. quest_step->SetTaskGroup(task_group);
  9004. quest_step->SetDescription(desc);
  9005. return 0;
  9006. }
  9007. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  9008. if (!lua_interface)
  9009. return 0;
  9010. Quest* quest = lua_interface->GetQuest(state);
  9011. int32 step = lua_interface->GetInt32Value(state, 2);
  9012. string action = lua_interface->GetStringValue(state, 3);
  9013. lua_interface->ResetFunctionStack(state);
  9014. if (!quest) {
  9015. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  9016. return 0;
  9017. }
  9018. if (step == 0) {
  9019. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  9020. return 0;
  9021. }
  9022. if (action.length() == 0) {
  9023. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  9024. return 0;
  9025. }
  9026. quest->AddFailedAction(step, action);
  9027. return 0;
  9028. }
  9029. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  9030. if (!lua_interface)
  9031. return 0;
  9032. Spawn* player = lua_interface->GetSpawn(state);
  9033. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9034. int32 step = lua_interface->GetInt32Value(state, 3);
  9035. lua_interface->ResetFunctionStack(state);
  9036. if (!player) {
  9037. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  9038. return 0;
  9039. }
  9040. if (!player->IsPlayer()) {
  9041. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  9042. return 0;
  9043. }
  9044. if (quest_id == 0) {
  9045. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  9046. return 0;
  9047. }
  9048. if (step == 0) {
  9049. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  9050. return 0;
  9051. }
  9052. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  9053. if (!quest) {
  9054. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  9055. return 0;
  9056. }
  9057. quest->StepFailed(step);
  9058. return 0;
  9059. }
  9060. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  9061. if (!lua_interface)
  9062. return 0;
  9063. Spawn* player = lua_interface->GetSpawn(state);
  9064. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9065. lua_interface->ResetFunctionStack(state);
  9066. if (!player) {
  9067. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  9068. return 0;
  9069. }
  9070. if (!player->IsPlayer()) {
  9071. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  9072. return 0;
  9073. }
  9074. if (quest_id == 0) {
  9075. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  9076. return 0;
  9077. }
  9078. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestCompletedCount(quest_id));
  9079. return 1;
  9080. }
  9081. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  9082. if (!lua_interface)
  9083. return 0;
  9084. string name = lua_interface->GetStringValue(state);
  9085. string value = lua_interface->GetStringValue(state, 2);
  9086. string comment = lua_interface->GetStringValue(state, 3);
  9087. lua_interface->ResetFunctionStack(state);
  9088. if (name.length() == 0) {
  9089. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  9090. return 0;
  9091. }
  9092. if (value.length() == 0) {
  9093. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  9094. return 0;
  9095. }
  9096. string varname = string("lua_").append(name);
  9097. Variable* var = variables.FindVariable(varname);
  9098. if (var)
  9099. var->SetValue(value.c_str());
  9100. else {
  9101. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  9102. variables.AddVariable(var);
  9103. }
  9104. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  9105. return 0;
  9106. }
  9107. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  9108. if (!lua_interface)
  9109. return 0;
  9110. string name = lua_interface->GetStringValue(state);
  9111. lua_interface->ResetFunctionStack(state);
  9112. if (name.length() == 0) {
  9113. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  9114. return 0;
  9115. }
  9116. string varname = string("lua_").append(name);
  9117. Variable* var = variables.FindVariable(varname);
  9118. if (var)
  9119. lua_interface->SetStringValue(state, var->GetValue());
  9120. else
  9121. lua_interface->SetStringValue(state, "NULL");
  9122. return 1;
  9123. }
  9124. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  9125. if (!lua_interface)
  9126. return 0;
  9127. Spawn* player = lua_interface->GetSpawn(state);
  9128. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9129. lua_interface->ResetFunctionStack(state);
  9130. if (!player) {
  9131. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9132. return 0;
  9133. }
  9134. if (!player->IsPlayer()) {
  9135. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9136. return 0;
  9137. }
  9138. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  9139. return 1;
  9140. }
  9141. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  9142. if (!lua_interface)
  9143. return 0;
  9144. Spawn* player = lua_interface->GetSpawn(state);
  9145. int32 language_id = lua_interface->GetInt32Value(state, 2);
  9146. lua_interface->ResetFunctionStack(state);
  9147. if (!player) {
  9148. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  9149. return 0;
  9150. }
  9151. if (!player->IsPlayer()) {
  9152. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  9153. return 0;
  9154. }
  9155. Language* language = master_languages_list.GetLanguage(language_id);
  9156. if (language)
  9157. {
  9158. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  9159. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID(), 0);
  9160. }
  9161. return 0;
  9162. }
  9163. int EQ2Emu_lua_IsNight(lua_State* state) {
  9164. if (!lua_interface)
  9165. return 0;
  9166. ZoneServer* zone = lua_interface->GetZone(state);
  9167. lua_interface->ResetFunctionStack(state);
  9168. if (!zone) {
  9169. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  9170. return 0;
  9171. }
  9172. lua_interface->SetBooleanValue(state, zone->IsDusk());
  9173. return 1;
  9174. }
  9175. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  9176. if (!lua_interface)
  9177. return 0;
  9178. Spawn* spawn = lua_interface->GetSpawn(state);
  9179. lua_interface->ResetFunctionStack(state);
  9180. if (!spawn) {
  9181. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  9182. return 0;
  9183. }
  9184. if (!spawn->IsWidget()) {
  9185. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  9186. return 0;
  9187. }
  9188. ((Widget*)spawn)->SetMultiFloorLift(true);
  9189. if (spawn->GetZone())
  9190. spawn->GetZone()->AddTransportSpawn(spawn);
  9191. return 0;
  9192. }
  9193. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  9194. if (!lua_interface)
  9195. return 0;
  9196. Spawn* player = lua_interface->GetSpawn(state);
  9197. int32 path = lua_interface->GetInt32Value(state, 2);
  9198. lua_interface->ResetFunctionStack(state);
  9199. if (!player) {
  9200. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9201. return 0;
  9202. }
  9203. if (!player->IsPlayer()) {
  9204. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9205. return 0;
  9206. }
  9207. if (path == 0) {
  9208. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  9209. return 0;
  9210. }
  9211. Client* client = ((Player*)player)->GetClient();
  9212. if (!client) {
  9213. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9214. return 0;
  9215. }
  9216. client->SendFlightAutoMount(path);
  9217. return 0;
  9218. }
  9219. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  9220. if (!lua_interface)
  9221. return 0;
  9222. Spawn* player = lua_interface->GetSpawn(state);
  9223. if (!player) {
  9224. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  9225. return 0;
  9226. }
  9227. if (!player->IsPlayer()) {
  9228. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9229. return 0;
  9230. }
  9231. Client* client = ((Player*)player)->GetClient();
  9232. if (!client) {
  9233. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9234. return 0;
  9235. }
  9236. client->EndAutoMount();
  9237. return 0;
  9238. }
  9239. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  9240. if (!lua_interface)
  9241. return 0;
  9242. Spawn* player = lua_interface->GetSpawn(state);
  9243. lua_interface->ResetFunctionStack(state);
  9244. if (!player) {
  9245. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  9246. return 0;
  9247. }
  9248. if (!player->IsPlayer()) {
  9249. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  9250. return 0;
  9251. }
  9252. Client* client = ((Player*)player)->GetClient();
  9253. if (!client) {
  9254. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  9255. return 0;
  9256. }
  9257. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  9258. return 1;
  9259. }
  9260. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  9261. if (!lua_interface)
  9262. return 0;
  9263. Spawn* player = lua_interface->GetSpawn(state);
  9264. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9265. int32 value = lua_interface->GetInt32Value(state, 3);
  9266. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9267. lua_interface->ResetFunctionStack(state);
  9268. if (!player) {
  9269. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9270. return 0;
  9271. }
  9272. if (!player->IsPlayer()) {
  9273. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9274. return 0;
  9275. }
  9276. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  9277. return 0;
  9278. }
  9279. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  9280. if (!lua_interface)
  9281. return 0;
  9282. Spawn* player = lua_interface->GetSpawn(state);
  9283. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9284. lua_interface->ResetFunctionStack(state);
  9285. if (!player) {
  9286. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9287. return 0;
  9288. }
  9289. if (!player->IsPlayer()) {
  9290. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  9291. return 0;
  9292. }
  9293. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  9294. if (!hd)
  9295. return 0;
  9296. lua_interface->SetInt32Value(state, hd->Value);
  9297. lua_interface->SetInt32Value(state, hd->Value2);
  9298. return 2;
  9299. }
  9300. int EQ2Emu_lua_SetGridID(lua_State* state) {
  9301. if (!lua_interface)
  9302. return 0;
  9303. Spawn* spawn = lua_interface->GetSpawn(state);
  9304. int32 grid = lua_interface->GetInt32Value(state, 2);
  9305. lua_interface->ResetFunctionStack(state);
  9306. if (!spawn) {
  9307. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9308. return 0;
  9309. }
  9310. if (grid == 0) {
  9311. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  9312. return 0;
  9313. }
  9314. spawn->SetLocation(grid);
  9315. return 0;
  9316. }
  9317. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  9318. if (!lua_interface)
  9319. return 0;
  9320. Spawn* spawn = lua_interface->GetSpawn(state);
  9321. int32 event_id = lua_interface->GetInt32Value(state, 2);
  9322. int32 value1 = lua_interface->GetInt32Value(state, 3);
  9323. int32 value2 = lua_interface->GetInt32Value(state, 4);
  9324. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  9325. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  9326. lua_interface->ResetFunctionStack(state);
  9327. if (!spawn) {
  9328. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  9329. return 0;
  9330. }
  9331. //Add this quest to the list of required quests for this spawn
  9332. spawn->SetRequiredHistory(event_id, value1, value2);
  9333. //If private spawn value set
  9334. if (private_spawn) {
  9335. //Set the spawn to be private when not granted access via history
  9336. spawn->AddAllowAccessSpawn(spawn);
  9337. spawn->SetPrivateQuestSpawn(true);
  9338. }
  9339. //This value will override vis_flags in the vis packet
  9340. if (flag_override > 0)
  9341. spawn->SetQuestsRequiredOverride(flag_override);
  9342. return 0;
  9343. }
  9344. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  9345. if (!lua_interface)
  9346. return 0;
  9347. Spawn* player = lua_interface->GetSpawn(state);
  9348. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  9349. int32 step_id = lua_interface->GetInt32Value(state, 3);
  9350. lua_interface->ResetFunctionStack(state);
  9351. if (!player) {
  9352. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  9353. return 0;
  9354. }
  9355. if (!player->IsPlayer()) {
  9356. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  9357. return 0;
  9358. }
  9359. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  9360. return 1;
  9361. }
  9362. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  9363. if (!lua_interface)
  9364. return 0;
  9365. Spawn* player = lua_interface->GetSpawn(state);
  9366. int8 level = lua_interface->GetInt8Value(state, 2);
  9367. lua_interface->ResetFunctionStack(state);
  9368. if (!player) {
  9369. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  9370. return 0;
  9371. }
  9372. if (!player->IsPlayer()) {
  9373. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  9374. return 0;
  9375. }
  9376. if (level == 0) {
  9377. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  9378. return 0;
  9379. }
  9380. Client* client = ((Player*)player)->GetClient();
  9381. if (!client) {
  9382. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  9383. return 0;
  9384. }
  9385. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  9386. return 0;
  9387. }
  9388. int EQ2Emu_lua_AddCoin(lua_State* state) {
  9389. if (!lua_interface)
  9390. return 0;
  9391. Spawn* player = lua_interface->GetSpawn(state);
  9392. int32 amount = lua_interface->GetInt32Value(state, 2);
  9393. lua_interface->ResetFunctionStack(state);
  9394. if (!player) {
  9395. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9396. return 0;
  9397. }
  9398. if (!player->IsPlayer()) {
  9399. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9400. return 0;
  9401. }
  9402. if (amount == 0) {
  9403. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9404. return 0;
  9405. }
  9406. ((Player*)player)->AddCoins(amount);
  9407. return 0;
  9408. }
  9409. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  9410. if (!lua_interface)
  9411. return 0;
  9412. Spawn* player = lua_interface->GetSpawn(state);
  9413. int32 amount = lua_interface->GetInt32Value(state, 2);
  9414. lua_interface->ResetFunctionStack(state);
  9415. if (!player) {
  9416. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  9417. return 0;
  9418. }
  9419. if (!player->IsPlayer()) {
  9420. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  9421. return 0;
  9422. }
  9423. if (amount == 0) {
  9424. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  9425. return 0;
  9426. }
  9427. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  9428. return 1;
  9429. }
  9430. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  9431. if (!lua_interface)
  9432. return 0;
  9433. ZoneServer* zone = lua_interface->GetZone(state);
  9434. lua_interface->ResetFunctionStack(state);
  9435. if (!zone) {
  9436. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9437. return 0;
  9438. }
  9439. vector<Entity*> players = zone->GetPlayers();
  9440. if (players.size() == 0)
  9441. return 0;
  9442. lua_createtable(state, players.size(), 0);
  9443. int newTable = lua_gettop(state);
  9444. for (int32 i = 0; i < players.size(); i++) {
  9445. lua_interface->SetSpawnValue(state, players.at(i));
  9446. lua_rawseti(state, newTable, i + 1);
  9447. }
  9448. return 1;
  9449. }
  9450. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  9451. if (!lua_interface)
  9452. return 0;
  9453. ZoneServer* zone = lua_interface->GetZone(state, 1);
  9454. if (!zone) {
  9455. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  9456. return 0;
  9457. }
  9458. int32 group_id = lua_interface->GetInt32Value(state, 2);
  9459. lua_interface->ResetFunctionStack(state);
  9460. //Map of <placement_id, location_id>
  9461. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  9462. map<int32, int32>::iterator itr;
  9463. vector<Spawn*> group;
  9464. for (itr = locs->begin(); itr != locs->end(); itr++) {
  9465. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  9466. if (!location) {
  9467. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  9468. return 0;
  9469. }
  9470. Spawn* spawn = 0;
  9471. if (location->entities[0]) {
  9472. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  9473. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  9474. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  9475. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  9476. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  9477. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  9478. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  9479. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  9480. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  9481. spawn = zone->AddSignSpawn(location, location->entities[0]);
  9482. if(spawn && spawn->IsOmittedByDBFlag())
  9483. {
  9484. 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);
  9485. safe_delete(spawn);
  9486. continue;
  9487. }
  9488. if (spawn) {
  9489. const char* script = 0;
  9490. for (int x = 0; x < 3; x++) {
  9491. switch (x) {
  9492. case 0:
  9493. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  9494. break;
  9495. case 1:
  9496. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  9497. break;
  9498. case 2:
  9499. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  9500. break;
  9501. }
  9502. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9503. spawn->SetSpawnScript(string(script));
  9504. break;
  9505. }
  9506. }
  9507. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9508. lua_interface->SetSpawnValue(state, spawn);
  9509. group.push_back(spawn);
  9510. }
  9511. else {
  9512. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  9513. safe_delete(spawn);
  9514. }
  9515. }
  9516. }
  9517. if (!group.empty()) {
  9518. lua_createtable(state, group.size(), 0);
  9519. int newTable = lua_gettop(state);
  9520. for (int32 i = 0; i < group.size(); i++) {
  9521. lua_interface->SetSpawnValue(state, group[i]);
  9522. lua_rawseti(state, newTable, i + 1);
  9523. }
  9524. }
  9525. else
  9526. lua_pushnil(state);
  9527. return 1;
  9528. }
  9529. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9530. if (!lua_interface)
  9531. return 0;
  9532. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9533. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9534. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9535. lua_interface->ResetFunctionStack(state);
  9536. if (!spawn) {
  9537. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9538. return 0;
  9539. }
  9540. if (anim_id == 0) {
  9541. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9542. return 0;
  9543. }
  9544. if (leeway == 0)
  9545. leeway = 5000;
  9546. spawn->SetSpawnAnim(anim_id);
  9547. spawn->SetSpawnAnimLeeway(leeway);
  9548. return 0;
  9549. }
  9550. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9551. if (!lua_interface)
  9552. return 0;
  9553. Spawn* player = lua_interface->GetSpawn(state);
  9554. lua_interface->ResetFunctionStack(state);
  9555. if (!player || !player->IsPlayer()) {
  9556. return 0;
  9557. }
  9558. Client* client = ((Player*)player)->GetClient();
  9559. if (!client) {
  9560. return 0;
  9561. }
  9562. lua_interface->SetInt32Value(state, client->GetVersion());
  9563. return 1;
  9564. }
  9565. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9566. if (!lua_interface)
  9567. return 0;
  9568. Item* item = lua_interface->GetItem(state);
  9569. lua_interface->ResetFunctionStack(state);
  9570. if (!item) {
  9571. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9572. return 0;
  9573. }
  9574. lua_interface->SetInt32Value(state, item->details.item_id);
  9575. return 1;
  9576. }
  9577. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9578. if (!lua_interface)
  9579. return 0;
  9580. Spawn* spawn = lua_interface->GetSpawn(state);
  9581. lua_interface->ResetFunctionStack(state);
  9582. if (!spawn) {
  9583. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9584. return 0;
  9585. }
  9586. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9587. return 1;
  9588. }
  9589. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9590. if (!lua_interface)
  9591. return 0;
  9592. Spawn* spawn = lua_interface->GetSpawn(state);
  9593. lua_interface->ResetFunctionStack(state);
  9594. if (!spawn) {
  9595. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9596. return 0;
  9597. }
  9598. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9599. return 1;
  9600. }
  9601. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9602. if (!lua_interface)
  9603. return 0;
  9604. Spawn* spawn = lua_interface->GetSpawn(state);
  9605. lua_interface->ResetFunctionStack(state);
  9606. if (!spawn) {
  9607. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9608. return 0;
  9609. }
  9610. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9611. return 1;
  9612. }
  9613. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9614. if (!lua_interface)
  9615. return 0;
  9616. Spawn* spawn = lua_interface->GetSpawn(state);
  9617. lua_interface->ResetFunctionStack(state);
  9618. if (!spawn) {
  9619. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9620. return 0;
  9621. }
  9622. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9623. return 1;
  9624. }
  9625. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9626. if (!lua_interface)
  9627. return 0;
  9628. Spawn* spawn = lua_interface->GetSpawn(state);
  9629. float pct = lua_interface->GetFloatValue(state, 2);
  9630. lua_interface->ResetFunctionStack(state);
  9631. if (!spawn) {
  9632. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9633. return 0;
  9634. }
  9635. if (pct == 0) {
  9636. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9637. return 0;
  9638. }
  9639. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9640. lua_interface->SetInt32Value(state, amount);
  9641. return 1;
  9642. }
  9643. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9644. if (!lua_interface)
  9645. return 0;
  9646. Spawn* spawn = lua_interface->GetSpawn(state);
  9647. float pct = lua_interface->GetFloatValue(state, 2);
  9648. lua_interface->ResetFunctionStack(state);
  9649. if (!spawn) {
  9650. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9651. return 0;
  9652. }
  9653. if (pct == 0) {
  9654. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9655. return 0;
  9656. }
  9657. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9658. lua_interface->SetInt32Value(state, amount);
  9659. return 1;
  9660. }
  9661. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9662. if (!lua_interface)
  9663. return 0;
  9664. Spawn* spawn = lua_interface->GetSpawn(state);
  9665. lua_interface->ResetFunctionStack(state);
  9666. if (!spawn) {
  9667. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9668. return 0;
  9669. }
  9670. if (!spawn->IsPlayer()) {
  9671. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9672. return 0;
  9673. }
  9674. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9675. return 1;
  9676. }
  9677. int EQ2Emu_lua_Evac(lua_State* state) {
  9678. if (!lua_interface)
  9679. return 0;
  9680. Spawn* target = lua_interface->GetSpawn(state);
  9681. if (target) {
  9682. float x = target->GetZone()->GetSafeX();
  9683. float y = target->GetZone()->GetSafeY();
  9684. float z = target->GetZone()->GetSafeZ();
  9685. float h = target->GetZone()->GetSafeHeading();
  9686. target->SetX(x);
  9687. target->SetY(y);
  9688. target->SetZ(z);
  9689. target->SetHeading(h);
  9690. target->SetSpawnOrigX(x);
  9691. target->SetSpawnOrigY(y);
  9692. target->SetSpawnOrigZ(z);
  9693. target->SetSpawnOrigHeading(h);
  9694. if (target->IsPlayer()) {
  9695. Client* client = ((Player*)target)->GetClient();
  9696. if (client) {
  9697. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9698. int numargs = lua_interface->GetNumberOfArgs(state);
  9699. if(numargs == 4) {
  9700. x = lua_interface->GetFloatValue(state,1);
  9701. y = lua_interface->GetFloatValue(state,2);
  9702. z = lua_interface->GetFloatValue(state,3);
  9703. h = lua_interface->GetFloatValue(state,4);
  9704. }
  9705. client->SetReloadingZone(true);
  9706. target->SetX(x);
  9707. target->SetY(y);
  9708. target->SetZ(z);
  9709. target->SetHeading(h);
  9710. target->SetSpawnOrigX(x);
  9711. target->SetSpawnOrigY(y);
  9712. target->SetSpawnOrigZ(z);
  9713. target->SetSpawnOrigHeading(h);
  9714. target->SetAppearancePosition(x,y,z);
  9715. client->SetZoningCoords(x,y,z,h);
  9716. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9717. if (packet)
  9718. {
  9719. packet->setDataByName("x", x);
  9720. packet->setDataByName("y", y);
  9721. packet->setDataByName("z", z);
  9722. client->QueuePacket(packet->serialize());
  9723. safe_delete(packet);
  9724. }
  9725. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9726. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9727. }
  9728. }
  9729. lua_interface->ResetFunctionStack(state);
  9730. }
  9731. else {
  9732. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9733. if(!spell || !spell->caster || !spell->caster->GetZone()) {
  9734. lua_interface->ResetFunctionStack(state);
  9735. return 0;
  9736. }
  9737. ZoneServer* zone = spell->caster->GetZone();
  9738. float x = spell->caster->GetZone()->GetSafeX();
  9739. float y = spell->caster->GetZone()->GetSafeY();
  9740. float z = spell->caster->GetZone()->GetSafeZ();
  9741. float h = spell->caster->GetZone()->GetSafeHeading();
  9742. int numargs = lua_interface->GetNumberOfArgs(state);
  9743. if(numargs == 4) {
  9744. x = lua_interface->GetFloatValue(state,1);
  9745. y = lua_interface->GetFloatValue(state,2);
  9746. z = lua_interface->GetFloatValue(state,3);
  9747. h = lua_interface->GetFloatValue(state,4);
  9748. }
  9749. lua_interface->ResetFunctionStack(state);
  9750. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9751. for (int32 i = 0; i < spell->targets.size(); i++) {
  9752. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9753. if (!target2)
  9754. continue;
  9755. if (target2->IsPlayer()) {
  9756. Client* client = ((Player*)target2)->GetClient();
  9757. if (client) {
  9758. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9759. client->SetReloadingZone(true);
  9760. target2->SetX(x);
  9761. target2->SetY(y);
  9762. target2->SetZ(z);
  9763. target2->SetHeading(h);
  9764. target2->SetSpawnOrigX(x);
  9765. target2->SetSpawnOrigY(y);
  9766. target2->SetSpawnOrigZ(z);
  9767. target2->SetSpawnOrigHeading(h);
  9768. target2->SetAppearancePosition(x,y,z);
  9769. client->SetZoningCoords(x,y,z,h);
  9770. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9771. if (packet)
  9772. {
  9773. packet->setDataByName("x", x);
  9774. packet->setDataByName("y", y);
  9775. packet->setDataByName("z", z);
  9776. client->QueuePacket(packet->serialize());
  9777. safe_delete(packet);
  9778. }
  9779. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9780. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9781. }
  9782. }
  9783. }
  9784. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9785. }
  9786. return 0;
  9787. }
  9788. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9789. if (!lua_interface)
  9790. return 0;
  9791. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9792. lua_interface->ResetFunctionStack(state);
  9793. if (!luaspell || !luaspell->spell) {
  9794. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9795. return 0;
  9796. }
  9797. int8 tier = luaspell->spell->GetSpellTier();
  9798. lua_interface->SetInt32Value(state, tier);
  9799. return 1;
  9800. }
  9801. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9802. if (!lua_interface)
  9803. return 0;
  9804. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9805. lua_interface->ResetFunctionStack(state);
  9806. if (!luaspell || !luaspell->spell) {
  9807. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9808. return 0;
  9809. }
  9810. int32 spell_id = luaspell->spell->GetSpellID();
  9811. lua_interface->SetInt32Value(state, spell_id);
  9812. return 1;
  9813. }
  9814. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9815. if (!lua_interface)
  9816. return 0;
  9817. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9818. lua_interface->ResetFunctionStack(state);
  9819. if (!spawn) {
  9820. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9821. return 0;
  9822. }
  9823. if (!spawn->IsPlayer()) {
  9824. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9825. return 0;
  9826. }
  9827. ZoneServer* zone = spawn->GetZone();
  9828. if (!zone) {
  9829. return 0;
  9830. }
  9831. Client* client = ((Player*)spawn)->GetClient();
  9832. if (!client) {
  9833. return 0;
  9834. }
  9835. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9836. return 0;
  9837. }
  9838. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9839. if (!lua_interface)
  9840. return 0;
  9841. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9842. lua_interface->ResetFunctionStack(state);
  9843. if (!spawn) {
  9844. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9845. return 0;
  9846. }
  9847. if (!spawn->IsPlayer()) {
  9848. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9849. return 0;
  9850. }
  9851. ZoneServer* zone = spawn->GetZone();
  9852. if (!zone) {
  9853. return 0;
  9854. }
  9855. Client* client = ((Player*)spawn)->GetClient();
  9856. if (!client) {
  9857. return 0;
  9858. }
  9859. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9860. return 0;
  9861. }
  9862. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9863. if (!lua_interface)
  9864. return 0;
  9865. Spawn* caster = lua_interface->GetSpawn(state);
  9866. Spawn* target = lua_interface->GetSpawn(state, 2);
  9867. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9868. string spell_name = lua_interface->GetStringValue(state, 4);
  9869. lua_interface->ResetFunctionStack(state);
  9870. if (!caster) {
  9871. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9872. return 0;
  9873. }
  9874. if (!caster->IsEntity()) {
  9875. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9876. return 0;
  9877. }
  9878. if (!target) {
  9879. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9880. return 0;
  9881. }
  9882. if (!target->IsEntity()) {
  9883. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9884. return 0;
  9885. }
  9886. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9887. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9888. return 0;
  9889. }
  9890. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9891. if (!lua_interface)
  9892. return 0;
  9893. Spawn* player = lua_interface->GetSpawn(state);
  9894. int32 amount = lua_interface->GetInt32Value(state, 2);
  9895. lua_interface->ResetFunctionStack(state);
  9896. if (player && player->IsPlayer() && amount > 0) {
  9897. ((Player*)player)->AddXP(amount);
  9898. }
  9899. return 0;
  9900. }
  9901. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9902. if (!lua_interface)
  9903. return 0;
  9904. Spawn* player = lua_interface->GetSpawn(state);
  9905. int8 type = lua_interface->GetInt8Value(state, 2);
  9906. string text = lua_interface->GetStringValue(state, 3);
  9907. lua_interface->ResetFunctionStack(state);
  9908. Client* client = 0;
  9909. if (player && player->IsPlayer())
  9910. client = ((Player*)player)->GetClient();
  9911. if (!client || text.length() == 0) {
  9912. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9913. return 0;
  9914. }
  9915. client->SimpleMessage(type, text.c_str());
  9916. return 0;
  9917. }
  9918. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9919. if (!lua_interface)
  9920. return 0;
  9921. Spawn* player = lua_interface->GetSpawn(state);
  9922. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9923. lua_interface->ResetFunctionStack(state);
  9924. Client* client = 0;
  9925. if (player && player->IsPlayer())
  9926. client = ((Player*)player)->GetClient();
  9927. if (!client || !spawn) {
  9928. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9929. return 0;
  9930. }
  9931. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9932. if (!items) {
  9933. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9934. return 0;
  9935. }
  9936. client->SendLootResponsePacket(spawn->GetLootCoins(), items, spawn, true);
  9937. return 0;
  9938. }
  9939. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9940. if (!lua_interface)
  9941. return 0;
  9942. Spawn* spawnref = lua_interface->GetSpawn(state);
  9943. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9944. lua_interface->ResetFunctionStack(state);
  9945. if (spawn_id > 0 && spawnref) {
  9946. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9947. if (spawns.size() == 0) {
  9948. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9949. return 0;
  9950. }
  9951. Spawn* spawn = 0;
  9952. int16 index = MakeRandomInt(0, spawns.size());
  9953. if (index >= spawns.size() || index < 0)
  9954. index = 0;
  9955. spawn = spawns[index];
  9956. lua_interface->SetSpawnValue(state, spawn);
  9957. return 1;
  9958. }
  9959. else {
  9960. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9961. }
  9962. return 0;
  9963. }
  9964. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9965. Spawn* player = lua_interface->GetSpawn(state);
  9966. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9967. string name = lua_interface->GetStringValue(state, 3);
  9968. float distance = lua_interface->GetFloatValue(state, 4);
  9969. string command = lua_interface->GetStringValue(state, 5);
  9970. string error_text = lua_interface->GetStringValue(state, 6);
  9971. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9972. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9973. lua_interface->ResetFunctionStack(state);
  9974. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9975. if (distance == 0)
  9976. distance = 10.0f;
  9977. if (command.length() == 0)
  9978. command = name;
  9979. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9980. if (spawns.size() == 0) {
  9981. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9982. return 0;
  9983. }
  9984. Spawn* spawn = 0;
  9985. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9986. spawn = *itr;
  9987. if (spawn) {
  9988. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9989. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9990. }
  9991. }
  9992. }
  9993. return 0;
  9994. }
  9995. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9996. if (!lua_interface)
  9997. return 0;
  9998. Client* client = 0;
  9999. Spawn* player = lua_interface->GetSpawn(state);
  10000. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  10001. lua_interface->ResetFunctionStack(state);
  10002. if (player && player->IsPlayer() && player->GetZone())
  10003. client = ((Player*)player)->GetClient();
  10004. else{
  10005. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  10006. return 0;
  10007. }
  10008. if (client) {
  10009. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  10010. if (packet) {
  10011. packet->setDataByName("goal_num", goal_num);
  10012. client->QueuePacket(packet->serialize());
  10013. safe_delete(packet);
  10014. }
  10015. }
  10016. return 0;
  10017. }
  10018. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  10019. if (!lua_interface)
  10020. return 0;
  10021. Client* client = 0;
  10022. Spawn* player = lua_interface->GetSpawn(state);
  10023. lua_interface->ResetFunctionStack(state);
  10024. if (player && player->IsPlayer() && player->GetZone())
  10025. client = ((Player*)player)->GetClient();
  10026. else {
  10027. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  10028. return 0;
  10029. }
  10030. if (client) {
  10031. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  10032. }
  10033. return 0;
  10034. }
  10035. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  10036. if (!lua_interface)
  10037. return 0;
  10038. Client* client = 0;
  10039. Spawn* player = lua_interface->GetSpawn(state);
  10040. float duration = lua_interface->GetFloatValue(state, 2);
  10041. string text = lua_interface->GetStringValue(state, 3);
  10042. string voice = lua_interface->GetStringValue(state, 4);
  10043. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  10044. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  10045. string signal = lua_interface->GetStringValue(state, 7);
  10046. string goal1 = lua_interface->GetStringValue(state, 8);
  10047. string task1 = lua_interface->GetStringValue(state, 9);
  10048. string goal2 = lua_interface->GetStringValue(state, 10);
  10049. string task2 = lua_interface->GetStringValue(state, 11);
  10050. string goal3 = lua_interface->GetStringValue(state, 12);
  10051. string task3 = lua_interface->GetStringValue(state, 13);
  10052. string goal4 = lua_interface->GetStringValue(state, 14);
  10053. string task4 = lua_interface->GetStringValue(state, 15);
  10054. lua_interface->ResetFunctionStack(state);
  10055. if (!player) {
  10056. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  10057. return 0;
  10058. }
  10059. if (!player->IsPlayer()) {
  10060. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  10061. return 0;
  10062. }
  10063. else
  10064. client = ((Player*)player)->GetClient();
  10065. if (!client) {
  10066. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  10067. return 0;
  10068. }
  10069. if (text.length() == 0) {
  10070. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  10071. return 0;
  10072. }
  10073. if (duration >= 0 && duration < 2)
  10074. duration = 2;
  10075. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  10076. if (packet) {
  10077. packet->setDataByName("open_seconds_max", duration);
  10078. packet->setDataByName("text", text.c_str());
  10079. packet->setDataByName("voice", voice.c_str());
  10080. int8 num_goals = 1;
  10081. if (task2.length() > 0)
  10082. num_goals++;
  10083. if (task3.length() > 0)
  10084. num_goals++;
  10085. if (task4.length() > 0)
  10086. num_goals++;
  10087. packet->setArrayLengthByName("num_goals", num_goals);
  10088. for (int8 i = 0; i < num_goals; i++) {
  10089. packet->setSubArrayLengthByName("num_tasks", 1, i);
  10090. }
  10091. if (goal1.length() > 0)
  10092. packet->setArrayDataByName("goal_text", goal1.c_str());
  10093. if (goal2.length() > 0)
  10094. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  10095. if (goal3.length() > 0)
  10096. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  10097. if (goal4.length() > 0)
  10098. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  10099. packet->setSubArrayDataByName("task_text", task1.c_str());
  10100. if (task2.length() > 0)
  10101. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  10102. if (task3.length() > 0)
  10103. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  10104. if (task4.length() > 0)
  10105. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  10106. packet->setDataByName("complete_sound", "click");
  10107. packet->setDataByName("signal", signal.c_str());
  10108. packet->setDataByName("voice_key1", voice_key1);
  10109. packet->setDataByName("voice_key2", voice_key2);
  10110. client->QueuePacket(packet->serialize());
  10111. safe_delete(packet);
  10112. }
  10113. return 0;
  10114. }
  10115. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  10116. if (!lua_interface)
  10117. return 0;
  10118. Client* client = 0;
  10119. Spawn* player = lua_interface->GetSpawn(state);
  10120. string window = lua_interface->GetStringValue(state, 2);
  10121. int8 show = lua_interface->GetInt8Value(state, 3);
  10122. lua_interface->ResetFunctionStack(state);
  10123. if (!player) {
  10124. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  10125. return 0;
  10126. }
  10127. if (!player->IsPlayer()) {
  10128. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  10129. return 0;
  10130. }
  10131. else
  10132. client = ((Player*)player)->GetClient();
  10133. if (!client) {
  10134. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  10135. return 0;
  10136. }
  10137. if (window.length() == 0) {
  10138. lua_interface->LogError("LUA ShowWindow required parameters not given");
  10139. return 0;
  10140. }
  10141. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  10142. if (packet) {
  10143. packet->setDataByName("window", window.c_str());
  10144. packet->setDataByName("show", show);
  10145. client->QueuePacket(packet->serialize());
  10146. safe_delete(packet);
  10147. }
  10148. return 0;
  10149. }
  10150. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  10151. //See GameEvents.txt for options that can be used for this function
  10152. if (!lua_interface)
  10153. return 0;
  10154. Client* client = 0;
  10155. Spawn* player = lua_interface->GetSpawn(state);
  10156. string event_name = lua_interface->GetStringValue(state, 2);
  10157. int8 enabled = lua_interface->GetInt8Value(state, 3);
  10158. lua_interface->ResetFunctionStack(state);
  10159. if (!player || !player->IsPlayer()) {
  10160. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  10161. return 0;
  10162. }
  10163. client = ((Player*)player)->GetClient();
  10164. if (!client) {
  10165. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  10166. return 0;
  10167. }
  10168. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  10169. if (packet) {
  10170. packet->setDataByName("event_name", event_name.c_str());
  10171. packet->setDataByName("enabled", enabled);
  10172. client->QueuePacket(packet->serialize());
  10173. safe_delete(packet);
  10174. }
  10175. return 0;
  10176. }
  10177. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  10178. if (!lua_interface)
  10179. return 0;
  10180. Spawn* player = lua_interface->GetSpawn(state);
  10181. lua_interface->ResetFunctionStack(state);
  10182. if (player && player->IsPlayer()) {
  10183. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  10184. return 1;
  10185. }
  10186. return 0;
  10187. }
  10188. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  10189. if (!lua_interface)
  10190. return 0;
  10191. Spawn* player = lua_interface->GetSpawn(state);
  10192. int8 step = lua_interface->GetInt8Value(state, 2);
  10193. lua_interface->ResetFunctionStack(state);
  10194. if (player && player->IsPlayer() && step > 0) {
  10195. ((Player*)player)->SetTutorialStep(step);
  10196. }
  10197. return 0;
  10198. }
  10199. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  10200. if (!lua_interface)
  10201. return 0;
  10202. Client* client = 0;
  10203. Spawn* player = lua_interface->GetSpawn(state);
  10204. string window = lua_interface->GetStringValue(state, 2);
  10205. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  10206. lua_interface->ResetFunctionStack(state);
  10207. if (!player) {
  10208. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  10209. return 0;
  10210. }
  10211. if (!player->IsPlayer()) {
  10212. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  10213. return 0;
  10214. }
  10215. else
  10216. client = ((Player*)player)->GetClient();
  10217. if (!client) {
  10218. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  10219. return 0;
  10220. }
  10221. if (window.length() == 0) {
  10222. lua_interface->LogError("LUA FlashWindow required parameters not given");
  10223. return 0;
  10224. }
  10225. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  10226. if (packet) {
  10227. packet->setDataByName("window", window.c_str());
  10228. packet->setDataByName("flash_seconds", flash_seconds);
  10229. client->QueuePacket(packet->serialize());
  10230. safe_delete(packet);
  10231. }
  10232. return 0;
  10233. }
  10234. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  10235. if (!lua_interface)
  10236. return 0;
  10237. Spawn* spawn = lua_interface->GetSpawn(state);
  10238. Spawn* target = lua_interface->GetSpawn(state, 2);
  10239. lua_interface->ResetFunctionStack(state);
  10240. if (spawn && target)
  10241. return spawn->CheckLoS(target);
  10242. return 0;
  10243. }
  10244. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  10245. if (!lua_interface)
  10246. return 0;
  10247. Spawn* spawn = lua_interface->GetSpawn(state);
  10248. float x = lua_interface->GetFloatValue(state, 2);
  10249. float y = lua_interface->GetFloatValue(state, 3);
  10250. float z = lua_interface->GetFloatValue(state, 4);
  10251. lua_interface->ResetFunctionStack(state);
  10252. if (spawn)
  10253. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  10254. return 0;
  10255. }
  10256. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  10257. if (!lua_interface)
  10258. return 0;
  10259. ZoneServer* zone = lua_interface->GetZone(state);
  10260. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  10261. lua_interface->ResetFunctionStack(state);
  10262. if (zone)
  10263. zone->SetExpansionFlag(xpackFlag);
  10264. return 0;
  10265. }
  10266. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  10267. if (!lua_interface)
  10268. return 0;
  10269. ZoneServer* zone = lua_interface->GetZone(state);
  10270. lua_interface->ResetFunctionStack(state);
  10271. if (zone) {
  10272. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  10273. return 1;
  10274. }
  10275. return 0;
  10276. }
  10277. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  10278. if (!lua_interface)
  10279. return 0;
  10280. ZoneServer* zone = lua_interface->GetZone(state);
  10281. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  10282. lua_interface->ResetFunctionStack(state);
  10283. if (zone)
  10284. zone->SetHolidayFlag(holidayFlag);
  10285. return 0;
  10286. }
  10287. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  10288. if (!lua_interface)
  10289. return 0;
  10290. ZoneServer* zone = lua_interface->GetZone(state);
  10291. lua_interface->ResetFunctionStack(state);
  10292. if (zone) {
  10293. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  10294. return 1;
  10295. }
  10296. return 0;
  10297. }
  10298. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  10299. if (!lua_interface)
  10300. return 0;
  10301. Spawn* spawn = lua_interface->GetSpawn(state);
  10302. bool canbind = lua_interface->GetInt32Value(state, 2);
  10303. lua_interface->ResetFunctionStack(state);
  10304. if(!spawn) {
  10305. lua_interface->LogError("%s: LUA SetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10306. return 0;
  10307. }
  10308. ZoneServer* zone = spawn->GetZone();
  10309. if (zone)
  10310. zone->SetCanBind(canbind);
  10311. return 0;
  10312. }
  10313. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  10314. if (!lua_interface)
  10315. return 0;
  10316. Spawn* spawn = lua_interface->GetSpawn(state);
  10317. lua_interface->ResetFunctionStack(state);
  10318. if(!spawn) {
  10319. lua_interface->LogError("%s: LUA GetCanBind command error: spawn is not valid", lua_interface->GetScriptName(state));
  10320. return 0;
  10321. }
  10322. ZoneServer* zone = spawn->GetZone();
  10323. if (zone) {
  10324. lua_interface->SetInt32Value(state, zone->GetCanBind());
  10325. return 1;
  10326. }
  10327. return 0;
  10328. }
  10329. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  10330. if (!lua_interface)
  10331. return 0;
  10332. Spawn* spawn = lua_interface->GetSpawn(state);
  10333. bool cangate = lua_interface->GetInt32Value(state, 2);
  10334. lua_interface->ResetFunctionStack(state);
  10335. if(!spawn) {
  10336. lua_interface->LogError("%s: LUA SetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10337. return 0;
  10338. }
  10339. ZoneServer* zone = spawn->GetZone();
  10340. if (zone)
  10341. zone->SetCanGate(cangate);
  10342. return 0;
  10343. }
  10344. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  10345. if (!lua_interface)
  10346. return 0;
  10347. Spawn* spawn = lua_interface->GetSpawn(state);
  10348. lua_interface->ResetFunctionStack(state);
  10349. if(!spawn) {
  10350. lua_interface->LogError("%s: LUA GetCanGate command error: spawn is not valid", lua_interface->GetScriptName(state));
  10351. return 0;
  10352. }
  10353. ZoneServer* zone = spawn->GetZone();
  10354. if (zone) {
  10355. lua_interface->SetInt32Value(state, zone->GetCanGate());
  10356. return 1;
  10357. }
  10358. return 0;
  10359. }
  10360. int EQ2Emu_lua_SetCanEvac(lua_State* state) {
  10361. if (!lua_interface)
  10362. return 0;
  10363. Spawn* spawn = lua_interface->GetSpawn(state);
  10364. bool canevac = lua_interface->GetInt32Value(state, 2);
  10365. lua_interface->ResetFunctionStack(state);
  10366. if(!spawn) {
  10367. lua_interface->LogError("%s: LUA SetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10368. return 0;
  10369. }
  10370. ZoneServer* zone = spawn->GetZone();
  10371. if (zone)
  10372. zone->SetCanEvac(canevac);
  10373. return 0;
  10374. }
  10375. int EQ2Emu_lua_GetCanEvac(lua_State* state) {
  10376. if (!lua_interface)
  10377. return 0;
  10378. Spawn* spawn = lua_interface->GetSpawn(state);
  10379. lua_interface->ResetFunctionStack(state);
  10380. if(!spawn) {
  10381. lua_interface->LogError("%s: LUA GetCanEvac command error: spawn is not valid", lua_interface->GetScriptName(state));
  10382. return 0;
  10383. }
  10384. ZoneServer* zone = spawn->GetZone();
  10385. if (zone) {
  10386. lua_interface->SetInt32Value(state, zone->GetCanEvac());
  10387. return 1;
  10388. }
  10389. return 0;
  10390. }
  10391. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  10392. if (!lua_interface)
  10393. return 0;
  10394. Spawn* spawn = lua_interface->GetSpawn(state);
  10395. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  10396. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  10397. float distance = lua_interface->GetFloatValue(state, 4);
  10398. string in_range_function = lua_interface->GetStringValue(state, 5);
  10399. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  10400. lua_interface->ResetFunctionStack(state);
  10401. if (spawn && distance > 0 && in_range_function.length() > 0)
  10402. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  10403. return 0;
  10404. }
  10405. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  10406. if (!lua_interface)
  10407. return 0;
  10408. Spawn* spawn = lua_interface->GetSpawn(state);
  10409. Spawn* target = lua_interface->GetSpawn(state, 2);
  10410. lua_interface->ResetFunctionStack(state);
  10411. if (spawn && target)
  10412. {
  10413. if (spawn->IsPlayer() && target->IsEntity())
  10414. {
  10415. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  10416. return 1;
  10417. }
  10418. else if (spawn->IsEntity() && target->IsEntity())
  10419. {
  10420. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  10421. return 1;
  10422. }
  10423. }
  10424. return 0;
  10425. }
  10426. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  10427. if (!lua_interface)
  10428. return 0;
  10429. Spawn* spawn = lua_interface->GetSpawn(state);
  10430. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10431. lua_interface->ResetFunctionStack(state);
  10432. if (spawn && spawn->IsEntity())
  10433. {
  10434. ((Entity*)spawn)->SetSeeInvisSpell(val);
  10435. if (spawn->IsPlayer())
  10436. {
  10437. Client* client = ((Player*)spawn)->GetClient();
  10438. if (client)
  10439. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  10440. }
  10441. }
  10442. return 0;
  10443. }
  10444. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  10445. if (!lua_interface)
  10446. return 0;
  10447. Spawn* spawn = lua_interface->GetSpawn(state);
  10448. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  10449. lua_interface->ResetFunctionStack(state);
  10450. if (spawn && spawn->IsEntity())
  10451. {
  10452. ((Entity*)spawn)->SetSeeHideSpell(val);
  10453. if (spawn->IsPlayer())
  10454. {
  10455. Client* client = ((Player*)spawn)->GetClient();
  10456. if (client)
  10457. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  10458. }
  10459. }
  10460. return 0;
  10461. }
  10462. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  10463. {
  10464. if (!lua_interface)
  10465. return 0;
  10466. Spawn* player = lua_interface->GetSpawn(state);
  10467. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  10468. string command = lua_interface->GetStringValue(state, 3);
  10469. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10470. lua_interface->ResetFunctionStack(state);
  10471. if (spawn && player && player->IsPlayer())
  10472. {
  10473. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10474. bool res = false;
  10475. if (cmd)
  10476. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  10477. lua_interface->SetBooleanValue(state, res);
  10478. return 1;
  10479. }
  10480. return 0;
  10481. }
  10482. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  10483. {
  10484. if (!lua_interface)
  10485. return 0;
  10486. Spawn* spawn = lua_interface->GetSpawn(state);
  10487. int32 charID = lua_interface->GetInt32Value(state, 2);
  10488. string command = lua_interface->GetStringValue(state, 3);
  10489. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  10490. lua_interface->ResetFunctionStack(state);
  10491. if (spawn && charID)
  10492. {
  10493. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  10494. bool res = false;
  10495. if (cmd)
  10496. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  10497. lua_interface->SetBooleanValue(state, res);
  10498. return 1;
  10499. }
  10500. return 0;
  10501. }
  10502. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  10503. {
  10504. if (!lua_interface)
  10505. return 0;
  10506. Spawn* spawn = lua_interface->GetSpawn(state);
  10507. string command = lua_interface->GetStringValue(state, 2);
  10508. lua_interface->ResetFunctionStack(state);
  10509. if (spawn && command.length() > 0)
  10510. spawn->RemovePrimaryEntityCommand(command.c_str());
  10511. return 0;
  10512. }
  10513. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  10514. if (!lua_interface)
  10515. return 0;
  10516. Spawn* spawn = lua_interface->GetSpawn(state);
  10517. float distance = lua_interface->GetFloatValue(state, 2);
  10518. string command = lua_interface->GetStringValue(state, 3);
  10519. Spawn* player = lua_interface->GetSpawn(state, 4);
  10520. lua_interface->ResetFunctionStack(state);
  10521. if (spawn) {
  10522. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  10523. }
  10524. return 0;
  10525. }
  10526. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  10527. if (!lua_interface)
  10528. return 0;
  10529. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10530. Spawn* spawn = lua_interface->GetSpawn(state);
  10531. Spawn* player = lua_interface->GetSpawn(state, 2);
  10532. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  10533. lua_interface->ResetFunctionStack(state);
  10534. if (spawn && player && transport_id && player->IsPlayer()) {
  10535. Client* client = 0;
  10536. if (player && player->IsPlayer())
  10537. client = ((Player*)player)->GetClient();
  10538. if (!client)
  10539. return 0;
  10540. vector<TransportDestination*> destinations;
  10541. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  10542. if (destinations.size())
  10543. {
  10544. client->SetTemporaryTransportID(transport_id);
  10545. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  10546. }
  10547. else
  10548. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  10549. }
  10550. return 0;
  10551. }
  10552. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  10553. if (!lua_interface)
  10554. return 0;
  10555. Spawn* player = lua_interface->GetSpawn(state);
  10556. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  10557. lua_interface->ResetFunctionStack(state);
  10558. if (player && player->IsPlayer()) {
  10559. Client* client = 0;
  10560. if (player && player->IsPlayer())
  10561. client = ((Player*)player)->GetClient();
  10562. if (!client)
  10563. return 0;
  10564. client->SetTemporaryTransportID(transport_id);
  10565. }
  10566. return 0;
  10567. }
  10568. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  10569. if (!lua_interface)
  10570. return 0;
  10571. Spawn* player = lua_interface->GetSpawn(state);
  10572. lua_interface->ResetFunctionStack(state);
  10573. if (player && player->IsPlayer()) {
  10574. Client* client = 0;
  10575. if (player && player->IsPlayer())
  10576. client = ((Player*)player)->GetClient();
  10577. if (!client)
  10578. return 0;
  10579. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10580. return 1;
  10581. }
  10582. return 0;
  10583. }
  10584. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10585. if (!lua_interface)
  10586. return 0;
  10587. Spawn* spawn = lua_interface->GetSpawn(state);
  10588. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10589. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10590. if (!spawn) {
  10591. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10592. return 0;
  10593. }
  10594. if (!spawn->IsEntity()) {
  10595. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10596. return 0;
  10597. }
  10598. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10599. {
  10600. 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);
  10601. return 0;
  10602. }
  10603. lua_interface->ResetFunctionStack(state);
  10604. if (spell && spell->targets.size() > 0) {
  10605. ZoneServer* zone = spell->caster->GetZone();
  10606. for (int8 i = 0; i < spell->targets.size(); i++) {
  10607. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10608. if (target && target->IsEntity()) {
  10609. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10610. if (target->IsPlayer())
  10611. ((Player*)target)->SetCharSheetChanged(true);
  10612. }
  10613. }
  10614. }
  10615. else {
  10616. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10617. if (spawn->IsPlayer())
  10618. ((Player*)spawn)->SetCharSheetChanged(true);
  10619. }
  10620. return 0;
  10621. }
  10622. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10623. if (!lua_interface)
  10624. return 0;
  10625. Spawn* spawn = lua_interface->GetSpawn(state);
  10626. lua_interface->ResetFunctionStack(state);
  10627. if (!spawn) {
  10628. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10629. return 0;
  10630. }
  10631. if (!spawn->IsEntity()) {
  10632. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10633. return 0;
  10634. }
  10635. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10636. return 1;
  10637. }
  10638. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10639. if (!lua_interface)
  10640. return 0;
  10641. int32 spell_id = lua_interface->GetInt32Value(state);
  10642. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10643. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10644. if (spell_id > 0) {
  10645. if (spell_tier == 0)
  10646. spell_tier = 1;
  10647. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10648. if(!spell) {
  10649. lua_interface->LogError("%s: GetSpell: Failed, spell id %u spell tier %u does not exist.", lua_interface->GetScriptName(state), spell_id, spell_tier);
  10650. lua_interface->ResetFunctionStack(state);
  10651. return 0;
  10652. }
  10653. LuaSpell* lua_spell = 0;
  10654. if(custom_lua_script.size() > 0)
  10655. {
  10656. // attempt to load the custom script since it isn't already loaded
  10657. // we will re-obtain the lua_spell further below
  10658. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10659. {
  10660. 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());
  10661. lua_interface->LoadLuaSpell(custom_lua_script);
  10662. }
  10663. }
  10664. else
  10665. custom_lua_script = spell->GetSpellData()->lua_script;
  10666. if (!lua_spell && lua_interface)
  10667. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10668. lua_interface->ResetFunctionStack(state);
  10669. if (!lua_spell)
  10670. {
  10671. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10672. return 0;
  10673. }
  10674. lua_spell->spell = new Spell(spell);
  10675. lua_interface->AddCustomSpell(lua_spell);
  10676. lua_interface->SetSpellValue(state, lua_spell);
  10677. return 1;
  10678. }
  10679. return 0;
  10680. }
  10681. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10682. if (!lua_interface)
  10683. return 0;
  10684. LuaSpell* spell = lua_interface->GetSpell(state);
  10685. string field = lua_interface->GetStringValue(state, 2);
  10686. lua_interface->ResetFunctionStack(state);
  10687. if (!spell) {
  10688. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10689. return 0;
  10690. }
  10691. if (!spell->spell || !spell->spell->GetSpellData()) {
  10692. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10693. return 0;
  10694. }
  10695. boost::to_lower(field);
  10696. return spell->spell->GetSpellData(state, field);
  10697. }
  10698. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10699. if (!lua_interface)
  10700. return 0;
  10701. LuaSpell* spell = lua_interface->GetSpell(state);
  10702. string field = lua_interface->GetStringValue(state, 2);
  10703. int8 fieldArg = 3; // field value after the initial set
  10704. if (!spell) {
  10705. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10706. lua_interface->ResetFunctionStack(state);
  10707. return 0;
  10708. }
  10709. if (!spell->spell || !spell->spell->GetSpellData()) {
  10710. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10711. lua_interface->ResetFunctionStack(state);
  10712. return 0;
  10713. }
  10714. boost::to_lower(field);
  10715. bool valSet = false;
  10716. spell->spell->SetSpellData(state, field, fieldArg);
  10717. lua_interface->ResetFunctionStack(state);
  10718. return valSet;
  10719. }
  10720. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10721. if (!lua_interface)
  10722. return 0;
  10723. LuaSpell* spell = lua_interface->GetSpell(state);
  10724. int8 idx = lua_interface->GetInt32Value(state, 2);
  10725. if (!spell) {
  10726. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10727. lua_interface->ResetFunctionStack(state);
  10728. return 0;
  10729. }
  10730. if (!spell->spell || !spell->spell->GetSpellData()) {
  10731. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10732. lua_interface->ResetFunctionStack(state);
  10733. return 0;
  10734. }
  10735. if (spell->spell->lua_data.size() <= idx)
  10736. {
  10737. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10738. lua_interface->ResetFunctionStack(state);
  10739. return 0;
  10740. }
  10741. bool setVal = true;
  10742. LUAData* data = spell->spell->lua_data[idx];
  10743. switch (data->type)
  10744. {
  10745. case 0:
  10746. {
  10747. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10748. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10749. data->int_value = value;
  10750. data->int_value2 = value2;
  10751. break;
  10752. }
  10753. case 1:
  10754. {
  10755. float value = lua_interface->GetFloatValue(state, 3);
  10756. float value2 = lua_interface->GetFloatValue(state, 4);
  10757. data->float_value = value;
  10758. data->float_value2 = value2;
  10759. break;
  10760. }
  10761. case 2:
  10762. {
  10763. bool value = lua_interface->GetBooleanValue(state, 3);
  10764. data->bool_value = value;
  10765. break;
  10766. }
  10767. case 3:
  10768. {
  10769. string value = lua_interface->GetStringValue(state, 3);
  10770. string value2 = lua_interface->GetStringValue(state, 4);
  10771. data->string_value = value;
  10772. data->string_value2 = value2;
  10773. break;
  10774. }
  10775. default:
  10776. setVal = false;
  10777. }
  10778. lua_interface->ResetFunctionStack(state);
  10779. return setVal;
  10780. }
  10781. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10782. if (!lua_interface)
  10783. return 0;
  10784. LuaSpell* spell = lua_interface->GetSpell(state);
  10785. int8 idx = lua_interface->GetInt32Value(state, 2);
  10786. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10787. lua_interface->ResetFunctionStack(state);
  10788. if (!spell) {
  10789. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10790. return 0;
  10791. }
  10792. if (!spell->spell || !spell->spell->GetSpellData()) {
  10793. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10794. return 0;
  10795. }
  10796. if (spell->spell->lua_data.size() <= idx)
  10797. {
  10798. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10799. return 0;
  10800. }
  10801. bool setVal = true;
  10802. LUAData* data = spell->spell->lua_data[idx];
  10803. switch (data->type)
  10804. {
  10805. case 0:
  10806. {
  10807. if(!secondfield)
  10808. lua_interface->SetSInt32Value(state, data->int_value);
  10809. else
  10810. lua_interface->SetSInt32Value(state, data->int_value2);
  10811. break;
  10812. }
  10813. case 1:
  10814. {
  10815. if (!secondfield)
  10816. lua_interface->SetFloatValue(state, data->float_value);
  10817. else
  10818. lua_interface->SetFloatValue(state, data->float_value2);
  10819. break;
  10820. }
  10821. case 2:
  10822. {
  10823. lua_interface->SetBooleanValue(state, data->bool_value);
  10824. break;
  10825. }
  10826. case 3:
  10827. {
  10828. if (!secondfield)
  10829. lua_interface->SetStringValue(state, data->string_value.c_str());
  10830. else
  10831. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10832. break;
  10833. }
  10834. default:
  10835. setVal = false;
  10836. }
  10837. return setVal;
  10838. }
  10839. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10840. if (!lua_interface)
  10841. return 0;
  10842. LuaSpell* spell = lua_interface->GetSpell(state);
  10843. int8 idx = lua_interface->GetInt32Value(state, 2);
  10844. string field = lua_interface->GetStringValue(state, 3);
  10845. boost::to_lower(field);
  10846. if (!spell) {
  10847. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10848. lua_interface->ResetFunctionStack(state);
  10849. return 0;
  10850. }
  10851. if (!spell->spell || !spell->spell->GetSpellData()) {
  10852. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10853. lua_interface->ResetFunctionStack(state);
  10854. return 0;
  10855. }
  10856. if (spell->spell->effects.size() <= idx)
  10857. {
  10858. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10859. lua_interface->ResetFunctionStack(state);
  10860. return 0;
  10861. }
  10862. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10863. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10864. if (field == "description")
  10865. effect->description = string(lua_interface->GetStringValue(state, 4));
  10866. else if (field == "bullet")
  10867. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10868. else if (field == "percentage")
  10869. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10870. else { // no match
  10871. lua_interface->ResetFunctionStack(state);
  10872. return 0;
  10873. }
  10874. lua_interface->ResetFunctionStack(state);
  10875. return 1;
  10876. }
  10877. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10878. if (!lua_interface)
  10879. return 0;
  10880. LuaSpell* spell = lua_interface->GetSpell(state);
  10881. int8 idx = lua_interface->GetInt32Value(state, 2);
  10882. string field = lua_interface->GetStringValue(state, 3);
  10883. lua_interface->ResetFunctionStack(state);
  10884. boost::to_lower(field);
  10885. if (!spell) {
  10886. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10887. return 0;
  10888. }
  10889. if (!spell->spell || !spell->spell->GetSpellData()) {
  10890. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10891. return 0;
  10892. }
  10893. if (spell->spell->effects.size() <= idx)
  10894. {
  10895. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10896. return 0;
  10897. }
  10898. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10899. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10900. if (field == "description")
  10901. lua_interface->SetStringValue(state, effect->description.c_str());
  10902. else if (field == "bullet")
  10903. lua_interface->SetInt32Value(state, effect->subbullet);
  10904. else if (field == "percentage")
  10905. lua_interface->SetInt32Value(state, effect->percentage);
  10906. else // no match
  10907. return 0;
  10908. return 1;
  10909. }
  10910. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10911. if (!lua_interface)
  10912. return 0;
  10913. LuaSpell* spell = lua_interface->GetSpell(state);
  10914. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10915. Spawn* target = lua_interface->GetSpawn(state, 3);
  10916. lua_interface->ResetFunctionStack(state);
  10917. if (!target) {
  10918. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10919. return 0;
  10920. }
  10921. if (!target->IsEntity()) {
  10922. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10923. return 0;
  10924. }
  10925. if (!spell) {
  10926. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10927. return 0;
  10928. }
  10929. if (caster && !caster->IsEntity()) {
  10930. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10931. return 0;
  10932. }
  10933. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10934. return 0;
  10935. }
  10936. int EQ2Emu_lua_InWater(lua_State* state) {
  10937. if (!lua_interface)
  10938. return 0;
  10939. Spawn* spawn = lua_interface->GetSpawn(state);
  10940. lua_interface->ResetFunctionStack(state);
  10941. if (spawn) {
  10942. lua_interface->SetBooleanValue(state, spawn->InWater());
  10943. return 1;
  10944. }
  10945. return 0;
  10946. }
  10947. int EQ2Emu_lua_InLava(lua_State* state) {
  10948. if (!lua_interface)
  10949. return 0;
  10950. Spawn* spawn = lua_interface->GetSpawn(state);
  10951. lua_interface->ResetFunctionStack(state);
  10952. if (spawn) {
  10953. lua_interface->SetBooleanValue(state, spawn->InLava());
  10954. return 1;
  10955. }
  10956. return 0;
  10957. }
  10958. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10959. if (!lua_interface)
  10960. return 0;
  10961. Spawn* attacker = lua_interface->GetSpawn(state);
  10962. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10963. int8 type = lua_interface->GetInt8Value(state, 3);
  10964. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10965. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10966. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10967. string spell_name = lua_interface->GetStringValue(state, 7);
  10968. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10969. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10970. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10971. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10972. bool take_power = (lua_interface->GetInt8Value(state, 12) == 1);
  10973. lua_interface->ResetFunctionStack(state);
  10974. if (!attacker) {
  10975. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10976. lua_interface->SetBooleanValue(state, false);
  10977. return 1;
  10978. }
  10979. if (!attacker->IsEntity()) {
  10980. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10981. lua_interface->SetBooleanValue(state, false);
  10982. return 1;
  10983. }
  10984. if (!victim) {
  10985. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10986. lua_interface->SetBooleanValue(state, false);
  10987. return 1;
  10988. }
  10989. if (!victim->IsEntity()) {
  10990. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10991. lua_interface->SetBooleanValue(state, false);
  10992. return 1;
  10993. }
  10994. 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);
  10995. lua_interface->SetBooleanValue(state, has_damaged);
  10996. return 1;
  10997. }
  10998. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10999. if (!lua_interface)
  11000. return 0;
  11001. Spawn* spawn = lua_interface->GetSpawn(state);
  11002. lua_interface->ResetFunctionStack(state);
  11003. if (spawn) {
  11004. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  11005. return 1;
  11006. }
  11007. return 0;
  11008. }
  11009. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  11010. if (!lua_interface)
  11011. return 0;
  11012. Spawn* spawn = lua_interface->GetSpawn(state);
  11013. bool invul = lua_interface->GetBooleanValue(state, 2);
  11014. lua_interface->ResetFunctionStack(state);
  11015. if (spawn) {
  11016. spawn->SetInvulnerable(invul);
  11017. }
  11018. return 0;
  11019. }
  11020. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  11021. if (!lua_interface)
  11022. return 0;
  11023. string category = lua_interface->GetStringValue(state);
  11024. string name = lua_interface->GetStringValue(state, 2);
  11025. lua_interface->ResetFunctionStack(state);
  11026. Rule *ret = 0;
  11027. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11028. lua_interface->SetBooleanValue(state, ret->GetBool());
  11029. return 1;
  11030. }
  11031. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11032. return 0;
  11033. }
  11034. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  11035. if (!lua_interface)
  11036. return 0;
  11037. string category = lua_interface->GetStringValue(state);
  11038. string name = lua_interface->GetStringValue(state, 2);
  11039. lua_interface->ResetFunctionStack(state);
  11040. Rule *ret = 0;
  11041. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11042. lua_interface->SetInt32Value(state, ret->GetInt32());
  11043. return 1;
  11044. }
  11045. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11046. return 0;
  11047. }
  11048. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  11049. if (!lua_interface)
  11050. return 0;
  11051. string category = lua_interface->GetStringValue(state);
  11052. string name = lua_interface->GetStringValue(state, 2);
  11053. lua_interface->ResetFunctionStack(state);
  11054. Rule *ret = 0;
  11055. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  11056. lua_interface->SetFloatValue(state, ret->GetFloat());
  11057. return 1;
  11058. }
  11059. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  11060. return 0;
  11061. }
  11062. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  11063. if (!lua_interface)
  11064. return 0;
  11065. Spawn* spawn = lua_interface->GetSpawn(state);
  11066. string type = lua_interface->GetStringValue(state, 2);
  11067. lua_interface->ResetFunctionStack(state);
  11068. if (spawn) {
  11069. int res = 1;
  11070. boost::to_lower(type);
  11071. if(type == "assigned_aa")
  11072. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  11073. else if ( type == "unassigned_aa")
  11074. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  11075. else if ( type == "assigned_tradeskill_aa")
  11076. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  11077. else if ( type == "unassigned_tradeskill_aa")
  11078. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  11079. else if ( type == "assigned_prestige_aa")
  11080. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  11081. else if ( type == "unassigned_prestige_aa")
  11082. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  11083. else if ( type == "assigned_tradeskill_prestige_aa")
  11084. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  11085. else if ( type == "unassigned_tradeskill_prestige_aa")
  11086. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  11087. else
  11088. res = 0;
  11089. return res;
  11090. }
  11091. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  11092. return 0;
  11093. }
  11094. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  11095. if (!lua_interface)
  11096. return 0;
  11097. Spawn* spawn = lua_interface->GetSpawn(state);
  11098. string type = lua_interface->GetStringValue(state, 2);
  11099. sint32 value = lua_interface->GetSInt32Value(state, 3);
  11100. lua_interface->ResetFunctionStack(state);
  11101. if (spawn) {
  11102. boost::to_lower(type);
  11103. if(type == "assigned_aa")
  11104. spawn->SetAssignedAA((sint16)value);
  11105. else if ( type == "unassigned_aa")
  11106. spawn->SetUnassignedAA((sint16)value);
  11107. else if ( type == "assigned_tradeskill_aa")
  11108. spawn->SetTradeskillAA((sint16)value);
  11109. else if ( type == "unassigned_tradeskill_aa")
  11110. spawn->SetUnassignedTradeskillAA((sint16)value);
  11111. else if ( type == "assigned_prestige_aa")
  11112. spawn->SetPrestigeAA((sint16)value);
  11113. else if ( type == "unassigned_prestige_aa")
  11114. spawn->SetUnassignedPrestigeAA((sint16)value);
  11115. else if ( type == "assigned_tradeskill_prestige_aa")
  11116. spawn->SetTradeskillPrestigeAA((sint16)value);
  11117. else if ( type == "unassigned_tradeskill_prestige_aa")
  11118. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  11119. if(spawn->IsPlayer())
  11120. ((Player*)spawn)->SetCharSheetChanged(true);
  11121. }
  11122. return 0;
  11123. }
  11124. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  11125. if (!lua_interface)
  11126. return 0;
  11127. string titleName = lua_interface->GetStringValue(state);
  11128. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  11129. lua_interface->ResetFunctionStack(state);
  11130. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  11131. lua_interface->SetSInt32Value(state, index);
  11132. return 1;
  11133. }
  11134. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  11135. if (!lua_interface)
  11136. return 0;
  11137. Spawn* spawn = lua_interface->GetSpawn(state);
  11138. string titleName = lua_interface->GetStringValue(state, 2);
  11139. lua_interface->ResetFunctionStack(state);
  11140. if(!spawn->IsPlayer())
  11141. {
  11142. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  11143. lua_interface->SetSInt32Value(state, -1);
  11144. return 1;
  11145. }
  11146. Player* player = (Player*)spawn;
  11147. // check if player already has the title, don't need to add twice
  11148. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11149. if ( playerHasTitle)
  11150. {
  11151. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  11152. return 1;
  11153. }
  11154. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  11155. if(!title)
  11156. {
  11157. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11158. lua_interface->SetSInt32Value(state, -1);
  11159. return 1;
  11160. }
  11161. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  11162. if(returnIdx < 0)
  11163. {
  11164. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11165. }
  11166. lua_interface->SetSInt32Value(state, returnIdx);
  11167. player->GetClient()->SendTitleUpdate();
  11168. return 1;
  11169. }
  11170. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  11171. if (!lua_interface)
  11172. return 0;
  11173. Spawn* spawn = lua_interface->GetSpawn(state);
  11174. string titleName = lua_interface->GetStringValue(state, 2);
  11175. lua_interface->ResetFunctionStack(state);
  11176. if(!spawn->IsPlayer())
  11177. {
  11178. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11179. return 0;
  11180. }
  11181. Player* player = (Player*)spawn;
  11182. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11183. if(!title)
  11184. {
  11185. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11186. return 0;
  11187. }
  11188. if(title->GetPrefix())
  11189. {
  11190. 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());
  11191. return 0;
  11192. }
  11193. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  11194. player->GetClient()->SendTitleUpdate();
  11195. return 1;
  11196. }
  11197. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  11198. if (!lua_interface)
  11199. return 0;
  11200. Spawn* spawn = lua_interface->GetSpawn(state);
  11201. string titleName = lua_interface->GetStringValue(state, 2);
  11202. lua_interface->ResetFunctionStack(state);
  11203. if(!spawn->IsPlayer())
  11204. {
  11205. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11206. return 0;
  11207. }
  11208. Player* player = (Player*)spawn;
  11209. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  11210. if(!title)
  11211. {
  11212. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  11213. return 0;
  11214. }
  11215. if(!title->GetPrefix())
  11216. {
  11217. 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());
  11218. return 0;
  11219. }
  11220. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  11221. player->GetClient()->SendTitleUpdate();
  11222. return 1;
  11223. }
  11224. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  11225. if (!lua_interface)
  11226. return 0;
  11227. Spawn* spawn = lua_interface->GetSpawn(state);
  11228. lua_interface->ResetFunctionStack(state);
  11229. if(!spawn->IsPlayer())
  11230. {
  11231. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  11232. return 0;
  11233. }
  11234. Player* player = (Player*)spawn;
  11235. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  11236. player->GetClient()->SendTitleUpdate();
  11237. return 1;
  11238. }
  11239. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  11240. if (!lua_interface)
  11241. return 0;
  11242. Spawn* spawn = lua_interface->GetSpawn(state);
  11243. lua_interface->ResetFunctionStack(state);
  11244. if(!spawn->IsPlayer())
  11245. {
  11246. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  11247. return 0;
  11248. }
  11249. Player* player = (Player*)spawn;
  11250. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  11251. player->GetClient()->SendTitleUpdate();
  11252. return 1;
  11253. }
  11254. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  11255. if (!lua_interface)
  11256. return 0;
  11257. Spawn* spawn = lua_interface->GetSpawn(state);
  11258. string field = lua_interface->GetStringValue(state, 2);
  11259. lua_interface->ResetFunctionStack(state);
  11260. if(!spawn || !spawn->IsEntity())
  11261. {
  11262. 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));
  11263. return 0;
  11264. }
  11265. Entity* ent = (Entity*)spawn;
  11266. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  11267. return 1;
  11268. }
  11269. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  11270. if (!lua_interface)
  11271. return 0;
  11272. Spawn* spawn = lua_interface->GetSpawn(state);
  11273. string field = lua_interface->GetStringValue(state, 2);
  11274. lua_interface->ResetFunctionStack(state);
  11275. if(!spawn || !spawn->IsEntity())
  11276. {
  11277. 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));
  11278. return 0;
  11279. }
  11280. Entity* ent = (Entity*)spawn;
  11281. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  11282. return 1;
  11283. }
  11284. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  11285. if (!lua_interface)
  11286. return 0;
  11287. Spawn* spawn = lua_interface->GetSpawn(state);
  11288. string field = lua_interface->GetStringValue(state, 2);
  11289. lua_interface->ResetFunctionStack(state);
  11290. if(!spawn || !spawn->IsEntity())
  11291. {
  11292. 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));
  11293. return 0;
  11294. }
  11295. Entity* ent = (Entity*)spawn;
  11296. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  11297. return 1;
  11298. }
  11299. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  11300. if (!lua_interface)
  11301. return 0;
  11302. Spawn* spawn = lua_interface->GetSpawn(state);
  11303. string field = lua_interface->GetStringValue(state, 2);
  11304. lua_interface->ResetFunctionStack(state);
  11305. if(!spawn || !spawn->IsEntity())
  11306. {
  11307. 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));
  11308. return 0;
  11309. }
  11310. Entity* ent = (Entity*)spawn;
  11311. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  11312. return 1;
  11313. }
  11314. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  11315. if (!lua_interface)
  11316. return 0;
  11317. Spawn* spawn = lua_interface->GetSpawn(state);
  11318. string field = lua_interface->GetStringValue(state, 2);
  11319. string value = lua_interface->GetStringValue(state, 3);
  11320. lua_interface->ResetFunctionStack(state);
  11321. if(!spawn || !spawn->IsEntity())
  11322. {
  11323. 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));
  11324. return 0;
  11325. }
  11326. Entity* ent = (Entity*)spawn;
  11327. bool set_ = ent->SetInfoStructString(field, value);
  11328. lua_interface->SetBooleanValue(state, set_);
  11329. return 1;
  11330. }
  11331. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  11332. if (!lua_interface)
  11333. return 0;
  11334. Spawn* spawn = lua_interface->GetSpawn(state);
  11335. string field = lua_interface->GetStringValue(state, 2);
  11336. int64 value = lua_interface->GetInt64Value(state, 3);
  11337. lua_interface->ResetFunctionStack(state);
  11338. if(!spawn || !spawn->IsEntity())
  11339. {
  11340. 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));
  11341. return 0;
  11342. }
  11343. Entity* ent = (Entity*)spawn;
  11344. bool set_ = ent->SetInfoStructUInt(field, value);
  11345. lua_interface->SetBooleanValue(state, set_);
  11346. return 1;
  11347. }
  11348. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  11349. if (!lua_interface)
  11350. return 0;
  11351. Spawn* spawn = lua_interface->GetSpawn(state);
  11352. string field = lua_interface->GetStringValue(state, 2);
  11353. sint64 value = lua_interface->GetSInt64Value(state, 3);
  11354. lua_interface->ResetFunctionStack(state);
  11355. if(!spawn || !spawn->IsEntity())
  11356. {
  11357. 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));
  11358. return 0;
  11359. }
  11360. Entity* ent = (Entity*)spawn;
  11361. bool set_ = ent->SetInfoStructSInt(field, value);
  11362. lua_interface->SetBooleanValue(state, set_);
  11363. return 1;
  11364. }
  11365. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  11366. if (!lua_interface)
  11367. return 0;
  11368. Spawn* spawn = lua_interface->GetSpawn(state);
  11369. string field = lua_interface->GetStringValue(state, 2);
  11370. float value = lua_interface->GetFloatValue(state, 3);
  11371. lua_interface->ResetFunctionStack(state);
  11372. if(!spawn || !spawn->IsEntity())
  11373. {
  11374. 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));
  11375. return 0;
  11376. }
  11377. Entity* ent = (Entity*)spawn;
  11378. bool set_ = ent->SetInfoStructFloat(field, value);
  11379. lua_interface->SetBooleanValue(state, set_);
  11380. return 1;
  11381. }
  11382. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  11383. if (!lua_interface)
  11384. return 0;
  11385. Spawn* spawn = lua_interface->GetSpawn(state);
  11386. bool value = lua_interface->GetBooleanValue(state, 2);
  11387. lua_interface->ResetFunctionStack(state);
  11388. if(!spawn || !spawn->IsPlayer())
  11389. {
  11390. 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));
  11391. return 0;
  11392. }
  11393. ((Player*)spawn)->SetCharSheetChanged(value);
  11394. return 0;
  11395. }
  11396. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  11397. if (!lua_interface)
  11398. return 0;
  11399. Spawn* spawn = lua_interface->GetSpawn(state);
  11400. std::string fromName = lua_interface->GetStringValue(state, 2);
  11401. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11402. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11403. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11404. int32 copper = lua_interface->GetInt32Value(state, 6);
  11405. int32 silver = lua_interface->GetInt32Value(state, 7);
  11406. int32 gold = lua_interface->GetInt32Value(state, 8);
  11407. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11408. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11409. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11410. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11411. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11412. lua_interface->ResetFunctionStack(state);
  11413. if(!spawn || !spawn->IsPlayer())
  11414. {
  11415. 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));
  11416. lua_interface->SetBooleanValue(state, false);
  11417. return 1;
  11418. }
  11419. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11420. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11421. lua_interface->SetBooleanValue(state, true);
  11422. return 1;
  11423. }
  11424. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  11425. if (!lua_interface)
  11426. return 0;
  11427. int32 char_id = lua_interface->GetInt32Value(state);
  11428. std::string fromName = lua_interface->GetStringValue(state, 2);
  11429. std::string subjectName = lua_interface->GetStringValue(state, 3);
  11430. std::string mailBody = lua_interface->GetStringValue(state, 4);
  11431. int8 mailType = lua_interface->GetInt8Value(state, 5);
  11432. int32 copper = lua_interface->GetInt32Value(state, 6);
  11433. int32 silver = lua_interface->GetInt32Value(state, 7);
  11434. int32 gold = lua_interface->GetInt32Value(state, 8);
  11435. int32 platinum = lua_interface->GetInt32Value(state, 9);
  11436. int32 item_id = lua_interface->GetInt32Value(state, 10);
  11437. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  11438. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  11439. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  11440. lua_interface->ResetFunctionStack(state);
  11441. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  11442. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  11443. lua_interface->SetBooleanValue(state, true);
  11444. return 1;
  11445. }
  11446. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  11447. Spawn* widget;
  11448. if (lua_interface) {
  11449. widget = lua_interface->GetSpawn(state);
  11450. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  11451. lua_interface->ResetFunctionStack(state);
  11452. if (widget && widget->IsWidget())
  11453. {
  11454. ((Widget*)widget)->OpenDoor();
  11455. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  11456. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11457. }
  11458. else
  11459. 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));
  11460. }
  11461. return 0;
  11462. }
  11463. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  11464. Spawn* widget;
  11465. if (lua_interface) {
  11466. widget = lua_interface->GetSpawn(state);
  11467. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  11468. lua_interface->ResetFunctionStack(state);
  11469. if (widget && widget->IsWidget())
  11470. {
  11471. ((Widget*)widget)->CloseDoor();
  11472. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  11473. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  11474. }
  11475. else
  11476. 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));
  11477. }
  11478. return 0;
  11479. }
  11480. int EQ2Emu_lua_IsOpen(lua_State* state) {
  11481. if (!lua_interface)
  11482. return 0;
  11483. Spawn* widget = lua_interface->GetSpawn(state);
  11484. lua_interface->ResetFunctionStack(state);
  11485. if (widget && widget->IsWidget())
  11486. {
  11487. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  11488. return 1;
  11489. }
  11490. return 0;
  11491. }
  11492. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  11493. if (!lua_interface)
  11494. return 0;
  11495. sint32 min = lua_interface->GetSInt32Value(state);
  11496. sint32 max = lua_interface->GetSInt32Value(state, 2);
  11497. lua_interface->ResetFunctionStack(state);
  11498. sint32 result = MakeRandomInt(min, max);
  11499. lua_interface->SetSInt32Value(state, result);
  11500. return 1;
  11501. }
  11502. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  11503. if (!lua_interface)
  11504. return 0;
  11505. float min = lua_interface->GetFloatValue(state);
  11506. float max = lua_interface->GetFloatValue(state, 2);
  11507. lua_interface->ResetFunctionStack(state);
  11508. float result = MakeRandomFloat(min, max);
  11509. lua_interface->SetFloatValue(state, result);
  11510. return 1;
  11511. }
  11512. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  11513. if (!lua_interface)
  11514. return 0;
  11515. Spawn* spawn = lua_interface->GetSpawn(state);
  11516. int32 value = lua_interface->GetInt32Value(state, 2);
  11517. lua_interface->ResetFunctionStack(state);
  11518. if(!spawn)
  11519. {
  11520. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11521. lua_interface->SetBooleanValue(state, false);
  11522. return 1;
  11523. }
  11524. spawn->AddIconValue(value);
  11525. lua_interface->SetBooleanValue(state, true);
  11526. return 1;
  11527. }
  11528. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  11529. if (!lua_interface)
  11530. return 0;
  11531. Spawn* spawn = lua_interface->GetSpawn(state);
  11532. int32 value = lua_interface->GetInt32Value(state, 2);
  11533. lua_interface->ResetFunctionStack(state);
  11534. if(!spawn)
  11535. {
  11536. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11537. lua_interface->SetBooleanValue(state, false);
  11538. return 1;
  11539. }
  11540. spawn->RemoveIconValue(value);
  11541. lua_interface->SetBooleanValue(state, true);
  11542. return 1;
  11543. }
  11544. int EQ2Emu_lua_GetShardID(lua_State* state) {
  11545. Spawn* npc = lua_interface->GetSpawn(state);
  11546. lua_interface->ResetFunctionStack(state);
  11547. if (npc && npc->IsNPC()) {
  11548. NPC* shard = (NPC*)npc;
  11549. int32 shardid = shard->GetShardID();
  11550. lua_interface->SetInt32Value(state, shardid);
  11551. return 1;
  11552. }
  11553. lua_interface->SetInt32Value(state, 0);
  11554. return 1;
  11555. }
  11556. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  11557. Spawn* npc = lua_interface->GetSpawn(state);
  11558. lua_interface->ResetFunctionStack(state);
  11559. if (npc && npc->IsNPC()) {
  11560. NPC* shard = (NPC*)npc;
  11561. int32 charid = shard->GetShardCharID();
  11562. lua_interface->SetInt32Value(state, charid);
  11563. return 1;
  11564. }
  11565. lua_interface->SetInt32Value(state, 0);
  11566. return 1;
  11567. }
  11568. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  11569. Spawn* npc = lua_interface->GetSpawn(state);
  11570. lua_interface->ResetFunctionStack(state);
  11571. if (npc && npc->IsNPC()) {
  11572. NPC* shard = (NPC*)npc;
  11573. int64 timestamp = shard->GetShardCreatedTimestamp();
  11574. lua_interface->SetSInt64Value(state, timestamp);
  11575. return 1;
  11576. }
  11577. lua_interface->SetSInt64Value(state, 0);
  11578. return 1;
  11579. }
  11580. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  11581. if (!lua_interface)
  11582. return 0;
  11583. int32 shardid = lua_interface->GetInt32Value(state);
  11584. lua_interface->ResetFunctionStack(state);
  11585. if(shardid < 1)
  11586. lua_interface->SetBooleanValue(state, false);
  11587. else
  11588. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  11589. return 1;
  11590. }
  11591. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  11592. if (!lua_interface)
  11593. return 0;
  11594. Spawn* spawn = lua_interface->GetSpawn(state);
  11595. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  11596. if (spawn) {
  11597. spawn->PauseMovement(delay_in_ms);
  11598. }
  11599. lua_interface->ResetFunctionStack(state);
  11600. return 0;
  11601. }
  11602. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11603. if (!lua_interface)
  11604. return 0;
  11605. Spawn* spawn = lua_interface->GetSpawn(state);
  11606. if (spawn) {
  11607. spawn->ResetMovement();
  11608. }
  11609. lua_interface->ResetFunctionStack(state);
  11610. return 0;
  11611. }
  11612. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11613. Player* player = (Player*)lua_interface->GetSpawn(state);
  11614. int8 level = lua_interface->GetInt8Value(state, 2);
  11615. lua_interface->ResetFunctionStack(state);
  11616. if (player && player->IsPlayer() && level > 0) {
  11617. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11618. return 1;
  11619. }
  11620. return 0;
  11621. }
  11622. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11623. Player* player = (Player*)lua_interface->GetSpawn(state);
  11624. int8 level = lua_interface->GetInt8Value(state, 2);
  11625. lua_interface->ResetFunctionStack(state);
  11626. if (player && player->IsPlayer() && level > 0) {
  11627. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11628. return 1;
  11629. }
  11630. return 0;
  11631. }
  11632. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11633. ZoneServer* zone = lua_interface->GetZone(state);
  11634. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11635. lua_interface->ResetFunctionStack(state);
  11636. if (zone) {
  11637. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11638. if (spawn) {
  11639. lua_interface->SetSpawnValue(state, spawn);
  11640. return 1;
  11641. }
  11642. }
  11643. return 0;
  11644. }
  11645. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11646. if (!lua_interface)
  11647. return 0;
  11648. Spawn* spawn = lua_interface->GetSpawn(state);
  11649. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11650. lua_interface->ResetFunctionStack(state);
  11651. bool res = false;
  11652. if(spawn && spawn->IsTransportSpawn())
  11653. {
  11654. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11655. spawn->SetRailID(rail_id);
  11656. res = true;
  11657. }
  11658. else if (!spawn) {
  11659. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11660. }
  11661. else if(!spawn->IsTransportSpawn()) {
  11662. 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());
  11663. }
  11664. lua_interface->SetBooleanValue(state, res);
  11665. return 1;
  11666. }
  11667. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11668. if (!lua_interface)
  11669. return 0;
  11670. ZoneServer* zone = lua_interface->GetZone(state);
  11671. lua_interface->ResetFunctionStack(state);
  11672. if (zone) {
  11673. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11674. return 1;
  11675. }
  11676. return 0;
  11677. }
  11678. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11679. if (!lua_interface)
  11680. return 0;
  11681. Spawn* spawn = lua_interface->GetSpawn(state);
  11682. lua_interface->ResetFunctionStack(state);
  11683. if (spawn) {
  11684. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11685. return 1;
  11686. }
  11687. return 0;
  11688. }
  11689. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11690. if (!lua_interface)
  11691. return 0;
  11692. Spawn* player = lua_interface->GetSpawn(state);
  11693. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11694. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11695. lua_interface->ResetFunctionStack(state);
  11696. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11697. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11698. }
  11699. else if(!zoneID) {
  11700. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11701. }
  11702. else
  11703. {
  11704. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11705. return 1;
  11706. }
  11707. return 0;
  11708. }
  11709. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11710. if (!lua_interface)
  11711. return 0;
  11712. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11713. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11714. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11715. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11716. lua_interface->ResetFunctionStack(state);
  11717. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11718. world.GetWorldTimeStruct()->year = newYear;
  11719. world.GetWorldTimeStruct()->month = newMonth;
  11720. world.GetWorldTimeStruct()->hour = newHour;
  11721. world.GetWorldTimeStruct()->minute = newMinute;
  11722. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11723. return 0;
  11724. }
  11725. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11726. if (!lua_interface)
  11727. return 0;
  11728. lua_interface->ResetFunctionStack(state);
  11729. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11730. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11731. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11732. return 1;
  11733. }
  11734. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11735. if (!lua_interface)
  11736. return 0;
  11737. lua_interface->ResetFunctionStack(state);
  11738. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11739. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11740. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11741. return 1;
  11742. }
  11743. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11744. if (!lua_interface)
  11745. return 0;
  11746. lua_interface->ResetFunctionStack(state);
  11747. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11748. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11749. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11750. return 1;
  11751. }
  11752. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11753. if (!lua_interface)
  11754. return 0;
  11755. lua_interface->ResetFunctionStack(state);
  11756. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11757. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11758. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11759. return 1;
  11760. }
  11761. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11762. if (!lua_interface)
  11763. return 0;
  11764. lua_interface->ResetFunctionStack(state);
  11765. world.SendTimeUpdate();
  11766. return 0;
  11767. }
  11768. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11769. bool update_result = false;
  11770. Faction* faction = 0;
  11771. Spawn* spawn = lua_interface->GetSpawn(state);
  11772. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11773. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11774. lua_interface->ResetFunctionStack(state);
  11775. if(!spawn || !spawn->IsPlayer()) {
  11776. lua_interface->LogError("LUA ChangeFaction command error: player is not valid");
  11777. return 0;
  11778. }
  11779. Player* player = (Player*)spawn;
  11780. Client* client = player->GetClient();
  11781. if (faction_id > 0) {
  11782. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11783. if(hasfaction == 0) {
  11784. //they do not have the faction. Lets get the default value and feed it in.
  11785. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11786. //add the default faction for the player.
  11787. player->SetFactionValue(faction_id, defaultfaction);
  11788. }
  11789. if(increase >= 0) {
  11790. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11791. faction = master_faction_list.GetFaction(faction_id);
  11792. if(faction && update_result)
  11793. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11794. else if(faction)
  11795. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11796. lua_interface->SetBooleanValue(state, true);
  11797. return 1;
  11798. }
  11799. if(increase < 0){
  11800. //change the negative to a positive, since thats how decreasefaction() likes it.
  11801. increase *= -1;
  11802. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11803. faction = master_faction_list.GetFaction(faction_id);
  11804. if(faction && update_result)
  11805. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11806. else if(faction)
  11807. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11808. lua_interface->SetBooleanValue(state, true);
  11809. return 1;
  11810. }
  11811. }
  11812. lua_interface->SetBooleanValue(state, false);
  11813. return 1;
  11814. }
  11815. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11816. bool hascoin = 0;
  11817. Player* player = (Player*)lua_interface->GetSpawn(state);
  11818. int32 coins = lua_interface->GetInt32Value(state, 2);
  11819. lua_interface->ResetFunctionStack(state);
  11820. if (player && player->IsPlayer()) {
  11821. hascoin = player->HasCoins(coins);
  11822. if(hascoin == 0) {
  11823. lua_interface->SetBooleanValue(state, false);
  11824. return 1;
  11825. }
  11826. if(hascoin == 1) {
  11827. lua_interface->SetBooleanValue(state, true);
  11828. return 1;
  11829. }
  11830. }
  11831. return 0;
  11832. }
  11833. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11834. int32 loot_tier = 0;
  11835. Spawn* spawn = lua_interface->GetSpawn(state);
  11836. lua_interface->ResetFunctionStack(state);
  11837. if (spawn) {
  11838. loot_tier = spawn->GetLootTier();
  11839. lua_interface->SetInt32Value(state, loot_tier);
  11840. return 1;
  11841. }
  11842. return 0;
  11843. }
  11844. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11845. if (!lua_interface)
  11846. return 0;
  11847. Spawn* spawn = lua_interface->GetSpawn(state);
  11848. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11849. lua_interface->ResetFunctionStack(state);
  11850. if (spawn) {
  11851. spawn->SetLootTier(loot_tier);
  11852. lua_interface->SetBooleanValue(state, true);
  11853. return 1;
  11854. }
  11855. lua_interface->SetBooleanValue(state, false);
  11856. return 1;
  11857. }
  11858. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11859. int32 loot_drop_type = 0;
  11860. Spawn* spawn = lua_interface->GetSpawn(state);
  11861. lua_interface->ResetFunctionStack(state);
  11862. if (spawn) {
  11863. loot_drop_type = spawn->GetLootDropType();
  11864. lua_interface->SetInt32Value(state, loot_drop_type);
  11865. return 1;
  11866. }
  11867. return 0;
  11868. }
  11869. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11870. if (!lua_interface)
  11871. return 0;
  11872. Spawn* spawn = lua_interface->GetSpawn(state);
  11873. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11874. lua_interface->ResetFunctionStack(state);
  11875. if (spawn) {
  11876. spawn->SetLootDropType(loot_drop_type);
  11877. lua_interface->SetBooleanValue(state, true);
  11878. return 1;
  11879. }
  11880. lua_interface->SetBooleanValue(state, false);
  11881. return 1;
  11882. }
  11883. int EQ2Emu_lua_DamageEquippedItems(lua_State* state) {
  11884. if (!lua_interface)
  11885. return 0;
  11886. Spawn* spawn = lua_interface->GetSpawn(state);
  11887. int8 damage_amount = lua_interface->GetInt32Value(state, 2);
  11888. if(damage_amount > 100) {
  11889. damage_amount = 100;
  11890. }
  11891. if (!spawn) {
  11892. lua_interface->LogError("%s: LUA DamageEquippedItems command error: spawn is not valid", lua_interface->GetScriptName(state));
  11893. lua_interface->ResetFunctionStack(state);
  11894. return 0;
  11895. }
  11896. lua_interface->ResetFunctionStack(state);
  11897. if (spawn->IsPlayer()) {
  11898. if (((Player*)spawn)->GetClient() && ((Player*)spawn)->DamageEquippedItems(damage_amount, ((Player*)spawn)->GetClient()))
  11899. lua_interface->SetBooleanValue(state, true);
  11900. else
  11901. lua_interface->SetBooleanValue(state, false);
  11902. }
  11903. else {
  11904. lua_interface->SetBooleanValue(state, false);
  11905. }
  11906. return 1;
  11907. }
  11908. int EQ2Emu_lua_CreateWidgetRegion(lua_State* state) {
  11909. ZoneServer* zone = lua_interface->GetZone(state);
  11910. int32 version = lua_interface->GetInt32Value(state, 2);
  11911. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11912. if(region_map == nullptr) {
  11913. lua_interface->LogError("%s: LUA CreateWidgetRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11914. lua_interface->ResetFunctionStack(state);
  11915. return 0;
  11916. }
  11917. string region_name = lua_interface->GetStringValue(state, 3);
  11918. string env_name = lua_interface->GetStringValue(state, 4);
  11919. int32 grid_id = lua_interface->GetInt32Value(state, 5);
  11920. int32 widget_id = lua_interface->GetInt32Value(state, 6);
  11921. float dist = lua_interface->GetFloatValue(state, 7);
  11922. region_map->InsertRegionNode(zone, version, region_name, env_name, grid_id, widget_id, dist);
  11923. lua_interface->ResetFunctionStack(state);
  11924. lua_interface->SetBooleanValue(state, true);
  11925. return 1;
  11926. }
  11927. int EQ2Emu_lua_RemoveRegion(lua_State* state) {
  11928. ZoneServer* zone = lua_interface->GetZone(state);
  11929. int32 version = lua_interface->GetInt32Value(state, 2);
  11930. RegionMap* region_map = world.GetRegionMap(std::string(zone->GetZoneFile()), version);
  11931. if(region_map == nullptr) {
  11932. lua_interface->LogError("%s: LUA RemoveRegion command error: region map is not valid for version %u", lua_interface->GetScriptName(state), version);
  11933. lua_interface->ResetFunctionStack(state);
  11934. return 0;
  11935. }
  11936. string region_name = lua_interface->GetStringValue(state, 3);
  11937. region_map->RemoveRegionNode(region_name);
  11938. lua_interface->ResetFunctionStack(state);
  11939. lua_interface->SetBooleanValue(state, true);
  11940. return 1;
  11941. }
  11942. int EQ2Emu_lua_SetPlayerPOVGhost(lua_State* state) {
  11943. Client* client = nullptr;
  11944. Spawn* player = lua_interface->GetSpawn(state);
  11945. if (!player) {
  11946. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not valid");
  11947. lua_interface->SetBooleanValue(state, false);
  11948. lua_interface->ResetFunctionStack(state);
  11949. return 1;
  11950. }
  11951. if (!player->IsPlayer()) {
  11952. lua_interface->LogError("LUA SetPlayerPOVGhost command error: spawn is not a player");
  11953. lua_interface->SetBooleanValue(state, false);
  11954. lua_interface->ResetFunctionStack(state);
  11955. return 1;
  11956. }
  11957. client = player->GetClient();
  11958. if (!client) {
  11959. lua_interface->LogError("LUA SetPlayerPOVGhost command error: could not find client");
  11960. lua_interface->SetBooleanValue(state, false);
  11961. lua_interface->ResetFunctionStack(state);
  11962. return 1;
  11963. }
  11964. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  11965. bool success_sight = client->SetPlayerPOVGhost(spawn);
  11966. lua_interface->ResetFunctionStack(state);
  11967. lua_interface->SetBooleanValue(state, success_sight);
  11968. return 1;
  11969. }
  11970. int EQ2Emu_lua_SetCastOnAggroComplete(lua_State* state) {
  11971. if (!lua_interface)
  11972. return 0;
  11973. bool result = false;
  11974. Spawn* spawn = lua_interface->GetSpawn(state);
  11975. bool cast_completed = (lua_interface->GetInt8Value(state, 2) == 1);
  11976. lua_interface->ResetFunctionStack(state);
  11977. if (!spawn)
  11978. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11979. else if (!spawn->IsNPC())
  11980. lua_interface->LogError("%s: LUA SetCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11981. else
  11982. {
  11983. ((NPC*)spawn)->cast_on_aggro_completed = cast_completed;
  11984. result = true;
  11985. }
  11986. lua_interface->SetBooleanValue(state, result);
  11987. return 1;
  11988. }
  11989. int EQ2Emu_lua_IsCastOnAggroComplete(lua_State* state) {
  11990. if (!lua_interface)
  11991. return 0;
  11992. bool result = false;
  11993. Spawn* spawn = lua_interface->GetSpawn(state);
  11994. lua_interface->ResetFunctionStack(state);
  11995. if (!spawn)
  11996. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: Could not find spawn.", lua_interface->GetScriptName(state));
  11997. else if (!spawn->IsNPC())
  11998. lua_interface->LogError("%s: LUA IsCastOnAggroComplete error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  11999. else
  12000. {
  12001. if(((NPC*)spawn)->cast_on_aggro_completed)
  12002. result = true;
  12003. }
  12004. lua_interface->SetBooleanValue(state, result);
  12005. return 1;
  12006. }
  12007. int EQ2Emu_lua_AddRecipeBookToPlayer(lua_State* state) {
  12008. Client* client = nullptr;
  12009. Spawn* player = lua_interface->GetSpawn(state);
  12010. int32 recipe_book_id = lua_interface->GetInt32Value(state, 2);
  12011. lua_interface->ResetFunctionStack(state);
  12012. if (!player) {
  12013. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not valid");
  12014. lua_interface->SetBooleanValue(state, false);
  12015. return 1;
  12016. }
  12017. if (!player->IsPlayer()) {
  12018. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: spawn is not a player");
  12019. lua_interface->SetBooleanValue(state, false);
  12020. return 1;
  12021. }
  12022. client = player->GetClient();
  12023. if (!client) {
  12024. lua_interface->LogError("LUA AddRecipeBookToPlayer command error: could not find client");
  12025. lua_interface->SetBooleanValue(state, false);
  12026. return 1;
  12027. }
  12028. bool result = client->AddRecipeBookToPlayer(recipe_book_id);
  12029. lua_interface->SetBooleanValue(state, result);
  12030. return 1;
  12031. }
  12032. int EQ2Emu_lua_RemoveRecipeFromPlayer(lua_State* state) {
  12033. Client* client = nullptr;
  12034. Spawn* player = lua_interface->GetSpawn(state);
  12035. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  12036. lua_interface->ResetFunctionStack(state);
  12037. if (!player) {
  12038. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not valid");
  12039. lua_interface->SetBooleanValue(state, false);
  12040. return 1;
  12041. }
  12042. if (!player->IsPlayer()) {
  12043. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: spawn is not a player");
  12044. lua_interface->SetBooleanValue(state, false);
  12045. return 1;
  12046. }
  12047. client = player->GetClient();
  12048. if (!client) {
  12049. lua_interface->LogError("LUA RemoveRecipeFromPlayer command error: could not find client");
  12050. lua_interface->SetBooleanValue(state, false);
  12051. return 1;
  12052. }
  12053. bool result = client->RemoveRecipeFromPlayer(recipe_id);
  12054. lua_interface->SetBooleanValue(state, result);
  12055. return 1;
  12056. }
  12057. int EQ2Emu_lua_ReplaceWidgetFromClient(lua_State* state) {
  12058. Client* client = nullptr;
  12059. Spawn* player = lua_interface->GetSpawn(state);
  12060. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12061. bool delete_widget = (lua_interface->GetInt8Value(state, 3) == 1);
  12062. // rest are all optional fields
  12063. float x = lua_interface->GetFloatValue(state, 4);
  12064. float y = lua_interface->GetFloatValue(state, 5);
  12065. float z = lua_interface->GetFloatValue(state, 6);
  12066. int32 grid_id = lua_interface->GetInt32Value(state, 7);
  12067. lua_interface->ResetFunctionStack(state);
  12068. if (!player) {
  12069. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not valid");
  12070. lua_interface->SetBooleanValue(state, false);
  12071. return 1;
  12072. }
  12073. if (!player->IsPlayer()) {
  12074. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: spawn is not a player");
  12075. lua_interface->SetBooleanValue(state, false);
  12076. return 1;
  12077. }
  12078. if(!player->GetZone()) {
  12079. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  12080. lua_interface->SetBooleanValue(state, false);
  12081. return 1;
  12082. }
  12083. client = player->GetClient();
  12084. if (!client) {
  12085. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: could not find client");
  12086. lua_interface->SetBooleanValue(state, false);
  12087. return 1;
  12088. }
  12089. if(!client->IsReadyForUpdates()) {
  12090. lua_interface->LogError("LUA ReplaceWidgetFromClient command failed: client has not signaled sys_client_avatar_ready");
  12091. lua_interface->SetBooleanValue(state, false);
  12092. return 1;
  12093. }
  12094. client->SendReplaceWidget(widget_id, delete_widget, x, y, z, grid_id);
  12095. lua_interface->SetBooleanValue(state, true);
  12096. return 1;
  12097. }
  12098. int EQ2Emu_lua_RemoveWidgetFromSpawnMap(lua_State* state) {
  12099. Client* client = nullptr;
  12100. Spawn* spawn = lua_interface->GetSpawn(state);
  12101. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12102. lua_interface->ResetFunctionStack(state);
  12103. if (!spawn) {
  12104. lua_interface->LogError("LUA RemoveWidgetFromSpawnMap command error: spawn is not valid");
  12105. lua_interface->SetBooleanValue(state, false);
  12106. return 1;
  12107. }
  12108. if(!spawn->GetZone()) {
  12109. lua_interface->LogError("LUA ReplaceWidgetFromClient command error: player is not in a zone");
  12110. lua_interface->SetBooleanValue(state, false);
  12111. return 1;
  12112. }
  12113. spawn->AddIgnoredWidget(widget_id);
  12114. lua_interface->SetBooleanValue(state, true);
  12115. return 1;
  12116. }
  12117. int EQ2Emu_lua_RemoveWidgetFromZoneMap(lua_State* state) {
  12118. ZoneServer* zone = lua_interface->GetZone(state);
  12119. int32 widget_id = lua_interface->GetInt32Value(state, 2);
  12120. lua_interface->ResetFunctionStack(state);
  12121. if(!zone) {
  12122. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: zone is not valid");
  12123. lua_interface->SetBooleanValue(state, false);
  12124. return 1;
  12125. }
  12126. if(!zone->IsLoading()) {
  12127. lua_interface->LogError("LUA RemoveWidgetFromZoneMap command error: can only be called during zone loading, in preinit_zone_script ZoneScript function");
  12128. lua_interface->SetBooleanValue(state, false);
  12129. return 1;
  12130. }
  12131. zone->AddIgnoredWidget(widget_id);
  12132. lua_interface->SetBooleanValue(state, true);
  12133. return 1;
  12134. }
  12135. int EQ2Emu_lua_SendHearCast(lua_State* state) {
  12136. if (!lua_interface)
  12137. return 0;
  12138. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  12139. Spawn* spawn = lua_interface->GetSpawn(state);
  12140. int32 spell_visual_id = lua_interface->GetInt32Value(state, 2);
  12141. int16 cast_time = lua_interface->GetInt16Value(state, 3);
  12142. Spawn* caster = lua_interface->GetSpawn(state, 4);
  12143. Spawn* target = lua_interface->GetSpawn(state, 5);
  12144. lua_interface->ResetFunctionStack(state);
  12145. if(spell && spawn && spawn->IsEntity()) {
  12146. ZoneServer* zone = spawn->GetZone();
  12147. if(zone) {
  12148. zone->SendCastSpellPacket(spell, caster && caster->IsEntity() ? (Entity*)caster : (Entity*)spawn, spell_visual_id, cast_time > 0 ? cast_time : 0xFFFF);
  12149. }
  12150. }
  12151. else if (spawn) {
  12152. if (spawn->IsPlayer()) {
  12153. Client* client = ((Player*)spawn)->GetClient();
  12154. if (client) {
  12155. client->SendHearCast(caster ? caster : client->GetPlayer(), target ? target : client->GetPlayer(), spell_visual_id, cast_time);
  12156. }
  12157. }
  12158. }
  12159. return 0;
  12160. }
  12161. int EQ2Emu_lua_GetCharacterFlag(lua_State* state) {
  12162. if (!lua_interface)
  12163. return 0;
  12164. Spawn* player = lua_interface->GetSpawn(state);
  12165. sint32 flag_id = lua_interface->GetSInt32Value(state, 2);
  12166. lua_interface->ResetFunctionStack(state);
  12167. if (!player) {
  12168. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  12169. return 0;
  12170. }
  12171. if (!player->IsPlayer()) {
  12172. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  12173. return 0;
  12174. }
  12175. bool ret = ((Player*)player)->get_character_flag(flag_id);
  12176. lua_interface->SetBooleanValue(state, ret);
  12177. return 1;
  12178. }
  12179. int EQ2Emu_lua_ToggleCharacterFlag(lua_State* state) {
  12180. if (!lua_interface)
  12181. return 0;
  12182. Spawn* player = lua_interface->GetSpawn(state);
  12183. sint32 flag_id = lua_interface->GetSInt32Value(state, 2);
  12184. lua_interface->ResetFunctionStack(state);
  12185. if (!player) {
  12186. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  12187. return 0;
  12188. }
  12189. if (!player->IsPlayer()) {
  12190. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  12191. return 0;
  12192. }
  12193. ((Player*)player)->toggle_character_flag(flag_id);
  12194. return 0;
  12195. }