LuaFunctions.cpp 388 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689
  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 = spawn->GetZone()->GetClientBySpawn(player);
  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_PlaySound(lua_State* state) {
  179. if (!lua_interface)
  180. return 0;
  181. Spawn* spawn = lua_interface->GetSpawn(state);
  182. string sound_string = lua_interface->GetStringValue(state, 2);
  183. float x = lua_interface->GetFloatValue(state, 3);
  184. float y = lua_interface->GetFloatValue(state, 4);
  185. float z = lua_interface->GetFloatValue(state, 5);
  186. Spawn* player = lua_interface->GetSpawn(state, 6);
  187. lua_interface->ResetFunctionStack(state);
  188. if (spawn && sound_string.length() > 0) {
  189. Client* client = 0;
  190. if (player && player->IsPlayer())
  191. client = spawn->GetZone()->GetClientBySpawn(player);
  192. if (client)
  193. spawn->GetZone()->PlaySoundFile(client, sound_string.c_str(), x, y, z);
  194. else
  195. spawn->GetZone()->PlaySoundFile(0, sound_string.c_str(), x, y, z);
  196. }
  197. return 0;
  198. }
  199. int EQ2Emu_lua_SetRequiredQuest(lua_State* state) {
  200. if (!lua_interface)
  201. return 0;
  202. Spawn* spawn = lua_interface->GetSpawn(state);
  203. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  204. int16 quest_step = lua_interface->GetInt16Value(state, 3);
  205. bool private_spawn = (lua_interface->GetInt8Value(state, 4) == 1);
  206. bool continued_access = (lua_interface->GetInt8Value(state, 5) == 1);
  207. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  208. lua_interface->ResetFunctionStack(state);
  209. if (!spawn) {
  210. lua_interface->LogError("%s: LUA SetRequiredQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  211. return 0;
  212. }
  213. if (quest_id > 0) {
  214. //Add this quest to the list of required quests for this spawn
  215. spawn->SetQuestsRequired(quest_id, quest_step);
  216. //If private spawn value set
  217. if (private_spawn) {
  218. //Set the spawn to be private when not granted access through this quest
  219. spawn->AddAllowAccessSpawn(spawn);
  220. spawn->SetPrivateQuestSpawn(true);
  221. }
  222. //This value allows access after a quest step, or the whole quest has been completed
  223. if (continued_access)
  224. spawn->SetQuestsRequiredContinuedAccess(true);
  225. //This value will override vis_flags in the vis packet
  226. if (flag_override > 0)
  227. spawn->SetQuestsRequiredOverride(flag_override);
  228. }
  229. return 0;
  230. }
  231. int EQ2Emu_lua_SpawnSetByDistance(lua_State* state) {
  232. if (!lua_interface)
  233. return 0;
  234. Spawn* spawn = lua_interface->GetSpawn(state);
  235. float max_distance = lua_interface->GetFloatValue(state, 2);
  236. string variable = lua_interface->GetStringValue(state, 3);
  237. string value = lua_interface->GetStringValue(state, 4);
  238. lua_interface->ResetFunctionStack(state);
  239. if (max_distance > 0 && spawn && value.length() > 0 && variable.length() > 0 && spawn->GetZone())
  240. spawn->GetZone()->SpawnSetByDistance(spawn, max_distance, variable, value);
  241. return 0;
  242. }
  243. int EQ2Emu_lua_PerformCameraShake(lua_State* state) {
  244. if (!lua_interface)
  245. return 0;
  246. Client* client = 0;
  247. Spawn* player = lua_interface->GetSpawn(state);
  248. if (!player) {
  249. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not valid");
  250. return 0;
  251. }
  252. if (!player->IsPlayer()) {
  253. lua_interface->LogError("LUA PerformCameraShake command error: spawn is not a player");
  254. return 0;
  255. }
  256. if (player->GetZone())
  257. client = player->GetZone()->GetClientBySpawn(player);
  258. if (!client) {
  259. lua_interface->LogError("LUA PerformCameraShake command error: could not find client");
  260. return 0;
  261. }
  262. float intensity = lua_interface->GetFloatValue(state, 2);
  263. int8 direction = lua_interface->GetInt8Value(state, 3);
  264. lua_interface->ResetFunctionStack(state);
  265. PacketStruct* packet = configReader.getStruct("WS_PerformCameraShakeMsg", client->GetVersion());
  266. if (packet) {
  267. /* Client Intensity Logic (does not restrict service side, but expect .01 - 1.0 range)
  268. v1 = *(float *)(a1 + 4);
  269. if ( v1 > 0.0 )
  270. v2 = fminf(v1, 1.0);
  271. else
  272. v2 = 0.1;
  273. */
  274. packet->setDataByName("intensity", intensity);
  275. if ( client->GetVersion() > 546 )
  276. packet->setDataByName("direction", direction);
  277. client->QueuePacket(packet->serialize());
  278. safe_delete(packet);
  279. }
  280. return 0;
  281. }
  282. int EQ2Emu_lua_KillSpawn(lua_State* state) {
  283. if (!lua_interface)
  284. return 0;
  285. Spawn* dead = lua_interface->GetSpawn(state);
  286. Spawn* killer = lua_interface->GetSpawn(state, 2);
  287. bool send_packet = (lua_interface->GetInt8Value(state, 3) == 1);
  288. lua_interface->ResetFunctionStack(state);
  289. if (dead && dead->Alive() && dead->GetZone())
  290. dead->GetZone()->KillSpawn(false, dead, killer, send_packet);
  291. return 0;
  292. }
  293. int EQ2Emu_lua_KillSpawnByDistance(lua_State* state) {
  294. if (!lua_interface)
  295. return 0;
  296. Spawn* spawn = lua_interface->GetSpawn(state);
  297. float max_distance = lua_interface->GetFloatValue(state, 2);
  298. bool include_players = lua_interface->GetInt8Value(state, 3);
  299. bool send_packet = (lua_interface->GetInt8Value(state, 4) == 1);
  300. lua_interface->ResetFunctionStack(state);
  301. if (max_distance > 0 && spawn && spawn->GetZone())
  302. spawn->GetZone()->KillSpawnByDistance(spawn, max_distance, include_players, send_packet);
  303. return 0;
  304. }
  305. int EQ2Emu_lua_Despawn(lua_State* state) {
  306. if (!lua_interface)
  307. return 0;
  308. Spawn* spawn = lua_interface->GetSpawn(state);
  309. int32 delay = lua_interface->GetInt32Value(state, 2);
  310. lua_interface->ResetFunctionStack(state);
  311. if (spawn && spawn->GetZone())
  312. spawn->GetZone()->Despawn(spawn, delay);
  313. return 0;
  314. }
  315. int EQ2Emu_lua_ChangeHandIcon(lua_State* state) {
  316. if (!lua_interface)
  317. return 0;
  318. Spawn* spawn = lua_interface->GetSpawn(state);
  319. int8 displayHandIcon = lua_interface->GetInt8Value(state, 2);
  320. lua_interface->ResetFunctionStack(state);
  321. if (spawn) {
  322. spawn->info_changed = true;
  323. spawn->SetShowHandIcon(displayHandIcon);
  324. }
  325. return 0;
  326. }
  327. //this function is used to force an update packet to be sent.
  328. //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
  329. int EQ2Emu_lua_SetVisualFlag(lua_State* state) {
  330. if (!lua_interface)
  331. return 0;
  332. Spawn* spawn = lua_interface->GetSpawn(state);
  333. lua_interface->ResetFunctionStack(state);
  334. if (spawn) {
  335. spawn->vis_changed = true;
  336. spawn->GetZone()->AddChangedSpawn(spawn);
  337. }
  338. return 0;
  339. }
  340. //this function is used to force an update packet to be sent.
  341. //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
  342. int EQ2Emu_lua_SetInfoFlag(lua_State* state) {
  343. if (!lua_interface)
  344. return 0;
  345. Spawn* spawn = lua_interface->GetSpawn(state);
  346. lua_interface->ResetFunctionStack(state);
  347. if (spawn) {
  348. spawn->info_changed = true;
  349. spawn->GetZone()->AddChangedSpawn(spawn);
  350. }
  351. return 0;
  352. }
  353. int EQ2Emu_lua_SendStateCommand(lua_State* state) {
  354. if (!lua_interface)
  355. return 0;
  356. Spawn* spawn = lua_interface->GetSpawn(state);
  357. int32 new_state = lua_interface->GetInt32Value(state, 2);
  358. Spawn* player = lua_interface->GetSpawn(state, 3);
  359. lua_interface->ResetFunctionStack(state);
  360. if (spawn) {
  361. if(player)
  362. {
  363. if(player->IsPlayer())
  364. {
  365. Client* client = ((Player*)player)->GetClient();
  366. if(client)
  367. {
  368. ClientPacketFunctions::SendStateCommand(client, client->GetPlayer()->GetIDWithPlayerSpawn(spawn), new_state);
  369. lua_interface->SetBooleanValue(state, true);
  370. return 1;
  371. }
  372. else
  373. 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());
  374. }
  375. else
  376. 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());
  377. }
  378. else
  379. {
  380. spawn->GetZone()->QueueStateCommandToClients(spawn->GetID(), new_state);
  381. lua_interface->SetBooleanValue(state, true);
  382. return 1;
  383. }
  384. }
  385. lua_interface->SetBooleanValue(state, false);
  386. return 1;
  387. }
  388. int EQ2Emu_lua_SpawnSet(lua_State* state) {
  389. if (!lua_interface)
  390. return 0;
  391. Spawn* spawn = lua_interface->GetSpawn(state);
  392. string variable = lua_interface->GetStringValue(state, 2);
  393. string value = lua_interface->GetStringValue(state, 3);
  394. 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.
  395. bool temporary_flag = true;
  396. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  397. int8 index = 0;
  398. if(num_args >= 5)
  399. {
  400. 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
  401. index = lua_interface->GetInt8Value(state, 6);
  402. }
  403. lua_interface->ResetFunctionStack(state);
  404. int32 type = commands.GetSpawnSetType(variable);
  405. if (type != 0xFFFFFFFF && value.length() > 0 && spawn)
  406. commands.SetSpawnCommand(0, spawn, type, value.c_str(), !no_update, temporary_flag, nullptr, index);
  407. return 0;
  408. }
  409. int EQ2Emu_lua_GetSpawn(lua_State* state) {
  410. if (!lua_interface)
  411. return 0;
  412. Spawn* spawn = lua_interface->GetSpawn(state);
  413. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  414. lua_interface->ResetFunctionStack(state);
  415. if (spawn && spawn_id > 0) {
  416. Spawn* closest_spawn = spawn->GetZone()->GetClosestSpawn(spawn, spawn_id);
  417. if (closest_spawn) {
  418. lua_interface->SetSpawnValue(state, closest_spawn);
  419. return 1;
  420. }
  421. }
  422. return 0;
  423. }
  424. int EQ2Emu_lua_GetSpawnFromList(lua_State* state) {
  425. if (!lua_interface)
  426. return 0;
  427. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  428. int32 position = lua_interface->GetInt32Value(state, 2);
  429. lua_interface->ResetFunctionStack(state);
  430. if (spawnList) {
  431. if (spawnList->size() > position) {
  432. lua_interface->SetSpawnValue(state, spawnList->at(position));
  433. return 1;
  434. }
  435. else {
  436. return 0;
  437. }
  438. return spawnList->size();
  439. }
  440. return 0;
  441. }
  442. int EQ2Emu_lua_GetSpawnListSize(lua_State* state) {
  443. if (!lua_interface)
  444. return 0;
  445. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  446. lua_interface->ResetFunctionStack(state);
  447. if (spawnList) {
  448. return spawnList->size();
  449. }
  450. return 0;
  451. }
  452. int EQ2Emu_lua_CreateSpawnList(lua_State* state) {
  453. if (!lua_interface)
  454. return 0;
  455. vector<Spawn*>* spawnList = new vector<Spawn*>();
  456. lua_interface->SetSpawnListValue(state, spawnList);
  457. return 1;
  458. }
  459. int EQ2Emu_lua_AddSpawnToSpawnList(lua_State* state) {
  460. if (!lua_interface)
  461. return 0;
  462. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  463. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  464. lua_interface->ResetFunctionStack(state);
  465. if (spawnList) {
  466. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  467. if (it == spawnList->end())
  468. spawnList->push_back(spawn);
  469. }
  470. return 0;
  471. }
  472. int EQ2Emu_lua_RemoveSpawnFromSpawnList(lua_State* state) {
  473. if (!lua_interface)
  474. return 0;
  475. vector<Spawn*>* spawnList = lua_interface->GetSpawnList(state);
  476. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  477. lua_interface->ResetFunctionStack(state);
  478. if (spawnList) {
  479. auto it = std::find(spawnList->begin(), spawnList->end(), spawn);
  480. if(it != spawnList->end())
  481. spawnList->erase(it);
  482. }
  483. return 0;
  484. }
  485. int EQ2Emu_lua_GetSpawnListBySpawnID(lua_State* state) {
  486. if (!lua_interface)
  487. return 0;
  488. Spawn* spawn = lua_interface->GetSpawn(state);
  489. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  490. lua_interface->ResetFunctionStack(state);
  491. if (spawn) {
  492. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByID(spawn_id);
  493. if (spawns.size() > 0) {
  494. vector<Spawn*>* spawnList = new vector<Spawn*>();
  495. vector<Spawn*>::iterator itr;
  496. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  497. spawnList->push_back(*itr);
  498. }
  499. lua_interface->SetSpawnListValue(state, spawnList);
  500. return 1;
  501. }
  502. }
  503. return 0;
  504. }
  505. int EQ2Emu_lua_GetSpawnListByRailID(lua_State* state) {
  506. if (!lua_interface)
  507. return 0;
  508. Spawn* spawn = lua_interface->GetSpawn(state);
  509. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  510. lua_interface->ResetFunctionStack(state);
  511. if (spawn) {
  512. vector<Spawn*> spawns = spawn->GetZone()->GetSpawnsByRailID(rail_id);
  513. if (spawns.size() > 0) {
  514. vector<Spawn*>* spawnList = new vector<Spawn*>();
  515. vector<Spawn*>::iterator itr;
  516. for (itr = spawns.begin(); itr != spawns.end(); itr++) {
  517. spawnList->push_back(*itr);
  518. }
  519. lua_interface->SetSpawnListValue(state, spawnList);
  520. return 1;
  521. }
  522. }
  523. return 0;
  524. }
  525. int EQ2Emu_lua_GetPassengerSpawnList(lua_State* state) {
  526. if (!lua_interface)
  527. return 0;
  528. Spawn* spawn = lua_interface->GetSpawn(state);
  529. lua_interface->ResetFunctionStack(state);
  530. if (spawn) {
  531. vector<Spawn*> spawns = spawn->GetPassengersOnRail();
  532. if (spawns.size() > 0) {
  533. lua_createtable(state, spawns.size(), 0);
  534. int newTable = lua_gettop(state);
  535. for (int32 i = 0; i < spawns.size(); i++) {
  536. lua_interface->SetSpawnValue(state, spawns.at(i));
  537. lua_rawseti(state, newTable, i + 1);
  538. }
  539. return 1;
  540. }
  541. }
  542. return 0;
  543. }
  544. int EQ2Emu_lua_GetVariableValue(lua_State* state) {
  545. if (!lua_interface)
  546. return 0;
  547. string variable_name = lua_interface->GetStringValue(state);
  548. lua_interface->ResetFunctionStack(state);
  549. Variable* var = variables.FindVariable(variable_name);
  550. if (var) {
  551. lua_interface->SetStringValue(state, var->GetValue());
  552. return 1;
  553. }
  554. return 0;
  555. }
  556. int EQ2Emu_lua_GetCoinMessage(lua_State* state) {
  557. if (!lua_interface)
  558. return 0;
  559. int32 total_coins = lua_interface->GetInt32Value(state);
  560. lua_interface->ResetFunctionStack(state);
  561. if (total_coins == 0) {
  562. lua_interface->SetStringValue(state, "0 copper");
  563. return 1;
  564. }
  565. char tmp[64] = { 0 };
  566. string message = "";
  567. int32 val = 0;
  568. if (total_coins >= 1000000) {
  569. val = total_coins / 1000000;
  570. total_coins -= 1000000 * val;
  571. sprintf(tmp, " %u Platinum", val);
  572. message.append(tmp);
  573. memset(tmp, 0, 64);
  574. }
  575. if (total_coins >= 10000) {
  576. val = total_coins / 10000;
  577. total_coins -= 10000 * val;
  578. sprintf(tmp, " %u Gold", val);
  579. message.append(tmp);
  580. memset(tmp, 0, 64);
  581. }
  582. if (total_coins >= 100) {
  583. val = total_coins / 100;
  584. total_coins -= 100 * val;
  585. sprintf(tmp, " %u Silver", val);
  586. message.append(tmp);
  587. memset(tmp, 0, 64);
  588. }
  589. if (total_coins > 0) {
  590. sprintf(tmp, " %u Copper", (int32)total_coins);
  591. message.append(tmp);
  592. }
  593. lua_interface->SetStringValue(state, message.c_str());
  594. return 1;
  595. }
  596. int EQ2Emu_lua_GetSpawnByGroupID(lua_State* state) {
  597. ZoneServer* zone = lua_interface->GetZone(state);
  598. int32 group_id = lua_interface->GetInt32Value(state, 2);
  599. lua_interface->ResetFunctionStack(state);
  600. if (zone) {
  601. Spawn* spawn = zone->GetSpawnGroup(group_id);
  602. if (spawn) {
  603. lua_interface->SetSpawnValue(state, spawn);
  604. return 1;
  605. }
  606. }
  607. return 0;
  608. }
  609. int EQ2Emu_lua_GetSpawnByLocationID(lua_State* state) {
  610. ZoneServer* zone = lua_interface->GetZone(state);
  611. int32 location_id = lua_interface->GetInt32Value(state, 2);
  612. lua_interface->ResetFunctionStack(state);
  613. if (zone) {
  614. Spawn* spawn = zone->GetSpawnByLocationID(location_id);
  615. if (spawn) {
  616. lua_interface->SetSpawnValue(state, spawn);
  617. return 1;
  618. }
  619. }
  620. return 0;
  621. }
  622. int EQ2Emu_lua_GetSpawnID(lua_State* state) {
  623. Spawn* spawn = lua_interface->GetSpawn(state);
  624. lua_interface->ResetFunctionStack(state);
  625. if (spawn) {
  626. lua_interface->SetInt32Value(state, spawn->GetDatabaseID());
  627. return 1;
  628. }
  629. return 0;
  630. }
  631. int EQ2Emu_lua_GetSpawnGroupID(lua_State* state) {
  632. Spawn* spawn = lua_interface->GetSpawn(state);
  633. lua_interface->ResetFunctionStack(state);
  634. if (spawn) {
  635. lua_interface->SetInt32Value(state, spawn->GetSpawnGroupID());
  636. return 1;
  637. }
  638. return 0;
  639. }
  640. int EQ2Emu_lua_SetSpawnGroupID(lua_State* state) {
  641. if (!lua_interface)
  642. return 0;
  643. Spawn* spawn = lua_interface->GetSpawn(state);
  644. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  645. lua_interface->ResetFunctionStack(state);
  646. if (spawn) {
  647. spawn->SetSpawnGroupID(new_group_id);
  648. lua_interface->SetBooleanValue(state, true);
  649. return 1;
  650. }
  651. lua_interface->SetBooleanValue(state, false);
  652. return 1;
  653. }
  654. int EQ2Emu_lua_AddSpawnToGroup(lua_State* state) {
  655. if (!lua_interface)
  656. return 0;
  657. Spawn* spawn = lua_interface->GetSpawn(state);
  658. int32 new_group_id = lua_interface->GetInt32Value(state, 2);
  659. lua_interface->ResetFunctionStack(state);
  660. if (spawn) {
  661. spawn->GetZone()->AddSpawnToGroup(spawn, new_group_id);
  662. lua_interface->SetBooleanValue(state, true);
  663. return 1;
  664. }
  665. lua_interface->SetBooleanValue(state, false);
  666. return 1;
  667. }
  668. int EQ2Emu_lua_GetSpawnLocationID(lua_State* state) {
  669. Spawn* spawn = lua_interface->GetSpawn(state);
  670. lua_interface->ResetFunctionStack(state);
  671. if (spawn) {
  672. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationID());
  673. return 1;
  674. }
  675. return 0;
  676. }
  677. int EQ2Emu_lua_GetSpawnLocationPlacementID(lua_State* state) {
  678. Spawn* spawn = lua_interface->GetSpawn(state);
  679. lua_interface->ResetFunctionStack(state);
  680. if (spawn) {
  681. lua_interface->SetInt32Value(state, spawn->GetSpawnLocationPlacementID());
  682. return 1;
  683. }
  684. return 0;
  685. }
  686. int EQ2Emu_lua_GetFactionAmount(lua_State* state) {
  687. Player* player = (Player*)lua_interface->GetSpawn(state);
  688. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  689. lua_interface->ResetFunctionStack(state);
  690. if (player && player->IsPlayer() && faction_id > 0) {
  691. lua_interface->SetSInt32Value(state, player->GetFactions()->GetFactionValue(faction_id));
  692. return 1;
  693. }
  694. return 0;
  695. }
  696. int EQ2Emu_lua_SetFactionID(lua_State* state) {
  697. if (!lua_interface)
  698. return 0;
  699. Spawn* spawn = lua_interface->GetSpawn(state);
  700. int32 value = lua_interface->GetInt32Value(state, 2);
  701. lua_interface->ResetFunctionStack(state);
  702. if (spawn) {
  703. spawn->SetFactionID(value);
  704. }
  705. return 0;
  706. }
  707. int EQ2Emu_lua_GetFactionID(lua_State* state) {
  708. Spawn* spawn = lua_interface->GetSpawn(state);
  709. lua_interface->ResetFunctionStack(state);
  710. if (spawn) {
  711. lua_interface->SetInt32Value(state, spawn->GetFactionID());
  712. return 1;
  713. }
  714. return 0;
  715. }
  716. int EQ2Emu_lua_GetGender(lua_State* state) {
  717. Spawn* spawn = lua_interface->GetSpawn(state);
  718. lua_interface->ResetFunctionStack(state);
  719. if (spawn) {
  720. lua_interface->SetInt32Value(state, spawn->GetGender());
  721. return 1;
  722. }
  723. return 0;
  724. }
  725. int EQ2Emu_lua_GetTarget(lua_State* state) {
  726. Spawn* spawn = lua_interface->GetSpawn(state);
  727. lua_interface->ResetFunctionStack(state);
  728. if (spawn && spawn->IsEntity() && ((Entity*)spawn)->GetTarget()) {
  729. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetTarget());
  730. return 1;
  731. }
  732. return 0;
  733. }
  734. int EQ2Emu_lua_PlayVoice(lua_State* state) {
  735. if (!lua_interface)
  736. return 0;
  737. Spawn* spawn = lua_interface->GetSpawn(state);
  738. string mp3_string = lua_interface->GetStringValue(state, 2);
  739. int32 key1 = lua_interface->GetInt32Value(state, 3);
  740. int32 key2 = lua_interface->GetInt32Value(state, 4);
  741. Spawn* player = lua_interface->GetSpawn(state, 5);
  742. lua_interface->ResetFunctionStack(state);
  743. if (spawn && mp3_string.length() > 0) {
  744. Client* client = 0;
  745. if (player && player->IsPlayer())
  746. client = spawn->GetZone()->GetClientBySpawn(player);
  747. if (client) {
  748. if (((Player*)player)->WasSentSpawn(spawn->GetID()))
  749. spawn->GetZone()->PlayVoice(client, spawn, mp3_string.c_str(), key1, key2);
  750. }
  751. else
  752. spawn->GetZone()->PlayVoice(spawn, mp3_string.c_str(), key1, key2);
  753. }
  754. return 0;
  755. }
  756. int EQ2Emu_lua_GetCurrentZoneSafeLocation(lua_State* state) {
  757. if (!lua_interface)
  758. return 0;
  759. Spawn* spawn = lua_interface->GetSpawn(state);
  760. lua_interface->ResetFunctionStack(state);
  761. if (spawn) {
  762. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeX());
  763. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeY());
  764. lua_interface->SetFloatValue(state, spawn->GetZone()->GetSafeZ());
  765. return 3;
  766. }
  767. return 0;
  768. }
  769. int EQ2Emu_lua_HasLootItem(lua_State* state) {
  770. if (!lua_interface)
  771. return 0;
  772. Spawn* spawn = lua_interface->GetSpawn(state);
  773. if (spawn) {
  774. int32 item_id = lua_interface->GetInt32Value(state, 2);
  775. lua_interface->ResetFunctionStack(state);
  776. lua_interface->SetBooleanValue(state, spawn->HasLootItemID(item_id));
  777. return 1;
  778. }
  779. lua_interface->ResetFunctionStack(state);
  780. return 0;
  781. }
  782. int EQ2Emu_lua_AddLootItem(lua_State* state) {
  783. if (!lua_interface)
  784. return 0;
  785. Spawn* spawn = lua_interface->GetSpawn(state);
  786. if (spawn && spawn->IsEntity()) {
  787. int32 item_id = lua_interface->GetInt32Value(state, 2);
  788. int16 charges = lua_interface->GetInt16Value(state, 3);
  789. if (charges == 0)
  790. charges = 1;
  791. ((Entity*)spawn)->AddLootItem(item_id, charges);
  792. }
  793. lua_interface->ResetFunctionStack(state);
  794. return 0;
  795. }
  796. int EQ2Emu_lua_RemoveLootItem(lua_State* state) {
  797. if (!lua_interface)
  798. return 0;
  799. Spawn* spawn = lua_interface->GetSpawn(state);
  800. if (spawn && spawn->IsEntity()) {
  801. int32 item_id = lua_interface->GetInt32Value(state, 2);
  802. Item* item = spawn->LootItem(item_id);
  803. safe_delete(item);
  804. }
  805. lua_interface->ResetFunctionStack(state);
  806. return 0;
  807. }
  808. int EQ2Emu_lua_AddLootCoin(lua_State* state) {
  809. if (!lua_interface)
  810. return 0;
  811. Spawn* spawn = lua_interface->GetSpawn(state);
  812. if (spawn) {
  813. int32 val = lua_interface->GetInt32Value(state, 2);
  814. spawn->AddLootCoins(val);
  815. }
  816. lua_interface->ResetFunctionStack(state);
  817. return 0;
  818. }
  819. int EQ2Emu_lua_GiveLoot(lua_State* state) {
  820. if (!lua_interface)
  821. return 0;
  822. Spawn* entity = lua_interface->GetSpawn(state);
  823. Spawn* player = lua_interface->GetSpawn(state, 2);
  824. if (entity && player && player->IsPlayer()) {
  825. int32 coins = lua_interface->GetInt32Value(state, 3);
  826. vector<Item*>* items = 0;
  827. int i = 0;
  828. int32 item_id = 0;
  829. while ((item_id = lua_interface->GetInt32Value(state, 4 + i))) {
  830. if (items == 0)
  831. items = new vector<Item*>;
  832. if (master_item_list.GetItem(item_id))
  833. items->push_back(master_item_list.GetItem(item_id));
  834. i++;
  835. }
  836. Client* client = 0;
  837. client = player->GetZone()->GetClientBySpawn(player);
  838. if (client)
  839. ((Player*)player)->AddPendingLootItems(entity->GetID(), items);
  840. if(coins > 0)
  841. entity->AddLootCoins(coins);
  842. safe_delete(items);
  843. }
  844. lua_interface->ResetFunctionStack(state);
  845. return 0;
  846. }
  847. int EQ2Emu_lua_HasPendingLootItem(lua_State* state) {
  848. if (!lua_interface)
  849. return 0;
  850. Spawn* entity = lua_interface->GetSpawn(state);
  851. Spawn* player = lua_interface->GetSpawn(state, 2);
  852. int32 item_id = lua_interface->GetInt32Value(state, 3);
  853. lua_interface->ResetFunctionStack(state);
  854. if (entity && entity->IsEntity() && player && player->IsPlayer() && item_id > 0) {
  855. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItem(entity->GetID(), item_id));
  856. return 1;
  857. }
  858. return 0;
  859. }
  860. int EQ2Emu_lua_HasPendingLoot(lua_State* state) {
  861. if (!lua_interface)
  862. return 0;
  863. Spawn* entity = lua_interface->GetSpawn(state);
  864. Spawn* player = lua_interface->GetSpawn(state, 2);
  865. lua_interface->ResetFunctionStack(state);
  866. if (entity && player && player->IsPlayer()) {
  867. lua_interface->SetBooleanValue(state, ((Player*)player)->HasPendingLootItems(entity->GetID()));
  868. return 1;
  869. }
  870. return 0;
  871. }
  872. int EQ2Emu_lua_CreateConversation(lua_State* state) {
  873. if (!lua_interface)
  874. return 0;
  875. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  876. safe_delete(conversation);
  877. lua_interface->ResetFunctionStack(state);
  878. conversation = new vector<ConversationOption>();
  879. lua_interface->SetConversationValue(state, conversation);
  880. return 1;
  881. }
  882. int EQ2Emu_lua_AddConversationOption(lua_State* state) {
  883. if (!lua_interface)
  884. return 0;
  885. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  886. if (conversation) {
  887. ConversationOption conv_option;
  888. conv_option.option = lua_interface->GetStringValue(state, 2);
  889. conv_option.function = lua_interface->GetStringValue(state, 3);
  890. if (conv_option.option.length() > 0)
  891. conversation->push_back(conv_option);
  892. }
  893. lua_interface->ResetFunctionStack(state);
  894. return 0;
  895. }
  896. int EQ2Emu_lua_CloseConversation(lua_State* state) {
  897. if (!lua_interface)
  898. return 0;
  899. Spawn* npc = lua_interface->GetSpawn(state);
  900. Spawn* player = lua_interface->GetSpawn(state, 2);
  901. lua_interface->ResetFunctionStack(state);
  902. if (npc && player && player->IsPlayer() && player->GetZone()) {
  903. Client* client = player->GetZone()->GetClientBySpawn(player);
  904. if (client) {
  905. int32 conversation_id = client->GetConversationID(npc, 0);
  906. client->CloseDialog(conversation_id);
  907. }
  908. }
  909. return 0;
  910. }
  911. int EQ2Emu_lua_CloseItemConversation(lua_State* state) {
  912. if (!lua_interface)
  913. return 0;
  914. Item* item = lua_interface->GetItem(state);
  915. Spawn* player = lua_interface->GetSpawn(state, 2);
  916. lua_interface->ResetFunctionStack(state);
  917. if (item && player && player->IsPlayer() && player->GetZone()) {
  918. Client* client = player->GetZone()->GetClientBySpawn(player);
  919. if (client) {
  920. int32 conversation_id = client->GetConversationID(0, item);
  921. client->CloseDialog(conversation_id);
  922. }
  923. }
  924. return 0;
  925. }
  926. int EQ2Emu_lua_StartDialogConversation(lua_State* state) {
  927. if (!lua_interface)
  928. return 0;
  929. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  930. Spawn* spawn = 0;
  931. Item* item = 0;
  932. int8 type = lua_interface->GetInt8Value(state, 2);
  933. if (type == 1 || type == 3)
  934. spawn = lua_interface->GetSpawn(state, 3);
  935. else if (type == 2 || type == 4)
  936. item = lua_interface->GetItem(state, 3);
  937. Spawn* player = lua_interface->GetSpawn(state, 4);
  938. string text = lua_interface->GetStringValue(state, 5);
  939. string mp3 = lua_interface->GetStringValue(state, 6);
  940. int32 key1 = lua_interface->GetInt32Value(state, 7);
  941. int32 key2 = lua_interface->GetInt32Value(state, 8);
  942. lua_interface->ResetFunctionStack(state);
  943. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  944. Client* client = player->GetZone()->GetClientBySpawn(player);
  945. if (client) {
  946. if (spawn) {
  947. // Need to do this so the function works the same as it did before
  948. if (type == 1)
  949. type++;
  950. if (mp3.length() > 0)
  951. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2);
  952. else
  953. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()));
  954. }
  955. else {
  956. if (mp3.length() > 0)
  957. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2);
  958. else
  959. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type);
  960. }
  961. }
  962. }
  963. safe_delete(conversation);
  964. lua_interface->SetConversationValue(state, NULL);
  965. return 0;
  966. }
  967. /*int EQ2Emu_lua_StartItemConversation(lua_State* state){
  968. if(!lua_interface)
  969. return 0;
  970. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  971. Item* item = lua_interface->GetItem(state, 2);
  972. Spawn* player = lua_interface->GetSpawn(state, 3);
  973. string text = lua_interface->GetStringValue(state, 4);
  974. string mp3 = lua_interface->GetStringValue(state, 5);
  975. int32 key1 = lua_interface->GetInt32Value(state, 6);
  976. int32 key2 = lua_interface->GetInt32Value(state, 7);
  977. if(conversation && text.length() > 0 && item && player && player->IsPlayer()){
  978. Client* client = player->GetZone()->GetClientBySpawn(player);
  979. if(client){
  980. if(mp3.length() > 0)
  981. client->DisplayConversation(item, conversation, (char*)text.c_str(), mp3.c_str(), key1, key2);
  982. else
  983. client->DisplayConversation(item, conversation, (char*)text.c_str());
  984. }
  985. safe_delete(conversation);
  986. }
  987. return 0;
  988. }*/
  989. int EQ2Emu_lua_StartConversation(lua_State* state) {
  990. if (!lua_interface)
  991. return 0;
  992. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  993. Spawn* source = lua_interface->GetSpawn(state, 2);
  994. Spawn* player = lua_interface->GetSpawn(state, 3);
  995. string text = lua_interface->GetStringValue(state, 4);
  996. string mp3 = lua_interface->GetStringValue(state, 5);
  997. int32 key1 = lua_interface->GetInt32Value(state, 6);
  998. int32 key2 = lua_interface->GetInt32Value(state, 7);
  999. lua_interface->ResetFunctionStack(state);
  1000. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  1001. Client* client = source->GetZone()->GetClientBySpawn(player);
  1002. if (mp3.length() > 0)
  1003. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2);
  1004. else
  1005. client->DisplayConversation(source, 1, conversation, text.c_str());
  1006. safe_delete(conversation);
  1007. lua_interface->SetConversationValue(state, NULL);
  1008. }
  1009. else
  1010. 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);
  1011. return 0;
  1012. }
  1013. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1014. if (!lua_interface)
  1015. return 0;
  1016. Spawn* spawn = lua_interface->GetSpawn(state);
  1017. float distance = lua_interface->GetFloatValue(state, 2);
  1018. string in_range_function = lua_interface->GetStringValue(state, 3);
  1019. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1020. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1021. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1022. return 0;
  1023. }
  1024. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1025. ZoneServer* zone = lua_interface->GetZone(state);
  1026. float x = lua_interface->GetFloatValue(state, 2);
  1027. float y = lua_interface->GetFloatValue(state, 3);
  1028. float z = lua_interface->GetFloatValue(state, 4);
  1029. float max_variation = lua_interface->GetFloatValue(state, 5);
  1030. string in_range_function = lua_interface->GetStringValue(state, 6);
  1031. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1032. lua_interface->ResetFunctionStack(state);
  1033. if (zone && in_range_function.length() > 0)
  1034. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1035. return 0;
  1036. }
  1037. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1038. if (!lua_interface)
  1039. return 0;
  1040. Spawn* spawn = lua_interface->GetSpawn(state);
  1041. if (spawn && spawn->IsEntity()) {
  1042. int32 val = lua_interface->GetInt32Value(state, 2);
  1043. ((Entity*)spawn)->SetLootCoins(val);
  1044. }
  1045. lua_interface->ResetFunctionStack(state);
  1046. return 0;
  1047. }
  1048. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1049. if (!lua_interface)
  1050. return 0;
  1051. Spawn* spawn = lua_interface->GetSpawn(state);
  1052. lua_interface->ResetFunctionStack(state);
  1053. if (spawn && spawn->IsEntity()) {
  1054. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1055. return 1;
  1056. }
  1057. return 0;
  1058. }
  1059. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1060. if (!lua_interface)
  1061. return 0;
  1062. Spawn* spawn = lua_interface->GetSpawn(state);
  1063. float x = lua_interface->GetFloatValue(state, 2);
  1064. float y = lua_interface->GetFloatValue(state, 3);
  1065. float z = lua_interface->GetFloatValue(state, 4);
  1066. float speed = lua_interface->GetFloatValue(state, 5);
  1067. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1068. string function = lua_interface->GetStringValue(state, 7);
  1069. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1070. float heading = lua_interface->GetFloatValue(state, 8);
  1071. if (spawn) {
  1072. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1073. spawn->GetZone()->AddMovementNPC(spawn);
  1074. }
  1075. lua_interface->ResetFunctionStack(state);
  1076. return 0;
  1077. }
  1078. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1079. if (!lua_interface)
  1080. return 0;
  1081. Spawn* spawn = lua_interface->GetSpawn(state);
  1082. lua_interface->ResetFunctionStack(state);
  1083. if (spawn) {
  1084. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1085. return 1;
  1086. }
  1087. return 0;
  1088. }
  1089. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1090. if (!lua_interface)
  1091. return 0;
  1092. Spawn* spawn = lua_interface->GetSpawn(state);
  1093. lua_interface->ResetFunctionStack(state);
  1094. if (spawn && spawn->IsPlayer()) {
  1095. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1096. return 1;
  1097. }
  1098. lua_interface->SetInt32Value(state, 0);
  1099. return 1;
  1100. }
  1101. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1102. if (!lua_interface)
  1103. return 0;
  1104. Spawn* spawn = lua_interface->GetSpawn(state);
  1105. Spawn* target = lua_interface->GetSpawn(state, 2);
  1106. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1107. bool reset_action_state = true;
  1108. if(num_args > 2)
  1109. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1110. if (spawn && target) {
  1111. if (spawn->IsEntity())
  1112. // ((Entity*)spawn)->FaceTarget(target);
  1113. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1114. }
  1115. lua_interface->ResetFunctionStack(state);
  1116. return 0;
  1117. }
  1118. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1119. if (!lua_interface)
  1120. return 0;
  1121. Spawn* spawn = lua_interface->GetSpawn(state);
  1122. float x = lua_interface->GetFloatValue(state, 2);
  1123. float y = lua_interface->GetFloatValue(state, 3);
  1124. float z = lua_interface->GetFloatValue(state, 4);
  1125. float speed = lua_interface->GetFloatValue(state, 5);
  1126. string lua_function = lua_interface->GetStringValue(state, 6);
  1127. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1128. if (spawn) {
  1129. if (speed == 0)
  1130. speed = spawn->GetSpeed();
  1131. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1132. }
  1133. lua_interface->ResetFunctionStack(state);
  1134. return 0;
  1135. }
  1136. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1137. if (!lua_interface)
  1138. return 0;
  1139. Spawn* spawn = lua_interface->GetSpawn(state);
  1140. lua_interface->ResetFunctionStack(state);
  1141. if (spawn) {
  1142. spawn->ClearRunningLocations();
  1143. }
  1144. return 0;
  1145. }
  1146. int EQ2Emu_lua_Say(lua_State* state) {
  1147. if (!lua_interface)
  1148. return 0;
  1149. Spawn* spawn = lua_interface->GetSpawn(state);
  1150. string message = lua_interface->GetStringValue(state, 2);
  1151. Spawn* player = lua_interface->GetSpawn(state, 3);
  1152. int32 language = lua_interface->GetInt32Value(state, 4);
  1153. if (spawn && message.length() > 0) {
  1154. Client* client = 0;
  1155. if (player && player->IsPlayer())
  1156. client = spawn->GetZone()->GetClientBySpawn(player);
  1157. if (client)
  1158. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1159. else
  1160. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1161. }
  1162. lua_interface->ResetFunctionStack(state);
  1163. return 0;
  1164. }
  1165. int EQ2Emu_lua_Shout(lua_State* state) {
  1166. if (!lua_interface)
  1167. return 0;
  1168. Spawn* spawn = lua_interface->GetSpawn(state);
  1169. string message = lua_interface->GetStringValue(state, 2);
  1170. Spawn* player = lua_interface->GetSpawn(state, 3);
  1171. float dist = lua_interface->GetFloatValue(state, 4);
  1172. if (spawn && message.length() > 0) {
  1173. Client* client = 0;
  1174. if (player && player->IsPlayer())
  1175. client = spawn->GetZone()->GetClientBySpawn(player);
  1176. if (client)
  1177. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1178. else
  1179. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1180. }
  1181. lua_interface->ResetFunctionStack(state);
  1182. return 0;
  1183. }
  1184. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1185. if (!lua_interface)
  1186. return 0;
  1187. Spawn* spawn = lua_interface->GetSpawn(state);
  1188. string message = lua_interface->GetStringValue(state, 2);
  1189. Spawn* player = lua_interface->GetSpawn(state, 3);
  1190. if (spawn && message.length() > 0) {
  1191. Client* client = 0;
  1192. if (player && player->IsPlayer())
  1193. client = spawn->GetZone()->GetClientBySpawn(player);
  1194. if (client)
  1195. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1196. else
  1197. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1198. }
  1199. lua_interface->ResetFunctionStack(state);
  1200. return 0;
  1201. }
  1202. int EQ2Emu_lua_Emote(lua_State* state) {
  1203. if (!lua_interface)
  1204. return 0;
  1205. Spawn* spawn = lua_interface->GetSpawn(state);
  1206. string message = lua_interface->GetStringValue(state, 2);
  1207. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1208. Spawn* player = lua_interface->GetSpawn(state, 4);
  1209. char* to = 0;
  1210. if (spawn2)
  1211. to = spawn2->GetName();
  1212. if (spawn && message.length() > 0) {
  1213. Client* client = 0;
  1214. if (player && player->IsPlayer())
  1215. client = spawn->GetZone()->GetClientBySpawn(player);
  1216. if (client)
  1217. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1218. else
  1219. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1220. }
  1221. lua_interface->ResetFunctionStack(state);
  1222. return 0;
  1223. }
  1224. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1225. if (!lua_interface)
  1226. return 0;
  1227. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1228. if (!luaspell)
  1229. return 0;
  1230. Spawn* caster = luaspell->caster;
  1231. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1232. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1233. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1234. Spawn* target = lua_interface->GetSpawn(state, 4);
  1235. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1236. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1237. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1238. lua_interface->ResetFunctionStack(state);
  1239. boost::to_lower(heal_type);
  1240. if (caster && caster->IsEntity()) {
  1241. bool success = false;
  1242. luaspell->resisted = false;
  1243. if (target) {
  1244. float distance = caster->GetDistance(target, true);
  1245. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1246. success = true;
  1247. }
  1248. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1249. Spawn* target = 0;
  1250. ZoneServer* zone = luaspell->caster->GetZone();
  1251. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1252. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1253. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1254. float distance = caster->GetDistance(target, true);
  1255. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1256. }
  1257. }
  1258. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1259. success = true;
  1260. }
  1261. if (success) {
  1262. if (caster->GetZone())
  1263. caster->GetZone()->TriggerCharSheetTimer();
  1264. }
  1265. }
  1266. return 0;
  1267. }
  1268. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1269. if (!lua_interface)
  1270. return 0;
  1271. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1272. if (!luaspell)
  1273. return 0;
  1274. Spawn* caster = luaspell->caster;
  1275. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1276. float percentage = lua_interface->GetFloatValue(state, 2);
  1277. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1278. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1279. Spawn* target = lua_interface->GetSpawn(state, 5);
  1280. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1281. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1282. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1283. lua_interface->ResetFunctionStack(state);
  1284. boost::to_lower(heal_type);
  1285. int32 min_heal = 0, max_heal = 0;
  1286. if (caster && caster->IsEntity() && target) {
  1287. if(percentage <= 0.0f)
  1288. {
  1289. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1290. return 0;
  1291. }
  1292. if(heal_type == "power")
  1293. {
  1294. if(current_value)
  1295. {
  1296. if(caster_value)
  1297. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1298. else
  1299. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1300. }
  1301. else
  1302. {
  1303. if(caster_value)
  1304. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1305. else
  1306. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1307. }
  1308. }
  1309. else
  1310. {
  1311. if(current_value)
  1312. {
  1313. if(caster_value)
  1314. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1315. else
  1316. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1317. }
  1318. else
  1319. {
  1320. if(caster_value)
  1321. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1322. else
  1323. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1324. }
  1325. }
  1326. bool success = false;
  1327. luaspell->resisted = false;
  1328. if (target) {
  1329. float distance = caster->GetDistance(target, true);
  1330. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1331. success = true;
  1332. }
  1333. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1334. Spawn* target = 0;
  1335. ZoneServer* zone = luaspell->caster->GetZone();
  1336. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1337. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1338. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1339. float distance = caster->GetDistance(target, true);
  1340. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1341. }
  1342. }
  1343. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1344. success = true;
  1345. }
  1346. if (success) {
  1347. if (caster->GetZone())
  1348. caster->GetZone()->TriggerCharSheetTimer();
  1349. }
  1350. }
  1351. return 0;
  1352. }
  1353. int EQ2Emu_lua_AddItem(lua_State* state) {
  1354. if (!lua_interface)
  1355. return 0;
  1356. Spawn* spawn = lua_interface->GetSpawn(state);
  1357. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1358. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1359. lua_interface->ResetFunctionStack(state);
  1360. // default of 1 quantity to add
  1361. if (quantity == 0)
  1362. quantity = 1;
  1363. if (spawn && spawn->IsPlayer()) {
  1364. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1365. if (client && item_id > 0) {
  1366. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1367. return 1;
  1368. }
  1369. }
  1370. lua_interface->SetBooleanValue(state, false);
  1371. return 1;
  1372. }
  1373. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1374. if (!lua_interface)
  1375. return 0;
  1376. Spawn* spawn = lua_interface->GetSpawn(state);
  1377. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1378. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1379. string location = lua_interface->GetStringValue(state, 4);
  1380. int16 item_count = lua_interface->GetInt16Value(state,5);
  1381. //devn00b: if we dont have a count, assume 1 item.
  1382. if(!item_count) {
  1383. item_count = 1;
  1384. }
  1385. lua_interface->ResetFunctionStack(state);
  1386. if (spawn && spawn->IsPlayer()) {
  1387. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1388. if (client && item_id > 0) {
  1389. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1390. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1391. else
  1392. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1393. if (send_messages) {
  1394. Item* item = master_item_list.GetItem(item_id);
  1395. if (item) {
  1396. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1397. string popup_text = "You receive " + item->name;
  1398. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1399. }
  1400. }
  1401. return 1;
  1402. }
  1403. }
  1404. lua_interface->SetBooleanValue(state, false);
  1405. return 1;
  1406. }
  1407. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1408. Spawn* spawn = lua_interface->GetSpawn(state);
  1409. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1410. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1411. lua_interface->ResetFunctionStack(state);
  1412. // default of 1 to remove
  1413. if (quantity == 0)
  1414. quantity = 1;
  1415. Client* client;
  1416. Item* item;
  1417. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1418. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1419. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1420. if (client->RemoveItem(item, quantity)) {
  1421. lua_interface->SetBooleanValue(state, true);
  1422. return 1;
  1423. }
  1424. }
  1425. }
  1426. }
  1427. lua_interface->SetBooleanValue(state, false);
  1428. return 1;
  1429. }
  1430. int EQ2Emu_lua_HasItem(lua_State* state) {
  1431. Spawn* player = lua_interface->GetSpawn(state);
  1432. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1433. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1434. lua_interface->ResetFunctionStack(state);
  1435. if (player && player->IsPlayer()) {
  1436. bool hasItem = false;
  1437. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1438. if (!hasItem)
  1439. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1440. lua_interface->SetBooleanValue(state, hasItem);
  1441. return 1;
  1442. }
  1443. lua_interface->SetBooleanValue(state, false);
  1444. return 1;
  1445. }
  1446. int EQ2Emu_lua_Spawn(lua_State* state) {
  1447. if (!lua_interface)
  1448. return 0;
  1449. ZoneServer* zone = lua_interface->GetZone(state);
  1450. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1451. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1452. float x = lua_interface->GetFloatValue(state, 4);
  1453. float y = lua_interface->GetFloatValue(state, 5);
  1454. float z = lua_interface->GetFloatValue(state, 6);
  1455. float heading = lua_interface->GetFloatValue(state, 7);
  1456. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1457. Spawn* spawn = zone->GetSpawn(spawn_id);
  1458. if (!spawn)
  1459. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1460. else {
  1461. spawn->SetX(x);
  1462. spawn->SetZ(z);
  1463. spawn->SetY(y,true,true);
  1464. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1465. spawn->SetHeading(heading);
  1466. if (restricted_npc)
  1467. spawn->AddAllowAccessSpawn(spawn);
  1468. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1469. bool scriptActive = false;
  1470. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1471. scriptActive = true;
  1472. spawn->SetSpawnScript(string(spawn_script));
  1473. }
  1474. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1475. zone->AddSpawn(spawn);
  1476. if (scriptActive) {
  1477. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1478. }
  1479. lua_interface->ResetFunctionStack(state);
  1480. lua_interface->SetSpawnValue(state, spawn);
  1481. return 1;
  1482. }
  1483. }
  1484. else {
  1485. string output = "Invalid paramaters to LUA Spawn command: \n";
  1486. if (!zone)
  1487. output = output.append("\t").append("Missing zone reference. \n");
  1488. if (spawn_id == 0)
  1489. output = output.append("\t").append("Missing spawn_id.");
  1490. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1491. }
  1492. lua_interface->ResetFunctionStack(state);
  1493. return 0;
  1494. }
  1495. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1496. if (!lua_interface)
  1497. return 0;
  1498. ZoneServer* zone = lua_interface->GetZone(state);
  1499. lua_interface->ResetFunctionStack(state);
  1500. if (zone) {
  1501. lua_interface->SetStringValue(state, zone->GetZoneName());
  1502. return 1;
  1503. }
  1504. return 0;
  1505. }
  1506. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1507. if (!lua_interface)
  1508. return 0;
  1509. ZoneServer* zone = lua_interface->GetZone(state);
  1510. lua_interface->ResetFunctionStack(state);
  1511. if (zone) {
  1512. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1513. return 1;
  1514. }
  1515. return 0;
  1516. }
  1517. int EQ2Emu_lua_GetZone(lua_State* state) {
  1518. if (!lua_interface)
  1519. return 0;
  1520. int32 zone_id = lua_interface->GetInt32Value(state);
  1521. ZoneServer* zone = 0;
  1522. if (zone_id > 0)
  1523. zone = zone_list.Get(zone_id);
  1524. else {
  1525. string zone_name = lua_interface->GetStringValue(state);
  1526. if (zone_name.length() > 0) {
  1527. zone = zone_list.Get(zone_name.c_str());
  1528. }
  1529. else {
  1530. Spawn* spawn = lua_interface->GetSpawn(state);
  1531. if (spawn)
  1532. zone = spawn->GetZone();
  1533. }
  1534. }
  1535. lua_interface->ResetFunctionStack(state);
  1536. if (zone) {
  1537. lua_interface->SetZoneValue(state, zone);
  1538. return 1;
  1539. }
  1540. return 0;
  1541. }
  1542. int EQ2Emu_lua_AddHate(lua_State* state) {
  1543. Spawn* entity = lua_interface->GetSpawn(state);
  1544. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1545. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1546. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1547. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1548. if (entity && entity->IsEntity() && amount != 0) {
  1549. if (luaspell) {
  1550. ZoneServer* zone = luaspell->caster->GetZone();
  1551. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1552. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1553. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1554. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1555. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1556. if (send_packet)
  1557. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1558. }
  1559. }
  1560. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1561. }
  1562. else if (npc && npc->IsNPC() && npc->GetZone())
  1563. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1564. }
  1565. lua_interface->ResetFunctionStack(state);
  1566. return 0;
  1567. }
  1568. int EQ2Emu_lua_Zone(lua_State* state) {
  1569. if (!lua_interface)
  1570. return 0;
  1571. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1572. ZoneServer* zone = lua_interface->GetZone(state);
  1573. Spawn* player = lua_interface->GetSpawn(state, 2);
  1574. Client* client = 0;
  1575. if (player && player->IsPlayer())
  1576. client = player->GetZone()->GetClientBySpawn(player);
  1577. float x = lua_interface->GetFloatValue(state, 3);
  1578. float y = lua_interface->GetFloatValue(state, 4);
  1579. float z = lua_interface->GetFloatValue(state, 5);
  1580. float heading = lua_interface->GetFloatValue(state, 6);
  1581. if (zone && client) {
  1582. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1583. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1584. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1585. {
  1586. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1587. return 0;
  1588. }
  1589. if (x != 0 || y != 0 || z != 0) {
  1590. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1591. player->SetX(x);
  1592. player->SetY(y);
  1593. player->SetZ(z);
  1594. player->SetHeading(heading);
  1595. client->Zone(zone->GetZoneName(), false);
  1596. }
  1597. else
  1598. client->Zone(zone->GetZoneName());
  1599. }
  1600. else
  1601. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1602. lua_interface->ResetFunctionStack(state);
  1603. return 0;
  1604. }
  1605. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1606. if (!lua_interface)
  1607. return 0;
  1608. Spawn* spawn = lua_interface->GetSpawn(state);
  1609. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1610. if (spawn && spawn2)
  1611. spawn->AddAllowAccessSpawn(spawn2);
  1612. lua_interface->ResetFunctionStack(state);
  1613. return 0;
  1614. }
  1615. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1616. if (!lua_interface)
  1617. return 0;
  1618. Spawn* target = lua_interface->GetSpawn(state);
  1619. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1620. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1621. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1622. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1623. lua_interface->ResetFunctionStack(state);
  1624. if (!target) {
  1625. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1626. return 0;
  1627. }
  1628. if (!target->IsEntity()) {
  1629. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1630. return 0;
  1631. }
  1632. if (spell_id <= 0) {
  1633. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1634. return 0;
  1635. }
  1636. if (caster && !caster->IsEntity()) {
  1637. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1638. return 0;
  1639. }
  1640. if (spell_tier == 0)
  1641. spell_tier = 1;
  1642. if (!caster)
  1643. caster = target;
  1644. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1645. return 0;
  1646. }
  1647. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1648. if (!lua_interface)
  1649. return 0;
  1650. Spawn* target = lua_interface->GetSpawn(state);
  1651. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1652. if (!luaspell)
  1653. return 0;
  1654. Spawn* caster = luaspell->caster;
  1655. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1656. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1657. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1658. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1659. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1660. //lua_interface->ResetFunctionStack(state);
  1661. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1662. vector<int16> faction_req;
  1663. vector<int16> race_req;
  1664. int32 class_req = 0;
  1665. int32 i = 0;
  1666. int8 f = 0;
  1667. int8 r = 0;
  1668. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1669. if (class_id < 100) {
  1670. class_req += pow(2.0, double(class_id - 1));
  1671. }
  1672. else if (class_id > 100 && class_id < 1000) {
  1673. race_req.push_back(class_id);
  1674. r++;
  1675. }
  1676. else {
  1677. faction_req.push_back(class_id);
  1678. f++;
  1679. }
  1680. i++;
  1681. }
  1682. lua_interface->ResetFunctionStack(state);
  1683. if (caster && caster->IsEntity()) {
  1684. bool race_match = false;
  1685. bool success = false;
  1686. luaspell->resisted = false;
  1687. if (luaspell->targets.size() > 0) {
  1688. ZoneServer* zone = luaspell->caster->GetZone();
  1689. Spawn* target = 0;
  1690. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1691. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1692. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1693. if (race_req.size() > 0) {
  1694. for (int8 i = 0; i < race_req.size(); i++) {
  1695. if (target->GetLuaRaceId() == race_req[i]) {
  1696. race_match = true;
  1697. }
  1698. }
  1699. }
  1700. else
  1701. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1702. if (race_match == true) {
  1703. float distance = caster->GetDistance(target, true);
  1704. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1705. }
  1706. }
  1707. }
  1708. success = true;
  1709. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1710. }
  1711. else if (target) {
  1712. //check class and race/faction here
  1713. if (race_req.size() > 0) {
  1714. for (int8 i = 0; i < race_req.size(); i++) {
  1715. if (target->GetLuaRaceId() == race_req[i]) {
  1716. race_match = true;
  1717. }
  1718. }
  1719. }
  1720. else
  1721. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1722. if (race_match == true) {
  1723. float distance = caster->GetDistance(target, true);
  1724. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1725. success = true;
  1726. }
  1727. }
  1728. if (success) {
  1729. Spell* spell = luaspell->spell;
  1730. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1731. ((Player*)caster)->InCombat(true);
  1732. if (caster->GetZone())
  1733. caster->GetZone()->TriggerCharSheetTimer();
  1734. }
  1735. }
  1736. }
  1737. return 0;
  1738. }
  1739. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1740. if (!lua_interface)
  1741. return 0;
  1742. Spawn* spawn = lua_interface->GetSpawn(state);
  1743. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1744. lua_interface->ResetFunctionStack(state);
  1745. if (spawn && value != 0) {
  1746. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1747. spawn->SetPower(spawn->GetTotalPower());
  1748. else
  1749. spawn->SetPower(spawn->GetPower() + value);
  1750. }
  1751. return 0;
  1752. }
  1753. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1754. if (!lua_interface)
  1755. return 0;
  1756. Spawn* spawn = lua_interface->GetSpawn(state);
  1757. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1758. lua_interface->ResetFunctionStack(state);
  1759. if (spawn && value != 0) {
  1760. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1761. spawn->SetHP(spawn->GetTotalHP());
  1762. else
  1763. spawn->SetHP(spawn->GetHP() + value);
  1764. }
  1765. return 0;
  1766. }
  1767. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1768. if (!lua_interface)
  1769. return 0;
  1770. Spawn* spawn = lua_interface->GetSpawn(state);
  1771. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1772. lua_interface->ResetFunctionStack(state);
  1773. if (spawn && value != 0) {
  1774. spawn->SetPower(spawn->GetPower() + value);
  1775. if (value > spawn->GetTotalHPBase())
  1776. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1777. }
  1778. return 0;
  1779. }
  1780. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1781. if (!lua_interface)
  1782. return 0;
  1783. Spawn* spawn = lua_interface->GetSpawn(state);
  1784. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1785. lua_interface->ResetFunctionStack(state);
  1786. if (spawn && value != 0) {
  1787. spawn->SetHP(spawn->GetHP() + value);
  1788. if (value > spawn->GetTotalHPBase())
  1789. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1790. }
  1791. return 0;
  1792. }
  1793. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1794. if (!lua_interface)
  1795. return 0;
  1796. Spawn* spawn = lua_interface->GetSpawn(state);
  1797. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1798. lua_interface->ResetFunctionStack(state);
  1799. if (spawn) {
  1800. spawn->SetHP(value);
  1801. if (value > spawn->GetTotalHPBase())
  1802. spawn->SetTotalHP(value);
  1803. }
  1804. return 0;
  1805. }
  1806. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1807. if (!lua_interface)
  1808. return 0;
  1809. Spawn* spawn = lua_interface->GetSpawn(state);
  1810. float value = lua_interface->GetFloatValue(state, 2);
  1811. lua_interface->ResetFunctionStack(state);
  1812. if (spawn && spawn->IsEntity() && value > 0)
  1813. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1814. if (spawn->IsPlayer())
  1815. ((Player*)spawn)->SetCharSheetChanged(true);
  1816. return 0;
  1817. }
  1818. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1819. if (!lua_interface)
  1820. return 0;
  1821. Spawn* spawn = lua_interface->GetSpawn(state);
  1822. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1823. lua_interface->ResetFunctionStack(state);
  1824. if (spawn && spawn->IsEntity() && value > 0)
  1825. ((Entity*)spawn)->SetTotalHPBase(value);
  1826. return 0;
  1827. }
  1828. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1829. if (!lua_interface)
  1830. return 0;
  1831. Spawn* spawn = lua_interface->GetSpawn(state);
  1832. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1833. lua_interface->ResetFunctionStack(state);
  1834. if (spawn && value > 0) {
  1835. spawn->SetPower(value);
  1836. if (value > spawn->GetTotalPowerBase())
  1837. spawn->SetTotalPower(value);
  1838. }
  1839. return 0;
  1840. }
  1841. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1842. if (!lua_interface)
  1843. return 0;
  1844. Spawn* spawn = lua_interface->GetSpawn(state);
  1845. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1846. lua_interface->ResetFunctionStack(state);
  1847. if (spawn && spawn->IsEntity() && value > 0)
  1848. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1849. return 0;
  1850. }
  1851. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1852. if (!lua_interface)
  1853. return 0;
  1854. Spawn* spawn = lua_interface->GetSpawn(state);
  1855. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1856. lua_interface->ResetFunctionStack(state);
  1857. if (spawn && spawn->IsEntity() && value > 0)
  1858. ((Entity*)spawn)->SetTotalPowerBase(value);
  1859. return 0;
  1860. }
  1861. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1862. if (!lua_interface)
  1863. return 0;
  1864. Spawn* spawn = lua_interface->GetSpawn(state);
  1865. float x = lua_interface->GetFloatValue(state, 2);
  1866. float y = lua_interface->GetFloatValue(state, 3);
  1867. float z = lua_interface->GetFloatValue(state, 4);
  1868. float heading = lua_interface->GetFloatValue(state, 5);
  1869. lua_interface->ResetFunctionStack(state);
  1870. if (spawn) {
  1871. spawn->SetX(x);
  1872. spawn->SetY(y);
  1873. spawn->SetZ(z);
  1874. if (heading != 0)
  1875. spawn->SetHeading(heading);
  1876. spawn->SetSpawnOrigX(spawn->GetX());
  1877. spawn->SetSpawnOrigY(spawn->GetY());
  1878. spawn->SetSpawnOrigZ(spawn->GetZ());
  1879. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1880. if (spawn->IsPlayer()) {
  1881. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1882. if (client) {
  1883. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1884. client->QueuePacket(packet);
  1885. }
  1886. }
  1887. }
  1888. return 0;
  1889. }
  1890. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1891. if (!lua_interface)
  1892. return 0;
  1893. Spawn* spawn = lua_interface->GetSpawn(state);
  1894. float value = lua_interface->GetFloatValue(state, 2);
  1895. lua_interface->ResetFunctionStack(state);
  1896. if (spawn) {
  1897. spawn->SetHeading(value);
  1898. if (spawn->IsPlayer()) {
  1899. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1900. if (client) {
  1901. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1902. client->QueuePacket(packet);
  1903. }
  1904. }
  1905. }
  1906. return 0;
  1907. }
  1908. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1909. if (!lua_interface)
  1910. return 0;
  1911. Spawn* spawn = lua_interface->GetSpawn(state);
  1912. int16 value = lua_interface->GetInt16Value(state, 2);
  1913. lua_interface->ResetFunctionStack(state);
  1914. if (spawn)
  1915. spawn->SetModelType(value);
  1916. return 0;
  1917. }
  1918. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1919. if (!lua_interface)
  1920. return 0;
  1921. Spawn* spawn = lua_interface->GetSpawn(state);
  1922. int8 value = lua_interface->GetInt8Value(state, 2);
  1923. lua_interface->ResetFunctionStack(state);
  1924. if (spawn) {
  1925. if (spawn->IsPlayer())
  1926. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1927. else
  1928. spawn->SetAdventureClass(value);
  1929. }
  1930. return 0;
  1931. }
  1932. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1933. if (!lua_interface)
  1934. return 0;
  1935. Spawn* spawn = lua_interface->GetSpawn(state);
  1936. int8 value = lua_interface->GetInt8Value(state, 2);
  1937. lua_interface->ResetFunctionStack(state);
  1938. if (spawn) {
  1939. spawn->SetTradeskillClass(value);
  1940. if (spawn->IsEntity()) {
  1941. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1942. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1943. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1944. }
  1945. if (spawn->IsPlayer())
  1946. ((Player*)spawn)->SetCharSheetChanged(true);
  1947. }
  1948. return 0;
  1949. }
  1950. int EQ2Emu_lua_SetMount(lua_State* state) {
  1951. if (!lua_interface)
  1952. return 0;
  1953. Spawn* spawn = lua_interface->GetSpawn(state);
  1954. int16 value = lua_interface->GetInt16Value(state, 2);
  1955. if (spawn && spawn->IsEntity()) {
  1956. ((Entity*)spawn)->SetMount(value);
  1957. EQ2_Color color;
  1958. color.red = 255;
  1959. color.green = 255;
  1960. color.blue = 255;
  1961. ((Entity*)spawn)->SetMountColor(&color);
  1962. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1963. }
  1964. return 0;
  1965. }
  1966. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1967. if (!lua_interface)
  1968. return 0;
  1969. Spawn* spawn = lua_interface->GetSpawn(state);
  1970. EQ2_Color mount_color;
  1971. EQ2_Color saddle_color;
  1972. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1973. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1974. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1975. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1976. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1977. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1978. if (spawn && spawn->IsEntity()) {
  1979. ((Entity*)spawn)->SetMountColor(&mount_color);
  1980. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1981. }
  1982. return 0;
  1983. }
  1984. int EQ2Emu_lua_GetMount(lua_State* state) {
  1985. if (!lua_interface)
  1986. return 0;
  1987. Spawn* spawn = lua_interface->GetSpawn(state);
  1988. if (spawn && spawn->IsEntity()) {
  1989. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1990. return 1;
  1991. }
  1992. return 0;
  1993. }
  1994. int EQ2Emu_lua_GetRace(lua_State* state) {
  1995. if (!lua_interface)
  1996. return 0;
  1997. Spawn* spawn = lua_interface->GetSpawn(state);
  1998. if (spawn)
  1999. {
  2000. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2001. lua_interface->SetInt32Value(state, spawn->GetRace());
  2002. return 1;
  2003. }
  2004. return 0;
  2005. }
  2006. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2007. if (!lua_interface)
  2008. return 0;
  2009. Spawn* spawn = lua_interface->GetSpawn(state);
  2010. if (spawn) {
  2011. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2012. return 1;
  2013. }
  2014. return 0;
  2015. }
  2016. int EQ2Emu_lua_GetClass(lua_State* state) {
  2017. Spawn* spawn = lua_interface->GetSpawn(state);
  2018. if (spawn) {
  2019. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2020. return 1;
  2021. }
  2022. return 0;
  2023. }
  2024. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2025. Spawn* spawn = lua_interface->GetSpawn(state);
  2026. if (spawn) {
  2027. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2028. return 1;
  2029. }
  2030. return 0;
  2031. }
  2032. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2033. if (!lua_interface)
  2034. return 0;
  2035. Spawn* spawn = lua_interface->GetSpawn(state);
  2036. float value = lua_interface->GetFloatValue(state, 2);
  2037. lua_interface->ResetFunctionStack(state);
  2038. if (spawn) {
  2039. spawn->SetSpeed(value);
  2040. if(spawn->IsEntity())
  2041. ((Entity*)spawn)->SetSpeed(value);
  2042. if (spawn->IsPlayer()) {
  2043. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2044. if (client) {
  2045. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2046. if (packet) {
  2047. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2048. packet->setDataByName("speed", value);
  2049. packet->setDataByName("size", 0.51);
  2050. EQ2Packet* app = packet->serialize();
  2051. client->QueuePacket(app);
  2052. safe_delete(packet);
  2053. }
  2054. }
  2055. }
  2056. }
  2057. return 0;
  2058. }
  2059. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2060. if (!lua_interface)
  2061. return 0;
  2062. Spawn* spawn = lua_interface->GetSpawn(state);
  2063. const int16 type = lua_interface->GetInt16Value(state, 2);
  2064. const float value = lua_interface->GetFloatValue(state, 3);
  2065. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2066. int64 class_req = 0;
  2067. int32 class_id = 0;
  2068. vector<int16> faction_req;
  2069. vector<int16> race_req;
  2070. int32 i = 0;
  2071. int8 f = 0;
  2072. int8 r = 0;
  2073. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2074. if (class_id < 100) {
  2075. class_req += pow(2.0, double(class_id - 1));
  2076. }
  2077. else if (class_id > 100 && class_id < 1000) {
  2078. race_req.push_back(class_id);
  2079. r++;
  2080. }
  2081. else {
  2082. faction_req.push_back(class_id);
  2083. f++;
  2084. }
  2085. i++;
  2086. }
  2087. if (value != 0 && type >= 0) {
  2088. if (luaspell && luaspell->spell && luaspell->caster) {
  2089. ZoneServer* zone = luaspell->caster->GetZone();
  2090. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2091. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2092. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2093. if (target) {
  2094. if (target->IsPlayer()) {
  2095. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2096. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2097. if (((Player*)target)->GetGroupMemberInfo())
  2098. ((Player*)target)->UpdateGroupMemberInfo();
  2099. ((Player*)target)->SetCharSheetChanged(true);
  2100. }
  2101. else if (target->IsNPC())
  2102. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2103. else
  2104. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2105. }
  2106. }
  2107. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2108. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2109. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2110. }
  2111. else if (spawn && spawn->IsEntity()) {
  2112. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2113. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2114. if (spawn->IsPlayer())
  2115. ((Player*)spawn)->SetCharSheetChanged(true);
  2116. }
  2117. else
  2118. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2119. }
  2120. else
  2121. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2122. return 0;
  2123. }
  2124. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2125. if (!lua_interface)
  2126. return 0;
  2127. Spawn* spawn = lua_interface->GetSpawn(state);
  2128. int16 type = lua_interface->GetInt16Value(state, 2);
  2129. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2130. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2131. if (!spawn) {
  2132. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2133. return 0;
  2134. }
  2135. if (!spawn->IsEntity()) {
  2136. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2137. return 0;
  2138. }
  2139. if (value == 0) {
  2140. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2141. return 0;
  2142. }
  2143. if (!luaspell || !luaspell->spell) {
  2144. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2145. return 0;
  2146. }
  2147. int32 class_req = 0;
  2148. vector<int16> faction_req;
  2149. vector<int16> race_req;
  2150. int32 class_id = 0;
  2151. int32 i = 0;
  2152. int8 f = 0;
  2153. int8 r = 0;
  2154. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2155. if (class_id < 100) {
  2156. class_req += pow(2.0, double(class_id - 1));
  2157. }
  2158. else if (class_id > 100 && class_id < 1000) {
  2159. race_req.push_back(class_id);
  2160. r++;
  2161. }
  2162. else {
  2163. faction_req.push_back(class_id);
  2164. f++;
  2165. }
  2166. i++;
  2167. }
  2168. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2169. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2170. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2171. if (spawn->IsPlayer())
  2172. ((Player*)spawn)->SetCharSheetChanged(true);
  2173. return 0;
  2174. }
  2175. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2176. if (!lua_interface)
  2177. return 0;
  2178. Spawn* spawn = lua_interface->GetSpawn(state);
  2179. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2180. if (!spawn) {
  2181. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2182. return 0;
  2183. }
  2184. if (!spawn->IsEntity()) {
  2185. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2186. return 0;
  2187. }
  2188. if (!luaspell || !luaspell->spell) {
  2189. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2190. return 0;
  2191. }
  2192. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2193. if (spawn->IsPlayer())
  2194. ((Player*)spawn)->SetCharSheetChanged(true);
  2195. return 0;
  2196. }
  2197. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2198. if (!lua_interface)
  2199. return 0;
  2200. Spawn* spawn = lua_interface->GetSpawn(state);
  2201. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2202. if (luaspell && luaspell->spell) {
  2203. ZoneServer* zone = luaspell->caster->GetZone();
  2204. Spawn* target = 0;
  2205. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2206. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2207. target = zone->GetSpawnByID(luaspell->targets[i]);
  2208. if (target && target->IsEntity()) {
  2209. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2210. if (target->IsPlayer())
  2211. ((Player*)target)->SetCharSheetChanged(true);
  2212. }
  2213. }
  2214. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2215. }
  2216. else if (spawn && spawn->IsEntity()) {
  2217. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2218. if (spawn->IsPlayer())
  2219. ((Player*)spawn)->SetCharSheetChanged(true);
  2220. }
  2221. return 0;
  2222. }
  2223. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2224. if (!lua_interface)
  2225. return 0;
  2226. Spawn* spawn = lua_interface->GetSpawn(state);
  2227. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2228. float value = lua_interface->GetFloatValue(state, 3);
  2229. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2230. if (value != 0) {
  2231. int32 spell_id = 0;
  2232. if (luaspell && luaspell->spell && luaspell->caster) {
  2233. spell_id = luaspell->spell->GetSpellID();
  2234. ZoneServer* zone = luaspell->caster->GetZone();
  2235. Spawn* target = 0;
  2236. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2237. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2238. target = zone->GetSpawnByID(luaspell->targets[i]);
  2239. if (target && target->Alive()) {
  2240. if (target->IsPlayer()) {
  2241. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2242. Client* client = target->GetZone()->GetClientBySpawn(target);
  2243. if (client) {
  2244. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2245. if (packet)
  2246. client->QueuePacket(packet);
  2247. }
  2248. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2249. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2250. }
  2251. else if (target->IsNPC()) {
  2252. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2253. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2254. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2255. }
  2256. else
  2257. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2258. }
  2259. }
  2260. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2261. }
  2262. else if (spawn) {
  2263. if (spawn->IsPlayer()) {
  2264. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2265. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2266. if (client) {
  2267. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2268. if (packet)
  2269. client->QueuePacket(packet);
  2270. }
  2271. }
  2272. else if (spawn->IsNPC())
  2273. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2274. else
  2275. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2276. }
  2277. }
  2278. else
  2279. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2280. return 0;
  2281. }
  2282. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2283. if (!lua_interface)
  2284. return 0;
  2285. Spawn* spawn = lua_interface->GetSpawn(state);
  2286. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2287. if (spawn && spawn->IsPlayer()) {
  2288. int32 spell_id = 0;
  2289. if (luaspell && luaspell->spell) {
  2290. spell_id = luaspell->spell->GetSpellID();
  2291. ZoneServer* zone = luaspell->caster->GetZone();
  2292. Spawn* target = 0;
  2293. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2294. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2295. target = zone->GetSpawnByID(luaspell->targets[i]);
  2296. if (target) {
  2297. if (target->IsPlayer()) {
  2298. ((Player*)target)->RemoveSkillBonus(spell_id);
  2299. Client* client = target->GetZone()->GetClientBySpawn(target);
  2300. if (client) {
  2301. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2302. if (packet)
  2303. client->QueuePacket(packet);
  2304. }
  2305. }
  2306. else if (target->IsNPC())
  2307. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2308. else
  2309. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2310. }
  2311. }
  2312. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2313. }
  2314. else if (spawn) {
  2315. if (spawn->IsPlayer()) {
  2316. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2317. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2318. if (client) {
  2319. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2320. if (packet)
  2321. client->QueuePacket(packet);
  2322. }
  2323. }
  2324. else if (spawn->IsNPC())
  2325. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2326. else
  2327. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2328. }
  2329. }
  2330. return 0;
  2331. }
  2332. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2333. if (!lua_interface)
  2334. return 0;
  2335. Spawn* spawn = lua_interface->GetSpawn(state);
  2336. int8 type = lua_interface->GetInt32Value(state, 2);
  2337. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2338. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2339. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2340. ZoneServer* zone = luaspell->caster->GetZone();
  2341. Spawn* target = 0;
  2342. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2343. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2344. target = zone->GetSpawnByID(luaspell->targets[i]);
  2345. if (target && target->IsEntity()) {
  2346. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2347. ((Entity*)target)->AddMezSpell(luaspell);
  2348. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2349. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2350. if (target->IsNPC())
  2351. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2352. }
  2353. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2354. ((Entity*)target)->AddStifleSpell(luaspell);
  2355. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2356. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2357. if (target->IsNPC())
  2358. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2359. }
  2360. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2361. ((Entity*)target)->AddDazeSpell(luaspell);
  2362. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2363. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2364. if (target->IsNPC())
  2365. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2366. }
  2367. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2368. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2369. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2370. ((Entity*)target)->AddStunSpell(luaspell);
  2371. if (target->IsNPC())
  2372. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2373. }
  2374. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2375. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2376. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2377. ((Entity*)target)->AddRootSpell(luaspell);
  2378. if (target->IsNPC())
  2379. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2380. }
  2381. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2382. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2383. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2384. ((Entity*)target)->AddFearSpell(luaspell);
  2385. if (target->IsNPC())
  2386. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2387. }
  2388. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2389. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2390. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2391. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2392. }
  2393. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2394. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2395. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2396. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2397. }
  2398. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2399. ((Entity*)target)->AddSnareSpell(luaspell);
  2400. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2401. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2402. if (target->IsNPC())
  2403. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2404. }
  2405. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2406. ((Entity*)target)->AddFlightSpell(luaspell);
  2407. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2408. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2409. }
  2410. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2411. ((Entity*)target)->AddGlideSpell(luaspell);
  2412. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2413. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2414. }
  2415. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2416. ((Entity*)target)->AddSafefallSpell(luaspell);
  2417. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2418. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2419. }
  2420. else
  2421. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2422. }
  2423. else
  2424. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), target->GetName());
  2425. }
  2426. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2427. }
  2428. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2429. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2430. ((Entity*)spawn)->AddMezSpell(luaspell);
  2431. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2432. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2433. }
  2434. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2435. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2436. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2437. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2438. }
  2439. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2440. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2441. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2442. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2443. }
  2444. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2445. ((Entity*)spawn)->AddStunSpell(luaspell);
  2446. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2447. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2448. }
  2449. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2450. ((Entity*)spawn)->AddRootSpell(luaspell);
  2451. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2452. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2453. }
  2454. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2455. ((Entity*)spawn)->AddFearSpell(luaspell);
  2456. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2457. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2458. }
  2459. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2460. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2461. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2462. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2463. }
  2464. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2465. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2466. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2467. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2468. }
  2469. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2470. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2471. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2472. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2473. }
  2474. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2475. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2476. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2477. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2478. }
  2479. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2480. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2481. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2482. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2483. }
  2484. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2485. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2486. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2487. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2488. }
  2489. else
  2490. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2491. }
  2492. else
  2493. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), spawn->GetName());
  2494. return 0;
  2495. }
  2496. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2497. if (!lua_interface)
  2498. return 0;
  2499. Spawn* spawn = lua_interface->GetSpawn(state);
  2500. int8 type = lua_interface->GetInt8Value(state, 2);
  2501. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2502. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2503. if (spawn && spawn->IsEntity()) {
  2504. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2505. ZoneServer* zone = luaspell->caster->GetZone();
  2506. Spawn* target = 0;
  2507. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2508. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2509. target = zone->GetSpawnByID(luaspell->targets[i]);
  2510. if (target) {
  2511. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2512. ((Entity*)target)->RemoveMezSpell(luaspell);
  2513. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2514. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2515. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2516. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2517. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2518. ((Entity*)target)->RemoveStunSpell(luaspell);
  2519. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2520. ((Entity*)target)->RemoveRootSpell(luaspell);
  2521. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2522. ((Entity*)target)->RemoveFearSpell(luaspell);
  2523. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2524. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2525. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2526. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2527. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2528. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2529. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2530. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2531. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2532. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2533. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2534. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2535. else
  2536. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2537. }
  2538. }
  2539. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2540. }
  2541. else if (only_remove_spawn) {
  2542. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2543. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2544. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2545. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2546. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2547. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2548. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2549. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2550. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2551. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2552. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2553. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2554. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2555. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2556. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2557. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2558. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2559. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2560. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2561. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2562. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2563. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2564. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2565. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2566. else
  2567. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2568. }
  2569. }
  2570. return 0;
  2571. }
  2572. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2573. if (!lua_interface)
  2574. return 0;
  2575. Spawn* spawn = lua_interface->GetSpawn(state);
  2576. int8 type = lua_interface->GetInt8Value(state, 2);
  2577. bool hasEffect = false;
  2578. if (!spawn)
  2579. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2580. else if (!spawn->IsEntity())
  2581. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2582. else if (type < CONTROL_MAX_EFFECTS)
  2583. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2584. else
  2585. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2586. lua_interface->SetBooleanValue(state, hasEffect);
  2587. return 1;
  2588. }
  2589. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2590. if (!lua_interface)
  2591. return 0;
  2592. Spawn* spawn = lua_interface->GetSpawn(state);
  2593. float distance = 0.0f;
  2594. if (!spawn)
  2595. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2596. else if (!spawn->IsNPC())
  2597. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2598. else
  2599. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2600. lua_interface->SetFloatValue(state, distance);
  2601. return 1;
  2602. }
  2603. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2604. if (!lua_interface)
  2605. return 0;
  2606. Spawn* spawn = lua_interface->GetSpawn(state);
  2607. float distance = 0.0f;
  2608. if (!spawn)
  2609. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2610. else if (!spawn->IsNPC())
  2611. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2612. else
  2613. distance = ((NPC*)spawn)->GetAggroRadius();
  2614. lua_interface->SetFloatValue(state, distance);
  2615. return 1;
  2616. }
  2617. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2618. if (!lua_interface)
  2619. return 0;
  2620. Spawn* spawn = lua_interface->GetSpawn(state);
  2621. float distance = lua_interface->GetFloatValue(state, 2);
  2622. bool override = lua_interface->GetBooleanValue(state, 3);
  2623. bool result = false;
  2624. lua_interface->ResetFunctionStack(state);
  2625. if (!spawn)
  2626. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2627. else if (!spawn->IsNPC())
  2628. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2629. else
  2630. {
  2631. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2632. result = true;
  2633. }
  2634. lua_interface->SetBooleanValue(state, result);
  2635. return 1;
  2636. }
  2637. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2638. if (!lua_interface)
  2639. return 0;
  2640. Spawn* spawn = lua_interface->GetSpawn(state);
  2641. int16 value = lua_interface->GetInt16Value(state, 2);
  2642. if (spawn && spawn->IsEntity()) {
  2643. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2644. if (spawn->IsPlayer())
  2645. ((Player*)spawn)->SetCharSheetChanged(true);
  2646. }
  2647. return 0;
  2648. }
  2649. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2650. if (!lua_interface)
  2651. return 0;
  2652. Spawn* spawn = lua_interface->GetSpawn(state);
  2653. int16 value = lua_interface->GetInt16Value(state, 2);
  2654. if (spawn && spawn->IsEntity()) {
  2655. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2656. if (spawn->IsPlayer())
  2657. ((Player*)spawn)->SetCharSheetChanged(true);
  2658. }
  2659. return 0;
  2660. }
  2661. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2662. if (!lua_interface)
  2663. return 0;
  2664. Spawn* spawn = lua_interface->GetSpawn(state);
  2665. int16 value = lua_interface->GetInt16Value(state, 2);
  2666. if (spawn && spawn->IsEntity()) {
  2667. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2668. if (spawn->IsPlayer())
  2669. ((Player*)spawn)->SetCharSheetChanged(true);
  2670. }
  2671. return 0;
  2672. }
  2673. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2674. if (!lua_interface)
  2675. return 0;
  2676. Spawn* spawn = lua_interface->GetSpawn(state);
  2677. int16 value = lua_interface->GetInt16Value(state, 2);
  2678. if (spawn && spawn->IsEntity()) {
  2679. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2680. if (spawn->IsPlayer())
  2681. ((Player*)spawn)->SetCharSheetChanged(true);
  2682. }
  2683. return 0;
  2684. }
  2685. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2686. if (!lua_interface)
  2687. return 0;
  2688. Spawn* spawn = lua_interface->GetSpawn(state);
  2689. int16 value = lua_interface->GetInt16Value(state, 2);
  2690. if (spawn && spawn->IsEntity()) {
  2691. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2692. if (spawn->IsPlayer())
  2693. ((Player*)spawn)->SetCharSheetChanged(true);
  2694. }
  2695. return 0;
  2696. }
  2697. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2698. if (!lua_interface)
  2699. return 0;
  2700. Spawn* spawn = lua_interface->GetSpawn(state);
  2701. int8 value = lua_interface->GetInt8Value(state, 2);
  2702. if (spawn && spawn->IsEntity()) {
  2703. ((Entity*)spawn)->SetDeity(value);
  2704. if (spawn->IsPlayer())
  2705. ((Player*)spawn)->SetCharSheetChanged(true);
  2706. }
  2707. lua_interface->ResetFunctionStack(state);
  2708. return 0;
  2709. }
  2710. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2711. if (!lua_interface)
  2712. return 0;
  2713. Spawn* spawn = lua_interface->GetSpawn(state);
  2714. if (spawn && spawn->IsEntity()) {
  2715. int8 deity = ((Entity*)spawn)->GetDeity();
  2716. lua_interface->SetInt32Value(state, deity);
  2717. return 1;
  2718. }
  2719. return 0;
  2720. }
  2721. int EQ2Emu_lua_SetInt(lua_State* state) {
  2722. if (!lua_interface)
  2723. return 0;
  2724. Spawn* spawn = lua_interface->GetSpawn(state);
  2725. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2726. if (spawn && spawn->IsEntity()) {
  2727. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2728. if (spawn->IsPlayer())
  2729. ((Player*)spawn)->SetCharSheetChanged(true);
  2730. }
  2731. return 0;
  2732. }
  2733. int EQ2Emu_lua_SetWis(lua_State* state) {
  2734. if (!lua_interface)
  2735. return 0;
  2736. Spawn* spawn = lua_interface->GetSpawn(state);
  2737. float value = lua_interface->GetFloatValue(state, 2);
  2738. if (spawn && spawn->IsEntity()) {
  2739. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2740. if (spawn->IsPlayer())
  2741. ((Player*)spawn)->SetCharSheetChanged(true);
  2742. }
  2743. return 0;
  2744. }
  2745. int EQ2Emu_lua_SetSta(lua_State* state) {
  2746. if (!lua_interface)
  2747. return 0;
  2748. Spawn* spawn = lua_interface->GetSpawn(state);
  2749. float value = lua_interface->GetFloatValue(state, 2);
  2750. if (spawn && spawn->IsEntity()) {
  2751. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2752. if (spawn->IsPlayer())
  2753. ((Player*)spawn)->SetCharSheetChanged(true);
  2754. }
  2755. return 0;
  2756. }
  2757. int EQ2Emu_lua_SetStr(lua_State* state) {
  2758. if (!lua_interface)
  2759. return 0;
  2760. Spawn* spawn = lua_interface->GetSpawn(state);
  2761. float value = lua_interface->GetFloatValue(state, 2);
  2762. if (spawn && spawn->IsEntity()) {
  2763. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2764. if (spawn->IsPlayer())
  2765. ((Player*)spawn)->SetCharSheetChanged(true);
  2766. }
  2767. return 0;
  2768. }
  2769. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2770. if (!lua_interface)
  2771. return 0;
  2772. Spawn* spawn = lua_interface->GetSpawn(state);
  2773. float value = lua_interface->GetFloatValue(state, 2);
  2774. if (spawn && spawn->IsEntity()) {
  2775. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2776. if (spawn->IsPlayer())
  2777. ((Player*)spawn)->SetCharSheetChanged(true);
  2778. }
  2779. return 0;
  2780. }
  2781. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2782. if (!lua_interface)
  2783. return 0;
  2784. Spawn* spawn = lua_interface->GetSpawn(state);
  2785. if (spawn) {
  2786. lua_interface->SetInt32Value(state, spawn->GetHP());
  2787. return 1;
  2788. }
  2789. return 0;
  2790. }
  2791. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2792. if (!lua_interface)
  2793. return 0;
  2794. Spawn* spawn = lua_interface->GetSpawn(state);
  2795. if (spawn) {
  2796. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2797. return 1;
  2798. }
  2799. return 0;
  2800. }
  2801. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2802. if (!lua_interface)
  2803. return 0;
  2804. Spawn* spawn = lua_interface->GetSpawn(state);
  2805. if (spawn) {
  2806. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2807. return 1;
  2808. }
  2809. return 0;
  2810. }
  2811. int EQ2Emu_lua_GetName(lua_State* state) {
  2812. if (!lua_interface)
  2813. return 0;
  2814. Spawn* spawn = lua_interface->GetSpawn(state);
  2815. if (spawn) {
  2816. lua_interface->SetStringValue(state, spawn->GetName());
  2817. return 1;
  2818. }
  2819. return 0;
  2820. }
  2821. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2822. Spawn* spawn = lua_interface->GetSpawn(state);
  2823. if (spawn) {
  2824. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2825. return 1;
  2826. }
  2827. return 0;
  2828. }
  2829. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2830. if (!lua_interface)
  2831. return 0;
  2832. Spawn* spawn = lua_interface->GetSpawn(state);
  2833. if (spawn) {
  2834. lua_interface->SetInt32Value(state, spawn->GetPower());
  2835. return 1;
  2836. }
  2837. return 0;
  2838. }
  2839. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2840. if (!lua_interface)
  2841. return 0;
  2842. Spawn* spawn = lua_interface->GetSpawn(state);
  2843. if (spawn) {
  2844. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2845. return 1;
  2846. }
  2847. return 0;
  2848. }
  2849. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2850. if (!lua_interface)
  2851. return 0;
  2852. Spawn* spawn = lua_interface->GetSpawn(state);
  2853. if (spawn) {
  2854. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2855. return 1;
  2856. }
  2857. return 0;
  2858. }
  2859. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2860. if (!lua_interface)
  2861. return 0;
  2862. Spawn* spawn = lua_interface->GetSpawn(state);
  2863. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2864. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2865. if (spawn && spawn2) {
  2866. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2867. lua_interface->SetFloatValue(state, distance);
  2868. return 1;
  2869. }
  2870. return 0;
  2871. }
  2872. int EQ2Emu_lua_GetX(lua_State* state) {
  2873. if (!lua_interface)
  2874. return 0;
  2875. Spawn* spawn = lua_interface->GetSpawn(state);
  2876. if (spawn) {
  2877. lua_interface->SetFloatValue(state, spawn->GetX());
  2878. return 1;
  2879. }
  2880. return 0;
  2881. }
  2882. int EQ2Emu_lua_GetY(lua_State* state) {
  2883. if (!lua_interface)
  2884. return 0;
  2885. Spawn* spawn = lua_interface->GetSpawn(state);
  2886. if (spawn) {
  2887. lua_interface->SetFloatValue(state, spawn->GetY());
  2888. return 1;
  2889. }
  2890. return 0;
  2891. }
  2892. int EQ2Emu_lua_GetZ(lua_State* state) {
  2893. if (!lua_interface)
  2894. return 0;
  2895. Spawn* spawn = lua_interface->GetSpawn(state);
  2896. if (spawn) {
  2897. lua_interface->SetFloatValue(state, spawn->GetZ());
  2898. return 1;
  2899. }
  2900. return 0;
  2901. }
  2902. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2903. if (!lua_interface)
  2904. return 0;
  2905. Spawn* spawn = lua_interface->GetSpawn(state);
  2906. if (spawn) {
  2907. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2908. return 1;
  2909. }
  2910. return 0;
  2911. }
  2912. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2913. if (!lua_interface)
  2914. return 0;
  2915. Spawn* spawn = lua_interface->GetSpawn(state);
  2916. if (spawn) {
  2917. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2918. return 1;
  2919. }
  2920. return 0;
  2921. }
  2922. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2923. if (!lua_interface)
  2924. return 0;
  2925. Spawn* spawn = lua_interface->GetSpawn(state);
  2926. if (spawn) {
  2927. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2928. return 1;
  2929. }
  2930. return 0;
  2931. }
  2932. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2933. if (!lua_interface)
  2934. return 0;
  2935. Spawn* spawn = lua_interface->GetSpawn(state);
  2936. if (spawn && spawn->IsEntity()) {
  2937. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2938. return 1;
  2939. }
  2940. return 0;
  2941. }
  2942. int EQ2Emu_lua_GetInt(lua_State* state) {
  2943. if (!lua_interface)
  2944. return 0;
  2945. Spawn* spawn = lua_interface->GetSpawn(state);
  2946. if (spawn && spawn->IsEntity()) {
  2947. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2948. return 1;
  2949. }
  2950. return 0;
  2951. }
  2952. int EQ2Emu_lua_GetWis(lua_State* state) {
  2953. if (!lua_interface)
  2954. return 0;
  2955. Spawn* spawn = lua_interface->GetSpawn(state);
  2956. if (spawn && spawn->IsEntity()) {
  2957. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2958. return 1;
  2959. }
  2960. return 0;
  2961. }
  2962. int EQ2Emu_lua_GetSta(lua_State* state) {
  2963. if (!lua_interface)
  2964. return 0;
  2965. Spawn* spawn = lua_interface->GetSpawn(state);
  2966. if (spawn && spawn->IsEntity()) {
  2967. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2968. return 1;
  2969. }
  2970. return 0;
  2971. }
  2972. int EQ2Emu_lua_GetStr(lua_State* state) {
  2973. if (!lua_interface)
  2974. return 0;
  2975. Spawn* spawn = lua_interface->GetSpawn(state);
  2976. if (spawn && spawn->IsEntity()) {
  2977. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2978. return 1;
  2979. }
  2980. return 0;
  2981. }
  2982. int EQ2Emu_lua_GetAgi(lua_State* state) {
  2983. if (!lua_interface)
  2984. return 0;
  2985. Spawn* spawn = lua_interface->GetSpawn(state);
  2986. if (spawn && spawn->IsEntity()) {
  2987. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  2988. return 1;
  2989. }
  2990. return 0;
  2991. }
  2992. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  2993. if (!lua_interface)
  2994. return 0;
  2995. Spawn* spawn = lua_interface->GetSpawn(state);
  2996. if (spawn && spawn->IsEntity()) {
  2997. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  2998. return 1;
  2999. }
  3000. return 0;
  3001. }
  3002. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3003. if (!lua_interface)
  3004. return 0;
  3005. Spawn* spawn = lua_interface->GetSpawn(state);
  3006. if (spawn && spawn->IsEntity()) {
  3007. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3008. return 1;
  3009. }
  3010. return 0;
  3011. }
  3012. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3013. if (!lua_interface)
  3014. return 0;
  3015. Spawn* spawn = lua_interface->GetSpawn(state);
  3016. if (spawn && spawn->IsEntity()) {
  3017. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3018. return 1;
  3019. }
  3020. return 0;
  3021. }
  3022. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3023. if (!lua_interface)
  3024. return 0;
  3025. Spawn* spawn = lua_interface->GetSpawn(state);
  3026. if (spawn && spawn->IsEntity()) {
  3027. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3028. return 1;
  3029. }
  3030. return 0;
  3031. }
  3032. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3033. if (!lua_interface)
  3034. return 0;
  3035. Spawn* spawn = lua_interface->GetSpawn(state);
  3036. if (spawn && spawn->IsEntity()) {
  3037. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3038. return 1;
  3039. }
  3040. return 0;
  3041. }
  3042. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3043. if (!lua_interface)
  3044. return 0;
  3045. Spawn* player = lua_interface->GetSpawn(state);
  3046. if (!player || !player->IsPlayer()) {
  3047. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3048. return 0;
  3049. }
  3050. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3051. if (quest_id <= 0) {
  3052. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3053. return 0;
  3054. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3055. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3056. return 0;
  3057. }
  3058. int32 step = lua_interface->GetInt32Value(state, 3);
  3059. if (step > 0) {
  3060. Client* client = player->GetZone()->GetClientBySpawn(player);
  3061. if (client)
  3062. client->AddPendingQuestUpdate(quest_id, step);
  3063. } else {
  3064. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3065. }
  3066. return 0;
  3067. }
  3068. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3069. Spawn* player = lua_interface->GetSpawn(state);
  3070. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3071. int32 step = lua_interface->GetInt32Value(state, 3);
  3072. int32 progress = lua_interface->GetInt32Value(state, 4);
  3073. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3074. Client* client = player->GetZone()->GetClientBySpawn(player);
  3075. if (client)
  3076. client->AddPendingQuestUpdate(quest_id, step, progress);
  3077. }
  3078. return 0;
  3079. }
  3080. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3081. if (!lua_interface)
  3082. return 0;
  3083. Spawn* player = lua_interface->GetSpawn(state);
  3084. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3085. if (player && player->IsPlayer() && quest_id > 0) {
  3086. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3087. return 1;
  3088. }
  3089. return 0;
  3090. }
  3091. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3092. if (!lua_interface)
  3093. return 0;
  3094. Spawn* player = lua_interface->GetSpawn(state);
  3095. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3096. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3097. if (player && player->IsPlayer() && quest_id > 0) {
  3098. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3099. return 1;
  3100. }
  3101. return 0;
  3102. }
  3103. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3104. if (!lua_interface)
  3105. return 0;
  3106. Spawn* player = lua_interface->GetSpawn(state);
  3107. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3108. if (player && player->IsPlayer() && quest_id > 0) {
  3109. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3110. return 1;
  3111. }
  3112. return 0;
  3113. }
  3114. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3115. if (!lua_interface)
  3116. return 0;
  3117. Quest* quest = lua_interface->GetQuest(state);
  3118. string name = lua_interface->GetStringValue(state, 2);
  3119. string type = lua_interface->GetStringValue(state, 3);
  3120. string zone = lua_interface->GetStringValue(state, 4);
  3121. int16 level = lua_interface->GetInt16Value(state, 5);
  3122. string description = lua_interface->GetStringValue(state, 6);
  3123. bool load = true;
  3124. if (!quest) {
  3125. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3126. load = false;
  3127. }
  3128. if (load && name.length() == 0) {
  3129. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3130. load = false;
  3131. }
  3132. if (load && type.length() == 0) {
  3133. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3134. load = false;
  3135. }
  3136. if (load && zone.length() == 0) {
  3137. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3138. load = false;
  3139. }
  3140. if (load && description.length() == 0) {
  3141. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3142. load = false;
  3143. }
  3144. if (load && level == 0) {
  3145. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3146. load = false;
  3147. }
  3148. if (load)
  3149. quest->RegisterQuest(name, type, zone, level, description);
  3150. return 0;
  3151. }
  3152. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3153. if (!lua_interface)
  3154. return 0;
  3155. Quest* quest = lua_interface->GetQuest(state);
  3156. if (quest) {
  3157. int8 level = lua_interface->GetInt16Value(state, 2);
  3158. quest->SetPrereqLevel(level);
  3159. }
  3160. return 0;
  3161. }
  3162. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3163. if (!lua_interface)
  3164. return 0;
  3165. Quest* quest = lua_interface->GetQuest(state);
  3166. if (quest) {
  3167. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3168. quest->AddPrereqQuest(quest_id);
  3169. }
  3170. return 0;
  3171. }
  3172. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3173. if (!lua_interface)
  3174. return 0;
  3175. Quest* quest = lua_interface->GetQuest(state);
  3176. if (quest) {
  3177. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3178. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3179. if (quantity == 0)
  3180. quantity = 1;
  3181. Item* master_item = master_item_list.GetItem(item_id);
  3182. if (master_item) {
  3183. Item* item = new Item(master_item);
  3184. item->details.count = quantity;
  3185. quest->AddPrereqItem(item);
  3186. }
  3187. }
  3188. return 0;
  3189. }
  3190. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3191. if (!lua_interface)
  3192. return 0;
  3193. Spawn* player = lua_interface->GetSpawn(state);
  3194. if(!player || !player->IsPlayer()) {
  3195. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3196. return 0;
  3197. }
  3198. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3199. if (quest_id > 0) {
  3200. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3201. return 1;
  3202. } else {
  3203. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3204. }
  3205. return 0;
  3206. }
  3207. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3208. if (!lua_interface)
  3209. return 0;
  3210. Quest* quest = lua_interface->GetQuest(state);
  3211. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3212. lua_interface->ResetFunctionStack(state);
  3213. if (quest && spawn_id > 0)
  3214. quest->SetQuestReturnNPC(spawn_id);
  3215. return 0;
  3216. }
  3217. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3218. if (!lua_interface)
  3219. return 0;
  3220. Spawn* spawn = lua_interface->GetSpawn(state);
  3221. int32 time = lua_interface->GetInt32Value(state, 2);
  3222. string function = lua_interface->GetStringValue(state, 3);
  3223. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3224. Spawn* player = lua_interface->GetSpawn(state, 5);
  3225. lua_interface->ResetFunctionStack(state);
  3226. if (!spawn) {
  3227. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3228. return 0;
  3229. }
  3230. if (time <= 0) {
  3231. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3232. return 0;
  3233. }
  3234. if (function.length() == 0) {
  3235. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3236. return 0;
  3237. }
  3238. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3239. if ( time < 10)
  3240. time = 10;
  3241. timer->timer = Timer::GetCurrentTime2() + time;
  3242. timer->function = function;
  3243. timer->spawn = spawn->GetID();
  3244. timer->player = player ? player->GetID() : 0;
  3245. if (max_count == 0)
  3246. max_count = 1;
  3247. timer->max_count = max_count;
  3248. timer->current_count = 0;
  3249. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3250. return 0;
  3251. }
  3252. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3253. if (!lua_interface)
  3254. return 0;
  3255. Spawn* spawn = lua_interface->GetSpawn(state);
  3256. string function = lua_interface->GetStringValue(state, 2);
  3257. lua_interface->ResetFunctionStack(state);
  3258. if (!spawn) {
  3259. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3260. return 0;
  3261. }
  3262. if(!spawn->GetZone()) {
  3263. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3264. return 0;
  3265. }
  3266. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3267. return 0;
  3268. }
  3269. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3270. if (!lua_interface)
  3271. return 0;
  3272. Spawn* player = lua_interface->GetSpawn(state);
  3273. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3274. lua_interface->ResetFunctionStack(state);
  3275. if (player && player->IsPlayer() && quest_id > 0) {
  3276. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3277. return 1;
  3278. }
  3279. return 0;
  3280. }
  3281. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3282. if (!lua_interface)
  3283. return 0;
  3284. Spawn* player = lua_interface->GetSpawn(state);
  3285. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3286. lua_interface->ResetFunctionStack(state);
  3287. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3288. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3289. if (quest)
  3290. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3291. return 1;
  3292. }
  3293. return 0;
  3294. }
  3295. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3296. if (!lua_interface)
  3297. return 0;
  3298. Spawn* player = lua_interface->GetSpawn(state);
  3299. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3300. lua_interface->ResetFunctionStack(state);
  3301. if (player && player->IsPlayer() && quest_id > 0) {
  3302. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3303. return 1;
  3304. }
  3305. return 0;
  3306. }
  3307. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3308. if (!lua_interface)
  3309. return 0;
  3310. Spawn* npc = lua_interface->GetSpawn(state);
  3311. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3312. lua_interface->ResetFunctionStack(state);
  3313. if (npc && !npc->IsPlayer() && quest_id > 0)
  3314. npc->AddProvidedQuest(quest_id);
  3315. return 0;
  3316. }
  3317. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3318. if (!lua_interface)
  3319. return 0;
  3320. Spawn* npc = lua_interface->GetSpawn(state);
  3321. Spawn* player = lua_interface->GetSpawn(state, 2);
  3322. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3323. bool forced = lua_interface->GetBooleanValue(state, 4);
  3324. lua_interface->ResetFunctionStack(state);
  3325. /* NPC is allowed to be null */
  3326. if (player && player->IsPlayer() && quest_id > 0) {
  3327. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3328. if (master_quest) {
  3329. Client* client = player->GetZone()->GetClientBySpawn(player);
  3330. if (!client) {
  3331. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3332. }
  3333. Quest* quest = new Quest(master_quest);
  3334. if (!quest) {
  3335. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3336. }
  3337. if (client && quest) {
  3338. if (npc)
  3339. quest->SetQuestGiver(npc->GetDatabaseID());
  3340. else
  3341. quest->SetQuestGiver(0);
  3342. client->AddPendingQuest(quest, forced);
  3343. }
  3344. }
  3345. else {
  3346. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3347. }
  3348. }
  3349. else {
  3350. 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);
  3351. }
  3352. return 0;
  3353. }
  3354. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3355. if (!lua_interface)
  3356. return 0;
  3357. Quest* quest = lua_interface->GetQuest(state);
  3358. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3359. lua_interface->ResetFunctionStack(state);
  3360. if (quest) {
  3361. quest->AddPrereqClass(class_id);
  3362. }
  3363. return 0;
  3364. }
  3365. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3366. if (!lua_interface)
  3367. return 0;
  3368. Quest* quest = lua_interface->GetQuest(state);
  3369. int8 race = lua_interface->GetInt8Value(state, 2);
  3370. lua_interface->ResetFunctionStack(state);
  3371. if (quest) {
  3372. quest->AddPrereqRace(race);
  3373. }
  3374. return 0;
  3375. }
  3376. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3377. if (!lua_interface)
  3378. return 0;
  3379. Quest* quest = lua_interface->GetQuest(state);
  3380. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3381. lua_interface->ResetFunctionStack(state);
  3382. if (quest) {
  3383. quest->AddPrereqModelType(model_type);
  3384. }
  3385. return 0;
  3386. }
  3387. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3388. if (!lua_interface)
  3389. return 0;
  3390. Quest* quest = lua_interface->GetQuest(state);
  3391. int8 level = lua_interface->GetInt8Value(state, 2);
  3392. lua_interface->ResetFunctionStack(state);
  3393. if (!quest) {
  3394. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3395. return 0;
  3396. }
  3397. quest->SetPrereqTSLevel(level);
  3398. return 0;
  3399. }
  3400. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3401. if (!lua_interface)
  3402. return 0;
  3403. Quest* quest = lua_interface->GetQuest(state);
  3404. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3405. lua_interface->ResetFunctionStack(state);
  3406. if (!quest) {
  3407. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3408. return 0;
  3409. }
  3410. quest->AddPrereqTradeskillClass(class_id);
  3411. return 0;
  3412. }
  3413. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3414. if (!lua_interface)
  3415. return 0;
  3416. Quest* quest = lua_interface->GetQuest(state);
  3417. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3418. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3419. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3420. lua_interface->ResetFunctionStack(state);
  3421. if (quest) {
  3422. quest->AddPrereqFaction(faction_id, min, max);
  3423. }
  3424. return 0;
  3425. }
  3426. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3427. if (!lua_interface)
  3428. return 0;
  3429. Quest* quest = lua_interface->GetQuest(state);
  3430. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3431. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3432. lua_interface->ResetFunctionStack(state);
  3433. if (quest) {
  3434. if (quantity == 0)
  3435. quantity = 1;
  3436. Item* master_item = master_item_list.GetItem(item_id);
  3437. if (master_item) {
  3438. Item* item = new Item(master_item);
  3439. item->details.count = quantity;
  3440. quest->AddSelectableRewardItem(item);
  3441. }
  3442. }
  3443. return 0;
  3444. }
  3445. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3446. if (!lua_interface)
  3447. return 0;
  3448. Quest* quest = lua_interface->GetQuest(state);
  3449. if (quest) {
  3450. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3451. vector<Item*>* items = quest->GetRewardItems();
  3452. if (items) {
  3453. vector<Item*>::iterator itr;
  3454. for (itr = items->begin(); itr != items->end(); itr++) {
  3455. if (*itr && (*itr)->details.item_id == item_id) {
  3456. lua_interface->SetBooleanValue(state, true);
  3457. return 1;
  3458. }
  3459. }
  3460. }
  3461. }
  3462. lua_interface->SetBooleanValue(state, false);
  3463. return 1;
  3464. }
  3465. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3466. if (!lua_interface)
  3467. return 0;
  3468. Quest* quest = lua_interface->GetQuest(state);
  3469. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3470. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3471. lua_interface->ResetFunctionStack(state);
  3472. if (quest) {
  3473. if (quantity == 0)
  3474. quantity = 1;
  3475. Item* master_item = master_item_list.GetItem(item_id);
  3476. if (master_item) {
  3477. Item* item = new Item(master_item);
  3478. item->details.count = quantity;
  3479. quest->AddRewardItem(item);
  3480. }
  3481. }
  3482. return 0;
  3483. }
  3484. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3485. if (!lua_interface)
  3486. return 0;
  3487. Quest* quest = lua_interface->GetQuest(state);
  3488. int32 copper = lua_interface->GetInt32Value(state, 2);
  3489. int32 silver = lua_interface->GetInt32Value(state, 3);
  3490. int32 gold = lua_interface->GetInt32Value(state, 4);
  3491. int32 plat = lua_interface->GetInt32Value(state, 5);
  3492. lua_interface->ResetFunctionStack(state);
  3493. if (quest) {
  3494. quest->AddRewardCoins(copper, silver, gold, plat);
  3495. }
  3496. return 0;
  3497. }
  3498. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3499. if (!lua_interface)
  3500. return 0;
  3501. Quest* quest = lua_interface->GetQuest(state);
  3502. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3503. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3504. lua_interface->ResetFunctionStack(state);
  3505. if (quest && faction_id > 0 && amount != 0)
  3506. quest->AddRewardFaction(faction_id, amount);
  3507. return 0;
  3508. }
  3509. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3510. if (!lua_interface)
  3511. return 0;
  3512. Quest* quest = lua_interface->GetQuest(state);
  3513. int32 status = lua_interface->GetInt32Value(state, 2);
  3514. lua_interface->ResetFunctionStack(state);
  3515. if (quest) {
  3516. quest->SetRewardStatus(status);
  3517. }
  3518. return 0;
  3519. }
  3520. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3521. if (!lua_interface)
  3522. return 0;
  3523. Quest* quest = lua_interface->GetQuest(state);
  3524. int32 status = lua_interface->GetInt32Value(state, 2);
  3525. lua_interface->ResetFunctionStack(state);
  3526. if (quest) {
  3527. quest->SetStatusTmpReward(status);
  3528. }
  3529. return 0;
  3530. }
  3531. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3532. if (!lua_interface)
  3533. return 0;
  3534. Quest* quest = lua_interface->GetQuest(state);
  3535. int64 coins = lua_interface->GetInt64Value(state, 2);
  3536. lua_interface->ResetFunctionStack(state);
  3537. if (quest) {
  3538. quest->SetCoinTmpReward(coins);
  3539. }
  3540. return 0;
  3541. }
  3542. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3543. if (!lua_interface)
  3544. return 0;
  3545. Quest* quest = lua_interface->GetQuest(state);
  3546. string comment = lua_interface->GetStringValue(state, 2);
  3547. lua_interface->ResetFunctionStack(state);
  3548. if (quest) {
  3549. quest->SetRewardComment(comment);
  3550. }
  3551. return 0;
  3552. }
  3553. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3554. if (!lua_interface)
  3555. return 0;
  3556. Quest* quest = lua_interface->GetQuest(state);
  3557. int32 exp = lua_interface->GetInt32Value(state, 2);
  3558. lua_interface->ResetFunctionStack(state);
  3559. if (quest) {
  3560. quest->SetRewardXP(exp);
  3561. }
  3562. return 0;
  3563. }
  3564. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3565. Quest* quest = lua_interface->GetQuest(state);
  3566. int32 step = lua_interface->GetInt32Value(state, 2);
  3567. string description = lua_interface->GetStringValue(state, 3);
  3568. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3569. float percentage = lua_interface->GetFloatValue(state, 5);
  3570. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3571. int16 icon = lua_interface->GetInt16Value(state, 7);
  3572. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3573. if (quest) {
  3574. const char* taskgroup = 0;
  3575. if (str_taskgroup.length() > 0)
  3576. taskgroup = str_taskgroup.c_str();
  3577. int32 id = 0;
  3578. vector<int32>* ids = 0;
  3579. int i = 0;
  3580. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3581. if (ids == 0)
  3582. ids = new vector<int32>;
  3583. ids->push_back(id);
  3584. i++;
  3585. }
  3586. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3587. if (quest_step && icon && quantity > 0)
  3588. quest_step->SetIcon(icon);
  3589. if (quest->GetPlayer()) {
  3590. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3591. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3592. }
  3593. }
  3594. lua_interface->ResetFunctionStack(state);
  3595. return 0;
  3596. }
  3597. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3598. {
  3599. if (!lua_interface)
  3600. return 0;
  3601. Quest* quest = lua_interface->GetQuest(state);
  3602. int32 step = lua_interface->GetInt32Value(state, 2);
  3603. string description = lua_interface->GetStringValue(state, 3);
  3604. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3605. float percentage = lua_interface->GetFloatValue(state, 5);
  3606. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3607. int16 icon = lua_interface->GetInt16Value(state, 7);
  3608. if (quest) {
  3609. const char* taskgroup = 0;
  3610. if (str_taskgroup.length() > 0)
  3611. taskgroup = str_taskgroup.c_str();
  3612. int32 id = 0;
  3613. vector<int32>* ids = 0;
  3614. int i = 0;
  3615. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3616. if (ids == 0)
  3617. ids = new vector<int32>;
  3618. ids->push_back(id);
  3619. i++;
  3620. }
  3621. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3622. if (quest_step && icon > 0 && quantity > 0)
  3623. quest_step->SetIcon(icon);
  3624. if (quest->GetPlayer()) {
  3625. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3626. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3627. }
  3628. safe_delete(ids);
  3629. }
  3630. lua_interface->ResetFunctionStack(state);
  3631. return 0;
  3632. }
  3633. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3634. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3635. }
  3636. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3637. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3638. }
  3639. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3640. if (!lua_interface)
  3641. return 0;
  3642. Quest* quest = lua_interface->GetQuest(state);
  3643. int32 step = lua_interface->GetInt32Value(state, 2);
  3644. string description = lua_interface->GetStringValue(state, 3);
  3645. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3646. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3647. int16 icon = lua_interface->GetInt16Value(state, 6);
  3648. if (quest) {
  3649. const char* taskgroup = 0;
  3650. if (str_taskgroup.length() > 0)
  3651. taskgroup = str_taskgroup.c_str();
  3652. int32 npc_id = 0;
  3653. vector<int32>* ids = 0;
  3654. int i = 0;
  3655. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3656. if (ids == 0)
  3657. ids = new vector<int32>;
  3658. ids->push_back(npc_id);
  3659. i++;
  3660. }
  3661. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3662. if (quest_step && icon > 0)
  3663. quest_step->SetIcon(icon);
  3664. if (quest->GetPlayer()) {
  3665. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3666. if(client)
  3667. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3668. }
  3669. safe_delete(ids);
  3670. }
  3671. lua_interface->ResetFunctionStack(state);
  3672. return 0;
  3673. }
  3674. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3675. if (!lua_interface)
  3676. return 0;
  3677. Quest* quest = lua_interface->GetQuest(state);
  3678. int32 step = lua_interface->GetInt32Value(state, 2);
  3679. string description = lua_interface->GetStringValue(state, 3);
  3680. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3681. float percentage = lua_interface->GetFloatValue(state, 5);
  3682. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3683. int16 icon = lua_interface->GetInt16Value(state, 7);
  3684. if (quest) {
  3685. const char* taskgroup = 0;
  3686. if (str_taskgroup.length() > 0)
  3687. taskgroup = str_taskgroup.c_str();
  3688. int32 item_id = 0;
  3689. vector<int32>* ids = 0;
  3690. int i = 0;
  3691. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3692. if (ids == 0)
  3693. ids = new vector<int32>;
  3694. ids->push_back(item_id);
  3695. i++;
  3696. }
  3697. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3698. if (quest_step && icon > 0 && quantity > 0)
  3699. quest_step->SetIcon(icon);
  3700. if (quest->GetPlayer()) {
  3701. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3702. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3703. }
  3704. safe_delete(ids);
  3705. }
  3706. lua_interface->ResetFunctionStack(state);
  3707. return 0;
  3708. }
  3709. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3710. if (!lua_interface)
  3711. return 0;
  3712. Quest* quest = lua_interface->GetQuest(state);
  3713. int32 step = lua_interface->GetInt32Value(state, 2);
  3714. string description = lua_interface->GetStringValue(state, 3);
  3715. float max_variation = lua_interface->GetFloatValue(state, 4);
  3716. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3717. int16 icon = lua_interface->GetInt16Value(state, 6);
  3718. if (quest) {
  3719. const char* taskgroup = 0;
  3720. if (str_taskgroup.length() > 0)
  3721. taskgroup = str_taskgroup.c_str();
  3722. vector<Location>* locations = 0;
  3723. int8 i = 7;
  3724. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3725. while (true) {
  3726. Location loc;
  3727. loc.x = lua_interface->GetFloatValue(state, i);
  3728. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3729. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3730. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3731. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3732. break;
  3733. if (locations == 0)
  3734. locations = new vector<Location>;
  3735. locations->push_back(loc);
  3736. i += 4;
  3737. }
  3738. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3739. if (quest_step && icon > 0)
  3740. quest_step->SetIcon(icon);
  3741. if (quest->GetPlayer()) {
  3742. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3743. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3744. }
  3745. }
  3746. lua_interface->ResetFunctionStack(state);
  3747. return 0;
  3748. }
  3749. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3750. if (!lua_interface)
  3751. return 0;
  3752. Quest* quest = lua_interface->GetQuest(state);
  3753. int32 step = lua_interface->GetInt32Value(state, 2);
  3754. string description = lua_interface->GetStringValue(state, 3);
  3755. float max_variation = lua_interface->GetFloatValue(state, 4);
  3756. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3757. int16 icon = lua_interface->GetInt16Value(state, 6);
  3758. if (quest) {
  3759. const char* taskgroup = 0;
  3760. if (str_taskgroup.length() > 0)
  3761. taskgroup = str_taskgroup.c_str();
  3762. vector<Location>* locations = 0;
  3763. int8 i = 7;
  3764. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3765. while (true) {
  3766. Location loc;
  3767. loc.x = lua_interface->GetFloatValue(state, i);
  3768. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3769. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3770. loc.zone_id = 0;
  3771. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3772. break;
  3773. if (locations == 0)
  3774. locations = new vector<Location>;
  3775. locations->push_back(loc);
  3776. i += 3;
  3777. }
  3778. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3779. if (quest_step && icon > 0)
  3780. quest_step->SetIcon(icon);
  3781. if (quest->GetPlayer()) {
  3782. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3783. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3784. }
  3785. }
  3786. lua_interface->ResetFunctionStack(state);
  3787. return 0;
  3788. }
  3789. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3790. if (!lua_interface)
  3791. return 0;
  3792. Quest* quest = lua_interface->GetQuest(state);
  3793. int32 step = lua_interface->GetInt32Value(state, 2);
  3794. string description = lua_interface->GetStringValue(state, 3);
  3795. float max_variation = lua_interface->GetFloatValue(state, 4);
  3796. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3797. int16 icon = lua_interface->GetInt16Value(state, 6);
  3798. if (quest) {
  3799. const char* taskgroup = 0;
  3800. if (str_taskgroup.length() > 0)
  3801. taskgroup = str_taskgroup.c_str();
  3802. vector<Location>* locations = 0;
  3803. int i = 7;
  3804. while (true) {
  3805. Location loc;
  3806. loc.x = lua_interface->GetFloatValue(state, i);
  3807. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3808. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3809. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3810. break;
  3811. if (locations == 0)
  3812. locations = new vector<Location>;
  3813. locations->push_back(loc);
  3814. i += 3;
  3815. }
  3816. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3817. if (quest_step && icon > 0)
  3818. quest_step->SetIcon(icon);
  3819. if (quest->GetPlayer()) {
  3820. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3821. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3822. }
  3823. }
  3824. lua_interface->ResetFunctionStack(state);
  3825. return 0;
  3826. }
  3827. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3828. Quest* quest = lua_interface->GetQuest(state);
  3829. int32 step = lua_interface->GetInt32Value(state, 2);
  3830. string description = lua_interface->GetStringValue(state, 3);
  3831. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3832. float percentage = lua_interface->GetFloatValue(state, 5);
  3833. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3834. int16 icon = lua_interface->GetInt16Value(state, 7);
  3835. if (quest) {
  3836. const char* taskgroup = 0;
  3837. if (str_taskgroup.length() > 0)
  3838. taskgroup = str_taskgroup.c_str();
  3839. int32 spell_id = 0;
  3840. vector<int32>* ids = 0;
  3841. int i = 0;
  3842. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3843. if (ids == 0)
  3844. ids = new vector<int32>;
  3845. ids->push_back(spell_id);
  3846. i++;
  3847. }
  3848. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3849. if (quest_step && icon > 0 && quantity > 0)
  3850. quest_step->SetIcon(icon);
  3851. if (quest->GetPlayer()) {
  3852. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3853. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3854. }
  3855. safe_delete(ids);
  3856. }
  3857. lua_interface->ResetFunctionStack(state);
  3858. return 0;
  3859. }
  3860. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3861. if (!lua_interface)
  3862. return 0;
  3863. Quest* quest = lua_interface->GetQuest(state);
  3864. int32 step = lua_interface->GetInt32Value(state, 2);
  3865. string description = lua_interface->GetStringValue(state, 3);
  3866. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3867. float percentage = lua_interface->GetFloatValue(state, 5);
  3868. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3869. int16 icon = lua_interface->GetInt16Value(state, 7);
  3870. if (quest) {
  3871. const char* taskgroup = 0;
  3872. if (str_taskgroup.length() > 0)
  3873. taskgroup = str_taskgroup.c_str();
  3874. int32 item_id = 0;
  3875. vector<int32>* ids = 0;
  3876. int i = 0;
  3877. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3878. if (ids == 0)
  3879. ids = new vector<int32>;
  3880. ids->push_back(item_id);
  3881. i++;
  3882. }
  3883. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3884. if (quest_step && icon > 0 && quantity > 0)
  3885. quest_step->SetIcon(icon);
  3886. if (quest->GetPlayer()) {
  3887. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3888. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3889. }
  3890. safe_delete(ids);
  3891. }
  3892. lua_interface->ResetFunctionStack(state);
  3893. return 0;
  3894. }
  3895. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3896. if (!lua_interface)
  3897. return 0;
  3898. Quest* quest = lua_interface->GetQuest(state);
  3899. int32 step = lua_interface->GetInt32Value(state, 2);
  3900. string description = lua_interface->GetStringValue(state, 3);
  3901. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3902. float percentage = lua_interface->GetFloatValue(state, 5);
  3903. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3904. int16 icon = lua_interface->GetInt16Value(state, 7);
  3905. if (quest) {
  3906. const char* taskgroup = 0;
  3907. if (str_taskgroup.length() > 0)
  3908. taskgroup = str_taskgroup.c_str();
  3909. int32 item_id = 0;
  3910. vector<int32>* ids = 0;
  3911. int i = 0;
  3912. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3913. if (ids == 0)
  3914. ids = new vector<int32>;
  3915. ids->push_back(item_id);
  3916. i++;
  3917. }
  3918. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3919. if (quest_step && icon > 0 && quantity > 0)
  3920. quest_step->SetIcon(icon);
  3921. if (quest->GetPlayer()) {
  3922. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3923. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3924. }
  3925. safe_delete(ids);
  3926. }
  3927. lua_interface->ResetFunctionStack(state);
  3928. return 0;
  3929. }
  3930. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3931. if (!lua_interface)
  3932. return 0;
  3933. Quest* quest = lua_interface->GetQuest(state);
  3934. string action = lua_interface->GetStringValue(state, 2);
  3935. lua_interface->ResetFunctionStack(state);
  3936. if (quest) {
  3937. if (action.length() > 0)
  3938. quest->SetCompleteAction(action);
  3939. }
  3940. return 0;
  3941. }
  3942. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3943. if (!lua_interface)
  3944. return 0;
  3945. Quest* quest = lua_interface->GetQuest(state);
  3946. int32 step = lua_interface->GetInt32Value(state, 2);
  3947. string action = lua_interface->GetStringValue(state, 3);
  3948. lua_interface->ResetFunctionStack(state);
  3949. if (quest) {
  3950. if (step > 0 && action.length() > 0)
  3951. quest->AddCompleteAction(step, action);
  3952. }
  3953. return 0;
  3954. }
  3955. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3956. if (!lua_interface)
  3957. return 0;
  3958. Quest* quest = lua_interface->GetQuest(state);
  3959. int32 step = lua_interface->GetInt32Value(state, 2);
  3960. string action = lua_interface->GetStringValue(state, 3);
  3961. lua_interface->ResetFunctionStack(state);
  3962. if (quest) {
  3963. if (step > 0 && action.length() > 0)
  3964. quest->AddProgressAction(step, action);
  3965. }
  3966. return 0;
  3967. }
  3968. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3969. if (!lua_interface)
  3970. return 0;
  3971. Quest* quest = lua_interface->GetQuest(state);
  3972. string description = lua_interface->GetStringValue(state, 2);
  3973. lua_interface->ResetFunctionStack(state);
  3974. if (quest && description.length() > 0)
  3975. quest->SetDescription(description);
  3976. return 0;
  3977. }
  3978. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3979. if (!lua_interface)
  3980. return 0;
  3981. Quest* quest = lua_interface->GetQuest(state);
  3982. string description = lua_interface->GetStringValue(state, 2);
  3983. lua_interface->ResetFunctionStack(state);
  3984. if (quest && description.length() > 0)
  3985. quest->SetCompletedDescription(description);
  3986. return 0;
  3987. }
  3988. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(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. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  3995. lua_interface->ResetFunctionStack(state);
  3996. if (quest && step > 0 && description.length() > 0) {
  3997. quest->SetTaskGroupDescription(step, description, display_bullets);
  3998. /* if (quest->GetPlayer()) {
  3999. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4000. if (client)
  4001. client->SendQuestUpdateStep(quest, step, false);
  4002. }*/
  4003. }
  4004. return 0;
  4005. }
  4006. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4007. if (!lua_interface)
  4008. return 0;
  4009. Quest* quest = lua_interface->GetQuest(state);
  4010. int32 step = lua_interface->GetInt32Value(state, 2);
  4011. string description = lua_interface->GetStringValue(state, 3);
  4012. lua_interface->ResetFunctionStack(state);
  4013. if (quest && step > 0 && description.length() > 0) {
  4014. quest->SetStepDescription(step, description);
  4015. /*if (quest->GetPlayer()) {
  4016. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4017. if (client)
  4018. client->SendQuestUpdateStepImmediately(quest, step);
  4019. }*/
  4020. }
  4021. return 0;
  4022. }
  4023. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4024. Quest* quest = lua_interface->GetQuest(state);
  4025. string zone = lua_interface->GetStringValue(state, 2);
  4026. lua_interface->ResetFunctionStack(state);
  4027. if (quest && zone.length() > 0)
  4028. quest->SetZone(zone);
  4029. return 0;
  4030. }
  4031. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4032. if (!lua_interface)
  4033. return 0;
  4034. Quest* quest = lua_interface->GetQuest(state);
  4035. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4036. lua_interface->ResetFunctionStack(state);
  4037. if (quest && spawn) {
  4038. if (spawn->IsPlayer()) {
  4039. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4040. if (client)
  4041. {
  4042. client->AddPendingQuestAcceptReward(quest);
  4043. client->AddPendingQuestReward(quest);
  4044. }
  4045. }
  4046. }
  4047. return 0;
  4048. }
  4049. int EQ2Emu_lua_Harvest(lua_State* state) {
  4050. if (!lua_interface)
  4051. return 0;
  4052. Spawn* player = lua_interface->GetSpawn(state);
  4053. Spawn* node = lua_interface->GetSpawn(state, 2);
  4054. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4055. Client* client = player->GetZone()->GetClientBySpawn(player);
  4056. if (client) {
  4057. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  4058. ((GroundSpawn*)node)->ProcessHarvest(client);
  4059. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4060. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4061. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4062. }
  4063. }
  4064. }
  4065. else if (player && player->IsPlayer()) {
  4066. Client* client = player->GetZone()->GetClientBySpawn(player);
  4067. if (client)
  4068. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4069. }
  4070. lua_interface->ResetFunctionStack(state);
  4071. return 0;
  4072. }
  4073. int EQ2Emu_lua_Bind(lua_State* state) {
  4074. if (!lua_interface)
  4075. return 0;
  4076. Spawn* spawn = lua_interface->GetSpawn(state);
  4077. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4078. float x = lua_interface->GetFloatValue(state, 3);
  4079. float y = lua_interface->GetFloatValue(state, 4);
  4080. float z = lua_interface->GetFloatValue(state, 5);
  4081. float h = lua_interface->GetFloatValue(state, 6);
  4082. lua_interface->ResetFunctionStack(state);
  4083. if (!spawn) {
  4084. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4085. return 0;
  4086. }
  4087. if (!spawn->IsPlayer()) {
  4088. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4089. return 0;
  4090. }
  4091. if (zone_id == 0) {
  4092. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4093. if (!client) {
  4094. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4095. return 0;
  4096. }
  4097. if (!client->Bind())
  4098. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4099. }
  4100. else {
  4101. Player* player = (Player*)spawn;
  4102. player->GetPlayerInfo()->SetBindZone(zone_id);
  4103. player->GetPlayerInfo()->SetBindX(x);
  4104. player->GetPlayerInfo()->SetBindY(y);
  4105. player->GetPlayerInfo()->SetBindZ(z);
  4106. player->GetPlayerInfo()->SetBindHeading(h);
  4107. }
  4108. return 0;
  4109. }
  4110. int EQ2Emu_lua_Gate(lua_State* state) {
  4111. if (!lua_interface)
  4112. return 0;
  4113. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4114. Spawn* spawn = lua_interface->GetSpawn(state);
  4115. lua_interface->ResetFunctionStack(state);
  4116. if (spawn) {
  4117. if (spawn->IsPlayer()) {
  4118. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4119. if (client) {
  4120. if (!client->Gate((spell != nullptr) ? true : false))
  4121. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4122. }
  4123. }
  4124. }
  4125. return 0;
  4126. }
  4127. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4128. if (!lua_interface)
  4129. return 0;
  4130. bool ret = false;
  4131. Spawn* spawn = lua_interface->GetSpawn(state);
  4132. lua_interface->ResetFunctionStack(state);
  4133. if (spawn) {
  4134. if (spawn->IsPlayer()) {
  4135. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4136. if (client)
  4137. ret = client->BindAllowed();
  4138. }
  4139. }
  4140. lua_interface->SetBooleanValue(state, ret);
  4141. return 1;
  4142. }
  4143. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4144. if (!lua_interface)
  4145. return 0;
  4146. bool ret = false;
  4147. Spawn* spawn = lua_interface->GetSpawn(state);
  4148. lua_interface->ResetFunctionStack(state);
  4149. if (spawn) {
  4150. if (spawn->IsPlayer()) {
  4151. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4152. if (client)
  4153. ret = client->GateAllowed();
  4154. }
  4155. }
  4156. lua_interface->SetBooleanValue(state, ret);
  4157. return 1;
  4158. }
  4159. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4160. Spawn* spawn = lua_interface->GetSpawn(state);
  4161. lua_interface->ResetFunctionStack(state);
  4162. if (spawn) {
  4163. lua_interface->SetBooleanValue(state, spawn->Alive());
  4164. return 1;
  4165. }
  4166. return 0;
  4167. }
  4168. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4169. if (!lua_interface)
  4170. return 0;
  4171. Spawn* spawn = lua_interface->GetSpawn(state);
  4172. lua_interface->ResetFunctionStack(state);
  4173. if (spawn && spawn->IsEntity()) {
  4174. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4175. return 1;
  4176. }
  4177. return 0;
  4178. }
  4179. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4180. Spawn* spawn = lua_interface->GetSpawn(state);
  4181. string message = lua_interface->GetStringValue(state, 2);
  4182. string color_str = lua_interface->GetStringValue(state, 3);
  4183. lua_interface->ResetFunctionStack(state);
  4184. int8 color = CHANNEL_NARRATIVE;
  4185. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4186. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4187. if (client) {
  4188. if (color_str.length() > 0) {
  4189. // leave for backwards compat, but all future should just use the number
  4190. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4191. color = CHANNEL_COLOR_RED;
  4192. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4193. color = CHANNEL_COLOR_YELLOW;
  4194. else
  4195. {
  4196. // use a number to specify the channel as per Commands/Commands.h defines
  4197. color = (int8)atoul(color_str.c_str());
  4198. }
  4199. }
  4200. client->SimpleMessage(color, message.c_str());
  4201. }
  4202. }
  4203. return 0;
  4204. }
  4205. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4206. Spawn* spawn = lua_interface->GetSpawn(state);
  4207. string message = lua_interface->GetStringValue(state, 2);
  4208. int8 red = lua_interface->GetInt8Value(state, 3);
  4209. int8 green = lua_interface->GetInt8Value(state, 4);
  4210. int8 blue = lua_interface->GetInt8Value(state, 5);
  4211. lua_interface->ResetFunctionStack(state);
  4212. if (!spawn) {
  4213. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4214. return 0;
  4215. }
  4216. int32 words = ::CountWordsInString(message.c_str());
  4217. if (words < 5)
  4218. words = 5;
  4219. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4220. if (client)
  4221. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4222. return 0;
  4223. }
  4224. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4225. Spawn* spawn = lua_interface->GetSpawn(state);
  4226. int8 param = lua_interface->GetInt8Value(state, 2);
  4227. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4228. int8 value = lua_interface->GetInt8Value(state, 4);
  4229. lua_interface->ResetFunctionStack(state);
  4230. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4231. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4232. if (client) {
  4233. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4234. switch (param) {
  4235. case 1: {
  4236. packet->setDataByName("parameter1", param_value);
  4237. break;
  4238. }
  4239. case 2: {
  4240. packet->setDataByName("parameter2", param_value);
  4241. break;
  4242. }
  4243. case 3: {
  4244. packet->setDataByName("parameter3", param_value);
  4245. break;
  4246. }
  4247. case 4: {
  4248. packet->setDataByName("parameter4", param_value);
  4249. break;
  4250. }
  4251. case 5: {
  4252. packet->setDataByName("parameter5", param_value);
  4253. break;
  4254. }
  4255. }
  4256. packet->setDataByName("value", value);
  4257. client->QueuePacket(packet->serialize());
  4258. safe_delete(packet);
  4259. }
  4260. }
  4261. return 0;
  4262. }
  4263. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4264. Spawn* spawn = lua_interface->GetSpawn(state);
  4265. lua_interface->ResetFunctionStack(state);
  4266. if (spawn && spawn->IsPlayer()) {
  4267. if (((Player*)spawn)->GetIsTracking())
  4268. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4269. else
  4270. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4271. }
  4272. return 0;
  4273. }
  4274. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4275. Spawn* player = lua_interface->GetSpawn(state);
  4276. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4277. string name = lua_interface->GetStringValue(state, 3);
  4278. float distance = lua_interface->GetFloatValue(state, 4);
  4279. string command = lua_interface->GetStringValue(state, 5);
  4280. string error_text = lua_interface->GetStringValue(state, 6);
  4281. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4282. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4283. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4284. lua_interface->ResetFunctionStack(state);
  4285. if (spawn) {
  4286. if (distance == 0)
  4287. distance = 10.0f;
  4288. if (command.length() == 0)
  4289. command = name;
  4290. if (command.length() < 1 && name.length() < 1)
  4291. {
  4292. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4293. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4294. spawn->RemovePrimaryCommands();
  4295. }
  4296. else
  4297. {
  4298. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4299. }
  4300. }
  4301. return 0;
  4302. }
  4303. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4304. if (!lua_interface)
  4305. return 0;
  4306. Spawn* player = lua_interface->GetSpawn(state);
  4307. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4308. int16 tier = lua_interface->GetInt16Value(state, 3);
  4309. lua_interface->ResetFunctionStack(state);
  4310. if (player && player->IsPlayer()) {
  4311. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4312. return 1;
  4313. }
  4314. return 0;
  4315. }
  4316. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4317. if (!lua_interface)
  4318. return 0;
  4319. Spawn* player = lua_interface->GetSpawn(state);
  4320. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4321. int16 tier = lua_interface->GetInt16Value(state, 3);
  4322. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4323. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4324. bool add_to_hotbar = true;
  4325. if (num_args > 4) {
  4326. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4327. }
  4328. lua_interface->ResetFunctionStack(state);
  4329. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4330. if (player && spell && player->IsPlayer()) {
  4331. Client* client = player->GetClient();
  4332. if (client) {
  4333. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4334. {
  4335. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4336. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4337. client->GetPlayer()->UnlockSpell(spell);
  4338. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4339. }
  4340. else
  4341. {
  4342. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4343. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4344. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4345. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4346. client->GetPlayer()->UnlockSpell(spell);
  4347. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4348. }
  4349. //if (client ) {
  4350. // ((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);
  4351. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4352. if (outapp)
  4353. client->QueuePacket(outapp);
  4354. }
  4355. }
  4356. return 0;
  4357. }
  4358. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4359. if (!lua_interface)
  4360. return 0;
  4361. Spawn* player = lua_interface->GetSpawn(state);
  4362. lua_interface->ResetFunctionStack(state);
  4363. if (player && player->IsPlayer()) {
  4364. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4365. return 1;
  4366. }
  4367. return 0;
  4368. }
  4369. int EQ2Emu_lua_Attack(lua_State* state) {
  4370. if (lua_interface) {
  4371. Spawn* npc = lua_interface->GetSpawn(state);
  4372. Spawn* player = lua_interface->GetSpawn(state, 2);
  4373. lua_interface->ResetFunctionStack(state);
  4374. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4375. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4376. }
  4377. return 0;
  4378. }
  4379. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4380. if (lua_interface) {
  4381. Spawn* target = lua_interface->GetSpawn(state);
  4382. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4383. lua_interface->ResetFunctionStack(state);
  4384. if (target && target->GetZone())
  4385. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4386. }
  4387. return 0;
  4388. }
  4389. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4390. Spawn* player;
  4391. if (lua_interface) {
  4392. player = lua_interface->GetSpawn(state);
  4393. lua_interface->ResetFunctionStack(state);
  4394. if (player && player->IsPlayer()) {
  4395. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4396. return 1;
  4397. }
  4398. }
  4399. return 0;
  4400. }
  4401. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4402. Spawn* player;
  4403. Client* client;
  4404. if (lua_interface) {
  4405. player = lua_interface->GetSpawn(state);
  4406. lua_interface->ResetFunctionStack(state);
  4407. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4408. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4409. client->HandInCollections();
  4410. }
  4411. return 0;
  4412. }
  4413. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4414. Spawn* widget;
  4415. if (lua_interface) {
  4416. widget = lua_interface->GetSpawn(state);
  4417. lua_interface->ResetFunctionStack(state);
  4418. if (widget && widget->IsWidget())
  4419. ((Widget*)widget)->HandleUse(nullptr, "");
  4420. }
  4421. return 0;
  4422. }
  4423. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4424. Spawn* spawn = 0;
  4425. int32 primary_list = 0;
  4426. int32 secondary_list = 0;
  4427. if (lua_interface) {
  4428. spawn = lua_interface->GetSpawn(state);
  4429. primary_list = lua_interface->GetInt32Value(state, 2);
  4430. secondary_list = lua_interface->GetInt32Value(state, 3);
  4431. lua_interface->ResetFunctionStack(state);
  4432. if (!spawn->IsNPC()) {
  4433. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4434. return 0;
  4435. }
  4436. NPC* npc = (NPC*)spawn;
  4437. npc->SetPrimarySpellList(primary_list);
  4438. npc->SetSecondarySpellList(secondary_list);
  4439. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4440. }
  4441. return 0;
  4442. }
  4443. int EQ2Emu_lua_GetPet(lua_State* state) {
  4444. if (!lua_interface)
  4445. return 0;
  4446. Spawn* spawn = lua_interface->GetSpawn(state);
  4447. lua_interface->ResetFunctionStack(state);
  4448. if (spawn) {
  4449. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4450. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4451. return 1;
  4452. }
  4453. }
  4454. return 0;
  4455. }
  4456. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4457. if (!lua_interface)
  4458. return 0;
  4459. Spawn* spawn = lua_interface->GetSpawn(state);
  4460. lua_interface->ResetFunctionStack(state);
  4461. if (spawn) {
  4462. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4463. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4464. return 1;
  4465. }
  4466. }
  4467. return 0;
  4468. }
  4469. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4470. if (!lua_interface)
  4471. return 0;
  4472. Spawn* spawn = lua_interface->GetSpawn(state);
  4473. lua_interface->ResetFunctionStack(state);
  4474. if (spawn) {
  4475. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4476. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4477. return 1;
  4478. }
  4479. }
  4480. return 0;
  4481. }
  4482. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4483. if (!lua_interface)
  4484. return 0;
  4485. Spawn* spawn = lua_interface->GetSpawn(state);
  4486. lua_interface->ResetFunctionStack(state);
  4487. if (spawn) {
  4488. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4489. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4490. return 1;
  4491. }
  4492. }
  4493. return 0;
  4494. }
  4495. int EQ2Emu_lua_Charm(lua_State* state) {
  4496. if (!lua_interface)
  4497. return 0;
  4498. Spawn* owner = lua_interface->GetSpawn(state);
  4499. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4500. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4501. lua_interface->ResetFunctionStack(state);
  4502. if (!luaspell) {
  4503. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4504. return 0;
  4505. }
  4506. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4507. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4508. pet->SetPet(true);
  4509. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4510. ((NPC*)pet)->SetOwner((Entity*)owner);
  4511. // If owner is player and player does not have a summoned pet set the players charsheet
  4512. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4513. Player* player = (Player*)owner;
  4514. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4515. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4516. player->GetInfoStruct()->set_pet_movement(2);
  4517. player->GetInfoStruct()->set_pet_behavior(3);
  4518. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4519. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4520. // Make sure the values get sent to the client
  4521. player->SetCharSheetChanged(true);
  4522. }
  4523. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4524. pet->SetSpawnScript("");
  4525. // Set faction to the same as the owner
  4526. pet->SetFactionID(owner->GetFactionID());
  4527. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4528. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4529. // Clear hate list
  4530. ((NPC*)pet)->Brain()->ClearHate();
  4531. // Set the brain to a pet brain
  4532. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4533. }
  4534. return 0;
  4535. }
  4536. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4537. if (!lua_interface)
  4538. return 0;
  4539. Spawn* spawn = lua_interface->GetSpawn(state);
  4540. lua_interface->ResetFunctionStack(state);
  4541. if (!spawn) {
  4542. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4543. return 0;
  4544. }
  4545. vector<Spawn*> groupMembers;
  4546. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4547. groupMembers = *spawn->GetSpawnGroup();
  4548. }
  4549. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4550. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4551. deque<GroupMemberInfo*>::iterator itr;
  4552. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4553. if (group)
  4554. {
  4555. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4556. deque<GroupMemberInfo*>* members = group->GetMembers();
  4557. GroupMemberInfo* info = 0;
  4558. for (itr = members->begin(); itr != members->end(); itr++) {
  4559. info = *itr;
  4560. if (info->client)
  4561. groupMembers.push_back(info->client->GetPlayer());
  4562. }
  4563. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4564. }
  4565. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4566. }
  4567. else
  4568. return 0;
  4569. lua_createtable(state, groupMembers.size(), 0);
  4570. int newTable = lua_gettop(state);
  4571. for (int32 i = 0; i < groupMembers.size(); i++) {
  4572. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4573. lua_rawseti(state, newTable, i + 1);
  4574. }
  4575. return 1;
  4576. }
  4577. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4578. if (!lua_interface)
  4579. return 0;
  4580. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4581. lua_interface->SetOptionWindowValue(state, option_window);
  4582. return 1;
  4583. }
  4584. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4585. if (!lua_interface)
  4586. return 0;
  4587. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4588. if (option_window) {
  4589. OptionWindowOption option_window_option;
  4590. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4591. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4592. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4593. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4594. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4595. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4596. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4597. option_window->push_back(option_window_option);
  4598. }
  4599. return 0;
  4600. }
  4601. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4602. if (!lua_interface)
  4603. return 0;
  4604. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4605. Spawn* player = lua_interface->GetSpawn(state, 2);
  4606. string window_title = lua_interface->GetStringValue(state, 3);
  4607. string cancel_command = lua_interface->GetStringValue(state, 4);
  4608. Client* client = player->GetZone()->GetClientBySpawn(player);
  4609. if (option_window && window_title.length() > 0 && client) {
  4610. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4611. if (!packet)
  4612. return 0;
  4613. packet->setDataByName("title_text", window_title.c_str());
  4614. if (cancel_command.length() > 0)
  4615. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4616. packet->setArrayLengthByName("num_selections", option_window->size());
  4617. vector<OptionWindowOption>::iterator itr;
  4618. int8 i = 0;
  4619. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4620. OptionWindowOption opt = *itr;
  4621. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4622. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4623. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4624. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4625. if (opt.optionCommand.length() > 0)
  4626. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4627. if (opt.optionConfirmTitle.length() > 0)
  4628. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4629. i++;
  4630. }
  4631. client->QueuePacket(packet->serialize());
  4632. safe_delete(option_window);
  4633. safe_delete(packet);
  4634. }
  4635. return 0;
  4636. }
  4637. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4638. if (!lua_interface)
  4639. return 0;
  4640. Spawn* spawn = lua_interface->GetSpawn(state);
  4641. if (spawn) {
  4642. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4643. return 1;
  4644. }
  4645. else
  4646. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4647. return 0;
  4648. }
  4649. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4650. if (!lua_interface)
  4651. return 0;
  4652. Spawn* spawn = lua_interface->GetSpawn(state);
  4653. if (spawn) {
  4654. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4655. return 1;
  4656. }
  4657. else
  4658. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4659. return 0;
  4660. }
  4661. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4662. if (!lua_interface)
  4663. return 0;
  4664. Spawn* spawn = lua_interface->GetSpawn(state);
  4665. if (spawn) {
  4666. int8 class_id = spawn->GetTradeskillClass();
  4667. // Need to add 42 for the offset in the array
  4668. class_id += 44;
  4669. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4670. return 1;
  4671. }
  4672. else
  4673. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4674. return 0;
  4675. }
  4676. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4677. if (!lua_interface)
  4678. return 0;
  4679. Spawn* spawn = lua_interface->GetSpawn(state);
  4680. int16 level = lua_interface->GetInt8Value(state, 2);
  4681. if (spawn) {
  4682. if (spawn->IsPlayer())
  4683. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4684. else
  4685. spawn->SetTSLevel(level);
  4686. }
  4687. else
  4688. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4689. return 0;
  4690. }
  4691. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4692. if (!lua_interface)
  4693. return 0;
  4694. Spawn* spawn = lua_interface->GetSpawn(state);
  4695. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4696. if (spawn) {
  4697. spawn->SetAttackable(attackable);
  4698. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4699. }
  4700. return 0;
  4701. }
  4702. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4703. // Check to see if we have a valid lua_interface
  4704. if (!lua_interface)
  4705. return 0;
  4706. // Get the spawn that is getting the pet
  4707. Spawn* spawn = lua_interface->GetSpawn(state);
  4708. // Get the DB ID of the pet
  4709. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4710. // The max level the pet can gain
  4711. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4712. // Get the spell that this command was called from
  4713. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4714. // Check to make sure the spawn pointer is valid
  4715. if (!spawn) {
  4716. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4717. return 0;
  4718. }
  4719. // Check to make sure the spawn is an entity
  4720. if (!spawn->IsEntity()) {
  4721. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4722. return 0;
  4723. }
  4724. // Check to make sure the spawn doesn't already have a pet of this type
  4725. if (((Entity*)spawn)->GetPet()) {
  4726. if (spawn->IsPlayer()) {
  4727. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4728. if (client)
  4729. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4730. }
  4731. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4732. return 0;
  4733. }
  4734. // Check to see if the DB ID for the pet is set
  4735. if (pet_id == 0) {
  4736. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4737. return 0;
  4738. }
  4739. // Check to see if the pointer to the spell is valid
  4740. if (!luaspell) {
  4741. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4742. return 0;
  4743. }
  4744. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4745. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4746. if (!pet) {
  4747. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4748. return 0;
  4749. }
  4750. // Check to make sure the pet is an npc
  4751. if (!pet->IsNPC()) {
  4752. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4753. return 0;
  4754. }
  4755. // Spawn the pet at the same location as the owner
  4756. pet->SetX(spawn->GetX());
  4757. pet->SetY(spawn->GetY());
  4758. pet->SetZ(spawn->GetZ());
  4759. pet->SetLocation(spawn->GetLocation());
  4760. pet->SetHeading(spawn->GetHeading());
  4761. spawn->GetZone()->AddSpawn(pet);
  4762. /*
  4763. const char* spawn_script = world.GetSpawnScript(pet_id);
  4764. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4765. spawn->SetSpawnScript(string(spawn_script));
  4766. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4767. }*/
  4768. // Get a random pet name
  4769. string random_pet_name;
  4770. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4771. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4772. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4773. // If player set various values for the char sheet (pet window)
  4774. if (spawn->IsPlayer()) {
  4775. Player* player = (Player*)spawn;
  4776. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4777. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4778. player->GetInfoStruct()->set_pet_movement(2);
  4779. player->GetInfoStruct()->set_pet_behavior(3);
  4780. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4781. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4782. // Make sure the values get sent to the client
  4783. player->SetCharSheetChanged(true);
  4784. }
  4785. // Set the pets name
  4786. pet->SetName(random_pet_name.c_str());
  4787. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4788. if (max_level > 0)
  4789. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4790. else
  4791. pet->SetLevel(spawn->GetLevel());
  4792. // Set the max level this pet can reach
  4793. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4794. // Set the faction of the pet to the same faction as the owner
  4795. pet->SetFactionID(spawn->GetFactionID());
  4796. // Set the spawn as a pet
  4797. pet->SetPet(true);
  4798. // Give a pointer of the owner to the pet
  4799. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4800. // Give a pointer of the pet to the owner
  4801. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4802. // Set the pet type
  4803. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4804. // Set the spell id used to create this pet
  4805. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4806. // Set the spell tier used to create this pet
  4807. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4808. // Set the pets spawn type to 6
  4809. pet->SetSpawnType(6);
  4810. // Set the pets brain
  4811. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4812. // Check to see if the pet has a subtitle
  4813. if (strlen(pet->GetSubTitle()) > 0) {
  4814. // Add the players name to the front of the sub title
  4815. string pet_subtitle;
  4816. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4817. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4818. // Set the pets subtitle to the new one
  4819. pet->SetSubTitle(pet_subtitle.c_str());
  4820. }
  4821. // Add the "Pet Options" entity command to the pet
  4822. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4823. // Set the pet as the return value for this function
  4824. lua_interface->SetSpawnValue(state, pet);
  4825. return 1;
  4826. }
  4827. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4828. if (!lua_interface)
  4829. return 0;
  4830. Spawn* spawn = lua_interface->GetSpawn(state);
  4831. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4832. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4833. if (!spawn) {
  4834. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4835. return 0;
  4836. }
  4837. if (!spawn->IsEntity()) {
  4838. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4839. return 0;
  4840. }
  4841. if (((Entity*)spawn)->GetDeityPet()) {
  4842. if (spawn->IsPlayer()) {
  4843. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4844. if (client)
  4845. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4846. }
  4847. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4848. return 0;
  4849. }
  4850. if (pet_id == 0) {
  4851. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4852. return 0;
  4853. }
  4854. if (!luaspell) {
  4855. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4856. return 0;
  4857. }
  4858. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4859. if (!pet) {
  4860. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4861. return 0;
  4862. }
  4863. if (!pet->IsNPC()) {
  4864. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4865. return 0;
  4866. }
  4867. pet->SetX(spawn->GetX());
  4868. pet->SetY(spawn->GetY());
  4869. pet->SetZ(spawn->GetZ());
  4870. pet->SetLocation(spawn->GetLocation());
  4871. pet->SetHeading(spawn->GetHeading());
  4872. spawn->GetZone()->AddSpawn(pet);
  4873. string random_pet_name;
  4874. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4875. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4876. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4877. pet->SetName(random_pet_name.c_str());
  4878. pet->SetLevel(spawn->GetLevel());
  4879. pet->SetFactionID(spawn->GetFactionID());
  4880. pet->SetPet(true);
  4881. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4882. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4883. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4884. pet->SetSpawnType(6);
  4885. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4886. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4887. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4888. if (strlen(pet->GetSubTitle()) > 0) {
  4889. string pet_subtitle;
  4890. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4891. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4892. pet->SetSubTitle(pet_subtitle.c_str());
  4893. }
  4894. // deity and cosmetic pets are not attackable
  4895. pet->SetAttackable(false);
  4896. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4897. lua_interface->SetSpawnValue(state, pet);
  4898. return 1;
  4899. }
  4900. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4901. if (!lua_interface)
  4902. return 0;
  4903. Spawn* spawn = lua_interface->GetSpawn(state);
  4904. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4905. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4906. if (!spawn) {
  4907. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4908. return 0;
  4909. }
  4910. if (!spawn->IsEntity()) {
  4911. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4912. return 0;
  4913. }
  4914. if (((Entity*)spawn)->GetCosmeticPet()) {
  4915. if (spawn->IsPlayer()) {
  4916. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4917. if (client)
  4918. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4919. }
  4920. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4921. return 0;
  4922. }
  4923. if (pet_id == 0) {
  4924. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4925. return 0;
  4926. }
  4927. if (!luaspell) {
  4928. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4929. return 0;
  4930. }
  4931. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4932. if (!pet) {
  4933. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4934. return 0;
  4935. }
  4936. if (!pet->IsNPC()) {
  4937. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4938. return 0;
  4939. }
  4940. pet->SetX(spawn->GetX());
  4941. pet->SetY(spawn->GetY());
  4942. pet->SetZ(spawn->GetZ());
  4943. pet->SetLocation(spawn->GetLocation());
  4944. pet->SetHeading(spawn->GetHeading());
  4945. spawn->GetZone()->AddSpawn(pet);
  4946. string random_pet_name;
  4947. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4948. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4949. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4950. pet->SetName(random_pet_name.c_str());
  4951. pet->SetLevel(spawn->GetLevel());
  4952. pet->SetFactionID(spawn->GetFactionID());
  4953. pet->SetPet(true);
  4954. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4955. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4956. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4957. pet->SetSpawnType(6);
  4958. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4959. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4960. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4961. if (strlen(pet->GetSubTitle()) > 0) {
  4962. string pet_subtitle;
  4963. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4964. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4965. pet->SetSubTitle(pet_subtitle.c_str());
  4966. }
  4967. pet->SetAttackable(false);
  4968. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4969. lua_interface->SetSpawnValue(state, pet);
  4970. return 1;
  4971. }
  4972. int EQ2Emu_lua_DismissPet(lua_State* state) {
  4973. if (!lua_interface)
  4974. return 0;
  4975. Spawn* spawn = lua_interface->GetSpawn(state);
  4976. if (!spawn) {
  4977. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  4978. return 0;
  4979. }
  4980. if (!spawn->IsPet()) {
  4981. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  4982. return 0;
  4983. }
  4984. if (!((NPC*)spawn)->IsDismissing())
  4985. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  4986. return 0;
  4987. }
  4988. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  4989. if (!lua_interface)
  4990. return 0;
  4991. Quest* quest = lua_interface->GetQuest(state);
  4992. if (!quest) {
  4993. 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));
  4994. return 0;
  4995. }
  4996. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  4997. if (feather_color > 0)
  4998. quest->SetFeatherColor(feather_color);
  4999. return 0;
  5000. }
  5001. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5002. if (!lua_interface)
  5003. return 0;
  5004. Spawn* spawn = lua_interface->GetSpawn(state);
  5005. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5006. if (!spawn) {
  5007. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5008. return 0;
  5009. }
  5010. if (!spawn2) {
  5011. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5012. return 0;
  5013. }
  5014. spawn->RemoveSpawnAccess(spawn2);
  5015. return 0;
  5016. }
  5017. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5018. if (!lua_interface)
  5019. return 0;
  5020. ZoneServer* zone = lua_interface->GetZone(state);
  5021. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5022. if (!zone) {
  5023. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5024. return 0;
  5025. }
  5026. if (location_id == 0) {
  5027. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5028. return 0;
  5029. }
  5030. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5031. if (!location) {
  5032. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5033. return 0;
  5034. }
  5035. Spawn* spawn = 0;
  5036. if (location->entities[0]) {
  5037. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5038. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5039. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5040. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5041. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5042. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5043. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5044. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5045. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5046. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5047. if(spawn && spawn->IsOmittedByDBFlag())
  5048. {
  5049. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5050. safe_delete(spawn);
  5051. spawn = 0;
  5052. return 0;
  5053. }
  5054. if (spawn) {
  5055. const char* script = 0;
  5056. for (int x = 0; x < 3; x++) {
  5057. switch (x) {
  5058. case 0:
  5059. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5060. break;
  5061. case 1:
  5062. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5063. break;
  5064. case 2:
  5065. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5066. break;
  5067. }
  5068. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5069. spawn->SetSpawnScript(string(script));
  5070. break;
  5071. }
  5072. }
  5073. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5074. lua_interface->SetSpawnValue(state, spawn);
  5075. return 1;
  5076. }
  5077. else {
  5078. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5079. safe_delete(spawn);
  5080. }
  5081. }
  5082. return 0;
  5083. }
  5084. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5085. if (!lua_interface)
  5086. return 0;
  5087. Spawn* caster = lua_interface->GetSpawn(state);
  5088. Spawn* target = lua_interface->GetSpawn(state, 2);
  5089. int32 id = lua_interface->GetInt32Value(state, 3);
  5090. string command = lua_interface->GetStringValue(state, 4);
  5091. if (!caster) {
  5092. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5093. return 0;
  5094. }
  5095. if (!target) {
  5096. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5097. return 0;
  5098. }
  5099. if (!caster->IsPlayer()) {
  5100. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5101. return 0;
  5102. }
  5103. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5104. if (!entity_command) {
  5105. 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());
  5106. return 0;
  5107. }
  5108. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  5109. if (!client) {
  5110. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5111. return 0;
  5112. }
  5113. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5114. return 0;
  5115. }
  5116. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5117. if (!lua_interface)
  5118. return 0;
  5119. Spawn* spawn = lua_interface->GetSpawn(state);
  5120. if (!spawn) {
  5121. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5122. return 0;
  5123. }
  5124. if (!spawn->IsNPC()) {
  5125. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5126. return 0;
  5127. }
  5128. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5129. return 0;
  5130. }
  5131. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5132. if (!lua_interface)
  5133. return 0;
  5134. Spawn* spawn = lua_interface->GetSpawn(state);
  5135. int16 tick = lua_interface->GetInt16Value(state, 2);
  5136. if (!spawn) {
  5137. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5138. return 0;
  5139. }
  5140. if (!spawn->IsNPC()) {
  5141. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5142. return 0;
  5143. }
  5144. if (tick < 20) {
  5145. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5146. return 0;
  5147. }
  5148. ((NPC*)spawn)->Brain()->SetTick(tick);
  5149. return 0;
  5150. }
  5151. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5152. if (!lua_interface)
  5153. return 0;
  5154. Spawn* spawn = lua_interface->GetSpawn(state);
  5155. Spawn* target = lua_interface->GetSpawn(state, 2);
  5156. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5157. if (!spawn) {
  5158. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5159. return 0;
  5160. }
  5161. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5162. spawn->SetFollowTarget(target, follow_distance);
  5163. return 0;
  5164. }
  5165. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5166. if (!lua_interface)
  5167. return 0;
  5168. Spawn* spawn = lua_interface->GetSpawn(state);
  5169. if (!spawn) {
  5170. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5171. return 0;
  5172. }
  5173. Spawn* target = spawn->GetFollowTarget();
  5174. if (target) {
  5175. lua_interface->SetSpawnValue(state, target);
  5176. return 1;
  5177. }
  5178. return 0;
  5179. }
  5180. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5181. if (!lua_interface)
  5182. return 0;
  5183. Spawn* spawn = lua_interface->GetSpawn(state);
  5184. if (!spawn) {
  5185. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5186. return 0;
  5187. }
  5188. if (spawn->following)
  5189. spawn->following = false;
  5190. else
  5191. spawn->following = true;
  5192. return 0;
  5193. }
  5194. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5195. if (!lua_interface)
  5196. return 0;
  5197. Spawn* spawn = lua_interface->GetSpawn(state);
  5198. if (!spawn) {
  5199. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5200. return 0;
  5201. }
  5202. lua_interface->SetBooleanValue(state, spawn->following);
  5203. return 1;
  5204. }
  5205. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5206. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5207. // I will attempt to explain how this function works for future refrence
  5208. // Fist lets make sure lua_interface is valid, if not return out
  5209. if (!lua_interface)
  5210. return 0;
  5211. // Next we grab the first 2 params same as we usually would
  5212. Spawn* spawn = lua_interface->GetSpawn(state);
  5213. string var = lua_interface->GetStringValue(state, 2);
  5214. // 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
  5215. // 1 = Spawn
  5216. // 2 = Zone
  5217. // 3 = Item
  5218. // 4 = Quest
  5219. // 5 = String
  5220. // 6 = nil (null)
  5221. int8 dataType = 0;
  5222. // Define pointers for each potential type
  5223. Spawn* spawnVal = 0;
  5224. ZoneServer* zone = 0;
  5225. Item* item = 0;
  5226. Quest* quest = 0;
  5227. string val;
  5228. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5229. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5230. // options window are also light user data be we do not handle those.
  5231. // We check with lua_islightuserdata(lua_State*, index)
  5232. if (lua_islightuserdata(state, 3)) {
  5233. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5234. // and convert it to LUAUserData*
  5235. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5236. // Check to make sure the data we got is valid, if not give an error
  5237. if (!data || !data->IsCorrectlyInitialized()) {
  5238. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5239. }
  5240. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5241. else if (data->IsSpawn()) {
  5242. spawnVal = data->spawn;
  5243. dataType = 1;
  5244. }
  5245. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5246. else if (data->IsZone()) {
  5247. zone = data->zone;
  5248. dataType = 2;
  5249. }
  5250. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5251. else if (data->IsItem()) {
  5252. item = data->item;
  5253. dataType = 3;
  5254. }
  5255. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5256. else if (data->IsQuest()) {
  5257. quest = data->quest;
  5258. dataType = 4;
  5259. }
  5260. }
  5261. // Wasn't light user data, check if it is nil(null)
  5262. else if (lua_isnil(state, 3)) {
  5263. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5264. dataType = 6;
  5265. }
  5266. // Wasn't light user data or nil (null), must be a string
  5267. else {
  5268. // Set the string and dataType variable
  5269. val = lua_interface->GetStringValue(state, 3);
  5270. dataType = 5;
  5271. }
  5272. // We now have all the params, lets check to make sure they are valid
  5273. if (!spawn) {
  5274. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5275. return 0;
  5276. }
  5277. if (var.length() == 0) {
  5278. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5279. return 0;
  5280. }
  5281. if (dataType == 0) {
  5282. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5283. return 0;
  5284. }
  5285. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5286. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5287. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5288. switch (dataType) {
  5289. case 1:
  5290. // 1 = Spawn
  5291. spawn->AddTempVariable(var, spawnVal);
  5292. break;
  5293. case 2:
  5294. // 2 = Zone
  5295. spawn->AddTempVariable(var, zone);
  5296. break;
  5297. case 3:
  5298. // 3 = Item
  5299. spawn->AddTempVariable(var, item);
  5300. break;
  5301. case 4:
  5302. // 4 = Quest
  5303. spawn->AddTempVariable(var, quest);
  5304. break;
  5305. case 5:
  5306. // 5 = String
  5307. spawn->AddTempVariable(var, val);
  5308. break;
  5309. case 6:
  5310. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5311. spawn->DeleteTempVariable(var);
  5312. break;
  5313. }
  5314. // And we are done so return out
  5315. return 0;
  5316. }
  5317. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5318. if (!lua_interface)
  5319. return 0;
  5320. Spawn* spawn = lua_interface->GetSpawn(state);
  5321. string var = lua_interface->GetStringValue(state, 2);
  5322. if (!spawn) {
  5323. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5324. return 0;
  5325. }
  5326. if (var.length() == 0) {
  5327. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5328. return 0;
  5329. }
  5330. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5331. int8 type = spawn->GetTempVariableType(var);
  5332. Spawn* spawn2 = 0;
  5333. ZoneServer* zone = 0;
  5334. Item* item = 0;
  5335. Quest* quest = 0;
  5336. // Set the lua function return value based on the type of data the variable contains
  5337. switch (type) {
  5338. case 1:
  5339. spawn2 = spawn->GetTempVariableSpawn(var);
  5340. if (!spawn2)
  5341. return 0;
  5342. lua_interface->SetSpawnValue(state, spawn2);
  5343. break;
  5344. case 2:
  5345. zone = spawn->GetTempVariableZone(var);
  5346. if (!zone)
  5347. return 0;
  5348. lua_interface->SetZoneValue(state, zone);
  5349. break;
  5350. case 3:
  5351. item = spawn->GetTempVariableItem(var);
  5352. if (!item)
  5353. return 0;
  5354. lua_interface->SetItemValue(state, item);
  5355. break;
  5356. case 4:
  5357. quest = spawn->GetTempVariableQuest(var);
  5358. if (!quest)
  5359. return 0;
  5360. lua_interface->SetQuestValue(state, quest);
  5361. break;
  5362. case 5:
  5363. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5364. break;
  5365. default:
  5366. // Not a valid type then the variable was not set so return out
  5367. return 0;
  5368. }
  5369. // Return value was set so return out
  5370. return 1;
  5371. }
  5372. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5373. {
  5374. if (!lua_interface)
  5375. return 0;
  5376. Quest* quest = lua_interface->GetQuest(state);
  5377. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5378. string description = lua_interface->GetStringValue(state, 3);
  5379. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5380. if (!quest) {
  5381. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5382. lua_interface->SetBooleanValue(state, false);
  5383. return 1;
  5384. }
  5385. if (!spawn) {
  5386. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5387. lua_interface->SetBooleanValue(state, false);
  5388. return 1;
  5389. }
  5390. if (!spawn->IsPlayer()) {
  5391. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5392. lua_interface->SetBooleanValue(state, false);
  5393. return 1;
  5394. }
  5395. if (item_id == 0) {
  5396. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5397. lua_interface->SetBooleanValue(state, false);
  5398. return 1;
  5399. }
  5400. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5401. if (!client) {
  5402. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5403. lua_interface->SetBooleanValue(state, false);
  5404. return 1;
  5405. }
  5406. Item* item = master_item_list.GetItem(item_id);
  5407. if (!item) {
  5408. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5409. lua_interface->SetBooleanValue(state, false);
  5410. return 1;
  5411. }
  5412. Item* firstItem = new Item(item);
  5413. quest->AddTmpRewardItem(firstItem);
  5414. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5415. bool itemsAddedSuccessfully = true;
  5416. if(num_args > 4)
  5417. {
  5418. for(int8 n=5;n<num_args+1;n++)
  5419. {
  5420. int32 new_item = lua_interface->GetInt32Value(state, n);
  5421. Item* tmpItem = master_item_list.GetItem(new_item);
  5422. if(tmpItem)
  5423. {
  5424. Item* newTmpItem = new Item(tmpItem);
  5425. quest->AddTmpRewardItem(newTmpItem);
  5426. }
  5427. else
  5428. itemsAddedSuccessfully = false;
  5429. }
  5430. }
  5431. client->AddPendingQuestAcceptReward(quest);
  5432. client->DisplayQuestComplete(quest, true, description);
  5433. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5434. return 1;
  5435. }
  5436. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5437. if (!lua_interface)
  5438. return 0;
  5439. Quest* quest = lua_interface->GetQuest(state);
  5440. if (!quest) {
  5441. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5442. return 0;
  5443. }
  5444. quest->SetRepeatable(true);
  5445. return 0;
  5446. }
  5447. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5448. if (!lua_interface)
  5449. return 0;
  5450. Spawn* spawn = lua_interface->GetSpawn(state);
  5451. if (!spawn) {
  5452. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5453. return 0;
  5454. }
  5455. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5456. string ret = classes.GetClassNameCase(base_class);
  5457. if (ret.length() > 0) {
  5458. lua_interface->SetStringValue(state, ret.c_str());
  5459. return 1;
  5460. }
  5461. return 0;
  5462. }
  5463. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5464. if (!lua_interface)
  5465. return 0;
  5466. Spawn* player = lua_interface->GetSpawn(state);
  5467. if (player && player->IsPlayer()) {
  5468. Client* client = player->GetClient();
  5469. if (client)
  5470. client->SendWaypoints();
  5471. }
  5472. return 0;
  5473. }
  5474. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5475. if (!lua_interface)
  5476. return 0;
  5477. Spawn* player = lua_interface->GetSpawn(state);
  5478. string name = lua_interface->GetStringValue(state, 2);
  5479. int32 type = lua_interface->GetInt32Value(state, 3);
  5480. if (type == 0)
  5481. type = 2;
  5482. if (name.length() > 0) {
  5483. if (player && player->IsPlayer()) {
  5484. Client* client = player->GetClient();
  5485. if (client)
  5486. client->AddWaypoint(name, type);
  5487. }
  5488. }
  5489. return 0;
  5490. }
  5491. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5492. if (!lua_interface)
  5493. return 0;
  5494. Spawn* player = lua_interface->GetSpawn(state);
  5495. string name = lua_interface->GetStringValue(state, 2);
  5496. if (name.length() > 0) {
  5497. if (player && player->IsPlayer()) {
  5498. Client* client = player->GetClient();
  5499. if (client)
  5500. client->RemoveWaypoint(name);
  5501. }
  5502. }
  5503. return 0;
  5504. }
  5505. int EQ2Emu_lua_AddWard(lua_State* state) {
  5506. if (!lua_interface)
  5507. return 0;
  5508. int32 damage = lua_interface->GetInt32Value(state);
  5509. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5510. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5511. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5512. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5513. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5514. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5515. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5516. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5517. bool ward_was_added = false;
  5518. ZoneServer* zone = spell->caster->GetZone();
  5519. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5520. for (int32 i = 0; i < spell->targets.size(); i++) {
  5521. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5522. if (!target)
  5523. continue;
  5524. if (target->IsEntity()) {
  5525. // If the ward is already active remove it
  5526. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5527. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5528. // Create new ward info
  5529. WardInfo* ward = new WardInfo;
  5530. ward->Spell = spell;
  5531. ward->BaseDamage = damage;
  5532. ward->DamageLeft = damage;
  5533. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5534. ward->keepWard = keepWard;
  5535. ward->WardType = wardType;
  5536. if (damageAbsorptionPercent > 100)
  5537. damageAbsorptionPercent = 100;
  5538. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5539. if (damageAbsorptionMaxHealthPercent > 100)
  5540. damageAbsorptionMaxHealthPercent = 100;
  5541. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5542. ward->RedirectDamagePercent = redirectDamagePercent;
  5543. ward->LastRedirectDamage = 0;
  5544. ward->LastAbsorbedDamage = 0;
  5545. ward->HitCount = 0;
  5546. spell->num_triggers = maxHitCount;
  5547. spell->had_triggers = true;
  5548. spell->cancel_after_all_triggers = false;
  5549. ward->MaxHitCount = maxHitCount;
  5550. if (wardType == WARD_TYPE_MAGICAL)
  5551. ward->DamageType = damageTypes;
  5552. // Add the ward to the entity
  5553. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5554. ward_was_added = true;
  5555. }
  5556. }
  5557. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5558. if (ward_was_added && spell->caster->IsPlayer()) {
  5559. spell->had_dmg_remaining = true;
  5560. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5561. }
  5562. return 0;
  5563. }
  5564. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5565. if (!lua_interface)
  5566. return 0;
  5567. int32 amount = lua_interface->GetInt32Value(state);
  5568. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5569. WardInfo* ward = 0;
  5570. ZoneServer* zone = spell->caster->GetZone();
  5571. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5572. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5573. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5574. ward = target->GetWard(spell->spell->GetSpellID());
  5575. if (target && ward) {
  5576. ward->DamageLeft += amount;
  5577. if (ward->DamageLeft > ward->BaseDamage)
  5578. ward->DamageLeft = ward->BaseDamage;
  5579. for (int32 i = 0; i < spell->targets.size(); i++) {
  5580. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5581. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5582. }
  5583. }
  5584. }
  5585. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5586. if (ward && spell->caster->IsPlayer())
  5587. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5588. return 0;
  5589. }
  5590. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5591. if (!lua_interface)
  5592. return 0;
  5593. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5594. if (!spell) {
  5595. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5596. return 0;
  5597. }
  5598. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5599. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5600. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5601. if (ward) {
  5602. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5603. return 1;
  5604. }
  5605. }
  5606. return 0;
  5607. }
  5608. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5609. if (!lua_interface)
  5610. return 0;
  5611. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5612. if (!spell) {
  5613. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5614. return 0;
  5615. }
  5616. string type = lua_interface->GetStringValue(state, 2);
  5617. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5618. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5619. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5620. if (ward) {
  5621. if (boost::iequals(type, "damageleft"))
  5622. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5623. else if (boost::iequals(type, "basedamage"))
  5624. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5625. else if (boost::iequals(type, "keepward"))
  5626. lua_interface->SetBooleanValue(state, ward->keepWard);
  5627. else if (boost::iequals(type, "wardtype"))
  5628. lua_interface->SetInt32Value(state, ward->WardType);
  5629. else if (boost::iequals(type, "dmgabsorptionpct"))
  5630. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5631. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5632. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5633. else if (boost::iequals(type, "redirectdamagepercent"))
  5634. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5635. else if (boost::iequals(type, "lastredirectdamage"))
  5636. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5637. else if (boost::iequals(type, "lastabsorbeddamage"))
  5638. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5639. else if (boost::iequals(type, "hitcount"))
  5640. lua_interface->SetInt32Value(state, ward->HitCount);
  5641. else if (boost::iequals(type, "maxhitcount"))
  5642. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5643. else
  5644. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5645. return 1;
  5646. }
  5647. }
  5648. return 0;
  5649. }
  5650. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5651. if (!lua_interface)
  5652. return 0;
  5653. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5654. ZoneServer* zone = spell->caster->GetZone();
  5655. Spawn* target = 0;
  5656. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5657. for (int32 i = 0; i < spell->targets.size(); i++) {
  5658. target = zone->GetSpawnByID(spell->targets.at(i));
  5659. if (target && target->IsEntity()) {
  5660. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5661. }
  5662. }
  5663. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5664. return 0;
  5665. }
  5666. int EQ2Emu_lua_Interrupt(lua_State* state)
  5667. {
  5668. if (!lua_interface)
  5669. return 0;
  5670. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5671. Spawn* target = lua_interface->GetSpawn(state, 2);
  5672. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5673. if (!caster)
  5674. {
  5675. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5676. return 0;
  5677. }
  5678. if (!target)
  5679. {
  5680. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5681. return 0;
  5682. }
  5683. if (!spell) {
  5684. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5685. return 0;
  5686. }
  5687. if (!target->IsEntity() && !spell)
  5688. {
  5689. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5690. return 0;
  5691. }
  5692. if (!target && spell) {
  5693. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5694. for (int8 i = 0; i < spell->targets.size(); i++) {
  5695. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5696. if (!target || !target->IsEntity())
  5697. continue;
  5698. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5699. }
  5700. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5701. }
  5702. else
  5703. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5704. return 0;
  5705. }
  5706. int EQ2Emu_lua_Stealth(lua_State* state) {
  5707. if (!lua_interface)
  5708. return 0;
  5709. int8 type = lua_interface->GetInt8Value(state);
  5710. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5711. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5712. if (!spell) {
  5713. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5714. return 0;
  5715. }
  5716. ZoneServer* zone = spell->caster->GetZone();
  5717. if (spawn) {
  5718. if (spawn->IsEntity()) {
  5719. if (type == 1) {
  5720. ((Entity*)spawn)->AddStealthSpell(spell);
  5721. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5722. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5723. }
  5724. else if (type == 2) {
  5725. ((Entity*)spawn)->AddInvisSpell(spell);
  5726. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5727. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5728. }
  5729. return 0;
  5730. }
  5731. else {
  5732. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5733. return 0;
  5734. }
  5735. }
  5736. else {
  5737. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5738. for (int32 i = 0; i < spell->targets.size(); i++) {
  5739. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5740. if (!spawn || !spawn->IsEntity())
  5741. continue;
  5742. if (type == 1) {
  5743. ((Entity*)spawn)->AddStealthSpell(spell);
  5744. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5745. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5746. }
  5747. else if (type == 2) {
  5748. ((Entity*)spawn)->AddInvisSpell(spell);
  5749. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5750. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5751. }
  5752. else {
  5753. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5754. break;
  5755. }
  5756. }
  5757. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5758. }
  5759. return 0;
  5760. }
  5761. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5762. if (!lua_interface)
  5763. return 0;
  5764. Spawn* spawn = lua_interface->GetSpawn(state);
  5765. if (!spawn) {
  5766. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5767. return 0;
  5768. }
  5769. if (spawn->IsEntity()) {
  5770. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5771. return 1;
  5772. }
  5773. else
  5774. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5775. return 0;
  5776. }
  5777. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5778. if (!lua_interface)
  5779. return 0;
  5780. Spawn* spawn = lua_interface->GetSpawn(state);
  5781. if (!spawn) {
  5782. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5783. return 0;
  5784. }
  5785. if (spawn->IsEntity()) {
  5786. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5787. return 1;
  5788. }
  5789. else
  5790. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5791. return 0;
  5792. }
  5793. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5794. if (!lua_interface)
  5795. return 0;
  5796. Spawn* player = lua_interface->GetSpawn(state);
  5797. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5798. lua_interface->ResetFunctionStack(state);
  5799. if (!player->IsPlayer()) {
  5800. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5801. return 0;
  5802. }
  5803. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5804. return 1;
  5805. }
  5806. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5807. if (!lua_interface)
  5808. return 0;
  5809. Spawn* player = lua_interface->GetSpawn(state);
  5810. int8 slot = lua_interface->GetInt8Value(state, 2);
  5811. lua_interface->ResetFunctionStack(state);
  5812. if (!player) {
  5813. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5814. return 0;
  5815. }
  5816. if (!player->IsPlayer()) {
  5817. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5818. return 0;
  5819. }
  5820. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5821. if (!item) {
  5822. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5823. return 0;
  5824. }
  5825. lua_interface->SetItemValue(state, item);
  5826. return 1;
  5827. }
  5828. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5829. if (!lua_interface)
  5830. return 0;
  5831. Spawn* player = lua_interface->GetSpawn(state);
  5832. int32 id = lua_interface->GetInt32Value(state, 2);
  5833. lua_interface->ResetFunctionStack(state);
  5834. if (!player) {
  5835. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5836. return 0;
  5837. }
  5838. if (!player->IsPlayer()) {
  5839. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5840. return 0;
  5841. }
  5842. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5843. if (!item) {
  5844. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5845. return 0;
  5846. }
  5847. lua_interface->SetItemValue(state, item);
  5848. return 1;
  5849. }
  5850. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5851. if (!lua_interface)
  5852. return 0;
  5853. Spawn* spawn = lua_interface->GetSpawn(state);
  5854. int8 slot = lua_interface->GetInt8Value(state, 2);
  5855. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5856. lua_interface->ResetFunctionStack(state);
  5857. if (!spawn) {
  5858. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5859. return 0;
  5860. }
  5861. if (!spawn->IsEntity()) {
  5862. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5863. return 0;
  5864. }
  5865. Item* item = master_item_list.GetItem(item_id);
  5866. if (!item) {
  5867. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5868. return 0;
  5869. }
  5870. Item* copy = new Item(item);
  5871. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5872. if(result)
  5873. {
  5874. ((Entity*)spawn)->SetEquipment(copy, slot);
  5875. spawn->vis_changed = true;
  5876. if(spawn->IsPlayer())
  5877. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5878. }
  5879. else
  5880. {
  5881. safe_delete(copy);
  5882. }
  5883. lua_interface->SetBooleanValue(state, result);
  5884. return 1;
  5885. }
  5886. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5887. if (!lua_interface)
  5888. return 0;
  5889. Spawn* spawn = lua_interface->GetSpawn(state);
  5890. int8 slot = lua_interface->GetInt8Value(state, 2);
  5891. Item* item = lua_interface->GetItem(state, 3);
  5892. lua_interface->ResetFunctionStack(state);
  5893. if (!spawn) {
  5894. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5895. return 0;
  5896. }
  5897. if (!spawn->IsEntity()) {
  5898. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5899. return 0;
  5900. }
  5901. if (!item) {
  5902. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5903. return 0;
  5904. }
  5905. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5906. if(result)
  5907. {
  5908. ((Entity*)spawn)->SetEquipment(item, slot);
  5909. spawn->vis_changed = true;
  5910. if(spawn->IsPlayer())
  5911. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5912. }
  5913. lua_interface->SetBooleanValue(state, result);
  5914. return 1;
  5915. }
  5916. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5917. if (!lua_interface)
  5918. return 0;
  5919. Spawn* spawn = lua_interface->GetSpawn(state);
  5920. int8 slot = lua_interface->GetInt8Value(state, 2);
  5921. bool no_delete_item = (lua_interface->GetBooleanValue(state, 2) == false); // if not set then we default to deleting it, otherwise if set to true we don't delete
  5922. lua_interface->ResetFunctionStack(state);
  5923. if (!spawn) {
  5924. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5925. return 0;
  5926. }
  5927. if (!spawn->IsEntity()) {
  5928. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5929. return 0;
  5930. }
  5931. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5932. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5933. spawn->vis_changed = true;
  5934. if(spawn->IsPlayer())
  5935. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5936. lua_interface->SetBooleanValue(state, true);
  5937. return 1;
  5938. }
  5939. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5940. if (!lua_interface)
  5941. return 0;
  5942. Spawn* spawn = lua_interface->GetSpawn(state);
  5943. int8 slot = lua_interface->GetInt8Value(state, 2);
  5944. int16 type = lua_interface->GetInt16Value(state, 3);
  5945. int8 r = lua_interface->GetInt8Value(state, 4);
  5946. int8 g = lua_interface->GetInt8Value(state, 5);
  5947. int8 b = lua_interface->GetInt8Value(state, 6);
  5948. int8 h_r = lua_interface->GetInt8Value(state, 7);
  5949. int8 h_g = lua_interface->GetInt8Value(state, 8);
  5950. int8 h_b = lua_interface->GetInt8Value(state, 9);
  5951. lua_interface->ResetFunctionStack(state);
  5952. if (!spawn) {
  5953. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  5954. return 0;
  5955. }
  5956. if (!spawn->IsEntity()) {
  5957. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5958. return 0;
  5959. }
  5960. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  5961. spawn->vis_changed = true;
  5962. lua_interface->SetBooleanValue(state, true);
  5963. return 1;
  5964. }
  5965. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  5966. if (!lua_interface)
  5967. return 0;
  5968. Spawn* player = lua_interface->GetSpawn(state);
  5969. int32 id = lua_interface->GetInt32Value(state, 2);
  5970. int8 count = lua_interface->GetInt8Value(state, 3);
  5971. bool include_bank = lua_interface->GetInt8Value(state, 4);
  5972. lua_interface->ResetFunctionStack(state);
  5973. if (!player) {
  5974. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5975. return 0;
  5976. }
  5977. if (!player->IsPlayer()) {
  5978. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5979. return 0;
  5980. }
  5981. if (!count)
  5982. count = 1;
  5983. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  5984. if (!item) {
  5985. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  5986. return 0;
  5987. }
  5988. lua_interface->SetItemValue(state, item);
  5989. return 1;
  5990. }
  5991. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  5992. if (!lua_interface)
  5993. return 0;
  5994. Spawn* spawn = lua_interface->GetSpawn(state);
  5995. int32 anim = lua_interface->GetInt32Value(state, 2);
  5996. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  5997. int8 type = lua_interface->GetInt8Value(state, 4);
  5998. if (!spawn) {
  5999. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6000. return 0;
  6001. }
  6002. if (spawn2) {
  6003. if (spawn2->IsPlayer()) {
  6004. if (type != 1 && type != 2)
  6005. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6006. else
  6007. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6008. return 0;
  6009. }
  6010. else {
  6011. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6012. return 0;
  6013. }
  6014. }
  6015. else
  6016. spawn->GetZone()->PlayAnimation(spawn, anim);
  6017. return 0;
  6018. }
  6019. int EQ2Emu_lua_IsPet(lua_State* state) {
  6020. if (!lua_interface)
  6021. return 0;
  6022. Spawn* spawn = lua_interface->GetSpawn(state);
  6023. if (!spawn) {
  6024. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6025. return 0;
  6026. }
  6027. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6028. return 1;
  6029. }
  6030. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6031. if (!lua_interface)
  6032. return 0;
  6033. Spawn* spawn = lua_interface->GetSpawn(state);
  6034. if (!spawn) {
  6035. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6036. return 0;
  6037. }
  6038. if (!spawn->IsNPC()) {
  6039. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6040. return 0;
  6041. }
  6042. if (((NPC*)spawn)->GetOwner()) {
  6043. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6044. return 1;
  6045. }
  6046. return 0;
  6047. }
  6048. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6049. if (!lua_interface)
  6050. return 0;
  6051. Spawn* spawn = lua_interface->GetSpawn(state);
  6052. Spawn* target = lua_interface->GetSpawn(state, 2);
  6053. if (!spawn) {
  6054. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6055. return 0;
  6056. }
  6057. if (!spawn) {
  6058. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6059. return 0;
  6060. }
  6061. spawn->SetTarget(target);
  6062. return 0;
  6063. }
  6064. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6065. if (!lua_interface)
  6066. return 0;
  6067. Spawn* spawn = lua_interface->GetSpawn(state);
  6068. bool val = lua_interface->GetBooleanValue(state, 2);
  6069. if (!spawn) {
  6070. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6071. return 0;
  6072. }
  6073. if (!spawn->IsEntity()) {
  6074. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6075. return 0;
  6076. }
  6077. ((Entity*)spawn)->InCombat(val);
  6078. if (val) {
  6079. spawn->ClearRunningLocations();
  6080. spawn->CalculateRunningLocation(true);
  6081. }
  6082. return 0;
  6083. }
  6084. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6085. if (!lua_interface)
  6086. return 0;
  6087. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6088. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6089. if (!spawn1) {
  6090. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6091. return 0;
  6092. }
  6093. if (!spawn2) {
  6094. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6095. return 0;
  6096. }
  6097. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6098. return 1;
  6099. }
  6100. int EQ2Emu_lua_Runback(lua_State* state) {
  6101. if (!lua_interface)
  6102. return 0;
  6103. Spawn* spawn = lua_interface->GetSpawn(state);
  6104. if (!spawn) {
  6105. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6106. return 0;
  6107. }
  6108. if (!spawn->IsNPC()) {
  6109. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6110. return 0;
  6111. }
  6112. ((NPC*)spawn)->Runback();
  6113. return 0;
  6114. }
  6115. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6116. if (!lua_interface)
  6117. return 0;
  6118. Spawn* spawn = lua_interface->GetSpawn(state);
  6119. if (!spawn) {
  6120. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6121. return 0;
  6122. }
  6123. if (!spawn->IsNPC()) {
  6124. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6125. return 0;
  6126. }
  6127. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6128. return 1;
  6129. }
  6130. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6131. if (!lua_interface)
  6132. return 0;
  6133. Spawn* spawn = lua_interface->GetSpawn(state);
  6134. if (!spawn) {
  6135. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6136. return 0;
  6137. }
  6138. if (!spawn->IsEntity()) {
  6139. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6140. return 0;
  6141. }
  6142. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6143. return 1;
  6144. }
  6145. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6146. if (!lua_interface)
  6147. return 0;
  6148. Spawn* spawn = lua_interface->GetSpawn(state);
  6149. if (!spawn) {
  6150. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6151. return 0;
  6152. }
  6153. if (!spawn->IsEntity()) {
  6154. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6155. return 0;
  6156. }
  6157. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6158. return 1;
  6159. }
  6160. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6161. if (!lua_interface)
  6162. return 0;
  6163. Spawn* spawn = lua_interface->GetSpawn(state);
  6164. if (!spawn) {
  6165. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6166. return 0;
  6167. }
  6168. if (!spawn->IsEntity()) {
  6169. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6170. return 0;
  6171. }
  6172. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6173. return 1;
  6174. }
  6175. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6176. if (!lua_interface)
  6177. return 0;
  6178. Spawn* spawn = lua_interface->GetSpawn(state);
  6179. if (!spawn) {
  6180. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6181. return 0;
  6182. }
  6183. if (!spawn->IsEntity()) {
  6184. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6185. return 0;
  6186. }
  6187. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6188. return 1;
  6189. }
  6190. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6191. if (!lua_interface)
  6192. return 0;
  6193. Spawn* spawn = lua_interface->GetSpawn(state);
  6194. Spawn* target = lua_interface->GetSpawn(state, 2);
  6195. float distance = lua_interface->GetFloatValue(state, 3);
  6196. if (!spawn) {
  6197. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6198. return 0;
  6199. }
  6200. if (!target) {
  6201. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6202. return 0;
  6203. }
  6204. if (!spawn->IsNPC()) {
  6205. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6206. return 0;
  6207. }
  6208. if (!target->IsEntity()) {
  6209. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6210. return 0;
  6211. }
  6212. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6213. return 1;
  6214. }
  6215. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6216. if (!lua_interface)
  6217. return 0;
  6218. Spawn* spawn = lua_interface->GetSpawn(state);
  6219. Spawn* target = lua_interface->GetSpawn(state, 2);
  6220. float distance = lua_interface->GetFloatValue(state, 3);
  6221. if (!spawn) {
  6222. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6223. return 0;
  6224. }
  6225. if (!target) {
  6226. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6227. return 0;
  6228. }
  6229. if (!spawn->IsNPC()) {
  6230. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6231. return 0;
  6232. }
  6233. if (!target->IsEntity()) {
  6234. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6235. return 0;
  6236. }
  6237. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6238. return 0;
  6239. }
  6240. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6241. if (!lua_interface)
  6242. return 0;
  6243. Spawn* spawn = lua_interface->GetSpawn(state);
  6244. if (!spawn) {
  6245. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6246. return 0;
  6247. }
  6248. if (!spawn->IsNPC()) {
  6249. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6250. return 0;
  6251. }
  6252. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6253. return 1;
  6254. }
  6255. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6256. if (!lua_interface)
  6257. return 0;
  6258. Spawn* spawn = lua_interface->GetSpawn(state);
  6259. if (!spawn) {
  6260. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6261. return 0;
  6262. }
  6263. if (!spawn->IsNPC()) {
  6264. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6265. return 0;
  6266. }
  6267. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6268. return 1;
  6269. }
  6270. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6271. if (!lua_interface)
  6272. return 0;
  6273. Spawn* spawn = lua_interface->GetSpawn(state);
  6274. if (!spawn) {
  6275. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6276. return 0;
  6277. }
  6278. if (!spawn->IsNPC()) {
  6279. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6280. return 0;
  6281. }
  6282. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6283. if (hated) {
  6284. lua_interface->SetSpawnValue(state, hated);
  6285. return 1;
  6286. }
  6287. return 0;
  6288. }
  6289. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6290. if (!lua_interface)
  6291. return 0;
  6292. Spawn* spawn = lua_interface->GetSpawn(state);
  6293. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6294. if (!spawn) {
  6295. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6296. return 0;
  6297. }
  6298. if (!spawn->IsNPC()) {
  6299. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6300. return 0;
  6301. }
  6302. if (!hated) {
  6303. ((NPC*)spawn)->Brain()->ClearHate();
  6304. return 0;
  6305. }
  6306. else
  6307. {
  6308. if (!hated->IsEntity()) {
  6309. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6310. return 0;
  6311. }
  6312. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6313. return 0;
  6314. }
  6315. return 0;
  6316. }
  6317. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6318. if (!lua_interface)
  6319. return 0;
  6320. Spawn* spawn = lua_interface->GetSpawn(state);
  6321. if (!spawn) {
  6322. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6323. return 0;
  6324. }
  6325. if (!spawn->IsNPC()) {
  6326. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6327. return 0;
  6328. }
  6329. ((NPC*)spawn)->Brain()->ClearEncounter();
  6330. return 0;
  6331. }
  6332. int EQ2Emu_lua_GetEncounter(lua_State* state) {
  6333. if (!lua_interface)
  6334. return 0;
  6335. Spawn* spawn = lua_interface->GetSpawn(state);
  6336. if (!spawn) {
  6337. lua_interface->LogError("%s: LUA GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6338. return 0;
  6339. }
  6340. if (!spawn->IsNPC()) {
  6341. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6342. return 0;
  6343. }
  6344. // Temp list to store hate list
  6345. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6346. if (encounterList->size() == 0) {
  6347. safe_delete(encounterList);
  6348. return 0;
  6349. }
  6350. lua_createtable(state, encounterList->size(), 0);
  6351. int newTable = lua_gettop(state);
  6352. for (int32 i = 0; i < encounterList->size(); i++) {
  6353. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6354. if (temp)
  6355. lua_interface->SetSpawnValue(state, temp);
  6356. lua_rawseti(state, newTable, i + 1);
  6357. }
  6358. safe_delete(encounterList);
  6359. return 1;
  6360. }
  6361. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6362. if (!lua_interface)
  6363. return 0;
  6364. Spawn* spawn = lua_interface->GetSpawn(state);
  6365. if (!spawn) {
  6366. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6367. return 0;
  6368. }
  6369. if (!spawn->IsNPC()) {
  6370. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6371. return 0;
  6372. }
  6373. // Temp list to store hate list
  6374. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6375. if (hateList->size() == 0) {
  6376. safe_delete(hateList);
  6377. return 0;
  6378. }
  6379. lua_createtable(state, hateList->size(), 0);
  6380. int newTable = lua_gettop(state);
  6381. for (int32 i = 0; i < hateList->size(); i++) {
  6382. lua_interface->SetSpawnValue(state, hateList->at(i));
  6383. lua_rawseti(state, newTable, i + 1);
  6384. }
  6385. safe_delete(hateList);
  6386. return 1;
  6387. }
  6388. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6389. if (!lua_interface)
  6390. return 0;
  6391. Spawn* spawn = lua_interface->GetSpawn(state);
  6392. if (!spawn) {
  6393. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6394. return 0;
  6395. }
  6396. if (spawn->IsPlayer()) {
  6397. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6398. lua_interface->SetBooleanValue(state, true);
  6399. else
  6400. lua_interface->SetBooleanValue(state, false);
  6401. return 1;
  6402. }
  6403. else {
  6404. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6405. return 1;
  6406. }
  6407. }
  6408. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6409. if (!lua_interface)
  6410. return 0;
  6411. Quest* quest = lua_interface->GetQuest(state);
  6412. if (!quest) {
  6413. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6414. return 0;
  6415. }
  6416. quest->SetCompletedFlag(true);
  6417. return 0;
  6418. }
  6419. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6420. if (!lua_interface)
  6421. return 0;
  6422. Spawn* spawn = lua_interface->GetSpawn(state);
  6423. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6424. int8 tier = lua_interface->GetInt8Value(state, 3);
  6425. if (!spawn) {
  6426. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6427. return 0;
  6428. }
  6429. if (!spawn->IsEntity()) {
  6430. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6431. return 0;
  6432. }
  6433. if (spellID == 0) {
  6434. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6435. return 0;
  6436. }
  6437. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6438. if (effect) {
  6439. if (tier > 0) {
  6440. // If a tier was passed chec to see if it is the same as the effect
  6441. if (tier == effect->tier)
  6442. lua_interface->SetBooleanValue(state, true);
  6443. else
  6444. lua_interface->SetBooleanValue(state, false);
  6445. return 1;
  6446. }
  6447. else {
  6448. // Have an effect but no tier was passed so return true
  6449. lua_interface->SetBooleanValue(state, true);
  6450. }
  6451. return 1;
  6452. }
  6453. // no effect so return false
  6454. lua_interface->SetBooleanValue(state, false);
  6455. return 1;
  6456. }
  6457. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6458. if (!lua_interface)
  6459. return 0;
  6460. Spawn* spawn = lua_interface->GetSpawn(state);
  6461. int32 id = lua_interface->GetInt32Value(state, 2);
  6462. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6463. Spawn* spawn2 = 0;
  6464. vector<Spawn*> list;
  6465. if (!spawn) {
  6466. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6467. return 0;
  6468. }
  6469. //If zone not provided, use spawn's zone
  6470. if (!zone)
  6471. zone = spawn->GetZone();
  6472. list = zone->GetSpawnsByID(id);
  6473. if (list.size() == 0) {
  6474. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6475. return 0;
  6476. }
  6477. vector<Spawn*>::iterator itr = list.begin();
  6478. for (int8 i = 0; i < list.size(); i++) {
  6479. spawn2 = itr[i];
  6480. if (spawn2)
  6481. spawn2->AddAllowAccessSpawn(spawn);
  6482. }
  6483. return 0;
  6484. }
  6485. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6486. if (!lua_interface)
  6487. return 0;
  6488. Spawn* spawn = lua_interface->GetSpawn(state);
  6489. int32 id = lua_interface->GetInt32Value(state, 2);
  6490. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6491. Spawn* spawn2 = 0;
  6492. if (!spawn) {
  6493. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6494. return 0;
  6495. }
  6496. //If zone not provided, use spawn's zone
  6497. if (!zone)
  6498. zone = spawn->GetZone();
  6499. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6500. vector<Spawn*>::iterator itr = list.begin();
  6501. if (list.size() == 0) {
  6502. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6503. return 0;
  6504. }
  6505. for (int8 i = 0; i < list.size(); i++) {
  6506. spawn2 = itr[i];
  6507. if (spawn2)
  6508. spawn2->RemoveSpawnAccess(spawn);
  6509. }
  6510. return 0;
  6511. }
  6512. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6513. if (!lua_interface)
  6514. return 0;
  6515. Quest* quest = lua_interface->GetQuest(state);
  6516. if (!quest) {
  6517. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6518. return 0;
  6519. }
  6520. quest->SetYellowName(true);
  6521. return 0;
  6522. }
  6523. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6524. if (!lua_interface)
  6525. return 0;
  6526. Spawn* spawn = lua_interface->GetSpawn(state);
  6527. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6528. if (!spawn) {
  6529. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6530. return 0;
  6531. }
  6532. if (!spawn->IsPlayer()) {
  6533. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6534. return 0;
  6535. }
  6536. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6537. return 1;
  6538. }
  6539. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6540. if (!lua_interface)
  6541. return 0;
  6542. Spawn* spawn = lua_interface->GetSpawn(state);
  6543. if (!spawn) {
  6544. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6545. return 0;
  6546. }
  6547. if (!spawn->IsPlayer()) {
  6548. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6549. return 0;
  6550. }
  6551. ZoneServer* zone = spawn->GetZone();
  6552. if (!zone) {
  6553. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6554. return 0;
  6555. }
  6556. Instance_Type iType = zone->GetInstanceType();
  6557. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6558. iType == GROUP_LOCKOUT_INSTANCE ||
  6559. iType == RAID_LOCKOUT_INSTANCE ||
  6560. iType == SOLO_PERSIST_INSTANCE ||
  6561. iType == GROUP_PERSIST_INSTANCE ||
  6562. iType == RAID_PERSIST_INSTANCE) {
  6563. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6564. if (data) {
  6565. // Check to see if the timer has already been set, if it has return out.
  6566. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6567. return 0;
  6568. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6569. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6570. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6571. if (client) {
  6572. string time_msg = "";
  6573. int32 time = data->success_lockout_time;
  6574. int16 hour;
  6575. int8 min;
  6576. int8 sec;
  6577. hour = time / 3600;
  6578. time = time % 3600;
  6579. min = time / 60;
  6580. time = time % 60;
  6581. sec = time;
  6582. if (hour > 0) {
  6583. char temp[10];
  6584. sprintf(temp, " %i", hour);
  6585. time_msg.append(temp);
  6586. time_msg.append(" hour");
  6587. time_msg.append((hour > 1) ? "s" : "");
  6588. }
  6589. if (min > 0) {
  6590. char temp[5];
  6591. sprintf(temp, " %i", min);
  6592. time_msg.append(temp);
  6593. time_msg.append(" minute");
  6594. time_msg.append((min > 1) ? "s" : "");
  6595. }
  6596. // Only add seconds if minutes and hours are 0
  6597. if (hour == 0 && min == 0 && sec > 0) {
  6598. char temp[5];
  6599. sprintf(temp, " %i", sec);
  6600. time_msg.append(temp);
  6601. time_msg.append(" second");
  6602. time_msg.append((sec > 1) ? "s" : "");
  6603. }
  6604. 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());
  6605. }
  6606. }
  6607. else
  6608. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6609. }
  6610. else
  6611. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6612. return 0;
  6613. }
  6614. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6615. if (!lua_interface)
  6616. return 0;
  6617. Spawn* spawn = lua_interface->GetSpawn(state);
  6618. if (!spawn) {
  6619. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6620. return 0;
  6621. }
  6622. if (!spawn->IsPlayer()) {
  6623. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6624. return 0;
  6625. }
  6626. ZoneServer* zone = spawn->GetZone();
  6627. if (!zone) {
  6628. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6629. return 0;
  6630. }
  6631. Instance_Type iType = zone->GetInstanceType();
  6632. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6633. iType == GROUP_LOCKOUT_INSTANCE ||
  6634. iType == RAID_LOCKOUT_INSTANCE ||
  6635. iType == SOLO_PERSIST_INSTANCE ||
  6636. iType == GROUP_PERSIST_INSTANCE ||
  6637. iType == RAID_PERSIST_INSTANCE) {
  6638. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6639. if (data) {
  6640. // Check to see if the timer has already been set, if it has return out.
  6641. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6642. return 0;
  6643. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6644. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6645. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6646. if (client) {
  6647. string time_msg = "";
  6648. int32 time = data->failure_lockout_time;
  6649. int16 hour;
  6650. int8 min;
  6651. int8 sec;
  6652. hour = time / 3600;
  6653. time = time % 3600;
  6654. min = time / 60;
  6655. time = time % 60;
  6656. sec = time;
  6657. if (hour > 0) {
  6658. char temp[10];
  6659. sprintf(temp, " %i", hour);
  6660. time_msg.append(temp);
  6661. time_msg.append(" hour");
  6662. time_msg.append((hour > 1) ? "s" : "");
  6663. }
  6664. if (min > 0) {
  6665. char temp[5];
  6666. sprintf(temp, " %i", min);
  6667. time_msg.append(temp);
  6668. time_msg.append(" minute");
  6669. time_msg.append((min > 1) ? "s" : "");
  6670. }
  6671. // Only add seconds if minutes and hours are 0
  6672. if (hour == 0 && min == 0 && sec > 0) {
  6673. char temp[5];
  6674. sprintf(temp, " %i", sec);
  6675. time_msg.append(temp);
  6676. time_msg.append(" second");
  6677. time_msg.append((sec > 1) ? "s" : "");
  6678. }
  6679. 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());
  6680. }
  6681. }
  6682. else
  6683. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6684. }
  6685. else
  6686. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6687. return 0;
  6688. }
  6689. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6690. if (!lua_interface)
  6691. return 0;
  6692. Spawn* spawn = lua_interface->GetSpawn(state);
  6693. if (!spawn) {
  6694. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6695. return 0;
  6696. }
  6697. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6698. return 1;
  6699. }
  6700. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6701. if (!lua_interface)
  6702. return 0;
  6703. Spawn* player = lua_interface->GetSpawn(state);
  6704. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6705. if (!player) {
  6706. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6707. return 0;
  6708. }
  6709. if (!player->IsPlayer()) {
  6710. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6711. return 0;
  6712. }
  6713. if (!ground) {
  6714. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6715. return 0;
  6716. }
  6717. if (!ground->IsGroundSpawn()) {
  6718. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6719. return 0;
  6720. }
  6721. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6722. if (!groundspawn_entries) {
  6723. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6724. return 0;
  6725. }
  6726. Skill* skill = 0;
  6727. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6728. if (collection_skill == "Collecting")
  6729. skill = ((Player*)player)->GetSkillByName("Gathering");
  6730. else
  6731. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6732. if (!skill) {
  6733. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6734. return 0;
  6735. }
  6736. vector<GroundSpawnEntry*>::iterator itr;
  6737. GroundSpawnEntry* entry = 0;
  6738. bool can_harvest = false;
  6739. sint32 min_skill = -1;
  6740. int16 totalSkill = skill->current_val;
  6741. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6742. if(skillID != 0xFFFFFFFF)
  6743. {
  6744. ((Entity*)player)->MStats.lock();
  6745. totalSkill += ((Entity*)player)->stats[skillID];
  6746. ((Entity*)player)->MStats.unlock();
  6747. }
  6748. // first, iterate through groundspawn_entries, discard tables player cannot use
  6749. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6750. {
  6751. entry = *itr;
  6752. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6753. min_skill = entry->min_skill_level;
  6754. // if player lacks skill, skip table
  6755. if (entry->min_skill_level > totalSkill)
  6756. continue;
  6757. // if bonus, but player lacks level, skip table
  6758. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6759. continue;
  6760. can_harvest = true;
  6761. break;
  6762. }
  6763. lua_interface->SetBooleanValue(state, can_harvest);
  6764. // If false, send the message to the client
  6765. if (!can_harvest) {
  6766. Client* client = player->GetZone()->GetClientBySpawn(player);
  6767. if (client) {
  6768. string msg = "You do not have enough skill to ";
  6769. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6770. msg.append("gather");
  6771. else if (collection_skill == "Mining")
  6772. msg.append("mine");
  6773. else if (collection_skill == "Trapping")
  6774. msg.append("trap");
  6775. else if (collection_skill == "Foresting")
  6776. msg.append("forest");
  6777. else if (collection_skill == "Fishing")
  6778. msg.append("catch");
  6779. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6780. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6781. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6782. }
  6783. }
  6784. return 1;
  6785. }
  6786. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6787. if (!lua_interface)
  6788. return 0;
  6789. Spawn* player = lua_interface->GetSpawn(state);
  6790. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6791. if (!player) {
  6792. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6793. return 0;
  6794. }
  6795. if (!player->IsPlayer()) {
  6796. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6797. return 0;
  6798. }
  6799. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6800. lua_interface->SetBooleanValue(state, ret);
  6801. return 1;
  6802. }
  6803. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6804. // Check to see if we have a valid lua_interface
  6805. if (!lua_interface)
  6806. return 0;
  6807. // Get the spawn that is getting the pet
  6808. Spawn* spawn = lua_interface->GetSpawn(state);
  6809. Spawn* target = lua_interface->GetSpawn(state, 2);
  6810. // Get the DB ID of the pet
  6811. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6812. float x = lua_interface->GetFloatValue(state, 4);
  6813. float y = lua_interface->GetFloatValue(state, 5);
  6814. float z = lua_interface->GetFloatValue(state, 6);
  6815. // Get the spell that this command was called from
  6816. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6817. // Check to make sure the spawn pointer is valid
  6818. if (!spawn) {
  6819. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6820. return 0;
  6821. }
  6822. // Check to make sure the spawn is an entity
  6823. if (!spawn->IsEntity()) {
  6824. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6825. return 0;
  6826. }
  6827. if (!target) {
  6828. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6829. return 0;
  6830. }
  6831. if (!target->IsEntity()) {
  6832. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6833. return 0;
  6834. }
  6835. // Check to see if the DB ID for the pet is set
  6836. if (pet_id == 0) {
  6837. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6838. return 0;
  6839. }
  6840. // Check to see if the pointer to the spell is valid
  6841. if (!luaspell) {
  6842. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6843. return 0;
  6844. }
  6845. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6846. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6847. if (!pet) {
  6848. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6849. return 0;
  6850. }
  6851. // Check to make sure the pet is an npc
  6852. if (!pet->IsNPC()) {
  6853. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6854. return 0;
  6855. }
  6856. if (x == 0)
  6857. x = spawn->GetX();
  6858. if (y == 0)
  6859. y = spawn->GetY();
  6860. if (z == 0)
  6861. z = spawn->GetZ();
  6862. // Spawn the pet at the same location as the owner
  6863. pet->SetX(x);
  6864. pet->SetY(y);
  6865. pet->SetZ(z);
  6866. pet->SetLocation(spawn->GetLocation());
  6867. pet->SetHeading(spawn->GetHeading());
  6868. spawn->GetZone()->AddSpawn(pet);
  6869. /*
  6870. const char* spawn_script = world.GetSpawnScript(pet_id);
  6871. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6872. spawn->SetSpawnScript(string(spawn_script));
  6873. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6874. }*/
  6875. // Get a random pet name
  6876. string random_pet_name;
  6877. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6878. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6879. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6880. // Set the pets name
  6881. pet->SetName(random_pet_name.c_str());
  6882. // Set the level of the pet to the owners level
  6883. pet->SetLevel(spawn->GetLevel());
  6884. // Set the faction of the pet to the same faction as the owner
  6885. pet->SetFactionID(spawn->GetFactionID());
  6886. // Set the spawn as a pet
  6887. pet->SetPet(true);
  6888. // Give a pointer of the owner to the pet
  6889. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6890. // Set the pet type
  6891. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6892. // Set the spell id used to create this pet
  6893. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6894. // Set the spell tier used to create this pet
  6895. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6896. // Set the pets spawn type to 6
  6897. pet->SetSpawnType(6);
  6898. // Set the pets brain
  6899. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6900. // Check to see if the pet has a subtitle
  6901. if (strlen(pet->GetSubTitle()) > 0) {
  6902. // Add the players name to the front of the sub title
  6903. string pet_subtitle;
  6904. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6905. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6906. // Set the pets subtitle to the new one
  6907. pet->SetSubTitle(pet_subtitle.c_str());
  6908. }
  6909. // Set the pet as the return value for this function
  6910. lua_interface->SetSpawnValue(state, pet);
  6911. return 1;
  6912. }
  6913. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6914. if (!lua_interface)
  6915. return 0;
  6916. Spawn* spawn = lua_interface->GetSpawn(state);
  6917. Spawn* player = lua_interface->GetSpawn(state, 2);
  6918. float max_distance = lua_interface->GetFloatValue(state, 3);
  6919. string type = lua_interface->GetStringValue(state, 4);
  6920. if (!spawn || (spawn && spawn->IsPlayer())) {
  6921. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6922. return 0;
  6923. }
  6924. if (!player || (player && !player->IsPlayer())) {
  6925. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6926. return 0;
  6927. }
  6928. Client* client = 0;
  6929. if (player->GetZone())
  6930. client = player->GetZone()->GetClientBySpawn(player);
  6931. if (!client) {
  6932. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6933. return 0;
  6934. }
  6935. //Set max_distance to default if not set or not proper value
  6936. if (max_distance <= 0)
  6937. max_distance = 500;
  6938. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6939. if (packet) {
  6940. float unknown2_3 = 0;
  6941. int8 placement_mode = 0;
  6942. if (type == "wall") {
  6943. placement_mode = 2;
  6944. unknown2_3 = 150;
  6945. }
  6946. else if (type == "ceiling")
  6947. placement_mode = 1;
  6948. packet->setDataByName("placement_mode", placement_mode);
  6949. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  6950. packet->setDataByName("model_type", spawn->GetModelType());
  6951. packet->setDataByName("unknown", 1); //size
  6952. packet->setDataByName("unknown2", 1); //size 2
  6953. packet->setDataByName("unknown2", .5, 1); //size 3
  6954. packet->setDataByName("unknown2", 3, 2);
  6955. packet->setDataByName("unknown2", unknown2_3, 3);
  6956. packet->setDataByName("max_distance", max_distance);
  6957. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  6958. client->QueuePacket(packet->serialize());
  6959. safe_delete(packet);
  6960. }
  6961. return 0;
  6962. }
  6963. int EQ2Emu_lua_GetItemType(lua_State* state) {
  6964. if (!lua_interface)
  6965. return 0;
  6966. Item* item = lua_interface->GetItem(state);
  6967. if (!item) {
  6968. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  6969. return 0;
  6970. }
  6971. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  6972. return 1;
  6973. }
  6974. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  6975. if (!lua_interface)
  6976. return 0;
  6977. Spawn* spawn = lua_interface->GetSpawn(state);
  6978. if (!spawn) {
  6979. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6980. return 0;
  6981. }
  6982. if (spawn->GetZone())
  6983. spawn->GetZone()->AddTransportSpawn(spawn);
  6984. return 0;
  6985. }
  6986. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  6987. if (!lua_interface)
  6988. return 0;
  6989. Spawn* spawn = lua_interface->GetSpawn(state);
  6990. if (!spawn) {
  6991. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  6992. return 0;
  6993. }
  6994. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  6995. return 1;
  6996. }
  6997. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  6998. if (!lua_interface)
  6999. return 0;
  7000. Skill* skill = lua_interface->GetSkill(state);
  7001. if (!skill) {
  7002. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7003. return 0;
  7004. }
  7005. lua_interface->SetInt32Value(state, skill->current_val);
  7006. return 1;
  7007. }
  7008. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7009. if (!lua_interface)
  7010. return 0;
  7011. Skill* skill = lua_interface->GetSkill(state);
  7012. if (!skill) {
  7013. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7014. return 0;
  7015. }
  7016. lua_interface->SetInt32Value(state, skill->max_val);
  7017. return 1;
  7018. }
  7019. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7020. if (!lua_interface)
  7021. return 0;
  7022. Skill* skill = lua_interface->GetSkill(state);
  7023. if (!skill) {
  7024. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7025. return 0;
  7026. }
  7027. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7028. return 1;
  7029. }
  7030. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7031. if (!lua_interface)
  7032. return 0;
  7033. Skill* skill = lua_interface->GetSkill(state);
  7034. int16 value = lua_interface->GetInt16Value(state, 2);
  7035. if (!skill) {
  7036. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7037. return 0;
  7038. }
  7039. skill->max_val = value;
  7040. if (skill->max_val < skill->current_val)
  7041. skill->current_val = skill->max_val;
  7042. return 0;
  7043. }
  7044. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7045. if (!lua_interface)
  7046. return 0;
  7047. Skill* skill = lua_interface->GetSkill(state);
  7048. int16 value = lua_interface->GetInt16Value(state, 2);
  7049. if (!skill) {
  7050. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7051. return 0;
  7052. }
  7053. if (value > skill->max_val)
  7054. skill->current_val = skill->max_val;
  7055. else
  7056. skill->current_val = value;
  7057. return 0;
  7058. }
  7059. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7060. if (!lua_interface)
  7061. return 0;
  7062. Spawn* player = lua_interface->GetSpawn(state);
  7063. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7064. if (skill_id > 0 && player && player->IsPlayer()) {
  7065. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7066. return 1;
  7067. }
  7068. return 0;
  7069. }
  7070. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7071. if (!lua_interface)
  7072. return 0;
  7073. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7074. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7075. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7076. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7077. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7078. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7079. if (player_spawn && player_spawn->IsPlayer()) {
  7080. Player* player = (Player*)player_spawn;
  7081. bool added = false;
  7082. if (!player->skill_list.HasSkill(skill_id)) {
  7083. player->AddSkill(skill_id, current_val, max_val, true);
  7084. added = true;
  7085. }
  7086. 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
  7087. Client* client = player->GetClient();
  7088. if (client) {
  7089. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7090. if (packet)
  7091. client->QueuePacket(packet);
  7092. }
  7093. }
  7094. if (added) {
  7095. lua_interface->SetBooleanValue(state, true);
  7096. return 1;
  7097. }
  7098. }
  7099. else {
  7100. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7101. }
  7102. }
  7103. else {
  7104. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7105. }
  7106. lua_interface->SetBooleanValue(state, false);
  7107. return 1;
  7108. }
  7109. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7110. if (!lua_interface)
  7111. return 0;
  7112. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7113. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7114. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7115. if (skill_id > 0) {
  7116. if (player_spawn && player_spawn->IsPlayer()) {
  7117. Player* player = (Player*)player_spawn;
  7118. if (player->skill_list.HasSkill(skill_id)) {
  7119. player->RemovePlayerSkill(skill_id);
  7120. if (!more_to_remove) {
  7121. Client* client = player->GetClient();
  7122. if (client) {
  7123. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7124. if (packet)
  7125. client->QueuePacket(packet);
  7126. }
  7127. }
  7128. }
  7129. }
  7130. else {
  7131. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7132. }
  7133. }
  7134. else {
  7135. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7136. }
  7137. return 0;
  7138. }
  7139. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7140. if (!lua_interface)
  7141. return 0;
  7142. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7143. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7144. int16 amount = lua_interface->GetInt8Value(state, 3);
  7145. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7146. if (amount > 0 && skill_type < 100) {
  7147. if (player_spawn && player_spawn->IsPlayer()) {
  7148. Player* player = (Player*)player_spawn;
  7149. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7150. if (!more_to_increase) {
  7151. Client* client = player->GetClient();
  7152. if (client) {
  7153. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7154. if (packet)
  7155. client->QueuePacket(packet);
  7156. }
  7157. }
  7158. }
  7159. else {
  7160. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7161. }
  7162. }
  7163. else {
  7164. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7165. }
  7166. return 0;
  7167. }
  7168. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7169. if (!lua_interface)
  7170. return 0;
  7171. Spawn* spawn = lua_interface->GetSpawn(state);
  7172. string name = lua_interface->GetStringValue(state, 2);
  7173. if (!spawn) {
  7174. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7175. return 0;
  7176. }
  7177. if (!spawn->IsEntity()) {
  7178. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7179. return 0;
  7180. }
  7181. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7182. if (skill) {
  7183. lua_interface->SetSkillValue(state, skill);
  7184. return 1;
  7185. }
  7186. return 0;
  7187. }
  7188. int EQ2Emu_lua_AddProc(lua_State* state) {
  7189. if (!lua_interface)
  7190. return 0;
  7191. Spawn* spawn = lua_interface->GetSpawn(state);
  7192. int8 type = lua_interface->GetInt8Value(state, 2);
  7193. float chance = lua_interface->GetFloatValue(state, 3);
  7194. Item* item = lua_interface->GetItem(state, 4);
  7195. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7196. LuaSpell* spell = 0;
  7197. if (!spawn && (!spell || !use_all_spelltargets)) {
  7198. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7199. return 0;
  7200. }
  7201. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7202. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7203. return 0;
  7204. }
  7205. if (!item)
  7206. spell = lua_interface->GetCurrentSpell(state);
  7207. if (!item && !spell) {
  7208. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7209. return 0;
  7210. }
  7211. if (spell && use_all_spelltargets) {
  7212. Spawn* target;
  7213. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7214. for (int8 i = 0; i < spell->targets.size(); i++) {
  7215. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7216. if (!target || !target->IsEntity())
  7217. continue;
  7218. ((Entity*)target)->AddProc(type, chance, item, spell);
  7219. }
  7220. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7221. }
  7222. else
  7223. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7224. return 0;
  7225. }
  7226. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7227. if (!lua_interface)
  7228. return 0;
  7229. Spawn* spawn = lua_interface->GetSpawn(state);
  7230. Item* item = lua_interface->GetItem(state, 2);
  7231. LuaSpell* spell = 0;
  7232. if (!spawn) {
  7233. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7234. return 0;
  7235. }
  7236. if (!spawn->IsEntity()) {
  7237. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7238. return 0;
  7239. }
  7240. if (!item)
  7241. spell = lua_interface->GetCurrentSpell(state);
  7242. if (!item && !spell) {
  7243. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7244. return 0;
  7245. }
  7246. if (spell) {
  7247. Spawn* target;
  7248. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7249. for (int8 i = 0; i < spell->targets.size(); i++) {
  7250. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7251. if (!target || !target->IsEntity())
  7252. continue;
  7253. ((Entity*)target)->RemoveProc(item, spell);
  7254. }
  7255. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7256. spell->caster->RemoveProc(item, spell);
  7257. }
  7258. else
  7259. ((Entity*)spawn)->RemoveProc(item, spell);
  7260. return 0;
  7261. }
  7262. int EQ2Emu_lua_Knockback(lua_State* state) {
  7263. if (!lua_interface)
  7264. return 0;
  7265. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7266. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7267. int32 duration = lua_interface->GetInt32Value(state, 3);
  7268. float vertical = lua_interface->GetFloatValue(state, 4);
  7269. float horizontal = lua_interface->GetFloatValue(state, 5);
  7270. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7271. if (!target_spawn) {
  7272. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7273. return 0;
  7274. }
  7275. if (!spawn) {
  7276. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7277. return 0;
  7278. }
  7279. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7280. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  7281. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7282. if (packet) {
  7283. packet->setDataByName("target_x", target_spawn->GetX());
  7284. packet->setDataByName("target_y", target_spawn->GetY());
  7285. packet->setDataByName("target_z", target_spawn->GetZ());
  7286. packet->setDataByName("vertical_movement", vertical);
  7287. packet->setDataByName("horizontal_movement", horizontal);
  7288. if (use_heading)
  7289. packet->setDataByName("use_player_heading", 1);
  7290. client->QueuePacket(packet->serialize());
  7291. }
  7292. safe_delete(packet);
  7293. }
  7294. return 0;
  7295. }
  7296. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7297. if (!lua_interface)
  7298. return 0;
  7299. Spawn* spawn = lua_interface->GetSpawn(state);
  7300. if (!spawn) {
  7301. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7302. return 0;
  7303. }
  7304. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7305. return 1;
  7306. }
  7307. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7308. if (!lua_interface)
  7309. return 0;
  7310. Spawn* caster = lua_interface->GetSpawn(state);
  7311. Spawn* target = lua_interface->GetSpawn(state, 2);
  7312. string name = lua_interface->GetStringValue(state, 3);
  7313. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7314. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7315. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7316. string success_msg = lua_interface->GetStringValue(state, 7);
  7317. string effect_msg = lua_interface->GetStringValue(state, 8);
  7318. if (!caster) {
  7319. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7320. return 0;
  7321. }
  7322. if (!caster->IsEntity()) {
  7323. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7324. return 0;
  7325. }
  7326. if (!target) {
  7327. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7328. return 0;
  7329. }
  7330. if (!target->IsEntity()) {
  7331. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7332. return 0;
  7333. }
  7334. if (name.length() == 0) {
  7335. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7336. return 0;
  7337. }
  7338. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7339. return 0;
  7340. }
  7341. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7342. if (!lua_interface)
  7343. return 0;
  7344. string name = lua_interface->GetStringValue(state);
  7345. if (name.length() == 0) {
  7346. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7347. return 0;
  7348. }
  7349. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7350. if (!skill) {
  7351. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7352. return 0;
  7353. }
  7354. lua_interface->SetInt32Value(state, skill->skill_id);
  7355. return 1;
  7356. }
  7357. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7358. if (!lua_interface)
  7359. return 0;
  7360. Spawn* spawn = lua_interface->GetSpawn(state);
  7361. if (!spawn) {
  7362. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7363. return 0;
  7364. }
  7365. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7366. return 1;
  7367. }
  7368. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7369. if (!lua_interface)
  7370. return 0;
  7371. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7372. if (!luaspell) {
  7373. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7374. return 0;
  7375. }
  7376. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7377. return 1;
  7378. }
  7379. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7380. if (!lua_interface)
  7381. return 0;
  7382. Spawn* spawn = lua_interface->GetSpawn(state);
  7383. Spawn* target = lua_interface->GetSpawn(state, 2);
  7384. if (!spawn) {
  7385. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7386. return 0;
  7387. }
  7388. if (!spawn->IsEntity()) {
  7389. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7390. return 0;
  7391. }
  7392. if (!target) {
  7393. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7394. return 0;
  7395. }
  7396. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7397. return 1;
  7398. }
  7399. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7400. if (!lua_interface)
  7401. return 0;
  7402. Spawn* spawn = lua_interface->GetSpawn(state);
  7403. Spawn* target = lua_interface->GetSpawn(state, 2);
  7404. if (!spawn) {
  7405. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7406. return 0;
  7407. }
  7408. if (!spawn->IsEntity()) {
  7409. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7410. return 0;
  7411. }
  7412. if (!target) {
  7413. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7414. return 0;
  7415. }
  7416. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7417. return 1;
  7418. }
  7419. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7420. if (!lua_interface)
  7421. return 0;
  7422. Item* item = lua_interface->GetItem(state);
  7423. if (!item) {
  7424. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7425. return 0;
  7426. }
  7427. lua_interface->SetInt32Value(state, item->details.count);
  7428. return 1;
  7429. }
  7430. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7431. if (!lua_interface)
  7432. return 0;
  7433. Item* item = lua_interface->GetItem(state);
  7434. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7435. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7436. if (!item) {
  7437. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7438. return 0;
  7439. }
  7440. if (!owner) {
  7441. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7442. return 0;
  7443. }
  7444. if (!owner->IsPlayer()) {
  7445. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7446. return 0;
  7447. }
  7448. if (item->stack_count < new_count) {
  7449. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7450. return 0;
  7451. }
  7452. if (new_count > 0) {
  7453. item->details.count = new_count;
  7454. item->save_needed = true;
  7455. }
  7456. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7457. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7458. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7459. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7460. else
  7461. {
  7462. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7463. return 0;
  7464. }
  7465. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7466. if (!client)
  7467. return 0;
  7468. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7469. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7470. if (app)
  7471. client->QueuePacket(app);
  7472. return 0;
  7473. }
  7474. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7475. if (!lua_interface)
  7476. return 0;
  7477. int32 time = lua_interface->GetInt32Value(state);
  7478. string function = lua_interface->GetStringValue(state, 2);
  7479. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7480. Spawn* target = lua_interface->GetSpawn(state, 4);
  7481. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7482. if (time == 0) {
  7483. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7484. return 0;
  7485. }
  7486. if (function.length() == 0) {
  7487. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7488. return 0;
  7489. }
  7490. if (!spell) {
  7491. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7492. return 0;
  7493. }
  7494. SpellScriptTimer* timer = new SpellScriptTimer;
  7495. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7496. #ifdef WIN32
  7497. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7498. #else
  7499. bzero(timer, sizeof(SpellScriptTimer));
  7500. #endif*/
  7501. timer->caster = 0;
  7502. timer->deleteWhenDone = false;
  7503. timer->target = 0;
  7504. timer->time = Timer::GetCurrentTime2() + time;
  7505. timer->customFunction = function;
  7506. timer->spell = spell;
  7507. if (caster)
  7508. timer->caster = caster->GetID();
  7509. if (target)
  7510. timer->target = target->GetID();
  7511. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7512. return 0;
  7513. }
  7514. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7515. if (!lua_interface)
  7516. return 0;
  7517. float hp_perc = lua_interface->GetFloatValue(state);
  7518. float power_perc = lua_interface->GetFloatValue(state, 2);
  7519. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7520. Spawn* target = lua_interface->GetSpawn(state, 4);
  7521. string heal_name = lua_interface->GetStringValue(state, 5);
  7522. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7523. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7524. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7525. if (!spell) {
  7526. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7527. return 0;
  7528. }
  7529. Entity* caster = spell->caster;
  7530. if (!caster) {
  7531. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7532. return 0;
  7533. }
  7534. Client* client = 0;
  7535. PendingResurrection* rez = 0;
  7536. ZoneServer* zone = spell->caster->GetZone();
  7537. if (!target) {
  7538. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7539. if (spell->targets.size() > 0) {
  7540. vector<int32> spell_targets = spell->targets;
  7541. for (int8 i = 0; i < spell_targets.size(); i++) {
  7542. target = zone->GetSpawnByID(spell_targets.at(i));
  7543. if (!target)
  7544. continue;
  7545. if (!target->IsPlayer())
  7546. continue;
  7547. client = target->GetZone()->GetClientBySpawn(target);
  7548. if (!client)
  7549. continue;
  7550. rez = client->GetCurrentRez();
  7551. if (rez->active)
  7552. continue;
  7553. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7554. rez->active = true;
  7555. rez->caster = caster;
  7556. rez->expire_timer = new Timer;
  7557. int32 duration = spell->spell->GetSpellDuration();
  7558. rez->expire_timer->Start(duration * 100);
  7559. rez->hp_perc = hp_perc;
  7560. rez->mp_perc = power_perc;
  7561. rez->range = spell->spell->GetSpellData()->range;
  7562. rez->spell_name = spell->spell->GetName();
  7563. if (heal_name.length() > 0)
  7564. rez->heal_name = heal_name;
  7565. else
  7566. rez->heal_name = rez->spell_name;
  7567. rez->no_calcs = no_calcs;
  7568. rez->crit_mod = crit_mod;
  7569. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7570. if (send_window)
  7571. client->SendResurrectionWindow();
  7572. else {
  7573. target->GetZone()->ResurrectSpawn(target, client);
  7574. rez->should_delete = true;
  7575. }
  7576. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7577. }
  7578. }
  7579. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7580. }
  7581. else {
  7582. client = target->GetZone()->GetClientBySpawn(target);
  7583. if (!client)
  7584. return 0;
  7585. rez = client->GetCurrentRez();
  7586. if (rez->active)
  7587. return 0;
  7588. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7589. rez->active = true;
  7590. rez->caster = caster;
  7591. rez->expire_timer = new Timer;
  7592. int32 duration = spell->spell->GetSpellDuration();
  7593. rez->expire_timer->Start(duration * 100);
  7594. rez->hp_perc = hp_perc;
  7595. rez->mp_perc = power_perc;
  7596. rez->range = spell->spell->GetSpellData()->range;
  7597. rez->spell_name = spell->spell->GetName();
  7598. if (heal_name.length() > 0)
  7599. rez->heal_name = heal_name;
  7600. else
  7601. rez->heal_name = rez->spell_name;
  7602. rez->no_calcs = no_calcs;
  7603. rez->crit_mod = crit_mod;
  7604. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7605. if (send_window)
  7606. client->SendResurrectionWindow();
  7607. else {
  7608. target->GetZone()->ResurrectSpawn(target, client);
  7609. rez->should_delete = true;
  7610. }
  7611. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7612. }
  7613. return 0;
  7614. }
  7615. int EQ2Emu_lua_SetVision(lua_State* state) {
  7616. if (!lua_interface)
  7617. return 0;
  7618. Spawn* spawn = lua_interface->GetSpawn(state);
  7619. int8 vision = lua_interface->GetInt8Value(state, 2);
  7620. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7621. if (!spawn) {
  7622. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7623. return 0;
  7624. }
  7625. if (!spawn->IsEntity()) {
  7626. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7627. return 0;
  7628. }
  7629. if (spell && spell->targets.size() > 0) {
  7630. ZoneServer* zone = spell->caster->GetZone();
  7631. for (int8 i = 0; i < spell->targets.size(); i++) {
  7632. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7633. if (target && target->IsEntity()) {
  7634. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7635. if (target->IsPlayer())
  7636. ((Player*)target)->SetCharSheetChanged(true);
  7637. }
  7638. }
  7639. }
  7640. else {
  7641. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7642. if (spawn->IsPlayer())
  7643. ((Player*)spawn)->SetCharSheetChanged(true);
  7644. }
  7645. return 0;
  7646. }
  7647. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7648. if (!lua_interface)
  7649. return 0;
  7650. Spawn* spawn = lua_interface->GetSpawn(state);
  7651. float intensity = lua_interface->GetFloatValue(state, 2);
  7652. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7653. if (!spawn) {
  7654. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7655. return 0;
  7656. }
  7657. if (!spawn->IsEntity()) {
  7658. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7659. return 0;
  7660. }
  7661. if (spell && spell->targets.size() > 0) {
  7662. ZoneServer* zone = spell->caster->GetZone();
  7663. for (int8 i = 0; i < spell->targets.size(); i++) {
  7664. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7665. if (target && target->IsEntity()) {
  7666. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7667. if (target->IsPlayer())
  7668. ((Player*)target)->SetCharSheetChanged(true);
  7669. }
  7670. }
  7671. }
  7672. else {
  7673. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7674. if (spawn->IsPlayer())
  7675. ((Player*)spawn)->SetCharSheetChanged(true);
  7676. }
  7677. return 0;
  7678. }
  7679. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7680. if (!lua_interface)
  7681. return 0;
  7682. Spawn* spawn = lua_interface->GetSpawn(state);
  7683. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7684. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7685. if (!spawn) {
  7686. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7687. return 0;
  7688. }
  7689. if (!spawn->IsEntity()) {
  7690. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7691. return 0;
  7692. }
  7693. if (spell && spell->targets.size() > 0) {
  7694. ZoneServer* zone = spell->caster->GetZone();
  7695. for (int8 i = 0; i < spell->targets.size(); i++) {
  7696. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7697. if (target && target->IsEntity()) {
  7698. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7699. if (target->IsPlayer())
  7700. ((Player*)target)->SetCharSheetChanged(true);
  7701. }
  7702. }
  7703. }
  7704. else {
  7705. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7706. if (spawn->IsPlayer())
  7707. ((Player*)spawn)->SetCharSheetChanged(true);
  7708. }
  7709. return 0;
  7710. }
  7711. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7712. if (!lua_interface)
  7713. return 0;
  7714. Item* item = lua_interface->GetItem(state);
  7715. int8 type = lua_interface->GetInt32Value(state, 2);
  7716. if (!item) {
  7717. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7718. return 0;
  7719. }
  7720. if (type == 1)
  7721. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7722. else if (type == 2)
  7723. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7724. return 1;
  7725. }
  7726. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7727. if (!lua_interface)
  7728. return 0;
  7729. Spawn* target = lua_interface->GetSpawn(state);
  7730. float val = lua_interface->GetFloatValue(state, 2);
  7731. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7732. // Added from Gangrenous post
  7733. if (spell && spell->resisted)
  7734. return 0;
  7735. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7736. if (val > 1.0f)
  7737. val = 1.0f - (val / 100.0f);
  7738. if (spell && spell->spell && spell->targets.size() > 0) {
  7739. ZoneServer* zone = spell->caster->GetZone();
  7740. for (int32 i = 0; i != spell->targets.size(); i++) {
  7741. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7742. if (spawn && spawn->IsEntity()) {
  7743. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7744. if (spawn->IsPlayer())
  7745. ((Player*)spawn)->SetCharSheetChanged(true);
  7746. }
  7747. }
  7748. }
  7749. else {
  7750. if (target && target->IsEntity()) {
  7751. ((Entity*)target)->SetSpeedMultiplier(val);
  7752. if (target->IsPlayer())
  7753. ((Player*)target)->SetCharSheetChanged(true);
  7754. }
  7755. }
  7756. return 0;
  7757. }
  7758. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7759. if (!lua_interface)
  7760. return 0;
  7761. Spawn* spawn = lua_interface->GetSpawn(state);
  7762. int16 model = lua_interface->GetInt16Value(state, 2);
  7763. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7764. if (spell && spell->spell && spell->targets.size() > 0) {
  7765. ZoneServer* zone = spell->caster->GetZone();
  7766. for (int32 i = 0; i < spell->targets.size(); i++) {
  7767. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7768. if (target)
  7769. target->SetIllusionModel(model);
  7770. }
  7771. }
  7772. else {
  7773. if (!spawn) {
  7774. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7775. return 0;
  7776. }
  7777. spawn->SetIllusionModel(model);
  7778. }
  7779. return 0;
  7780. }
  7781. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7782. if (!lua_interface)
  7783. return 0;
  7784. Spawn* spawn = lua_interface->GetSpawn(state);
  7785. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7786. if (spell && spell->spell && spell->targets.size() > 0) {
  7787. ZoneServer* zone = spell->caster->GetZone();
  7788. for (int32 i = 0; i < spell->targets.size(); i++) {
  7789. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7790. if (target)
  7791. target->SetIllusionModel(0);
  7792. }
  7793. }
  7794. else {
  7795. if (!spawn) {
  7796. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7797. return 0;
  7798. }
  7799. spawn->SetIllusionModel(0);
  7800. }
  7801. return 0;
  7802. }
  7803. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7804. if (!lua_interface)
  7805. return 0;
  7806. Spawn* caster = lua_interface->GetSpawn(state);
  7807. Spawn* target = lua_interface->GetSpawn(state, 2);
  7808. float chance = lua_interface->GetFloatValue(state, 3);
  7809. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7810. if (!caster) {
  7811. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7812. return 0;
  7813. }
  7814. if (!caster->IsEntity()) {
  7815. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7816. return 0;
  7817. }
  7818. if (!target) {
  7819. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7820. return 0;
  7821. }
  7822. if (!target->IsEntity()) {
  7823. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7824. return 0;
  7825. }
  7826. if (chance <= 0) {
  7827. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7828. return 0;
  7829. }
  7830. if (!spell) {
  7831. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7832. return 0;
  7833. }
  7834. if (((Entity*)caster)->GetThreatTransfer()) {
  7835. return 0;
  7836. }
  7837. ThreatTransfer* transfer = new ThreatTransfer;
  7838. transfer->Target = target->GetID();
  7839. transfer->Amount = chance;
  7840. transfer->Spell = spell;
  7841. ((Entity*)caster)->SetThreatTransfer(transfer);
  7842. return 0;
  7843. }
  7844. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7845. if (!lua_interface)
  7846. return 0;
  7847. Spawn* spawn = lua_interface->GetSpawn(state);
  7848. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7849. if (!spawn) {
  7850. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7851. return 0;
  7852. }
  7853. if (!spell) {
  7854. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7855. return 0;
  7856. }
  7857. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7858. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7859. ((Entity*)spawn)->SetThreatTransfer(0);
  7860. safe_delete(transfer);
  7861. }
  7862. return 0;
  7863. }
  7864. int EQ2Emu_lua_CureByType(lua_State* state) {
  7865. if (!lua_interface)
  7866. return 0;
  7867. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7868. if (!spell) {
  7869. lua_interface->LogError("%s: LUA CureByType command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7870. return 0;
  7871. }
  7872. int8 cure_count = lua_interface->GetInt8Value(state);
  7873. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7874. string cure_name = lua_interface->GetStringValue(state, 3);
  7875. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7876. Spawn* target = lua_interface->GetSpawn(state, 5);
  7877. if (target) {
  7878. if (!target->IsEntity()) {
  7879. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7880. return 0;
  7881. }
  7882. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7883. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7884. }
  7885. else {
  7886. ZoneServer* zone = spell->caster->GetZone();
  7887. vector<int32> targets = spell->targets;
  7888. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7889. for (int8 i = 0; i < targets.size(); i++) {
  7890. target = zone->GetSpawnByID(targets.at(i));
  7891. if (!target || !target->IsEntity())
  7892. continue;
  7893. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0)
  7894. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7895. }
  7896. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7897. }
  7898. return 0;
  7899. }
  7900. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7901. if (!lua_interface)
  7902. return 0;
  7903. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7904. if (!spell) {
  7905. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7906. return 0;
  7907. }
  7908. int8 cure_count = lua_interface->GetInt8Value(state);
  7909. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7910. string cure_name = lua_interface->GetStringValue(state, 3);
  7911. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7912. Spawn* target = lua_interface->GetSpawn(state, 5);
  7913. if (target) {
  7914. if (!target->IsEntity()) {
  7915. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7916. return 0;
  7917. }
  7918. if (((Entity*)target)->GetDetCount() > 0)
  7919. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7920. }
  7921. else {
  7922. ZoneServer* zone = spell->caster->GetZone();
  7923. vector<int32> targets = spell->targets;
  7924. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7925. for (int8 i = 0; i < targets.size(); i++) {
  7926. target = zone->GetSpawnByID(targets.at(i));
  7927. if (!target || !target->IsEntity())
  7928. continue;
  7929. if (((Entity*)target)->GetDetCount() > 0)
  7930. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7931. }
  7932. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7933. }
  7934. return 0;
  7935. }
  7936. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  7937. if (!lua_interface)
  7938. return 0;
  7939. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7940. if (!spell) {
  7941. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  7942. return 0;
  7943. }
  7944. if (!spell->caster) {
  7945. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  7946. return 0;
  7947. }
  7948. if (!spell->caster->GetZone()) {
  7949. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  7950. return 0;
  7951. }
  7952. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  7953. return 0;
  7954. }
  7955. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  7956. if (!lua_interface)
  7957. return 0;
  7958. Spawn* spawn = lua_interface->GetSpawn(state);
  7959. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7960. if (!spell) {
  7961. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  7962. return 0;
  7963. }
  7964. if (spawn && spawn->IsEntity())
  7965. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7966. else {
  7967. ZoneServer* zone = spell->caster->GetZone();
  7968. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7969. for (int32 i = 0; i < spell->targets.size(); i++) {
  7970. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7971. if (!spawn || !spawn->IsEntity())
  7972. continue;
  7973. ((Entity*)spawn)->RemoveStealthSpell(spell);
  7974. }
  7975. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7976. }
  7977. return 0;
  7978. }
  7979. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  7980. if (!lua_interface)
  7981. return 0;
  7982. Spawn* spawn = lua_interface->GetSpawn(state);
  7983. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7984. if (!spell) {
  7985. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  7986. return 0;
  7987. }
  7988. if (spawn && spawn->IsEntity())
  7989. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7990. else {
  7991. ZoneServer* zone = spell->caster->GetZone();
  7992. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7993. for (int32 i = 0; i < spell->targets.size(); i++) {
  7994. spawn = zone->GetSpawnByID(spell->targets.at(i));
  7995. if (!spawn || !spawn->IsEntity())
  7996. continue;
  7997. ((Entity*)spawn)->RemoveInvisSpell(spell);
  7998. }
  7999. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8000. }
  8001. return 0;
  8002. }
  8003. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8004. if (!lua_interface)
  8005. return 0;
  8006. Spawn* caster = lua_interface->GetSpawn(state);
  8007. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8008. if (!caster) {
  8009. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8010. return 0;
  8011. }
  8012. if (!caster->IsPlayer()) {
  8013. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8014. return 0;
  8015. }
  8016. Spawn* target = caster->GetTarget();
  8017. if (!target) {
  8018. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8019. return 0;
  8020. }
  8021. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  8022. if (!client) {
  8023. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8024. return 0;
  8025. }
  8026. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8027. if (ho) {
  8028. ho->SetTarget(target->GetID());
  8029. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8030. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8031. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8032. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8033. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8034. deque<GroupMemberInfo*>::iterator itr;
  8035. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8036. if (group)
  8037. {
  8038. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8039. deque<GroupMemberInfo*>* members = group->GetMembers();
  8040. for (itr = members->begin(); itr != members->end(); itr++) {
  8041. if ((*itr)->client)
  8042. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8043. }
  8044. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8045. }
  8046. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8047. }
  8048. else
  8049. safe_delete(ho);
  8050. }
  8051. else {
  8052. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8053. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8054. }
  8055. else
  8056. safe_delete(ho);
  8057. }
  8058. }
  8059. return 0;
  8060. }
  8061. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8062. if (!lua_interface)
  8063. return 0;
  8064. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8065. if (!spell) {
  8066. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8067. return 0;
  8068. }
  8069. int16 triggerCount = lua_interface->GetInt16Value(state);
  8070. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8071. if (!triggerCount) {
  8072. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8073. return 0;
  8074. }
  8075. spell->num_triggers = triggerCount;
  8076. spell->had_triggers = true;
  8077. spell->cancel_after_all_triggers = cancel_after_triggers;
  8078. return 0;
  8079. }
  8080. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8081. if (!lua_interface)
  8082. return 0;
  8083. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8084. if (!spell) {
  8085. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8086. return 0;
  8087. }
  8088. lua_interface->SetInt32Value(state, spell->num_triggers);
  8089. return 1;
  8090. }
  8091. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8092. if (!lua_interface)
  8093. return 0;
  8094. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8095. if (!spell) {
  8096. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8097. return 0;
  8098. }
  8099. int16 remove_count = lua_interface->GetInt16Value(state);
  8100. if (!remove_count)
  8101. remove_count = 1;
  8102. if (remove_count >= spell->num_triggers) {
  8103. spell->num_triggers = 0;
  8104. if (spell->cancel_after_all_triggers)
  8105. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8106. }
  8107. else {
  8108. spell->num_triggers -= remove_count;
  8109. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  8110. }
  8111. return 0;
  8112. }
  8113. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8114. if (!lua_interface)
  8115. return 0;
  8116. Spawn* spawn = lua_interface->GetSpawn(state);
  8117. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8118. if (!spawn) {
  8119. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8120. return 0;
  8121. }
  8122. if (!copy_spawn) {
  8123. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8124. return 0;
  8125. }
  8126. spawn->CopySpawnAppearance(copy_spawn);
  8127. return 0;
  8128. }
  8129. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8130. Spawn* spawn = lua_interface->GetSpawn(state);
  8131. int8 type = lua_interface->GetInt8Value(state, 2);
  8132. if (!spawn) {
  8133. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8134. return 0;
  8135. }
  8136. else if (!spawn->IsEntity()) {
  8137. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8138. return 0;
  8139. }
  8140. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8141. return 1;
  8142. }
  8143. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8144. if (!lua_interface)
  8145. return 0;
  8146. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8147. int8 type = lua_interface->GetInt8Value(state);
  8148. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8149. if (!spell) {
  8150. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8151. return 0;
  8152. }
  8153. if (spawn) {
  8154. if (!spawn->IsEntity()) {
  8155. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8156. return 0;
  8157. }
  8158. Entity* entity = ((Entity*)spawn);
  8159. entity->AddImmunity(spell, type);
  8160. }
  8161. else {
  8162. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8163. for (int8 i = 0; i < spell->targets.size(); i++) {
  8164. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8165. if (!spawn || !spawn->IsEntity())
  8166. continue;
  8167. Entity* entity = ((Entity*)spawn);
  8168. entity->AddImmunity(spell, type);
  8169. }
  8170. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8171. }
  8172. return 0;
  8173. }
  8174. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8175. if (!lua_interface)
  8176. return 0;
  8177. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8178. int8 type = lua_interface->GetInt8Value(state);
  8179. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8180. if (!spell) {
  8181. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8182. return 0;
  8183. }
  8184. if (spawn) {
  8185. if (!spawn->IsEntity()) {
  8186. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8187. return 0;
  8188. }
  8189. Entity* entity = ((Entity*)spawn);
  8190. entity->RemoveImmunity(spell, type);
  8191. }
  8192. else {
  8193. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8194. for (int8 i = 0; i < spell->targets.size(); i++) {
  8195. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8196. if (!spawn || !spawn->IsEntity())
  8197. continue;
  8198. Entity* entity = ((Entity*)spawn);
  8199. entity->RemoveImmunity(spell, type);
  8200. }
  8201. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8202. }
  8203. return 0;
  8204. }
  8205. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8206. if (!lua_interface)
  8207. return 0;
  8208. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8209. if (!spell) {
  8210. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8211. return 0;
  8212. }
  8213. float snare = lua_interface->GetFloatValue(state);
  8214. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8215. // convert the val to the speed multipler value (100 - val)
  8216. float val = 100.0 - snare;
  8217. val /= 100.0;
  8218. if (spawn) {
  8219. if (!spawn->IsEntity()) {
  8220. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8221. return 0;
  8222. }
  8223. ((Entity*)spawn)->SetSnareValue(spell, val);
  8224. }
  8225. else {
  8226. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8227. for (int8 i = 0; i < spell->targets.size(); i++) {
  8228. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8229. if (!spawn || !spawn->IsEntity())
  8230. continue;
  8231. ((Entity*)spawn)->SetSnareValue(spell, val);
  8232. }
  8233. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8234. }
  8235. return 0;
  8236. }
  8237. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8238. if (!lua_interface)
  8239. return 0;
  8240. Spawn* spawn = lua_interface->GetSpawn(state);
  8241. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8242. if (!spawn) {
  8243. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8244. return 0;
  8245. }
  8246. if (race_id == 0) {
  8247. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8248. return 0;
  8249. }
  8250. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8251. return 1;
  8252. }
  8253. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8254. if (!lua_interface)
  8255. return 0;
  8256. Spawn* spawn = lua_interface->GetSpawn(state);
  8257. if (!spawn) {
  8258. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8259. return 0;
  8260. }
  8261. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8262. return 1;
  8263. }
  8264. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8265. if (!lua_interface)
  8266. return 0;
  8267. Spawn* spawn = lua_interface->GetSpawn(state);
  8268. if (!spawn) {
  8269. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8270. return 0;
  8271. }
  8272. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8273. return 1;
  8274. }
  8275. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8276. if (!lua_interface)
  8277. return 0;
  8278. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8279. if (!spell) {
  8280. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8281. return 0;
  8282. }
  8283. lua_interface->SetStringValue(state, spell->spell->GetName());
  8284. return 1;
  8285. }
  8286. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8287. if (!lua_interface)
  8288. return 0;
  8289. Quest* quest = lua_interface->GetQuest(state);
  8290. if (!quest) {
  8291. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8292. return 0;
  8293. }
  8294. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8295. return 1;
  8296. }
  8297. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8298. if (!lua_interface)
  8299. return 0;
  8300. Quest* quest = lua_interface->GetQuest(state);
  8301. int32 flags = lua_interface->GetInt32Value(state, 2);
  8302. if (!quest) {
  8303. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8304. return 0;
  8305. }
  8306. quest->SetQuestFlags(flags);
  8307. return 0;
  8308. }
  8309. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8310. if (!lua_interface)
  8311. return 0;
  8312. Quest* quest = lua_interface->GetQuest(state);
  8313. Spawn* player = lua_interface->GetSpawn(state, 2);
  8314. int32 step = lua_interface->GetInt32Value(state, 3);
  8315. int32 duration = lua_interface->GetInt32Value(state, 4);
  8316. string action = lua_interface->GetStringValue(state, 5);
  8317. if (!quest) {
  8318. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8319. return 0;
  8320. }
  8321. if (!player) {
  8322. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8323. return 0;
  8324. }
  8325. if (!player->IsPlayer()) {
  8326. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8327. return 0;
  8328. }
  8329. if (step == 0) {
  8330. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8331. return 0;
  8332. }
  8333. if (duration == 0) {
  8334. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8335. return 0;
  8336. }
  8337. if (action.length() == 0) {
  8338. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8339. return 0;
  8340. }
  8341. Client* client = player->GetZone()->GetClientBySpawn(player);
  8342. if (!client) {
  8343. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8344. return 0;
  8345. }
  8346. quest->SetTimerStep(step);
  8347. quest->AddFailedAction(step, action);
  8348. quest->SetStepTimer(duration);
  8349. client->AddQuestTimer(quest->GetQuestID());
  8350. return 0;
  8351. }
  8352. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8353. if (!lua_interface)
  8354. return 0;
  8355. Quest* quest = lua_interface->GetQuest(state);
  8356. Spawn* player = lua_interface->GetSpawn(state, 2);
  8357. if (!quest) {
  8358. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8359. return 0;
  8360. }
  8361. if (!player) {
  8362. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8363. return 0;
  8364. }
  8365. if (!player->IsPlayer()) {
  8366. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8367. return 0;
  8368. }
  8369. Client* client = player->GetZone()->GetClientBySpawn(player);
  8370. if (!client) {
  8371. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8372. return 0;
  8373. }
  8374. quest->SetTimerStep(0);
  8375. quest->SetStepTimer(0);
  8376. client->RemoveQuestTimer(quest->GetQuestID());
  8377. return 0;
  8378. }
  8379. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8380. if (!lua_interface)
  8381. return 0;
  8382. Spawn* player = lua_interface->GetSpawn(state);
  8383. Quest* quest = lua_interface->GetQuest(state, 2);
  8384. int32 step = lua_interface->GetInt32Value(state, 3);
  8385. if (!player) {
  8386. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8387. return 0;
  8388. }
  8389. if (!player->IsPlayer()) {
  8390. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8391. return 0;
  8392. }
  8393. if (!quest) {
  8394. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8395. return 0;
  8396. }
  8397. if (step == 0) {
  8398. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8399. return 0;
  8400. }
  8401. Client* client = player->GetZone()->GetClientBySpawn(player);
  8402. if (!client) {
  8403. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8404. return 0;
  8405. }
  8406. if (quest->RemoveQuestStep(step, client)) {
  8407. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8408. client->GetCurrentZone()->SendQuestUpdates(client);
  8409. }
  8410. else
  8411. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8412. return 0;
  8413. }
  8414. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8415. if (!lua_interface)
  8416. return 0;
  8417. Quest* quest = lua_interface->GetQuest(state, 1);
  8418. int32 step = lua_interface->GetInt32Value(state, 2);
  8419. string desc = lua_interface->GetStringValue(state, 3);
  8420. string task_group = lua_interface->GetStringValue(state, 4);
  8421. if (!quest) {
  8422. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8423. return 0;
  8424. }
  8425. if (step == 0) {
  8426. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8427. return 0;
  8428. }
  8429. QuestStep* quest_step = quest->GetQuestStep(step);
  8430. if (!quest_step) {
  8431. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8432. return 0;
  8433. }
  8434. quest_step->SetStepProgress(0);
  8435. quest_step->SetTaskGroup(task_group);
  8436. quest_step->SetDescription(desc);
  8437. return 0;
  8438. }
  8439. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8440. if (!lua_interface)
  8441. return 0;
  8442. Quest* quest = lua_interface->GetQuest(state);
  8443. int32 step = lua_interface->GetInt32Value(state, 2);
  8444. string action = lua_interface->GetStringValue(state, 3);
  8445. if (!quest) {
  8446. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8447. return 0;
  8448. }
  8449. if (step == 0) {
  8450. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8451. return 0;
  8452. }
  8453. if (action.length() == 0) {
  8454. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8455. return 0;
  8456. }
  8457. quest->AddFailedAction(step, action);
  8458. return 0;
  8459. }
  8460. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8461. if (!lua_interface)
  8462. return 0;
  8463. Spawn* player = lua_interface->GetSpawn(state);
  8464. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8465. int32 step = lua_interface->GetInt32Value(state, 3);
  8466. if (!player) {
  8467. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8468. return 0;
  8469. }
  8470. if (!player->IsPlayer()) {
  8471. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8472. return 0;
  8473. }
  8474. if (quest_id == 0) {
  8475. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8476. return 0;
  8477. }
  8478. if (step == 0) {
  8479. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8480. return 0;
  8481. }
  8482. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8483. if (!quest) {
  8484. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8485. return 0;
  8486. }
  8487. quest->StepFailed(step);
  8488. return 0;
  8489. }
  8490. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8491. if (!lua_interface)
  8492. return 0;
  8493. Spawn* player = lua_interface->GetSpawn(state);
  8494. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8495. if (!player) {
  8496. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8497. return 0;
  8498. }
  8499. if (!player->IsPlayer()) {
  8500. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8501. return 0;
  8502. }
  8503. if (quest_id == 0) {
  8504. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8505. return 0;
  8506. }
  8507. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8508. if (!quest) {
  8509. lua_interface->SetInt32Value(state, 0);
  8510. return 1;
  8511. }
  8512. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8513. return 1;
  8514. }
  8515. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8516. if (!lua_interface)
  8517. return 0;
  8518. string name = lua_interface->GetStringValue(state);
  8519. string value = lua_interface->GetStringValue(state, 2);
  8520. string comment = lua_interface->GetStringValue(state, 3);
  8521. if (name.length() == 0) {
  8522. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8523. return 0;
  8524. }
  8525. if (value.length() == 0) {
  8526. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8527. return 0;
  8528. }
  8529. string varname = string("lua_").append(name);
  8530. Variable* var = variables.FindVariable(varname);
  8531. if (var)
  8532. var->SetValue(value.c_str());
  8533. else {
  8534. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8535. variables.AddVariable(var);
  8536. }
  8537. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8538. return 0;
  8539. }
  8540. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8541. if (!lua_interface)
  8542. return 0;
  8543. string name = lua_interface->GetStringValue(state);
  8544. if (name.length() == 0) {
  8545. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8546. return 0;
  8547. }
  8548. string varname = string("lua_").append(name);
  8549. Variable* var = variables.FindVariable(varname);
  8550. if (var)
  8551. lua_interface->SetStringValue(state, var->GetValue());
  8552. else
  8553. lua_interface->SetStringValue(state, "NULL");
  8554. return 1;
  8555. }
  8556. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8557. if (!lua_interface)
  8558. return 0;
  8559. Spawn* player = lua_interface->GetSpawn(state);
  8560. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8561. if (!player) {
  8562. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8563. return 0;
  8564. }
  8565. if (!player->IsPlayer()) {
  8566. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8567. return 0;
  8568. }
  8569. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8570. return 1;
  8571. }
  8572. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8573. if (!lua_interface)
  8574. return 0;
  8575. Spawn* player = lua_interface->GetSpawn(state);
  8576. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8577. if (!player) {
  8578. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8579. return 0;
  8580. }
  8581. if (!player->IsPlayer()) {
  8582. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8583. return 0;
  8584. }
  8585. Language* language = master_languages_list.GetLanguage(language_id);
  8586. if (language)
  8587. {
  8588. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8589. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID());
  8590. }
  8591. return 0;
  8592. }
  8593. int EQ2Emu_lua_IsNight(lua_State* state) {
  8594. if (!lua_interface)
  8595. return 0;
  8596. ZoneServer* zone = lua_interface->GetZone(state);
  8597. if (!zone) {
  8598. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8599. return 0;
  8600. }
  8601. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8602. return 1;
  8603. }
  8604. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8605. if (!lua_interface)
  8606. return 0;
  8607. Spawn* spawn = lua_interface->GetSpawn(state);
  8608. if (!spawn) {
  8609. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8610. return 0;
  8611. }
  8612. if (!spawn->IsWidget()) {
  8613. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8614. return 0;
  8615. }
  8616. ((Widget*)spawn)->SetMultiFloorLift(true);
  8617. if (spawn->GetZone())
  8618. spawn->GetZone()->AddTransportSpawn(spawn);
  8619. return 0;
  8620. }
  8621. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8622. if (!lua_interface)
  8623. return 0;
  8624. Spawn* player = lua_interface->GetSpawn(state);
  8625. int32 path = lua_interface->GetInt32Value(state, 2);
  8626. if (!player) {
  8627. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8628. return 0;
  8629. }
  8630. if (!player->IsPlayer()) {
  8631. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8632. return 0;
  8633. }
  8634. if (path == 0) {
  8635. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8636. return 0;
  8637. }
  8638. Client* client = player->GetZone()->GetClientBySpawn(player);
  8639. if (!client) {
  8640. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8641. return 0;
  8642. }
  8643. client->SendFlightAutoMount(path);
  8644. return 0;
  8645. }
  8646. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8647. if (!lua_interface)
  8648. return 0;
  8649. Spawn* player = lua_interface->GetSpawn(state);
  8650. if (!player) {
  8651. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8652. return 0;
  8653. }
  8654. if (!player->IsPlayer()) {
  8655. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8656. return 0;
  8657. }
  8658. Client* client = player->GetZone()->GetClientBySpawn(player);
  8659. if (!client) {
  8660. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8661. return 0;
  8662. }
  8663. client->EndAutoMount();
  8664. return 0;
  8665. }
  8666. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8667. if (!lua_interface)
  8668. return 0;
  8669. Spawn* player = lua_interface->GetSpawn(state);
  8670. if (!player) {
  8671. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8672. return 0;
  8673. }
  8674. if (!player->IsPlayer()) {
  8675. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8676. return 0;
  8677. }
  8678. Client* client = player->GetZone()->GetClientBySpawn(player);
  8679. if (!client) {
  8680. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8681. return 0;
  8682. }
  8683. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8684. return 1;
  8685. }
  8686. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8687. if (!lua_interface)
  8688. return 0;
  8689. Spawn* player = lua_interface->GetSpawn(state);
  8690. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8691. int32 value = lua_interface->GetInt32Value(state, 3);
  8692. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8693. if (!player) {
  8694. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8695. return 0;
  8696. }
  8697. if (!player->IsPlayer()) {
  8698. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8699. return 0;
  8700. }
  8701. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8702. return 0;
  8703. }
  8704. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8705. if (!lua_interface)
  8706. return 0;
  8707. Spawn* player = lua_interface->GetSpawn(state);
  8708. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8709. if (!player) {
  8710. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8711. return 0;
  8712. }
  8713. if (!player->IsPlayer()) {
  8714. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8715. return 0;
  8716. }
  8717. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8718. if (!hd)
  8719. return 0;
  8720. lua_interface->SetInt32Value(state, hd->Value);
  8721. lua_interface->SetInt32Value(state, hd->Value2);
  8722. return 2;
  8723. }
  8724. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8725. if (!lua_interface)
  8726. return 0;
  8727. Spawn* spawn = lua_interface->GetSpawn(state);
  8728. int32 grid = lua_interface->GetInt32Value(state, 2);
  8729. if (!spawn) {
  8730. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8731. return 0;
  8732. }
  8733. if (grid == 0) {
  8734. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8735. return 0;
  8736. }
  8737. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8738. return 0;
  8739. }
  8740. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8741. if (!lua_interface)
  8742. return 0;
  8743. Spawn* spawn = lua_interface->GetSpawn(state);
  8744. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8745. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8746. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8747. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8748. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8749. if (!spawn) {
  8750. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8751. return 0;
  8752. }
  8753. //Add this quest to the list of required quests for this spawn
  8754. spawn->SetRequiredHistory(event_id, value1, value2);
  8755. //If private spawn value set
  8756. if (private_spawn) {
  8757. //Set the spawn to be private when not granted access via history
  8758. spawn->AddAllowAccessSpawn(spawn);
  8759. spawn->SetPrivateQuestSpawn(true);
  8760. }
  8761. //This value will override vis_flags in the vis packet
  8762. if (flag_override > 0)
  8763. spawn->SetQuestsRequiredOverride(flag_override);
  8764. return 0;
  8765. }
  8766. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8767. if (!lua_interface)
  8768. return 0;
  8769. Spawn* player = lua_interface->GetSpawn(state);
  8770. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8771. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8772. if (!player) {
  8773. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8774. return 0;
  8775. }
  8776. if (!player->IsPlayer()) {
  8777. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8778. return 0;
  8779. }
  8780. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8781. return 1;
  8782. }
  8783. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8784. if (!lua_interface)
  8785. return 0;
  8786. Spawn* player = lua_interface->GetSpawn(state);
  8787. int8 level = lua_interface->GetInt8Value(state, 2);
  8788. if (!player) {
  8789. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8790. return 0;
  8791. }
  8792. if (!player->IsPlayer()) {
  8793. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8794. return 0;
  8795. }
  8796. if (level == 0) {
  8797. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8798. return 0;
  8799. }
  8800. Client* client = player->GetZone()->GetClientBySpawn(player);
  8801. if (!client) {
  8802. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8803. return 0;
  8804. }
  8805. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8806. return 0;
  8807. }
  8808. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8809. if (!lua_interface)
  8810. return 0;
  8811. Spawn* player = lua_interface->GetSpawn(state);
  8812. int32 amount = lua_interface->GetInt32Value(state, 2);
  8813. if (!player) {
  8814. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8815. return 0;
  8816. }
  8817. if (!player->IsPlayer()) {
  8818. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8819. return 0;
  8820. }
  8821. if (amount == 0) {
  8822. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8823. return 0;
  8824. }
  8825. ((Player*)player)->AddCoins(amount);
  8826. return 0;
  8827. }
  8828. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8829. if (!lua_interface)
  8830. return 0;
  8831. Spawn* player = lua_interface->GetSpawn(state);
  8832. int32 amount = lua_interface->GetInt32Value(state, 2);
  8833. if (!player) {
  8834. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8835. return 0;
  8836. }
  8837. if (!player->IsPlayer()) {
  8838. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8839. return 0;
  8840. }
  8841. if (amount == 0) {
  8842. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8843. return 0;
  8844. }
  8845. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8846. return 1;
  8847. }
  8848. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8849. if (!lua_interface)
  8850. return 0;
  8851. ZoneServer* zone = lua_interface->GetZone(state);
  8852. if (!zone) {
  8853. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8854. return 0;
  8855. }
  8856. vector<Entity*> players = zone->GetPlayers();
  8857. if (players.size() == 0)
  8858. return 0;
  8859. lua_createtable(state, players.size(), 0);
  8860. int newTable = lua_gettop(state);
  8861. for (int32 i = 0; i < players.size(); i++) {
  8862. lua_interface->SetSpawnValue(state, players.at(i));
  8863. lua_rawseti(state, newTable, i + 1);
  8864. }
  8865. return 1;
  8866. }
  8867. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8868. if (!lua_interface)
  8869. return 0;
  8870. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8871. if (!zone) {
  8872. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8873. return 0;
  8874. }
  8875. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8876. //Map of <placement_id, location_id>
  8877. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8878. map<int32, int32>::iterator itr;
  8879. vector<Spawn*> group;
  8880. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8881. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8882. if (!location) {
  8883. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8884. return 0;
  8885. }
  8886. Spawn* spawn = 0;
  8887. if (location->entities[0]) {
  8888. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8889. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8890. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8891. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8892. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8893. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8894. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8895. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8896. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8897. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8898. if(spawn && spawn->IsOmittedByDBFlag())
  8899. {
  8900. 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);
  8901. safe_delete(spawn);
  8902. continue;
  8903. }
  8904. if (spawn) {
  8905. const char* script = 0;
  8906. for (int x = 0; x < 3; x++) {
  8907. switch (x) {
  8908. case 0:
  8909. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  8910. break;
  8911. case 1:
  8912. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  8913. break;
  8914. case 2:
  8915. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  8916. break;
  8917. }
  8918. if (script && lua_interface->GetSpawnScript(script) != 0) {
  8919. spawn->SetSpawnScript(string(script));
  8920. break;
  8921. }
  8922. }
  8923. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  8924. lua_interface->SetSpawnValue(state, spawn);
  8925. group.push_back(spawn);
  8926. }
  8927. else {
  8928. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  8929. safe_delete(spawn);
  8930. }
  8931. }
  8932. }
  8933. if (!group.empty()) {
  8934. lua_createtable(state, group.size(), 0);
  8935. int newTable = lua_gettop(state);
  8936. for (int32 i = 0; i < group.size(); i++) {
  8937. lua_interface->SetSpawnValue(state, group[i]);
  8938. lua_rawseti(state, newTable, i + 1);
  8939. }
  8940. }
  8941. else
  8942. lua_pushnil(state);
  8943. return 1;
  8944. }
  8945. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  8946. if (!lua_interface)
  8947. return 0;
  8948. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  8949. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  8950. int16 leeway = lua_interface->GetInt16Value(state, 3);
  8951. if (!spawn) {
  8952. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  8953. return 0;
  8954. }
  8955. if (anim_id == 0) {
  8956. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  8957. return 0;
  8958. }
  8959. if (leeway == 0)
  8960. leeway = 5000;
  8961. spawn->SetSpawnAnim(anim_id);
  8962. spawn->SetSpawnAnimLeeway(leeway);
  8963. return 0;
  8964. }
  8965. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  8966. if (!lua_interface)
  8967. return 0;
  8968. Spawn* player = lua_interface->GetSpawn(state);
  8969. if (!player) {
  8970. return 0;
  8971. }
  8972. Client* client = player->GetZone()->GetClientBySpawn(player);
  8973. if (!client) {
  8974. return 0;
  8975. }
  8976. lua_interface->SetInt32Value(state, client->GetVersion());
  8977. return 1;
  8978. }
  8979. int EQ2Emu_lua_GetItemID(lua_State* state) {
  8980. if (!lua_interface)
  8981. return 0;
  8982. Item* item = lua_interface->GetItem(state);
  8983. if (!item) {
  8984. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  8985. return 0;
  8986. }
  8987. lua_interface->SetInt32Value(state, item->details.item_id);
  8988. return 1;
  8989. }
  8990. int EQ2Emu_lua_IsEntity(lua_State* state) {
  8991. if (!lua_interface)
  8992. return 0;
  8993. Spawn* spawn = lua_interface->GetSpawn(state);
  8994. if (!spawn) {
  8995. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  8996. return 0;
  8997. }
  8998. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  8999. return 1;
  9000. }
  9001. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9002. if (!lua_interface)
  9003. return 0;
  9004. Spawn* spawn = lua_interface->GetSpawn(state);
  9005. if (!spawn) {
  9006. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9007. return 0;
  9008. }
  9009. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9010. return 1;
  9011. }
  9012. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9013. if (!lua_interface)
  9014. return 0;
  9015. Spawn* spawn = lua_interface->GetSpawn(state);
  9016. if (!spawn) {
  9017. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9018. return 0;
  9019. }
  9020. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9021. return 1;
  9022. }
  9023. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9024. if (!lua_interface)
  9025. return 0;
  9026. Spawn* spawn = lua_interface->GetSpawn(state);
  9027. if (!spawn) {
  9028. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9029. return 0;
  9030. }
  9031. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9032. return 1;
  9033. }
  9034. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9035. if (!lua_interface)
  9036. return 0;
  9037. Spawn* spawn = lua_interface->GetSpawn(state);
  9038. float pct = lua_interface->GetFloatValue(state, 2);
  9039. if (!spawn) {
  9040. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9041. return 0;
  9042. }
  9043. if (pct == 0) {
  9044. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9045. return 0;
  9046. }
  9047. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9048. lua_interface->SetInt32Value(state, amount);
  9049. return 1;
  9050. }
  9051. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9052. if (!lua_interface)
  9053. return 0;
  9054. Spawn* spawn = lua_interface->GetSpawn(state);
  9055. float pct = lua_interface->GetFloatValue(state, 2);
  9056. if (!spawn) {
  9057. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9058. return 0;
  9059. }
  9060. if (pct == 0) {
  9061. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9062. return 0;
  9063. }
  9064. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9065. lua_interface->SetInt32Value(state, amount);
  9066. return 1;
  9067. }
  9068. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9069. if (!lua_interface)
  9070. return 0;
  9071. Spawn* spawn = lua_interface->GetSpawn(state);
  9072. if (!spawn) {
  9073. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9074. return 0;
  9075. }
  9076. if (!spawn->IsPlayer()) {
  9077. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9078. return 0;
  9079. }
  9080. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9081. return 1;
  9082. }
  9083. int EQ2Emu_lua_Evac(lua_State* state) {
  9084. if (!lua_interface)
  9085. return 0;
  9086. Spawn* target = lua_interface->GetSpawn(state);
  9087. if (target) {
  9088. float x = target->GetZone()->GetSafeX();
  9089. float y = target->GetZone()->GetSafeY();
  9090. float z = target->GetZone()->GetSafeZ();
  9091. float h = target->GetZone()->GetSafeHeading();
  9092. target->SetX(x);
  9093. target->SetY(y);
  9094. target->SetZ(z);
  9095. target->SetHeading(h);
  9096. target->SetSpawnOrigX(x);
  9097. target->SetSpawnOrigY(y);
  9098. target->SetSpawnOrigZ(z);
  9099. target->SetSpawnOrigHeading(h);
  9100. if (target->IsPlayer()) {
  9101. Client* client = target->GetZone()->GetClientBySpawn(target);
  9102. if (client) {
  9103. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9104. int numargs = lua_interface->GetNumberOfArgs(state);
  9105. if(numargs == 4) {
  9106. x = lua_interface->GetFloatValue(state,1);
  9107. y = lua_interface->GetFloatValue(state,2);
  9108. z = lua_interface->GetFloatValue(state,3);
  9109. h = lua_interface->GetFloatValue(state,4);
  9110. }
  9111. client->SetReloadingZone(true);
  9112. target->SetX(x);
  9113. target->SetY(y);
  9114. target->SetZ(z);
  9115. target->SetHeading(h);
  9116. target->SetSpawnOrigX(x);
  9117. target->SetSpawnOrigY(y);
  9118. target->SetSpawnOrigZ(z);
  9119. target->SetSpawnOrigHeading(h);
  9120. target->SetAppearancePosition(x,y,z);
  9121. client->SetZoningCoords(x,y,z,h);
  9122. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9123. if (packet)
  9124. {
  9125. packet->setDataByName("x", x);
  9126. packet->setDataByName("y", y);
  9127. packet->setDataByName("z", z);
  9128. client->QueuePacket(packet->serialize());
  9129. safe_delete(packet);
  9130. }
  9131. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9132. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9133. }
  9134. }
  9135. }
  9136. else {
  9137. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9138. ZoneServer* zone = spell->caster->GetZone();
  9139. float x = spell->caster->GetZone()->GetSafeX();
  9140. float y = spell->caster->GetZone()->GetSafeY();
  9141. float z = spell->caster->GetZone()->GetSafeZ();
  9142. float h = spell->caster->GetZone()->GetSafeHeading();
  9143. int numargs = lua_interface->GetNumberOfArgs(state);
  9144. if(numargs == 4) {
  9145. x = lua_interface->GetFloatValue(state,1);
  9146. y = lua_interface->GetFloatValue(state,2);
  9147. z = lua_interface->GetFloatValue(state,3);
  9148. h = lua_interface->GetFloatValue(state,4);
  9149. }
  9150. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9151. for (int32 i = 0; i < spell->targets.size(); i++) {
  9152. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9153. if (!target2)
  9154. continue;
  9155. if (target2->IsPlayer()) {
  9156. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  9157. if (client) {
  9158. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9159. client->SetReloadingZone(true);
  9160. target2->SetX(x);
  9161. target2->SetY(y);
  9162. target2->SetZ(z);
  9163. target2->SetHeading(h);
  9164. target2->SetSpawnOrigX(x);
  9165. target2->SetSpawnOrigY(y);
  9166. target2->SetSpawnOrigZ(z);
  9167. target2->SetSpawnOrigHeading(h);
  9168. target2->SetAppearancePosition(x,y,z);
  9169. client->SetZoningCoords(x,y,z,h);
  9170. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9171. if (packet)
  9172. {
  9173. packet->setDataByName("x", x);
  9174. packet->setDataByName("y", y);
  9175. packet->setDataByName("z", z);
  9176. client->QueuePacket(packet->serialize());
  9177. safe_delete(packet);
  9178. }
  9179. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9180. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9181. }
  9182. }
  9183. }
  9184. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9185. }
  9186. return 0;
  9187. }
  9188. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9189. if (!lua_interface)
  9190. return 0;
  9191. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9192. if (!luaspell) {
  9193. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9194. return 0;
  9195. }
  9196. int8 tier = luaspell->spell->GetSpellTier();
  9197. lua_interface->SetInt32Value(state, tier);
  9198. return 1;
  9199. }
  9200. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9201. if (!lua_interface)
  9202. return 0;
  9203. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9204. if (!luaspell) {
  9205. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9206. return 0;
  9207. }
  9208. int32 spell_id = luaspell->spell->GetSpellID();
  9209. lua_interface->SetInt32Value(state, spell_id);
  9210. return 1;
  9211. }
  9212. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9213. if (!lua_interface)
  9214. return 0;
  9215. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9216. if (!spawn) {
  9217. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9218. return 0;
  9219. }
  9220. if (!spawn->IsPlayer()) {
  9221. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9222. return 0;
  9223. }
  9224. ZoneServer* zone = spawn->GetZone();
  9225. if (!zone) {
  9226. return 0;
  9227. }
  9228. Client* client = zone->GetClientBySpawn(spawn);
  9229. if (!client) {
  9230. return 0;
  9231. }
  9232. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9233. return 0;
  9234. }
  9235. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9236. if (!lua_interface)
  9237. return 0;
  9238. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9239. if (!spawn) {
  9240. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9241. return 0;
  9242. }
  9243. if (!spawn->IsPlayer()) {
  9244. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9245. return 0;
  9246. }
  9247. ZoneServer* zone = spawn->GetZone();
  9248. if (!zone) {
  9249. return 0;
  9250. }
  9251. Client* client = zone->GetClientBySpawn(spawn);
  9252. if (!client) {
  9253. return 0;
  9254. }
  9255. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9256. return 0;
  9257. }
  9258. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9259. if (!lua_interface)
  9260. return 0;
  9261. Spawn* caster = lua_interface->GetSpawn(state);
  9262. Spawn* target = lua_interface->GetSpawn(state, 2);
  9263. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9264. string spell_name = lua_interface->GetStringValue(state, 4);
  9265. if (!caster) {
  9266. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9267. return 0;
  9268. }
  9269. if (!caster->IsEntity()) {
  9270. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9271. return 0;
  9272. }
  9273. if (!target) {
  9274. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9275. return 0;
  9276. }
  9277. if (!target->IsEntity()) {
  9278. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9279. return 0;
  9280. }
  9281. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9282. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9283. return 0;
  9284. }
  9285. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9286. if (!lua_interface)
  9287. return 0;
  9288. Spawn* player = lua_interface->GetSpawn(state);
  9289. int32 amount = lua_interface->GetInt32Value(state, 2);
  9290. if (player && player->IsPlayer() && amount > 0) {
  9291. ((Player*)player)->AddXP(amount);
  9292. ((Player*)player)->SetCharSheetChanged(true);
  9293. Client* client = player->GetZone()->GetClientBySpawn(player);
  9294. if (client) {
  9295. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  9296. }
  9297. }
  9298. return 0;
  9299. }
  9300. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9301. if (!lua_interface)
  9302. return 0;
  9303. Spawn* player = lua_interface->GetSpawn(state);
  9304. int8 type = lua_interface->GetInt8Value(state, 2);
  9305. string text = lua_interface->GetStringValue(state, 3);
  9306. Client* client = 0;
  9307. if (player && player->IsPlayer())
  9308. client = player->GetZone()->GetClientBySpawn(player);
  9309. if (!client || text.length() == 0) {
  9310. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9311. return 0;
  9312. }
  9313. client->SimpleMessage(type, text.c_str());
  9314. return 0;
  9315. }
  9316. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9317. if (!lua_interface)
  9318. return 0;
  9319. Spawn* player = lua_interface->GetSpawn(state);
  9320. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9321. Client* client = 0;
  9322. if (player && player->IsPlayer())
  9323. client = player->GetZone()->GetClientBySpawn(player);
  9324. if (!client || !spawn) {
  9325. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9326. return 0;
  9327. }
  9328. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9329. if (!items) {
  9330. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9331. return 0;
  9332. }
  9333. client->Loot(spawn->GetLootCoins(), items, spawn);
  9334. return 0;
  9335. }
  9336. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9337. if (!lua_interface)
  9338. return 0;
  9339. Spawn* spawnref = lua_interface->GetSpawn(state);
  9340. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9341. if (spawn_id > 0 && spawnref) {
  9342. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9343. if (spawns.size() == 0) {
  9344. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9345. return 0;
  9346. }
  9347. Spawn* spawn = 0;
  9348. int16 index = MakeRandomInt(0, spawns.size());
  9349. if (index >= spawns.size() || index < 0)
  9350. index = 0;
  9351. spawn = spawns[index];
  9352. lua_interface->SetSpawnValue(state, spawn);
  9353. return 1;
  9354. }
  9355. else {
  9356. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9357. }
  9358. return 0;
  9359. }
  9360. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9361. Spawn* player = lua_interface->GetSpawn(state);
  9362. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9363. string name = lua_interface->GetStringValue(state, 3);
  9364. float distance = lua_interface->GetFloatValue(state, 4);
  9365. string command = lua_interface->GetStringValue(state, 5);
  9366. string error_text = lua_interface->GetStringValue(state, 6);
  9367. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9368. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9369. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9370. if (distance == 0)
  9371. distance = 10.0f;
  9372. if (command.length() == 0)
  9373. command = name;
  9374. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9375. if (spawns.size() == 0) {
  9376. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9377. return 0;
  9378. }
  9379. Spawn* spawn = 0;
  9380. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9381. spawn = *itr;
  9382. if (spawn) {
  9383. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9384. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9385. }
  9386. }
  9387. }
  9388. return 0;
  9389. }
  9390. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9391. if (!lua_interface)
  9392. return 0;
  9393. Client* client = 0;
  9394. Spawn* player = lua_interface->GetSpawn(state);
  9395. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9396. if (player && player->IsPlayer() && player->GetZone())
  9397. client = player->GetZone()->GetClientBySpawn(player);
  9398. else{
  9399. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9400. return 0;
  9401. }
  9402. if (client) {
  9403. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9404. if (packet) {
  9405. packet->setDataByName("goal_num", goal_num);
  9406. client->QueuePacket(packet->serialize());
  9407. safe_delete(packet);
  9408. }
  9409. }
  9410. return 0;
  9411. }
  9412. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9413. if (!lua_interface)
  9414. return 0;
  9415. Client* client = 0;
  9416. Spawn* player = lua_interface->GetSpawn(state);
  9417. if (player && player->IsPlayer() && player->GetZone())
  9418. client = player->GetZone()->GetClientBySpawn(player);
  9419. else {
  9420. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9421. return 0;
  9422. }
  9423. if (client) {
  9424. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9425. }
  9426. return 0;
  9427. }
  9428. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9429. if (!lua_interface)
  9430. return 0;
  9431. Client* client = 0;
  9432. Spawn* player = lua_interface->GetSpawn(state);
  9433. float duration = lua_interface->GetFloatValue(state, 2);
  9434. string text = lua_interface->GetStringValue(state, 3);
  9435. string voice = lua_interface->GetStringValue(state, 4);
  9436. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9437. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9438. string signal = lua_interface->GetStringValue(state, 7);
  9439. string goal1 = lua_interface->GetStringValue(state, 8);
  9440. string task1 = lua_interface->GetStringValue(state, 9);
  9441. string goal2 = lua_interface->GetStringValue(state, 10);
  9442. string task2 = lua_interface->GetStringValue(state, 11);
  9443. string goal3 = lua_interface->GetStringValue(state, 12);
  9444. string task3 = lua_interface->GetStringValue(state, 13);
  9445. string goal4 = lua_interface->GetStringValue(state, 14);
  9446. string task4 = lua_interface->GetStringValue(state, 15);
  9447. if (!player) {
  9448. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9449. return 0;
  9450. }
  9451. if (!player->IsPlayer()) {
  9452. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9453. return 0;
  9454. }
  9455. else
  9456. client = ((Player*)player)->GetClient();
  9457. if (!client) {
  9458. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9459. return 0;
  9460. }
  9461. if (text.length() == 0) {
  9462. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9463. return 0;
  9464. }
  9465. if (duration >= 0 && duration < 2)
  9466. duration = 2;
  9467. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9468. if (packet) {
  9469. packet->setDataByName("open_seconds_max", duration);
  9470. packet->setDataByName("text", text.c_str());
  9471. packet->setDataByName("voice", voice.c_str());
  9472. int8 num_goals = 1;
  9473. if (task2.length() > 0)
  9474. num_goals++;
  9475. if (task3.length() > 0)
  9476. num_goals++;
  9477. if (task4.length() > 0)
  9478. num_goals++;
  9479. packet->setArrayLengthByName("num_goals", num_goals);
  9480. for (int8 i = 0; i < num_goals; i++) {
  9481. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9482. }
  9483. if (goal1.length() > 0)
  9484. packet->setArrayDataByName("goal_text", goal1.c_str());
  9485. if (goal2.length() > 0)
  9486. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9487. if (goal3.length() > 0)
  9488. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9489. if (goal4.length() > 0)
  9490. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9491. packet->setSubArrayDataByName("task_text", task1.c_str());
  9492. if (task2.length() > 0)
  9493. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9494. if (task3.length() > 0)
  9495. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9496. if (task4.length() > 0)
  9497. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9498. packet->setDataByName("complete_sound", "click");
  9499. packet->setDataByName("signal", signal.c_str());
  9500. packet->setDataByName("voice_key1", voice_key1);
  9501. packet->setDataByName("voice_key2", voice_key2);
  9502. client->QueuePacket(packet->serialize());
  9503. safe_delete(packet);
  9504. }
  9505. return 0;
  9506. }
  9507. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9508. if (!lua_interface)
  9509. return 0;
  9510. Client* client = 0;
  9511. Spawn* player = lua_interface->GetSpawn(state);
  9512. string window = lua_interface->GetStringValue(state, 2);
  9513. int8 show = lua_interface->GetInt8Value(state, 3);
  9514. if (!player) {
  9515. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9516. return 0;
  9517. }
  9518. if (!player->IsPlayer()) {
  9519. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9520. return 0;
  9521. }
  9522. else
  9523. client = ((Player*)player)->GetClient();
  9524. if (!client) {
  9525. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9526. return 0;
  9527. }
  9528. if (window.length() == 0) {
  9529. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9530. return 0;
  9531. }
  9532. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9533. if (packet) {
  9534. packet->setDataByName("window", window.c_str());
  9535. packet->setDataByName("show", show);
  9536. client->QueuePacket(packet->serialize());
  9537. safe_delete(packet);
  9538. }
  9539. return 0;
  9540. }
  9541. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9542. //See GameEvents.txt for options that can be used for this function
  9543. if (!lua_interface)
  9544. return 0;
  9545. Client* client = 0;
  9546. Spawn* player = lua_interface->GetSpawn(state);
  9547. string event_name = lua_interface->GetStringValue(state, 2);
  9548. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9549. if (!player || !player->IsPlayer()) {
  9550. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9551. return 0;
  9552. }
  9553. if (player->GetZone())
  9554. client = player->GetZone()->GetClientBySpawn(player);
  9555. if (!client) {
  9556. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9557. return 0;
  9558. }
  9559. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9560. if (packet) {
  9561. packet->setDataByName("event_name", event_name.c_str());
  9562. packet->setDataByName("enabled", enabled);
  9563. client->QueuePacket(packet->serialize());
  9564. safe_delete(packet);
  9565. }
  9566. return 0;
  9567. }
  9568. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9569. if (!lua_interface)
  9570. return 0;
  9571. Spawn* player = lua_interface->GetSpawn(state);
  9572. if (player && player->IsPlayer()) {
  9573. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9574. return 1;
  9575. }
  9576. return 0;
  9577. }
  9578. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9579. if (!lua_interface)
  9580. return 0;
  9581. Spawn* player = lua_interface->GetSpawn(state);
  9582. int8 step = lua_interface->GetInt8Value(state, 2);
  9583. if (player && player->IsPlayer() && step > 0) {
  9584. ((Player*)player)->SetTutorialStep(step);
  9585. }
  9586. return 0;
  9587. }
  9588. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9589. if (!lua_interface)
  9590. return 0;
  9591. Client* client = 0;
  9592. Spawn* player = lua_interface->GetSpawn(state);
  9593. string window = lua_interface->GetStringValue(state, 2);
  9594. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9595. if (!player) {
  9596. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9597. return 0;
  9598. }
  9599. if (!player->IsPlayer()) {
  9600. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9601. return 0;
  9602. }
  9603. else
  9604. client = ((Player*)player)->GetClient();
  9605. if (!client) {
  9606. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9607. return 0;
  9608. }
  9609. if (window.length() == 0) {
  9610. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9611. return 0;
  9612. }
  9613. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9614. if (packet) {
  9615. packet->setDataByName("window", window.c_str());
  9616. packet->setDataByName("flash_seconds", flash_seconds);
  9617. client->QueuePacket(packet->serialize());
  9618. safe_delete(packet);
  9619. }
  9620. return 0;
  9621. }
  9622. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9623. if (!lua_interface)
  9624. return 0;
  9625. Spawn* spawn = lua_interface->GetSpawn(state);
  9626. Spawn* target = lua_interface->GetSpawn(state, 2);
  9627. if (spawn && target)
  9628. return spawn->CheckLoS(target);
  9629. return 0;
  9630. }
  9631. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9632. if (!lua_interface)
  9633. return 0;
  9634. Spawn* spawn = lua_interface->GetSpawn(state);
  9635. float x = lua_interface->GetFloatValue(state, 2);
  9636. float y = lua_interface->GetFloatValue(state, 3);
  9637. float z = lua_interface->GetFloatValue(state, 4);
  9638. if (spawn)
  9639. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9640. return 0;
  9641. }
  9642. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9643. if (!lua_interface)
  9644. return 0;
  9645. ZoneServer* zone = lua_interface->GetZone(state);
  9646. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9647. if (zone)
  9648. zone->SetExpansionFlag(xpackFlag);
  9649. return 0;
  9650. }
  9651. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9652. if (!lua_interface)
  9653. return 0;
  9654. ZoneServer* zone = lua_interface->GetZone(state);
  9655. if (zone) {
  9656. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9657. return 1;
  9658. }
  9659. return 0;
  9660. }
  9661. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9662. if (!lua_interface)
  9663. return 0;
  9664. ZoneServer* zone = lua_interface->GetZone(state);
  9665. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9666. if (zone)
  9667. zone->SetHolidayFlag(holidayFlag);
  9668. return 0;
  9669. }
  9670. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9671. if (!lua_interface)
  9672. return 0;
  9673. ZoneServer* zone = lua_interface->GetZone(state);
  9674. if (zone) {
  9675. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9676. return 1;
  9677. }
  9678. return 0;
  9679. }
  9680. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9681. if (!lua_interface)
  9682. return 0;
  9683. Spawn* spawn = lua_interface->GetSpawn(state);
  9684. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9685. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9686. float distance = lua_interface->GetFloatValue(state, 4);
  9687. string in_range_function = lua_interface->GetStringValue(state, 5);
  9688. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9689. if (spawn && distance > 0 && in_range_function.length() > 0)
  9690. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9691. return 0;
  9692. }
  9693. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9694. if (!lua_interface)
  9695. return 0;
  9696. Spawn* spawn = lua_interface->GetSpawn(state);
  9697. Spawn* target = lua_interface->GetSpawn(state, 2);
  9698. if (spawn && target)
  9699. {
  9700. if (spawn->IsPlayer() && target->IsEntity())
  9701. {
  9702. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9703. return 1;
  9704. }
  9705. else if (spawn->IsEntity() && target->IsEntity())
  9706. {
  9707. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9708. return 1;
  9709. }
  9710. }
  9711. return 0;
  9712. }
  9713. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9714. if (!lua_interface)
  9715. return 0;
  9716. Spawn* spawn = lua_interface->GetSpawn(state);
  9717. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9718. if (spawn && spawn->IsEntity())
  9719. {
  9720. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9721. if (spawn->IsPlayer())
  9722. {
  9723. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9724. if (client)
  9725. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9726. }
  9727. }
  9728. return 0;
  9729. }
  9730. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9731. if (!lua_interface)
  9732. return 0;
  9733. Spawn* spawn = lua_interface->GetSpawn(state);
  9734. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9735. if (spawn && spawn->IsEntity())
  9736. {
  9737. ((Entity*)spawn)->SetSeeHideSpell(val);
  9738. if (spawn->IsPlayer())
  9739. {
  9740. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9741. if (client)
  9742. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9743. }
  9744. }
  9745. return 0;
  9746. }
  9747. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9748. {
  9749. if (!lua_interface)
  9750. return 0;
  9751. Spawn* player = lua_interface->GetSpawn(state);
  9752. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9753. string command = lua_interface->GetStringValue(state, 3);
  9754. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9755. lua_interface->ResetFunctionStack(state);
  9756. if (spawn && player && player->IsPlayer())
  9757. {
  9758. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9759. bool res = false;
  9760. if (cmd)
  9761. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9762. lua_interface->SetBooleanValue(state, res);
  9763. return 1;
  9764. }
  9765. return 0;
  9766. }
  9767. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  9768. {
  9769. if (!lua_interface)
  9770. return 0;
  9771. Spawn* spawn = lua_interface->GetSpawn(state);
  9772. int32 charID = lua_interface->GetInt32Value(state, 2);
  9773. string command = lua_interface->GetStringValue(state, 3);
  9774. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9775. lua_interface->ResetFunctionStack(state);
  9776. if (spawn && charID)
  9777. {
  9778. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9779. bool res = false;
  9780. if (cmd)
  9781. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  9782. lua_interface->SetBooleanValue(state, res);
  9783. return 1;
  9784. }
  9785. return 0;
  9786. }
  9787. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9788. {
  9789. if (!lua_interface)
  9790. return 0;
  9791. Spawn* spawn = lua_interface->GetSpawn(state);
  9792. string command = lua_interface->GetStringValue(state, 2);
  9793. lua_interface->ResetFunctionStack(state);
  9794. if (spawn && command.length() > 0)
  9795. spawn->RemovePrimaryEntityCommand(command.c_str());
  9796. return 0;
  9797. }
  9798. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9799. if (!lua_interface)
  9800. return 0;
  9801. Spawn* spawn = lua_interface->GetSpawn(state);
  9802. float distance = lua_interface->GetFloatValue(state, 2);
  9803. string command = lua_interface->GetStringValue(state, 3);
  9804. Spawn* player = lua_interface->GetSpawn(state, 4);
  9805. lua_interface->ResetFunctionStack(state);
  9806. if (spawn) {
  9807. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9808. }
  9809. return 0;
  9810. }
  9811. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9812. if (!lua_interface)
  9813. return 0;
  9814. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9815. Spawn* spawn = lua_interface->GetSpawn(state);
  9816. Spawn* player = lua_interface->GetSpawn(state, 2);
  9817. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9818. lua_interface->ResetFunctionStack(state);
  9819. if (spawn && player && transport_id && player->IsPlayer()) {
  9820. Client* client = 0;
  9821. if (player && player->IsPlayer())
  9822. client = player->GetZone()->GetClientBySpawn(player);
  9823. if (!client)
  9824. return 0;
  9825. vector<TransportDestination*> destinations;
  9826. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9827. if (destinations.size())
  9828. {
  9829. client->SetTemporaryTransportID(transport_id);
  9830. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  9831. }
  9832. else
  9833. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9834. }
  9835. return 0;
  9836. }
  9837. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9838. if (!lua_interface)
  9839. return 0;
  9840. Spawn* player = lua_interface->GetSpawn(state);
  9841. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9842. lua_interface->ResetFunctionStack(state);
  9843. if (player && player->IsPlayer()) {
  9844. Client* client = 0;
  9845. if (player && player->IsPlayer())
  9846. client = player->GetZone()->GetClientBySpawn(player);
  9847. if (!client)
  9848. return 0;
  9849. client->SetTemporaryTransportID(transport_id);
  9850. }
  9851. return 0;
  9852. }
  9853. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9854. if (!lua_interface)
  9855. return 0;
  9856. Spawn* player = lua_interface->GetSpawn(state);
  9857. lua_interface->ResetFunctionStack(state);
  9858. if (player && player->IsPlayer()) {
  9859. Client* client = 0;
  9860. if (player && player->IsPlayer())
  9861. client = player->GetZone()->GetClientBySpawn(player);
  9862. if (!client)
  9863. return 0;
  9864. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  9865. return 1;
  9866. }
  9867. return 0;
  9868. }
  9869. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  9870. if (!lua_interface)
  9871. return 0;
  9872. Spawn* spawn = lua_interface->GetSpawn(state);
  9873. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  9874. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9875. if (!spawn) {
  9876. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9877. return 0;
  9878. }
  9879. if (!spawn->IsEntity()) {
  9880. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9881. return 0;
  9882. }
  9883. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  9884. {
  9885. 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);
  9886. return 0;
  9887. }
  9888. lua_interface->ResetFunctionStack(state);
  9889. if (spell && spell->targets.size() > 0) {
  9890. ZoneServer* zone = spell->caster->GetZone();
  9891. for (int8 i = 0; i < spell->targets.size(); i++) {
  9892. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  9893. if (target && target->IsEntity()) {
  9894. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  9895. if (target->IsPlayer())
  9896. ((Player*)target)->SetCharSheetChanged(true);
  9897. }
  9898. }
  9899. }
  9900. else {
  9901. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  9902. if (spawn->IsPlayer())
  9903. ((Player*)spawn)->SetCharSheetChanged(true);
  9904. }
  9905. return 0;
  9906. }
  9907. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  9908. if (!lua_interface)
  9909. return 0;
  9910. Spawn* spawn = lua_interface->GetSpawn(state);
  9911. lua_interface->ResetFunctionStack(state);
  9912. if (!spawn) {
  9913. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  9914. return 0;
  9915. }
  9916. if (!spawn->IsEntity()) {
  9917. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  9918. return 0;
  9919. }
  9920. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  9921. return 1;
  9922. }
  9923. int EQ2Emu_lua_GetSpell(lua_State* state) {
  9924. if (!lua_interface)
  9925. return 0;
  9926. int32 spell_id = lua_interface->GetInt32Value(state);
  9927. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  9928. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  9929. if (spell_id > 0) {
  9930. if (spell_tier == 0)
  9931. spell_tier = 1;
  9932. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  9933. LuaSpell* lua_spell = 0;
  9934. if(custom_lua_script.size() > 0)
  9935. {
  9936. // attempt to load the custom script since it isn't already loaded
  9937. // we will re-obtain the lua_spell further below
  9938. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  9939. {
  9940. 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());
  9941. lua_interface->LoadLuaSpell(custom_lua_script);
  9942. }
  9943. }
  9944. else
  9945. custom_lua_script = spell->GetSpellData()->lua_script;
  9946. if (!lua_spell && lua_interface)
  9947. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  9948. if (!lua_spell)
  9949. {
  9950. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  9951. return 0;
  9952. }
  9953. lua_spell->spell = new Spell(spell);
  9954. lua_interface->AddCustomSpell(lua_spell);
  9955. lua_interface->SetSpellValue(state, lua_spell);
  9956. return 1;
  9957. }
  9958. return 0;
  9959. }
  9960. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  9961. if (!lua_interface)
  9962. return 0;
  9963. LuaSpell* spell = lua_interface->GetSpell(state);
  9964. string field = lua_interface->GetStringValue(state, 2);
  9965. if (!spell) {
  9966. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  9967. return 0;
  9968. }
  9969. if (!spell->spell || !spell->spell->GetSpellData()) {
  9970. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  9971. return 0;
  9972. }
  9973. boost::to_lower(field);
  9974. return spell->spell->GetSpellData(state, field);
  9975. }
  9976. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  9977. if (!lua_interface)
  9978. return 0;
  9979. LuaSpell* spell = lua_interface->GetSpell(state);
  9980. string field = lua_interface->GetStringValue(state, 2);
  9981. int8 fieldArg = 3; // field value after the initial set
  9982. if (!spell) {
  9983. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  9984. return 0;
  9985. }
  9986. if (!spell->spell || !spell->spell->GetSpellData()) {
  9987. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  9988. return 0;
  9989. }
  9990. boost::to_lower(field);
  9991. bool valSet = false;
  9992. spell->spell->SetSpellData(state, field, fieldArg);
  9993. return valSet;
  9994. }
  9995. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  9996. if (!lua_interface)
  9997. return 0;
  9998. LuaSpell* spell = lua_interface->GetSpell(state);
  9999. int8 idx = lua_interface->GetInt32Value(state, 2);
  10000. if (!spell) {
  10001. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10002. return 0;
  10003. }
  10004. if (!spell->spell || !spell->spell->GetSpellData()) {
  10005. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10006. return 0;
  10007. }
  10008. if (spell->spell->lua_data.size() <= idx)
  10009. {
  10010. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10011. return 0;
  10012. }
  10013. bool setVal = true;
  10014. LUAData* data = spell->spell->lua_data[idx];
  10015. switch (data->type)
  10016. {
  10017. case 0:
  10018. {
  10019. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10020. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10021. data->int_value = value;
  10022. data->int_value2 = value2;
  10023. break;
  10024. }
  10025. case 1:
  10026. {
  10027. float value = lua_interface->GetFloatValue(state, 3);
  10028. float value2 = lua_interface->GetFloatValue(state, 4);
  10029. data->float_value = value;
  10030. data->float_value2 = value2;
  10031. break;
  10032. }
  10033. case 2:
  10034. {
  10035. bool value = lua_interface->GetBooleanValue(state, 3);
  10036. data->bool_value = value;
  10037. break;
  10038. }
  10039. case 3:
  10040. {
  10041. string value = lua_interface->GetStringValue(state, 3);
  10042. string value2 = lua_interface->GetStringValue(state, 4);
  10043. data->string_value = value;
  10044. data->string_value2 = value2;
  10045. break;
  10046. }
  10047. default:
  10048. setVal = false;
  10049. }
  10050. return setVal;
  10051. }
  10052. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10053. if (!lua_interface)
  10054. return 0;
  10055. LuaSpell* spell = lua_interface->GetSpell(state);
  10056. int8 idx = lua_interface->GetInt32Value(state, 2);
  10057. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10058. if (!spell) {
  10059. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10060. return 0;
  10061. }
  10062. if (!spell->spell || !spell->spell->GetSpellData()) {
  10063. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10064. return 0;
  10065. }
  10066. if (spell->spell->lua_data.size() <= idx)
  10067. {
  10068. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10069. return 0;
  10070. }
  10071. bool setVal = true;
  10072. LUAData* data = spell->spell->lua_data[idx];
  10073. switch (data->type)
  10074. {
  10075. case 0:
  10076. {
  10077. if(!secondfield)
  10078. lua_interface->SetSInt32Value(state, data->int_value);
  10079. else
  10080. lua_interface->SetSInt32Value(state, data->int_value2);
  10081. break;
  10082. }
  10083. case 1:
  10084. {
  10085. if (!secondfield)
  10086. lua_interface->SetFloatValue(state, data->float_value);
  10087. else
  10088. lua_interface->SetFloatValue(state, data->float_value2);
  10089. break;
  10090. }
  10091. case 2:
  10092. {
  10093. lua_interface->SetBooleanValue(state, data->bool_value);
  10094. break;
  10095. }
  10096. case 3:
  10097. {
  10098. if (!secondfield)
  10099. lua_interface->SetStringValue(state, data->string_value.c_str());
  10100. else
  10101. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10102. break;
  10103. }
  10104. default:
  10105. setVal = false;
  10106. }
  10107. return setVal;
  10108. }
  10109. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10110. if (!lua_interface)
  10111. return 0;
  10112. LuaSpell* spell = lua_interface->GetSpell(state);
  10113. int8 idx = lua_interface->GetInt32Value(state, 2);
  10114. string field = lua_interface->GetStringValue(state, 3);
  10115. boost::to_lower(field);
  10116. if (!spell) {
  10117. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10118. return 0;
  10119. }
  10120. if (!spell->spell || !spell->spell->GetSpellData()) {
  10121. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10122. return 0;
  10123. }
  10124. if (spell->spell->effects.size() <= idx)
  10125. {
  10126. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10127. return 0;
  10128. }
  10129. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10130. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10131. if (field == "description")
  10132. effect->description = string(lua_interface->GetStringValue(state, 4));
  10133. else if (field == "bullet")
  10134. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10135. else if (field == "percentage")
  10136. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10137. else // no match
  10138. return 0;
  10139. return 1;
  10140. }
  10141. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10142. if (!lua_interface)
  10143. return 0;
  10144. LuaSpell* spell = lua_interface->GetSpell(state);
  10145. int8 idx = lua_interface->GetInt32Value(state, 2);
  10146. string field = lua_interface->GetStringValue(state, 3);
  10147. boost::to_lower(field);
  10148. if (!spell) {
  10149. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10150. return 0;
  10151. }
  10152. if (!spell->spell || !spell->spell->GetSpellData()) {
  10153. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10154. return 0;
  10155. }
  10156. if (spell->spell->effects.size() <= idx)
  10157. {
  10158. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10159. return 0;
  10160. }
  10161. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10162. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10163. if (field == "description")
  10164. lua_interface->SetStringValue(state, effect->description.c_str());
  10165. else if (field == "bullet")
  10166. lua_interface->SetInt32Value(state, effect->subbullet);
  10167. else if (field == "percentage")
  10168. lua_interface->SetInt32Value(state, effect->percentage);
  10169. else // no match
  10170. return 0;
  10171. return 1;
  10172. }
  10173. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10174. if (!lua_interface)
  10175. return 0;
  10176. LuaSpell* spell = lua_interface->GetSpell(state);
  10177. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10178. Spawn* target = lua_interface->GetSpawn(state, 3);
  10179. if (!target) {
  10180. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10181. return 0;
  10182. }
  10183. if (!target->IsEntity()) {
  10184. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10185. return 0;
  10186. }
  10187. if (!spell) {
  10188. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10189. return 0;
  10190. }
  10191. if (caster && !caster->IsEntity()) {
  10192. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10193. return 0;
  10194. }
  10195. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10196. return 0;
  10197. }
  10198. int EQ2Emu_lua_InWater(lua_State* state) {
  10199. if (!lua_interface)
  10200. return 0;
  10201. Spawn* spawn = lua_interface->GetSpawn(state);
  10202. lua_interface->ResetFunctionStack(state);
  10203. if (spawn) {
  10204. lua_interface->SetBooleanValue(state, spawn->InWater());
  10205. return 1;
  10206. }
  10207. return 0;
  10208. }
  10209. int EQ2Emu_lua_InLava(lua_State* state) {
  10210. if (!lua_interface)
  10211. return 0;
  10212. Spawn* spawn = lua_interface->GetSpawn(state);
  10213. lua_interface->ResetFunctionStack(state);
  10214. if (spawn) {
  10215. lua_interface->SetBooleanValue(state, spawn->InLava());
  10216. return 1;
  10217. }
  10218. return 0;
  10219. }
  10220. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10221. if (!lua_interface)
  10222. return 0;
  10223. Spawn* attacker = lua_interface->GetSpawn(state);
  10224. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10225. int8 type = lua_interface->GetInt8Value(state, 3);
  10226. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10227. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10228. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10229. string spell_name = lua_interface->GetStringValue(state, 7);
  10230. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10231. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10232. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10233. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10234. lua_interface->ResetFunctionStack(state);
  10235. if (!attacker) {
  10236. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10237. return 0;
  10238. }
  10239. if (!attacker->IsEntity()) {
  10240. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10241. return 0;
  10242. }
  10243. if (!victim) {
  10244. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10245. return 0;
  10246. }
  10247. if (!victim->IsEntity()) {
  10248. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10249. return 0;
  10250. }
  10251. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10252. return 0;
  10253. }
  10254. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10255. if (!lua_interface)
  10256. return 0;
  10257. Spawn* spawn = lua_interface->GetSpawn(state);
  10258. lua_interface->ResetFunctionStack(state);
  10259. if (spawn) {
  10260. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10261. return 1;
  10262. }
  10263. return 0;
  10264. }
  10265. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10266. if (!lua_interface)
  10267. return 0;
  10268. Spawn* spawn = lua_interface->GetSpawn(state);
  10269. bool invul = lua_interface->GetBooleanValue(state, 2);
  10270. lua_interface->ResetFunctionStack(state);
  10271. if (spawn) {
  10272. spawn->SetInvulnerable(invul);
  10273. }
  10274. return 0;
  10275. }
  10276. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10277. if (!lua_interface)
  10278. return 0;
  10279. string category = lua_interface->GetStringValue(state);
  10280. string name = lua_interface->GetStringValue(state, 2);
  10281. lua_interface->ResetFunctionStack(state);
  10282. Rule *ret = 0;
  10283. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10284. lua_interface->SetBooleanValue(state, ret->GetBool());
  10285. return 1;
  10286. }
  10287. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10288. return 0;
  10289. }
  10290. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10291. if (!lua_interface)
  10292. return 0;
  10293. string category = lua_interface->GetStringValue(state);
  10294. string name = lua_interface->GetStringValue(state, 2);
  10295. lua_interface->ResetFunctionStack(state);
  10296. Rule *ret = 0;
  10297. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10298. lua_interface->SetInt32Value(state, ret->GetInt32());
  10299. return 1;
  10300. }
  10301. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10302. return 0;
  10303. }
  10304. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10305. if (!lua_interface)
  10306. return 0;
  10307. string category = lua_interface->GetStringValue(state);
  10308. string name = lua_interface->GetStringValue(state, 2);
  10309. lua_interface->ResetFunctionStack(state);
  10310. Rule *ret = 0;
  10311. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10312. lua_interface->SetFloatValue(state, ret->GetFloat());
  10313. return 1;
  10314. }
  10315. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10316. return 0;
  10317. }
  10318. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10319. if (!lua_interface)
  10320. return 0;
  10321. Spawn* spawn = lua_interface->GetSpawn(state);
  10322. string type = lua_interface->GetStringValue(state, 2);
  10323. lua_interface->ResetFunctionStack(state);
  10324. if (spawn) {
  10325. int res = 1;
  10326. boost::to_lower(type);
  10327. if(type == "assigned_aa")
  10328. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10329. else if ( type == "unassigned_aa")
  10330. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10331. else if ( type == "assigned_tradeskill_aa")
  10332. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10333. else if ( type == "unassigned_tradeskill_aa")
  10334. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10335. else if ( type == "assigned_prestige_aa")
  10336. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10337. else if ( type == "unassigned_prestige_aa")
  10338. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10339. else if ( type == "assigned_tradeskill_prestige_aa")
  10340. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10341. else if ( type == "unassigned_tradeskill_prestige_aa")
  10342. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10343. else
  10344. res = 0;
  10345. return res;
  10346. }
  10347. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10348. return 0;
  10349. }
  10350. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10351. if (!lua_interface)
  10352. return 0;
  10353. Spawn* spawn = lua_interface->GetSpawn(state);
  10354. string type = lua_interface->GetStringValue(state, 2);
  10355. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10356. lua_interface->ResetFunctionStack(state);
  10357. if (spawn) {
  10358. boost::to_lower(type);
  10359. if(type == "assigned_aa")
  10360. spawn->SetAssignedAA((sint16)value);
  10361. else if ( type == "unassigned_aa")
  10362. spawn->SetUnassignedAA((sint16)value);
  10363. else if ( type == "assigned_tradeskill_aa")
  10364. spawn->SetTradeskillAA((sint16)value);
  10365. else if ( type == "unassigned_tradeskill_aa")
  10366. spawn->SetUnassignedTradeskillAA((sint16)value);
  10367. else if ( type == "assigned_prestige_aa")
  10368. spawn->SetPrestigeAA((sint16)value);
  10369. else if ( type == "unassigned_prestige_aa")
  10370. spawn->SetUnassignedPrestigeAA((sint16)value);
  10371. else if ( type == "assigned_tradeskill_prestige_aa")
  10372. spawn->SetTradeskillPrestigeAA((sint16)value);
  10373. else if ( type == "unassigned_tradeskill_prestige_aa")
  10374. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10375. if(spawn->IsPlayer())
  10376. ((Player*)spawn)->SetCharSheetChanged(true);
  10377. }
  10378. return 0;
  10379. }
  10380. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10381. if (!lua_interface)
  10382. return 0;
  10383. string titleName = lua_interface->GetStringValue(state);
  10384. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10385. lua_interface->ResetFunctionStack(state);
  10386. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10387. lua_interface->SetSInt32Value(state, index);
  10388. return 1;
  10389. }
  10390. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10391. if (!lua_interface)
  10392. return 0;
  10393. Spawn* spawn = lua_interface->GetSpawn(state);
  10394. string titleName = lua_interface->GetStringValue(state, 2);
  10395. lua_interface->ResetFunctionStack(state);
  10396. if(!spawn->IsPlayer())
  10397. {
  10398. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10399. lua_interface->SetSInt32Value(state, -1);
  10400. return 1;
  10401. }
  10402. Player* player = (Player*)spawn;
  10403. // check if player already has the title, don't need to add twice
  10404. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10405. if ( playerHasTitle)
  10406. {
  10407. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10408. return 1;
  10409. }
  10410. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10411. if(!title)
  10412. {
  10413. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10414. lua_interface->SetSInt32Value(state, -1);
  10415. return 1;
  10416. }
  10417. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10418. if(returnIdx < 0)
  10419. {
  10420. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10421. }
  10422. lua_interface->SetSInt32Value(state, returnIdx);
  10423. player->GetClient()->SendTitleUpdate();
  10424. return 1;
  10425. }
  10426. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10427. if (!lua_interface)
  10428. return 0;
  10429. Spawn* spawn = lua_interface->GetSpawn(state);
  10430. string titleName = lua_interface->GetStringValue(state, 2);
  10431. lua_interface->ResetFunctionStack(state);
  10432. if(!spawn->IsPlayer())
  10433. {
  10434. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10435. return 0;
  10436. }
  10437. Player* player = (Player*)spawn;
  10438. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10439. if(!title)
  10440. {
  10441. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10442. return 0;
  10443. }
  10444. if(title->GetPrefix())
  10445. {
  10446. 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());
  10447. return 0;
  10448. }
  10449. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10450. player->GetClient()->SendTitleUpdate();
  10451. return 1;
  10452. }
  10453. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10454. if (!lua_interface)
  10455. return 0;
  10456. Spawn* spawn = lua_interface->GetSpawn(state);
  10457. string titleName = lua_interface->GetStringValue(state, 2);
  10458. lua_interface->ResetFunctionStack(state);
  10459. if(!spawn->IsPlayer())
  10460. {
  10461. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10462. return 0;
  10463. }
  10464. Player* player = (Player*)spawn;
  10465. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10466. if(!title)
  10467. {
  10468. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10469. return 0;
  10470. }
  10471. if(!title->GetPrefix())
  10472. {
  10473. 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());
  10474. return 0;
  10475. }
  10476. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10477. player->GetClient()->SendTitleUpdate();
  10478. return 1;
  10479. }
  10480. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10481. if (!lua_interface)
  10482. return 0;
  10483. Spawn* spawn = lua_interface->GetSpawn(state);
  10484. lua_interface->ResetFunctionStack(state);
  10485. if(!spawn->IsPlayer())
  10486. {
  10487. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10488. return 0;
  10489. }
  10490. Player* player = (Player*)spawn;
  10491. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10492. player->GetClient()->SendTitleUpdate();
  10493. return 1;
  10494. }
  10495. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10496. if (!lua_interface)
  10497. return 0;
  10498. Spawn* spawn = lua_interface->GetSpawn(state);
  10499. lua_interface->ResetFunctionStack(state);
  10500. if(!spawn->IsPlayer())
  10501. {
  10502. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10503. return 0;
  10504. }
  10505. Player* player = (Player*)spawn;
  10506. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10507. player->GetClient()->SendTitleUpdate();
  10508. return 1;
  10509. }
  10510. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10511. if (!lua_interface)
  10512. return 0;
  10513. Spawn* spawn = lua_interface->GetSpawn(state);
  10514. string field = lua_interface->GetStringValue(state, 2);
  10515. lua_interface->ResetFunctionStack(state);
  10516. if(!spawn || !spawn->IsEntity())
  10517. {
  10518. 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));
  10519. return 0;
  10520. }
  10521. Entity* ent = (Entity*)spawn;
  10522. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10523. return 1;
  10524. }
  10525. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10526. if (!lua_interface)
  10527. return 0;
  10528. Spawn* spawn = lua_interface->GetSpawn(state);
  10529. string field = lua_interface->GetStringValue(state, 2);
  10530. lua_interface->ResetFunctionStack(state);
  10531. if(!spawn || !spawn->IsEntity())
  10532. {
  10533. 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));
  10534. return 0;
  10535. }
  10536. Entity* ent = (Entity*)spawn;
  10537. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10538. return 1;
  10539. }
  10540. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10541. if (!lua_interface)
  10542. return 0;
  10543. Spawn* spawn = lua_interface->GetSpawn(state);
  10544. string field = lua_interface->GetStringValue(state, 2);
  10545. lua_interface->ResetFunctionStack(state);
  10546. if(!spawn || !spawn->IsEntity())
  10547. {
  10548. 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));
  10549. return 0;
  10550. }
  10551. Entity* ent = (Entity*)spawn;
  10552. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10553. return 1;
  10554. }
  10555. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10556. if (!lua_interface)
  10557. return 0;
  10558. Spawn* spawn = lua_interface->GetSpawn(state);
  10559. string field = lua_interface->GetStringValue(state, 2);
  10560. lua_interface->ResetFunctionStack(state);
  10561. if(!spawn || !spawn->IsEntity())
  10562. {
  10563. 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));
  10564. return 0;
  10565. }
  10566. Entity* ent = (Entity*)spawn;
  10567. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10568. return 1;
  10569. }
  10570. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10571. if (!lua_interface)
  10572. return 0;
  10573. Spawn* spawn = lua_interface->GetSpawn(state);
  10574. string field = lua_interface->GetStringValue(state, 2);
  10575. string value = lua_interface->GetStringValue(state, 3);
  10576. lua_interface->ResetFunctionStack(state);
  10577. if(!spawn || !spawn->IsEntity())
  10578. {
  10579. 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));
  10580. return 0;
  10581. }
  10582. Entity* ent = (Entity*)spawn;
  10583. bool set_ = ent->SetInfoStructString(field, value);
  10584. lua_interface->SetBooleanValue(state, set_);
  10585. return 1;
  10586. }
  10587. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10588. if (!lua_interface)
  10589. return 0;
  10590. Spawn* spawn = lua_interface->GetSpawn(state);
  10591. string field = lua_interface->GetStringValue(state, 2);
  10592. int64 value = lua_interface->GetInt64Value(state, 3);
  10593. lua_interface->ResetFunctionStack(state);
  10594. if(!spawn || !spawn->IsEntity())
  10595. {
  10596. 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));
  10597. return 0;
  10598. }
  10599. Entity* ent = (Entity*)spawn;
  10600. bool set_ = ent->SetInfoStructUInt(field, value);
  10601. lua_interface->SetBooleanValue(state, set_);
  10602. return 1;
  10603. }
  10604. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10605. if (!lua_interface)
  10606. return 0;
  10607. Spawn* spawn = lua_interface->GetSpawn(state);
  10608. string field = lua_interface->GetStringValue(state, 2);
  10609. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10610. lua_interface->ResetFunctionStack(state);
  10611. if(!spawn || !spawn->IsEntity())
  10612. {
  10613. 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));
  10614. return 0;
  10615. }
  10616. Entity* ent = (Entity*)spawn;
  10617. bool set_ = ent->SetInfoStructSInt(field, value);
  10618. lua_interface->SetBooleanValue(state, set_);
  10619. return 1;
  10620. }
  10621. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10622. if (!lua_interface)
  10623. return 0;
  10624. Spawn* spawn = lua_interface->GetSpawn(state);
  10625. string field = lua_interface->GetStringValue(state, 2);
  10626. float value = lua_interface->GetFloatValue(state, 3);
  10627. lua_interface->ResetFunctionStack(state);
  10628. if(!spawn || !spawn->IsEntity())
  10629. {
  10630. 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));
  10631. return 0;
  10632. }
  10633. Entity* ent = (Entity*)spawn;
  10634. bool set_ = ent->SetInfoStructFloat(field, value);
  10635. lua_interface->SetBooleanValue(state, set_);
  10636. return 1;
  10637. }
  10638. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10639. if (!lua_interface)
  10640. return 0;
  10641. Spawn* spawn = lua_interface->GetSpawn(state);
  10642. bool value = lua_interface->GetBooleanValue(state, 2);
  10643. lua_interface->ResetFunctionStack(state);
  10644. if(!spawn || !spawn->IsPlayer())
  10645. {
  10646. 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));
  10647. return 0;
  10648. }
  10649. ((Player*)spawn)->SetCharSheetChanged(value);
  10650. return 0;
  10651. }
  10652. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10653. if (!lua_interface)
  10654. return 0;
  10655. Spawn* spawn = lua_interface->GetSpawn(state);
  10656. std::string fromName = lua_interface->GetStringValue(state, 2);
  10657. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10658. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10659. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10660. int32 copper = lua_interface->GetInt32Value(state, 6);
  10661. int32 silver = lua_interface->GetInt32Value(state, 7);
  10662. int32 gold = lua_interface->GetInt32Value(state, 8);
  10663. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10664. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10665. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10666. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10667. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10668. lua_interface->ResetFunctionStack(state);
  10669. if(!spawn || !spawn->IsPlayer())
  10670. {
  10671. 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));
  10672. lua_interface->SetBooleanValue(state, false);
  10673. return 1;
  10674. }
  10675. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10676. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10677. lua_interface->SetBooleanValue(state, true);
  10678. return 1;
  10679. }
  10680. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10681. if (!lua_interface)
  10682. return 0;
  10683. int32 char_id = lua_interface->GetInt32Value(state);
  10684. std::string fromName = lua_interface->GetStringValue(state, 2);
  10685. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10686. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10687. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10688. int32 copper = lua_interface->GetInt32Value(state, 6);
  10689. int32 silver = lua_interface->GetInt32Value(state, 7);
  10690. int32 gold = lua_interface->GetInt32Value(state, 8);
  10691. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10692. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10693. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10694. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10695. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10696. lua_interface->ResetFunctionStack(state);
  10697. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10698. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10699. lua_interface->SetBooleanValue(state, true);
  10700. return 1;
  10701. }
  10702. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10703. Spawn* widget;
  10704. if (lua_interface) {
  10705. widget = lua_interface->GetSpawn(state);
  10706. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10707. lua_interface->ResetFunctionStack(state);
  10708. if (widget && widget->IsWidget())
  10709. {
  10710. ((Widget*)widget)->OpenDoor();
  10711. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10712. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10713. }
  10714. else
  10715. 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));
  10716. }
  10717. return 0;
  10718. }
  10719. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10720. Spawn* widget;
  10721. if (lua_interface) {
  10722. widget = lua_interface->GetSpawn(state);
  10723. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10724. lua_interface->ResetFunctionStack(state);
  10725. if (widget && widget->IsWidget())
  10726. {
  10727. ((Widget*)widget)->CloseDoor();
  10728. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10729. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10730. }
  10731. else
  10732. 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));
  10733. }
  10734. return 0;
  10735. }
  10736. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10737. if (!lua_interface)
  10738. return 0;
  10739. Spawn* widget = lua_interface->GetSpawn(state);
  10740. lua_interface->ResetFunctionStack(state);
  10741. if (widget && widget->IsWidget())
  10742. {
  10743. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10744. return 1;
  10745. }
  10746. return 0;
  10747. }
  10748. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10749. if (!lua_interface)
  10750. return 0;
  10751. sint32 min = lua_interface->GetSInt32Value(state);
  10752. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10753. lua_interface->ResetFunctionStack(state);
  10754. sint32 result = MakeRandomInt(min, max);
  10755. lua_interface->SetSInt32Value(state, result);
  10756. return 1;
  10757. }
  10758. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10759. if (!lua_interface)
  10760. return 0;
  10761. float min = lua_interface->GetFloatValue(state);
  10762. float max = lua_interface->GetFloatValue(state, 2);
  10763. lua_interface->ResetFunctionStack(state);
  10764. float result = MakeRandomFloat(min, max);
  10765. lua_interface->SetFloatValue(state, result);
  10766. return 1;
  10767. }
  10768. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10769. if (!lua_interface)
  10770. return 0;
  10771. Spawn* spawn = lua_interface->GetSpawn(state);
  10772. int32 value = lua_interface->GetInt32Value(state, 2);
  10773. lua_interface->ResetFunctionStack(state);
  10774. if(!spawn)
  10775. {
  10776. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10777. lua_interface->SetBooleanValue(state, false);
  10778. return 1;
  10779. }
  10780. spawn->AddIconValue(value);
  10781. lua_interface->SetBooleanValue(state, true);
  10782. return 1;
  10783. }
  10784. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  10785. if (!lua_interface)
  10786. return 0;
  10787. Spawn* spawn = lua_interface->GetSpawn(state);
  10788. int32 value = lua_interface->GetInt32Value(state, 2);
  10789. lua_interface->ResetFunctionStack(state);
  10790. if(!spawn)
  10791. {
  10792. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10793. lua_interface->SetBooleanValue(state, false);
  10794. return 1;
  10795. }
  10796. spawn->RemoveIconValue(value);
  10797. lua_interface->SetBooleanValue(state, true);
  10798. return 1;
  10799. }
  10800. int EQ2Emu_lua_GetShardID(lua_State* state) {
  10801. Spawn* npc = lua_interface->GetSpawn(state);
  10802. lua_interface->ResetFunctionStack(state);
  10803. if (npc && npc->IsNPC()) {
  10804. NPC* shard = (NPC*)npc;
  10805. int32 shardid = shard->GetShardID();
  10806. lua_interface->SetInt32Value(state, shardid);
  10807. return 1;
  10808. }
  10809. lua_interface->SetInt32Value(state, 0);
  10810. return 1;
  10811. }
  10812. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  10813. Spawn* npc = lua_interface->GetSpawn(state);
  10814. lua_interface->ResetFunctionStack(state);
  10815. if (npc && npc->IsNPC()) {
  10816. NPC* shard = (NPC*)npc;
  10817. int32 charid = shard->GetShardCharID();
  10818. lua_interface->SetInt32Value(state, charid);
  10819. return 1;
  10820. }
  10821. lua_interface->SetInt32Value(state, 0);
  10822. return 1;
  10823. }
  10824. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  10825. Spawn* npc = lua_interface->GetSpawn(state);
  10826. lua_interface->ResetFunctionStack(state);
  10827. if (npc && npc->IsNPC()) {
  10828. NPC* shard = (NPC*)npc;
  10829. int64 timestamp = shard->GetShardCreatedTimestamp();
  10830. lua_interface->SetSInt64Value(state, timestamp);
  10831. return 1;
  10832. }
  10833. lua_interface->SetSInt64Value(state, 0);
  10834. return 1;
  10835. }
  10836. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  10837. if (!lua_interface)
  10838. return 0;
  10839. int32 shardid = lua_interface->GetInt32Value(state);
  10840. lua_interface->ResetFunctionStack(state);
  10841. if(shardid < 1)
  10842. lua_interface->SetBooleanValue(state, false);
  10843. else
  10844. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  10845. return 1;
  10846. }
  10847. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  10848. if (!lua_interface)
  10849. return 0;
  10850. Spawn* spawn = lua_interface->GetSpawn(state);
  10851. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  10852. if (spawn) {
  10853. spawn->PauseMovement(delay_in_ms);
  10854. }
  10855. lua_interface->ResetFunctionStack(state);
  10856. return 0;
  10857. }
  10858. int EQ2Emu_lua_StopMovement(lua_State* state) {
  10859. if (!lua_interface)
  10860. return 0;
  10861. Spawn* spawn = lua_interface->GetSpawn(state);
  10862. if (spawn) {
  10863. spawn->StopMovement();
  10864. }
  10865. lua_interface->ResetFunctionStack(state);
  10866. return 0;
  10867. }
  10868. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  10869. Player* player = (Player*)lua_interface->GetSpawn(state);
  10870. int8 level = lua_interface->GetInt8Value(state, 2);
  10871. lua_interface->ResetFunctionStack(state);
  10872. if (player && player->IsPlayer() && level > 0) {
  10873. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  10874. return 1;
  10875. }
  10876. return 0;
  10877. }
  10878. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  10879. Player* player = (Player*)lua_interface->GetSpawn(state);
  10880. int8 level = lua_interface->GetInt8Value(state, 2);
  10881. lua_interface->ResetFunctionStack(state);
  10882. if (player && player->IsPlayer() && level > 0) {
  10883. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  10884. return 1;
  10885. }
  10886. return 0;
  10887. }
  10888. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  10889. ZoneServer* zone = lua_interface->GetZone(state);
  10890. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  10891. lua_interface->ResetFunctionStack(state);
  10892. if (zone) {
  10893. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  10894. if (spawn) {
  10895. lua_interface->SetSpawnValue(state, spawn);
  10896. return 1;
  10897. }
  10898. }
  10899. return 0;
  10900. }
  10901. int EQ2Emu_lua_SetRailID(lua_State* state) {
  10902. if (!lua_interface)
  10903. return 0;
  10904. Spawn* spawn = lua_interface->GetSpawn(state);
  10905. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  10906. lua_interface->ResetFunctionStack(state);
  10907. bool res = false;
  10908. if(spawn && spawn->IsTransportSpawn())
  10909. {
  10910. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  10911. spawn->SetRailID(rail_id);
  10912. res = true;
  10913. }
  10914. else if (!spawn) {
  10915. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10916. }
  10917. else if(!spawn->IsTransportSpawn()) {
  10918. 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());
  10919. }
  10920. lua_interface->SetBooleanValue(state, res);
  10921. return 1;
  10922. }
  10923. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  10924. if (!lua_interface)
  10925. return 0;
  10926. ZoneServer* zone = lua_interface->GetZone(state);
  10927. lua_interface->ResetFunctionStack(state);
  10928. if (zone) {
  10929. lua_interface->SetBooleanValue(state, zone->IsLoading());
  10930. return 1;
  10931. }
  10932. return 0;
  10933. }
  10934. int EQ2Emu_lua_IsRunning(lua_State* state) {
  10935. if (!lua_interface)
  10936. return 0;
  10937. Spawn* spawn = lua_interface->GetSpawn(state);
  10938. lua_interface->ResetFunctionStack(state);
  10939. if (spawn) {
  10940. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  10941. return 1;
  10942. }
  10943. return 0;
  10944. }
  10945. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  10946. if (!lua_interface)
  10947. return 0;
  10948. Spawn* player = lua_interface->GetSpawn(state);
  10949. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  10950. bool displayClient = lua_interface->GetInt32Value(state, 3);
  10951. lua_interface->ResetFunctionStack(state);
  10952. if (!player || !player->IsPlayer() || !player->GetClient()) {
  10953. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  10954. }
  10955. else if(!zoneID) {
  10956. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  10957. }
  10958. else
  10959. {
  10960. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  10961. return 1;
  10962. }
  10963. return 0;
  10964. }
  10965. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  10966. if (!lua_interface)
  10967. return 0;
  10968. int16 newYear = lua_interface->GetInt16Value(state, 1);
  10969. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  10970. int16 newHour = lua_interface->GetInt16Value(state, 3);
  10971. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  10972. lua_interface->ResetFunctionStack(state);
  10973. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  10974. world.GetWorldTimeStruct()->year = newYear;
  10975. world.GetWorldTimeStruct()->month = newMonth;
  10976. world.GetWorldTimeStruct()->hour = newHour;
  10977. world.GetWorldTimeStruct()->minute = newMinute;
  10978. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  10979. return 0;
  10980. }
  10981. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  10982. if (!lua_interface)
  10983. return 0;
  10984. lua_interface->ResetFunctionStack(state);
  10985. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  10986. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  10987. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  10988. return 1;
  10989. }
  10990. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  10991. if (!lua_interface)
  10992. return 0;
  10993. lua_interface->ResetFunctionStack(state);
  10994. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  10995. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  10996. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  10997. return 1;
  10998. }
  10999. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11000. if (!lua_interface)
  11001. return 0;
  11002. lua_interface->ResetFunctionStack(state);
  11003. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11004. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11005. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11006. return 1;
  11007. }
  11008. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11009. if (!lua_interface)
  11010. return 0;
  11011. lua_interface->ResetFunctionStack(state);
  11012. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11013. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11014. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11015. return 1;
  11016. }
  11017. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11018. if (!lua_interface)
  11019. return 0;
  11020. lua_interface->ResetFunctionStack(state);
  11021. world.SendTimeUpdate();
  11022. return 0;
  11023. }