LuaFunctions.cpp 395 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998
  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. int8 language = lua_interface->GetInt8Value(state, 9);
  943. int numargs = lua_interface->GetNumberOfArgs(state);
  944. int8 can_close = 1;
  945. if(numargs > 9)
  946. can_close = lua_interface->GetInt32Value(state, 10);
  947. lua_interface->ResetFunctionStack(state);
  948. if (conversation && text.length() > 0 && (spawn || item) && player && player->IsPlayer()) {
  949. Client* client = player->GetZone()->GetClientBySpawn(player);
  950. if (client) {
  951. if (spawn) {
  952. // Need to do this so the function works the same as it did before
  953. if (type == 1)
  954. type++;
  955. if (mp3.length() > 0)
  956. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), mp3.c_str(), key1, key2, language, can_close);
  957. else
  958. client->DisplayConversation((Entity*)spawn, type, conversation, const_cast<char*>(text.c_str()), nullptr, 0, 0, language, can_close);
  959. }
  960. else {
  961. if (mp3.length() > 0)
  962. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, mp3.c_str(), key1, key2, language, can_close);
  963. else
  964. client->DisplayConversation(item, conversation, const_cast<char*>(text.c_str()), type, nullptr, 0, 0, language, can_close);
  965. }
  966. }
  967. }
  968. safe_delete(conversation);
  969. lua_interface->SetConversationValue(state, NULL);
  970. return 0;
  971. }
  972. int EQ2Emu_lua_StartConversation(lua_State* state) {
  973. if (!lua_interface)
  974. return 0;
  975. vector<ConversationOption>* conversation = lua_interface->GetConversation(state);
  976. Spawn* source = lua_interface->GetSpawn(state, 2);
  977. Spawn* player = lua_interface->GetSpawn(state, 3);
  978. string text = lua_interface->GetStringValue(state, 4);
  979. string mp3 = lua_interface->GetStringValue(state, 5);
  980. int32 key1 = lua_interface->GetInt32Value(state, 6);
  981. int32 key2 = lua_interface->GetInt32Value(state, 7);
  982. int8 language = lua_interface->GetInt32Value(state, 8);
  983. int numargs = lua_interface->GetNumberOfArgs(state);
  984. int8 can_close = 1;
  985. if(numargs > 8)
  986. can_close = lua_interface->GetInt32Value(state, 9);
  987. lua_interface->ResetFunctionStack(state);
  988. if (conversation && conversation->size() > 0 && text.length() > 0 && source && player && player->IsPlayer()) {
  989. Client* client = source->GetZone()->GetClientBySpawn(player);
  990. if (mp3.length() > 0)
  991. client->DisplayConversation(source, 1, conversation, text.c_str(), mp3.c_str(), key1, key2, language, can_close);
  992. else
  993. client->DisplayConversation(source, 1, conversation, text.c_str(), nullptr, 0, 0, language, can_close);
  994. safe_delete(conversation);
  995. lua_interface->SetConversationValue(state, NULL);
  996. }
  997. else
  998. 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);
  999. return 0;
  1000. }
  1001. int EQ2Emu_lua_SetPlayerProximityFunction(lua_State* state) {
  1002. if (!lua_interface)
  1003. return 0;
  1004. Spawn* spawn = lua_interface->GetSpawn(state);
  1005. float distance = lua_interface->GetFloatValue(state, 2);
  1006. string in_range_function = lua_interface->GetStringValue(state, 3);
  1007. string leaving_range_function = lua_interface->GetStringValue(state, 4);
  1008. if (spawn && !spawn->IsPlayer() && distance > 0 && in_range_function.length() > 0)
  1009. spawn->GetZone()->AddPlayerProximity(spawn, distance, in_range_function, leaving_range_function);
  1010. return 0;
  1011. }
  1012. int EQ2Emu_lua_SetLocationProximityFunction(lua_State* state) {
  1013. ZoneServer* zone = lua_interface->GetZone(state);
  1014. float x = lua_interface->GetFloatValue(state, 2);
  1015. float y = lua_interface->GetFloatValue(state, 3);
  1016. float z = lua_interface->GetFloatValue(state, 4);
  1017. float max_variation = lua_interface->GetFloatValue(state, 5);
  1018. string in_range_function = lua_interface->GetStringValue(state, 6);
  1019. string leaving_range_function = lua_interface->GetStringValue(state, 7);
  1020. lua_interface->ResetFunctionStack(state);
  1021. if (zone && in_range_function.length() > 0)
  1022. zone->AddLocationProximity(x, y, z, max_variation, in_range_function, leaving_range_function);
  1023. return 0;
  1024. }
  1025. int EQ2Emu_lua_SetLootCoin(lua_State* state) {
  1026. if (!lua_interface)
  1027. return 0;
  1028. Spawn* spawn = lua_interface->GetSpawn(state);
  1029. if (spawn && spawn->IsEntity()) {
  1030. int32 val = lua_interface->GetInt32Value(state, 2);
  1031. ((Entity*)spawn)->SetLootCoins(val);
  1032. }
  1033. lua_interface->ResetFunctionStack(state);
  1034. return 0;
  1035. }
  1036. int EQ2Emu_lua_GetLootCoin(lua_State* state) {
  1037. if (!lua_interface)
  1038. return 0;
  1039. Spawn* spawn = lua_interface->GetSpawn(state);
  1040. lua_interface->ResetFunctionStack(state);
  1041. if (spawn && spawn->IsEntity()) {
  1042. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetLootCoins());
  1043. return 1;
  1044. }
  1045. return 0;
  1046. }
  1047. int EQ2Emu_lua_MovementLoopAdd(lua_State* state) {
  1048. if (!lua_interface)
  1049. return 0;
  1050. Spawn* spawn = lua_interface->GetSpawn(state);
  1051. float x = lua_interface->GetFloatValue(state, 2);
  1052. float y = lua_interface->GetFloatValue(state, 3);
  1053. float z = lua_interface->GetFloatValue(state, 4);
  1054. float speed = lua_interface->GetFloatValue(state, 5);
  1055. int32 delay = lua_interface->GetInt32Value(state, 6); //this should be given as seconds, as it is converted to ms later
  1056. string function = lua_interface->GetStringValue(state, 7);
  1057. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1058. float heading = lua_interface->GetFloatValue(state, 8);
  1059. if (spawn) {
  1060. spawn->AddMovementLocation(x, y, z, speed, delay, function.c_str(), heading, (num_args > 7) ? true : false );
  1061. spawn->GetZone()->AddMovementNPC(spawn);
  1062. }
  1063. lua_interface->ResetFunctionStack(state);
  1064. return 0;
  1065. }
  1066. int EQ2Emu_lua_IsPlayer(lua_State* state) {
  1067. if (!lua_interface)
  1068. return 0;
  1069. Spawn* spawn = lua_interface->GetSpawn(state);
  1070. lua_interface->ResetFunctionStack(state);
  1071. if (spawn) {
  1072. lua_interface->SetBooleanValue(state, spawn->IsPlayer());
  1073. return 1;
  1074. }
  1075. return 0;
  1076. }
  1077. int EQ2Emu_lua_GetCharacterID(lua_State* state) {
  1078. if (!lua_interface)
  1079. return 0;
  1080. Spawn* spawn = lua_interface->GetSpawn(state);
  1081. lua_interface->ResetFunctionStack(state);
  1082. if (spawn && spawn->IsPlayer()) {
  1083. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetCharacterID());
  1084. return 1;
  1085. }
  1086. lua_interface->SetInt32Value(state, 0);
  1087. return 1;
  1088. }
  1089. int EQ2Emu_lua_FaceTarget(lua_State* state) {
  1090. if (!lua_interface)
  1091. return 0;
  1092. Spawn* spawn = lua_interface->GetSpawn(state);
  1093. Spawn* target = lua_interface->GetSpawn(state, 2);
  1094. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  1095. bool reset_action_state = true;
  1096. if(num_args > 2)
  1097. reset_action_state = lua_interface->GetBooleanValue(state, 3);
  1098. if (spawn && target) {
  1099. if (spawn->IsEntity())
  1100. // ((Entity*)spawn)->FaceTarget(target);
  1101. static_cast<Entity*>(spawn)->FaceTarget(target, reset_action_state);
  1102. }
  1103. lua_interface->ResetFunctionStack(state);
  1104. return 0;
  1105. }
  1106. int EQ2Emu_lua_MoveToLocation(lua_State* state) {
  1107. if (!lua_interface)
  1108. return 0;
  1109. Spawn* spawn = lua_interface->GetSpawn(state);
  1110. float x = lua_interface->GetFloatValue(state, 2);
  1111. float y = lua_interface->GetFloatValue(state, 3);
  1112. float z = lua_interface->GetFloatValue(state, 4);
  1113. float speed = lua_interface->GetFloatValue(state, 5);
  1114. string lua_function = lua_interface->GetStringValue(state, 6);
  1115. bool more_points = lua_interface->GetBooleanValue(state, 7);
  1116. if (spawn) {
  1117. if (speed == 0)
  1118. speed = spawn->GetSpeed();
  1119. spawn->AddRunningLocation(x, y, z, speed, 0.0f, true, !more_points, lua_function);
  1120. }
  1121. lua_interface->ResetFunctionStack(state);
  1122. return 0;
  1123. }
  1124. int EQ2Emu_lua_ClearRunningLocations(lua_State* state) {
  1125. if (!lua_interface)
  1126. return 0;
  1127. Spawn* spawn = lua_interface->GetSpawn(state);
  1128. lua_interface->ResetFunctionStack(state);
  1129. if (spawn) {
  1130. spawn->ClearRunningLocations();
  1131. }
  1132. return 0;
  1133. }
  1134. int EQ2Emu_lua_Say(lua_State* state) {
  1135. if (!lua_interface)
  1136. return 0;
  1137. Spawn* spawn = lua_interface->GetSpawn(state);
  1138. string message = lua_interface->GetStringValue(state, 2);
  1139. Spawn* player = lua_interface->GetSpawn(state, 3);
  1140. int32 language = lua_interface->GetInt32Value(state, 4);
  1141. if (spawn && message.length() > 0) {
  1142. Client* client = 0;
  1143. if (player && player->IsPlayer())
  1144. client = spawn->GetZone()->GetClientBySpawn(player);
  1145. if (client)
  1146. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1147. else
  1148. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SAY, message.c_str(), 30, 0, true, language);
  1149. }
  1150. lua_interface->ResetFunctionStack(state);
  1151. return 0;
  1152. }
  1153. int EQ2Emu_lua_Shout(lua_State* state) {
  1154. if (!lua_interface)
  1155. return 0;
  1156. Spawn* spawn = lua_interface->GetSpawn(state);
  1157. string message = lua_interface->GetStringValue(state, 2);
  1158. Spawn* player = lua_interface->GetSpawn(state, 3);
  1159. float dist = lua_interface->GetFloatValue(state, 4);
  1160. if (spawn && message.length() > 0) {
  1161. Client* client = 0;
  1162. if (player && player->IsPlayer())
  1163. client = spawn->GetZone()->GetClientBySpawn(player);
  1164. if (client)
  1165. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1166. else
  1167. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_SHOUT, message.c_str(), (dist > 0.0f) ? dist : 30.0f);
  1168. }
  1169. lua_interface->ResetFunctionStack(state);
  1170. return 0;
  1171. }
  1172. int EQ2Emu_lua_SayOOC(lua_State* state) {
  1173. if (!lua_interface)
  1174. return 0;
  1175. Spawn* spawn = lua_interface->GetSpawn(state);
  1176. string message = lua_interface->GetStringValue(state, 2);
  1177. Spawn* player = lua_interface->GetSpawn(state, 3);
  1178. if (spawn && message.length() > 0) {
  1179. Client* client = 0;
  1180. if (player && player->IsPlayer())
  1181. client = spawn->GetZone()->GetClientBySpawn(player);
  1182. if (client)
  1183. spawn->GetZone()->HandleChatMessage(client, spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1184. else
  1185. spawn->GetZone()->HandleChatMessage(spawn, 0, CHANNEL_OUT_OF_CHARACTER, message.c_str(), 30);
  1186. }
  1187. lua_interface->ResetFunctionStack(state);
  1188. return 0;
  1189. }
  1190. int EQ2Emu_lua_Emote(lua_State* state) {
  1191. if (!lua_interface)
  1192. return 0;
  1193. Spawn* spawn = lua_interface->GetSpawn(state);
  1194. string message = lua_interface->GetStringValue(state, 2);
  1195. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  1196. Spawn* player = lua_interface->GetSpawn(state, 4);
  1197. char* to = 0;
  1198. if (spawn2)
  1199. to = spawn2->GetName();
  1200. if (spawn && message.length() > 0) {
  1201. Client* client = 0;
  1202. if (player && player->IsPlayer())
  1203. client = spawn->GetZone()->GetClientBySpawn(player);
  1204. if (client)
  1205. spawn->GetZone()->HandleChatMessage(client, spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1206. else
  1207. spawn->GetZone()->HandleChatMessage(spawn, to, CHANNEL_EMOTE, message.c_str(), 30);
  1208. }
  1209. lua_interface->ResetFunctionStack(state);
  1210. return 0;
  1211. }
  1212. int EQ2Emu_lua_SpellHeal(lua_State* state) {
  1213. if (!lua_interface)
  1214. return 0;
  1215. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1216. if(!luaspell || luaspell->resisted) {
  1217. return 0;
  1218. }
  1219. Spawn* caster = luaspell->caster;
  1220. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1221. int32 min_heal = lua_interface->GetInt32Value(state, 2);
  1222. int32 max_heal = lua_interface->GetInt32Value(state, 3);
  1223. Spawn* target = lua_interface->GetSpawn(state, 4);
  1224. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1225. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1226. string custom_spell_name = lua_interface->GetStringValue(state, 7);//custom spell name
  1227. lua_interface->ResetFunctionStack(state);
  1228. boost::to_lower(heal_type);
  1229. if (caster && caster->IsEntity()) {
  1230. bool success = false;
  1231. luaspell->resisted = false;
  1232. if (target) {
  1233. float distance = caster->GetDistance(target, true);
  1234. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1235. success = true;
  1236. }
  1237. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1238. Spawn* target = 0;
  1239. ZoneServer* zone = luaspell->caster->GetZone();
  1240. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1241. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1242. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1243. float distance = caster->GetDistance(target, true);
  1244. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1245. }
  1246. }
  1247. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1248. success = true;
  1249. }
  1250. if (success) {
  1251. if (caster->GetZone())
  1252. caster->GetZone()->TriggerCharSheetTimer();
  1253. }
  1254. }
  1255. return 0;
  1256. }
  1257. int EQ2Emu_lua_SpellHealPct(lua_State* state) {
  1258. if (!lua_interface)
  1259. return 0;
  1260. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1261. if(!luaspell || luaspell->resisted) {
  1262. return 0;
  1263. }
  1264. Spawn* caster = luaspell->caster;
  1265. string heal_type = lua_interface->GetStringValue(state);//power, heal ect
  1266. float percentage = lua_interface->GetFloatValue(state, 2);
  1267. bool current_value = lua_interface->GetBooleanValue(state, 3);
  1268. bool caster_value = lua_interface->GetBooleanValue(state, 4);
  1269. Spawn* target = lua_interface->GetSpawn(state, 5);
  1270. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  1271. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  1272. string custom_spell_name = lua_interface->GetStringValue(state, 8);//custom spell name
  1273. lua_interface->ResetFunctionStack(state);
  1274. boost::to_lower(heal_type);
  1275. int32 min_heal = 0, max_heal = 0;
  1276. if (caster && caster->IsEntity() && target) {
  1277. if(percentage <= 0.0f)
  1278. {
  1279. LogWrite(LUA__ERROR, 0, "LUA", "Error applying SpellHealPct on '%s'. percentage %f is less than or equal to 0.",target->GetName(),percentage);
  1280. return 0;
  1281. }
  1282. if(heal_type == "power")
  1283. {
  1284. if(current_value)
  1285. {
  1286. if(caster_value)
  1287. min_heal = max_heal = (int32)(float)caster->GetPower() * (percentage / 100.0f);
  1288. else
  1289. min_heal = max_heal = (int32)(float)target->GetPower() * (percentage / 100.0f);
  1290. }
  1291. else
  1292. {
  1293. if(caster_value)
  1294. min_heal = max_heal = (int32)(float)caster->GetTotalPower() * (percentage / 100.0f);
  1295. else
  1296. min_heal = max_heal = (int32)(float)target->GetTotalPower() * (percentage / 100.0f);
  1297. }
  1298. }
  1299. else
  1300. {
  1301. if(current_value)
  1302. {
  1303. if(caster_value)
  1304. min_heal = max_heal = (int32)(float)caster->GetHP() * (percentage / 100.0f);
  1305. else
  1306. min_heal = max_heal = (int32)(float)target->GetHP() * (percentage / 100.0f);
  1307. }
  1308. else
  1309. {
  1310. if(caster_value)
  1311. min_heal = max_heal = (int32)(float)caster->GetTotalHP() * (percentage / 100.0f);
  1312. else
  1313. min_heal = max_heal = (int32)(float)target->GetTotalHP() * (percentage / 100.0f);
  1314. }
  1315. }
  1316. bool success = false;
  1317. luaspell->resisted = false;
  1318. if (target) {
  1319. float distance = caster->GetDistance(target, true);
  1320. if (((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name))
  1321. success = true;
  1322. }
  1323. if ((!success || luaspell->spell->GetSpellData()->group_spell) && luaspell->targets.size() > 0) {
  1324. Spawn* target = 0;
  1325. ZoneServer* zone = luaspell->caster->GetZone();
  1326. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1327. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1328. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1329. float distance = caster->GetDistance(target, true);
  1330. ((Entity*)caster)->SpellHeal(target, distance, luaspell, heal_type, min_heal, max_heal, crit_mod, no_calcs, custom_spell_name);
  1331. }
  1332. }
  1333. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1334. success = true;
  1335. }
  1336. if (success) {
  1337. if (caster->GetZone())
  1338. caster->GetZone()->TriggerCharSheetTimer();
  1339. }
  1340. }
  1341. return 0;
  1342. }
  1343. int EQ2Emu_lua_AddItem(lua_State* state) {
  1344. if (!lua_interface)
  1345. return 0;
  1346. Spawn* spawn = lua_interface->GetSpawn(state);
  1347. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1348. int16 quantity = lua_interface->GetInt32Value(state, 3);
  1349. lua_interface->ResetFunctionStack(state);
  1350. // default of 1 quantity to add
  1351. if (quantity == 0)
  1352. quantity = 1;
  1353. if (spawn && spawn->IsPlayer()) {
  1354. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1355. if (client && item_id > 0) {
  1356. lua_interface->SetBooleanValue(state, client->AddItem(item_id, quantity));
  1357. return 1;
  1358. }
  1359. }
  1360. lua_interface->SetBooleanValue(state, false);
  1361. return 1;
  1362. }
  1363. int EQ2Emu_lua_SummonItem(lua_State* state) {
  1364. if (!lua_interface)
  1365. return 0;
  1366. Spawn* spawn = lua_interface->GetSpawn(state);
  1367. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1368. bool send_messages = (lua_interface->GetInt8Value(state, 3) == 1);
  1369. string location = lua_interface->GetStringValue(state, 4);
  1370. int16 item_count = lua_interface->GetInt16Value(state,5);
  1371. //devn00b: if we dont have a count, assume 1 item.
  1372. if(!item_count) {
  1373. item_count = 1;
  1374. }
  1375. lua_interface->ResetFunctionStack(state);
  1376. if (spawn && spawn->IsPlayer()) {
  1377. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1378. if (client && item_id > 0) {
  1379. if (strncasecmp(location.c_str(), "bank", 4) == 0)
  1380. lua_interface->SetBooleanValue(state, client->AddItemToBank(item_id, item_count));
  1381. else
  1382. lua_interface->SetBooleanValue(state, client->AddItem(item_id, item_count));
  1383. if (send_messages) {
  1384. Item* item = master_item_list.GetItem(item_id);
  1385. if (item) {
  1386. if(item_count > 1) {
  1387. client->Message(CHANNEL_COLOR_YELLOW, "You receive %i %s.", item_count, item->CreateItemLink(client->GetVersion()).c_str());
  1388. string popup_text1 = "You receive "+ item_count;
  1389. string popup_text2 = " " + item->name;
  1390. string popup_text = popup_text1 + popup_text2;
  1391. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1392. // return 1;
  1393. } else {
  1394. client->Message(CHANNEL_COLOR_YELLOW, "You receive %s.", item->CreateItemLink(client->GetVersion()).c_str());
  1395. string popup_text = "You receive " + item->name;
  1396. client->SendPopupMessage(10, popup_text.c_str(), "ui_harvested_normal", 3, 0xFF, 0xFF, 0xFF);
  1397. }
  1398. }
  1399. }
  1400. return 1;
  1401. }
  1402. }
  1403. lua_interface->SetBooleanValue(state, false);
  1404. return 1;
  1405. }
  1406. int EQ2Emu_lua_RemoveItem(lua_State* state) {
  1407. Spawn* spawn = lua_interface->GetSpawn(state);
  1408. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1409. int16 quantity = lua_interface->GetInt16Value(state, 3);
  1410. lua_interface->ResetFunctionStack(state);
  1411. // default of 1 to remove
  1412. if (quantity == 0)
  1413. quantity = 1;
  1414. Client* client;
  1415. Item* item;
  1416. if (spawn && spawn->IsPlayer() && item_id > 0) {
  1417. if ((client = spawn->GetZone()->GetClientBySpawn(spawn))) {
  1418. if ((item = client->GetPlayer()->item_list.GetItemFromID(item_id))) {
  1419. if (client->RemoveItem(item, quantity)) {
  1420. lua_interface->SetBooleanValue(state, true);
  1421. return 1;
  1422. }
  1423. }
  1424. }
  1425. }
  1426. lua_interface->SetBooleanValue(state, false);
  1427. return 1;
  1428. }
  1429. int EQ2Emu_lua_HasItem(lua_State* state) {
  1430. Spawn* player = lua_interface->GetSpawn(state);
  1431. int32 item_id = lua_interface->GetInt32Value(state, 2);
  1432. bool include_bank = lua_interface->GetInt8Value(state, 3);
  1433. lua_interface->ResetFunctionStack(state);
  1434. if (player && player->IsPlayer()) {
  1435. bool hasItem = false;
  1436. hasItem = ((Player*)player)->item_list.HasItem(item_id, include_bank);
  1437. if (!hasItem)
  1438. hasItem = ((Player*)player)->GetEquipmentList()->HasItem(item_id);
  1439. lua_interface->SetBooleanValue(state, hasItem);
  1440. return 1;
  1441. }
  1442. lua_interface->SetBooleanValue(state, false);
  1443. return 1;
  1444. }
  1445. int EQ2Emu_lua_Spawn(lua_State* state) {
  1446. if (!lua_interface)
  1447. return 0;
  1448. ZoneServer* zone = lua_interface->GetZone(state);
  1449. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  1450. bool restricted_npc = (lua_interface->GetInt8Value(state, 3) == 1);
  1451. float x = lua_interface->GetFloatValue(state, 4);
  1452. float y = lua_interface->GetFloatValue(state, 5);
  1453. float z = lua_interface->GetFloatValue(state, 6);
  1454. float heading = lua_interface->GetFloatValue(state, 7);
  1455. if (zone && spawn_id > 0 && (x != 0 || y != 0 || z != 0)) {
  1456. Spawn* spawn = zone->GetSpawn(spawn_id);
  1457. if (!spawn)
  1458. lua_interface->LogError("%s: LUA Spawn command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), spawn_id);
  1459. else {
  1460. spawn->SetX(x);
  1461. spawn->SetZ(z);
  1462. spawn->SetY(y,true,true);
  1463. spawn->SetLocation(zone->GetClosestLocation(spawn));
  1464. spawn->SetHeading(heading);
  1465. if (restricted_npc)
  1466. spawn->AddAllowAccessSpawn(spawn);
  1467. const char* spawn_script = world.GetSpawnScript(spawn_id);
  1468. bool scriptActive = false;
  1469. if (spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0) {
  1470. scriptActive = true;
  1471. spawn->SetSpawnScript(string(spawn_script));
  1472. }
  1473. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_PRESPAWN);
  1474. zone->AddSpawn(spawn);
  1475. if (scriptActive) {
  1476. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  1477. }
  1478. lua_interface->ResetFunctionStack(state);
  1479. lua_interface->SetSpawnValue(state, spawn);
  1480. return 1;
  1481. }
  1482. }
  1483. else {
  1484. string output = "Invalid paramaters to LUA Spawn command: \n";
  1485. if (!zone)
  1486. output = output.append("\t").append("Missing zone reference. \n");
  1487. if (spawn_id == 0)
  1488. output = output.append("\t").append("Missing spawn_id.");
  1489. lua_interface->LogError("%s: Error in EQ2Emu_lua_Spawn - %s", lua_interface->GetScriptName(state), output.c_str());
  1490. }
  1491. lua_interface->ResetFunctionStack(state);
  1492. return 0;
  1493. }
  1494. int EQ2Emu_lua_GetZoneName(lua_State* state) {
  1495. if (!lua_interface)
  1496. return 0;
  1497. ZoneServer* zone = lua_interface->GetZone(state);
  1498. lua_interface->ResetFunctionStack(state);
  1499. if (zone) {
  1500. lua_interface->SetStringValue(state, zone->GetZoneName());
  1501. return 1;
  1502. }
  1503. return 0;
  1504. }
  1505. int EQ2Emu_lua_GetZoneID(lua_State* state) {
  1506. if (!lua_interface)
  1507. return 0;
  1508. ZoneServer* zone = lua_interface->GetZone(state);
  1509. lua_interface->ResetFunctionStack(state);
  1510. if (zone) {
  1511. lua_interface->SetInt32Value(state, zone->GetZoneID());
  1512. return 1;
  1513. }
  1514. return 0;
  1515. }
  1516. int EQ2Emu_lua_GetZone(lua_State* state) {
  1517. if (!lua_interface)
  1518. return 0;
  1519. int32 zone_id = lua_interface->GetInt32Value(state);
  1520. ZoneServer* zone = 0;
  1521. if (zone_id > 0)
  1522. zone = zone_list.Get(zone_id);
  1523. else {
  1524. string zone_name = lua_interface->GetStringValue(state);
  1525. if (zone_name.length() > 0) {
  1526. zone = zone_list.Get(zone_name.c_str());
  1527. }
  1528. else {
  1529. Spawn* spawn = lua_interface->GetSpawn(state);
  1530. if (spawn)
  1531. zone = spawn->GetZone();
  1532. }
  1533. }
  1534. lua_interface->ResetFunctionStack(state);
  1535. if (zone) {
  1536. lua_interface->SetZoneValue(state, zone);
  1537. return 1;
  1538. }
  1539. return 0;
  1540. }
  1541. int EQ2Emu_lua_AddHate(lua_State* state) {
  1542. Spawn* entity = lua_interface->GetSpawn(state);
  1543. Spawn* npc = lua_interface->GetSpawn(state, 2);
  1544. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  1545. bool send_packet = lua_interface->GetInt8Value(state, 4) == 1 ? true : false;
  1546. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1547. if(!luaspell || luaspell->resisted) {
  1548. return 0;
  1549. }
  1550. if (entity && entity->IsEntity() && amount != 0) {
  1551. if (luaspell) {
  1552. ZoneServer* zone = luaspell->caster->GetZone();
  1553. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1554. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1555. Spawn* spawn = zone->GetSpawnByID(luaspell->targets.at(i));
  1556. if (spawn && spawn->IsNPC() && spawn->Alive() && spawn->GetZone()) {
  1557. ((NPC*)spawn)->AddHate((Entity*)entity, amount);
  1558. if (send_packet)
  1559. entity->GetZone()->SendThreatPacket(entity, npc, amount, luaspell->spell->GetName());
  1560. }
  1561. }
  1562. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1563. }
  1564. else if (npc && npc->IsNPC() && npc->GetZone())
  1565. ((NPC*)npc)->AddHate((Entity*)entity, amount);
  1566. }
  1567. lua_interface->ResetFunctionStack(state);
  1568. return 0;
  1569. }
  1570. int EQ2Emu_lua_Zone(lua_State* state) {
  1571. if (!lua_interface)
  1572. return 0;
  1573. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  1574. ZoneServer* zone = lua_interface->GetZone(state);
  1575. Spawn* player = lua_interface->GetSpawn(state, 2);
  1576. Client* client = 0;
  1577. if (player && player->IsPlayer())
  1578. client = player->GetZone()->GetClientBySpawn(player);
  1579. float x = lua_interface->GetFloatValue(state, 3);
  1580. float y = lua_interface->GetFloatValue(state, 4);
  1581. float z = lua_interface->GetFloatValue(state, 5);
  1582. float heading = lua_interface->GetFloatValue(state, 6);
  1583. if (zone && client) {
  1584. LogWrite(LUA__DEBUG, 0, "LUA", "LUA Zone Request by Player: '%s' (%u)", player->GetName(), player->GetID());
  1585. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Zone: '%s' (%u)", zone->GetZoneName(), zone->GetZoneID());
  1586. if (!client->CheckZoneAccess(zone->GetZoneName()))
  1587. {
  1588. LogWrite(LUA__WARNING, 0, "LUA", "CheckZoneAccess() FAILED! LUA Zone Request Denied!");
  1589. return 0;
  1590. }
  1591. if (x != 0 || y != 0 || z != 0) {
  1592. LogWrite(LUA__DEBUG, 5, "LUA", "\tTo Coordinates: %2f, %2f, %2f, %2f", x, y, z, heading);
  1593. player->SetX(x);
  1594. player->SetY(y);
  1595. player->SetZ(z);
  1596. player->SetHeading(heading);
  1597. client->Zone(zone->GetZoneName(), false);
  1598. }
  1599. else
  1600. client->Zone(zone->GetZoneName());
  1601. }
  1602. else
  1603. lua_interface->LogError("%s: Error in EQ2Emu_lua_Zone: invalid zone or spawn input.", lua_interface->GetScriptName(state));
  1604. lua_interface->ResetFunctionStack(state);
  1605. return 0;
  1606. }
  1607. int EQ2Emu_lua_AddSpawnAccess(lua_State* state) {
  1608. if (!lua_interface)
  1609. return 0;
  1610. Spawn* spawn = lua_interface->GetSpawn(state);
  1611. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  1612. if (spawn && spawn2)
  1613. spawn->AddAllowAccessSpawn(spawn2);
  1614. lua_interface->ResetFunctionStack(state);
  1615. return 0;
  1616. }
  1617. int EQ2Emu_lua_CastSpell(lua_State* state) {
  1618. if (!lua_interface)
  1619. return 0;
  1620. Spawn* target = lua_interface->GetSpawn(state);
  1621. int32 spell_id = lua_interface->GetInt32Value(state, 2);
  1622. int8 spell_tier = lua_interface->GetInt8Value(state, 3);
  1623. Spawn* caster = lua_interface->GetSpawn(state, 4);
  1624. int16 custom_cast_time = lua_interface->GetInt16Value(state, 5);
  1625. lua_interface->ResetFunctionStack(state);
  1626. if (!target) {
  1627. lua_interface->LogError("%s: LUA CastSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  1628. return 0;
  1629. }
  1630. if (!target->IsEntity()) {
  1631. lua_interface->LogError("%s: LUA CastSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  1632. return 0;
  1633. }
  1634. if (spell_id <= 0) {
  1635. lua_interface->LogError("%s: LUA CastSpell command error: spell id is not valid", lua_interface->GetScriptName(state));
  1636. return 0;
  1637. }
  1638. if (caster && !caster->IsEntity()) {
  1639. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  1640. return 0;
  1641. }
  1642. if (spell_tier == 0)
  1643. spell_tier = 1;
  1644. if (!caster)
  1645. caster = target;
  1646. target->GetZone()->ProcessSpell(master_spell_list.GetSpell(spell_id, spell_tier), (Entity*)caster, (Entity*)target, true, false, NULL, custom_cast_time);
  1647. return 0;
  1648. }
  1649. int EQ2Emu_lua_SpellDamage(lua_State* state) {
  1650. if (!lua_interface)
  1651. return 0;
  1652. Spawn* target = lua_interface->GetSpawn(state);
  1653. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  1654. if(!luaspell || luaspell->resisted) {
  1655. return 0;
  1656. }
  1657. Spawn* caster = luaspell->caster;
  1658. sint32 type = lua_interface->GetSInt32Value(state, 2);
  1659. int32 min_damage = lua_interface->GetInt32Value(state, 3);
  1660. int32 max_damage = lua_interface->GetInt32Value(state, 4);
  1661. int8 crit_mod = lua_interface->GetInt32Value(state, 5);
  1662. bool no_calcs = lua_interface->GetInt32Value(state, 6) == 1;
  1663. //lua_interface->ResetFunctionStack(state);
  1664. int32 class_id = lua_interface->GetInt32Value(state, 7);
  1665. vector<int16> faction_req;
  1666. vector<int16> race_req;
  1667. int32 class_req = 0;
  1668. int32 i = 0;
  1669. int8 f = 0;
  1670. int8 r = 0;
  1671. while ((class_id = lua_interface->GetInt32Value(state, 7 + i))) {
  1672. if (class_id < 100) {
  1673. class_req += pow(2.0, double(class_id - 1));
  1674. }
  1675. else if (class_id > 100 && class_id < 1000) {
  1676. race_req.push_back(class_id);
  1677. r++;
  1678. }
  1679. else {
  1680. faction_req.push_back(class_id);
  1681. f++;
  1682. }
  1683. i++;
  1684. }
  1685. lua_interface->ResetFunctionStack(state);
  1686. if (caster && caster->IsEntity()) {
  1687. bool race_match = false;
  1688. bool success = false;
  1689. luaspell->resisted = false;
  1690. if (luaspell->targets.size() > 0) {
  1691. ZoneServer* zone = luaspell->caster->GetZone();
  1692. Spawn* target = 0;
  1693. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  1694. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  1695. if ((target = zone->GetSpawnByID(luaspell->targets[i]))) {
  1696. if (race_req.size() > 0) {
  1697. for (int8 i = 0; i < race_req.size(); i++) {
  1698. if (target->GetLuaRaceId() == race_req[i]) {
  1699. race_match = true;
  1700. }
  1701. }
  1702. }
  1703. else
  1704. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1705. if (race_match == true) {
  1706. float distance = caster->GetDistance(target, true);
  1707. ((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs);
  1708. }
  1709. }
  1710. }
  1711. success = true;
  1712. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  1713. }
  1714. else if (target) {
  1715. //check class and race/faction here
  1716. if (race_req.size() > 0) {
  1717. for (int8 i = 0; i < race_req.size(); i++) {
  1718. if (target->GetLuaRaceId() == race_req[i]) {
  1719. race_match = true;
  1720. }
  1721. }
  1722. }
  1723. else
  1724. race_match = true; // if the race_req.size = 0 then there is no race requirement and the race_match will be true
  1725. if (race_match == true) {
  1726. float distance = caster->GetDistance(target, true);
  1727. if (((Entity*)caster)->SpellAttack(target, distance, luaspell, type, min_damage, max_damage, crit_mod, no_calcs))
  1728. success = true;
  1729. }
  1730. }
  1731. if (success) {
  1732. Spell* spell = luaspell->spell;
  1733. if (caster->IsPlayer() && spell && spell->GetSpellData()->target_type == 1 && spell->GetSpellData()->spell_book_type == 1) { //offense combat art
  1734. ((Player*)caster)->InCombat(true);
  1735. if (caster->GetZone())
  1736. caster->GetZone()->TriggerCharSheetTimer();
  1737. }
  1738. }
  1739. }
  1740. return 0;
  1741. }
  1742. int EQ2Emu_lua_ModifyPower(lua_State* state) {
  1743. if (!lua_interface)
  1744. return 0;
  1745. Spawn* spawn = lua_interface->GetSpawn(state);
  1746. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1747. lua_interface->ResetFunctionStack(state);
  1748. if (spawn && value != 0) {
  1749. if (spawn->GetPower() + value > spawn->GetTotalPower())
  1750. spawn->SetPower(spawn->GetTotalPower());
  1751. else
  1752. spawn->SetPower(spawn->GetPower() + value);
  1753. }
  1754. return 0;
  1755. }
  1756. int EQ2Emu_lua_ModifyHP(lua_State* state) {
  1757. if (!lua_interface)
  1758. return 0;
  1759. Spawn* spawn = lua_interface->GetSpawn(state);
  1760. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1761. lua_interface->ResetFunctionStack(state);
  1762. if (spawn && value != 0) {
  1763. if (spawn->GetHP() + value > spawn->GetTotalHP())
  1764. spawn->SetHP(spawn->GetTotalHP());
  1765. else
  1766. spawn->SetHP(spawn->GetHP() + value);
  1767. }
  1768. return 0;
  1769. }
  1770. int EQ2Emu_lua_ModifyMaxPower(lua_State* state) {
  1771. if (!lua_interface)
  1772. return 0;
  1773. Spawn* spawn = lua_interface->GetSpawn(state);
  1774. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1775. lua_interface->ResetFunctionStack(state);
  1776. if (spawn && value != 0) {
  1777. spawn->SetPower(spawn->GetPower() + value);
  1778. if (value > spawn->GetTotalHPBase())
  1779. spawn->SetTotalPower(spawn->GetTotalPower() + value);
  1780. }
  1781. return 0;
  1782. }
  1783. int EQ2Emu_lua_ModifyMaxHP(lua_State* state) {
  1784. if (!lua_interface)
  1785. return 0;
  1786. Spawn* spawn = lua_interface->GetSpawn(state);
  1787. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1788. lua_interface->ResetFunctionStack(state);
  1789. if (spawn && value != 0) {
  1790. spawn->SetHP(spawn->GetHP() + value);
  1791. if (value > spawn->GetTotalHPBase())
  1792. spawn->SetTotalHP(spawn->GetTotalHP() + value);
  1793. }
  1794. return 0;
  1795. }
  1796. int EQ2Emu_lua_SetCurrentHP(lua_State* state) {
  1797. if (!lua_interface)
  1798. return 0;
  1799. Spawn* spawn = lua_interface->GetSpawn(state);
  1800. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1801. lua_interface->ResetFunctionStack(state);
  1802. if (spawn) {
  1803. spawn->SetHP(value);
  1804. if (value > spawn->GetTotalHPBase())
  1805. spawn->SetTotalHP(value);
  1806. }
  1807. return 0;
  1808. }
  1809. int EQ2Emu_lua_SetMaxHP(lua_State* state) {
  1810. if (!lua_interface)
  1811. return 0;
  1812. Spawn* spawn = lua_interface->GetSpawn(state);
  1813. float value = lua_interface->GetFloatValue(state, 2);
  1814. lua_interface->ResetFunctionStack(state);
  1815. if (spawn && spawn->IsEntity() && value > 0)
  1816. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_HEALTH, value - spawn->GetTotalHP());
  1817. if (spawn->IsPlayer())
  1818. ((Player*)spawn)->SetCharSheetChanged(true);
  1819. return 0;
  1820. }
  1821. int EQ2Emu_lua_SetMaxHPBase(lua_State* state) {
  1822. if (!lua_interface)
  1823. return 0;
  1824. Spawn* spawn = lua_interface->GetSpawn(state);
  1825. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1826. lua_interface->ResetFunctionStack(state);
  1827. if (spawn && spawn->IsEntity() && value > 0)
  1828. ((Entity*)spawn)->SetTotalHPBase(value);
  1829. return 0;
  1830. }
  1831. int EQ2Emu_lua_SetCurrentPower(lua_State* state) {
  1832. if (!lua_interface)
  1833. return 0;
  1834. Spawn* spawn = lua_interface->GetSpawn(state);
  1835. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1836. lua_interface->ResetFunctionStack(state);
  1837. if (spawn && value > 0) {
  1838. spawn->SetPower(value);
  1839. if (value > spawn->GetTotalPowerBase())
  1840. spawn->SetTotalPower(value);
  1841. }
  1842. return 0;
  1843. }
  1844. int EQ2Emu_lua_SetMaxPower(lua_State* state) {
  1845. if (!lua_interface)
  1846. return 0;
  1847. Spawn* spawn = lua_interface->GetSpawn(state);
  1848. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1849. lua_interface->ResetFunctionStack(state);
  1850. if (spawn && spawn->IsEntity() && value > 0)
  1851. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_POWER, value - spawn->GetTotalPower());
  1852. return 0;
  1853. }
  1854. int EQ2Emu_lua_SetMaxPowerBase(lua_State* state) {
  1855. if (!lua_interface)
  1856. return 0;
  1857. Spawn* spawn = lua_interface->GetSpawn(state);
  1858. sint32 value = lua_interface->GetSInt32Value(state, 2);
  1859. lua_interface->ResetFunctionStack(state);
  1860. if (spawn && spawn->IsEntity() && value > 0)
  1861. ((Entity*)spawn)->SetTotalPowerBase(value);
  1862. return 0;
  1863. }
  1864. int EQ2Emu_lua_SetPosition(lua_State* state) {
  1865. if (!lua_interface)
  1866. return 0;
  1867. Spawn* spawn = lua_interface->GetSpawn(state);
  1868. float x = lua_interface->GetFloatValue(state, 2);
  1869. float y = lua_interface->GetFloatValue(state, 3);
  1870. float z = lua_interface->GetFloatValue(state, 4);
  1871. float heading = lua_interface->GetFloatValue(state, 5);
  1872. lua_interface->ResetFunctionStack(state);
  1873. if (spawn) {
  1874. spawn->SetX(x);
  1875. spawn->SetY(y);
  1876. spawn->SetZ(z);
  1877. if (heading != 0)
  1878. spawn->SetHeading(heading);
  1879. spawn->SetSpawnOrigX(spawn->GetX());
  1880. spawn->SetSpawnOrigY(spawn->GetY());
  1881. spawn->SetSpawnOrigZ(spawn->GetZ());
  1882. spawn->SetSpawnOrigHeading(spawn->GetHeading());
  1883. if (spawn->IsPlayer()) {
  1884. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1885. if (client) {
  1886. EQ2Packet* packet = client->GetPlayer()->Move(x, y, z, client->GetVersion(), (heading == 0 ? -1.0f : (heading + 180.0f)));
  1887. client->QueuePacket(packet);
  1888. }
  1889. }
  1890. }
  1891. return 0;
  1892. }
  1893. int EQ2Emu_lua_SetHeading(lua_State* state) {
  1894. if (!lua_interface)
  1895. return 0;
  1896. Spawn* spawn = lua_interface->GetSpawn(state);
  1897. float value = lua_interface->GetFloatValue(state, 2);
  1898. lua_interface->ResetFunctionStack(state);
  1899. if (spawn) {
  1900. spawn->SetHeading(value);
  1901. if (spawn->IsPlayer()) {
  1902. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  1903. if (client) {
  1904. EQ2Packet* packet = client->GetPlayer()->Move(spawn->GetX(), spawn->GetY(), spawn->GetZ(), client->GetVersion(), value + 180.0f);
  1905. client->QueuePacket(packet);
  1906. }
  1907. }
  1908. }
  1909. return 0;
  1910. }
  1911. int EQ2Emu_lua_SetModelType(lua_State* state) {
  1912. if (!lua_interface)
  1913. return 0;
  1914. Spawn* spawn = lua_interface->GetSpawn(state);
  1915. int16 value = lua_interface->GetInt16Value(state, 2);
  1916. lua_interface->ResetFunctionStack(state);
  1917. if (spawn)
  1918. spawn->SetModelType(value);
  1919. return 0;
  1920. }
  1921. int EQ2Emu_lua_SetAdventureClass(lua_State* state) {
  1922. if (!lua_interface)
  1923. return 0;
  1924. Spawn* spawn = lua_interface->GetSpawn(state);
  1925. int8 value = lua_interface->GetInt8Value(state, 2);
  1926. lua_interface->ResetFunctionStack(state);
  1927. if (spawn) {
  1928. if (spawn->IsPlayer())
  1929. ((Player*)spawn)->SetPlayerAdventureClass(value);
  1930. else
  1931. spawn->SetAdventureClass(value);
  1932. }
  1933. return 0;
  1934. }
  1935. int EQ2Emu_lua_SetTradeskillClass(lua_State* state) {
  1936. if (!lua_interface)
  1937. return 0;
  1938. Spawn* spawn = lua_interface->GetSpawn(state);
  1939. int8 value = lua_interface->GetInt8Value(state, 2);
  1940. lua_interface->ResetFunctionStack(state);
  1941. if (spawn) {
  1942. spawn->SetTradeskillClass(value);
  1943. if (spawn->IsEntity()) {
  1944. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class1(classes.GetTSBaseClass(spawn->GetTradeskillClass()));
  1945. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class2(classes.GetSecondaryTSBaseClass(spawn->GetTradeskillClass()));
  1946. ((Entity*)spawn)->GetInfoStruct()->set_tradeskill_class3(spawn->GetTradeskillClass());
  1947. }
  1948. if (spawn->IsPlayer())
  1949. ((Player*)spawn)->SetCharSheetChanged(true);
  1950. }
  1951. return 0;
  1952. }
  1953. int EQ2Emu_lua_SetMount(lua_State* state) {
  1954. if (!lua_interface)
  1955. return 0;
  1956. Spawn* spawn = lua_interface->GetSpawn(state);
  1957. int16 value = lua_interface->GetInt16Value(state, 2);
  1958. if (spawn && spawn->IsEntity()) {
  1959. ((Entity*)spawn)->SetMount(value);
  1960. EQ2_Color color;
  1961. color.red = 255;
  1962. color.green = 255;
  1963. color.blue = 255;
  1964. ((Entity*)spawn)->SetMountColor(&color);
  1965. ((Entity*)spawn)->SetMountSaddleColor(&color);
  1966. }
  1967. return 0;
  1968. }
  1969. int EQ2Emu_lua_SetMountColor(lua_State* state) {
  1970. if (!lua_interface)
  1971. return 0;
  1972. Spawn* spawn = lua_interface->GetSpawn(state);
  1973. EQ2_Color mount_color;
  1974. EQ2_Color saddle_color;
  1975. mount_color.red = lua_interface->GetInt8Value(state, 2);
  1976. mount_color.green = lua_interface->GetInt8Value(state, 3);
  1977. mount_color.blue = lua_interface->GetInt8Value(state, 4);
  1978. saddle_color.red = lua_interface->GetInt8Value(state, 5);
  1979. saddle_color.green = lua_interface->GetInt8Value(state, 6);
  1980. saddle_color.blue = lua_interface->GetInt8Value(state, 7);
  1981. if (spawn && spawn->IsEntity()) {
  1982. ((Entity*)spawn)->SetMountColor(&mount_color);
  1983. ((Entity*)spawn)->SetMountSaddleColor(&saddle_color);
  1984. }
  1985. return 0;
  1986. }
  1987. int EQ2Emu_lua_GetMount(lua_State* state) {
  1988. if (!lua_interface)
  1989. return 0;
  1990. Spawn* spawn = lua_interface->GetSpawn(state);
  1991. if (spawn && spawn->IsEntity()) {
  1992. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetMount());
  1993. return 1;
  1994. }
  1995. return 0;
  1996. }
  1997. int EQ2Emu_lua_GetRace(lua_State* state) {
  1998. if (!lua_interface)
  1999. return 0;
  2000. Spawn* spawn = lua_interface->GetSpawn(state);
  2001. if (spawn)
  2002. {
  2003. LogWrite(LUA__DEBUG, 0, "LUA", "%s - Race: %i", __FUNCTION__, spawn->GetRace());
  2004. lua_interface->SetInt32Value(state, spawn->GetRace());
  2005. return 1;
  2006. }
  2007. return 0;
  2008. }
  2009. int EQ2Emu_lua_GetRaceName(lua_State* state) {
  2010. if (!lua_interface)
  2011. return 0;
  2012. Spawn* spawn = lua_interface->GetSpawn(state);
  2013. if (spawn) {
  2014. lua_interface->SetStringValue(state, races.GetRaceName(spawn->GetRace()));
  2015. return 1;
  2016. }
  2017. return 0;
  2018. }
  2019. int EQ2Emu_lua_GetClass(lua_State* state) {
  2020. Spawn* spawn = lua_interface->GetSpawn(state);
  2021. if (spawn) {
  2022. lua_interface->SetInt32Value(state, spawn->GetAdventureClass());
  2023. return 1;
  2024. }
  2025. return 0;
  2026. }
  2027. int EQ2Emu_lua_GetClassName(lua_State* state) {
  2028. Spawn* spawn = lua_interface->GetSpawn(state);
  2029. if (spawn) {
  2030. lua_interface->SetStringValue(state, classes.GetClassName(spawn->GetAdventureClass()));
  2031. return 1;
  2032. }
  2033. return 0;
  2034. }
  2035. int EQ2Emu_lua_SetSpeed(lua_State* state) {
  2036. if (!lua_interface)
  2037. return 0;
  2038. Spawn* spawn = lua_interface->GetSpawn(state);
  2039. float value = lua_interface->GetFloatValue(state, 2);
  2040. lua_interface->ResetFunctionStack(state);
  2041. if (spawn) {
  2042. spawn->SetSpeed(value);
  2043. if(spawn->IsEntity())
  2044. ((Entity*)spawn)->SetSpeed(value);
  2045. if (spawn->IsPlayer()) {
  2046. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2047. if (client) {
  2048. PacketStruct* packet = configReader.getStruct("WS_SetControlGhost", client->GetVersion());
  2049. if (packet) {
  2050. packet->setDataByName("spawn_id", 0xFFFFFFFF);
  2051. packet->setDataByName("speed", value);
  2052. packet->setDataByName("size", 0.51);
  2053. EQ2Packet* app = packet->serialize();
  2054. client->QueuePacket(app);
  2055. safe_delete(packet);
  2056. }
  2057. }
  2058. }
  2059. }
  2060. return 0;
  2061. }
  2062. int EQ2Emu_lua_AddSpellBonus(lua_State* state) {
  2063. if (!lua_interface)
  2064. return 0;
  2065. Spawn* spawn = lua_interface->GetSpawn(state);
  2066. const int16 type = lua_interface->GetInt16Value(state, 2);
  2067. const float value = lua_interface->GetFloatValue(state, 3);
  2068. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2069. if(!luaspell || luaspell->resisted) {
  2070. return 0;
  2071. }
  2072. int64 class_req = 0;
  2073. int32 class_id = 0;
  2074. vector<int16> faction_req;
  2075. vector<int16> race_req;
  2076. int32 i = 0;
  2077. int8 f = 0;
  2078. int8 r = 0;
  2079. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2080. if (class_id < 100) {
  2081. class_req += pow(2.0, double(class_id - 1));
  2082. }
  2083. else if (class_id > 100 && class_id < 1000) {
  2084. race_req.push_back(class_id);
  2085. r++;
  2086. }
  2087. else {
  2088. faction_req.push_back(class_id);
  2089. f++;
  2090. }
  2091. i++;
  2092. }
  2093. if (value != 0 && type >= 0) {
  2094. if (luaspell && luaspell->spell && luaspell->caster) {
  2095. ZoneServer* zone = luaspell->caster->GetZone();
  2096. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2097. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2098. Spawn* target = zone->GetSpawnByID(luaspell->targets[i]);
  2099. if (target) {
  2100. if (target->IsPlayer()) {
  2101. ((Player*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2102. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Player '%s'. Is a Group Member.", ((Player*)target)->GetName());
  2103. if (((Player*)target)->GetGroupMemberInfo())
  2104. ((Player*)target)->UpdateGroupMemberInfo();
  2105. ((Player*)target)->SetCharSheetChanged(true);
  2106. }
  2107. else if (target->IsNPC())
  2108. ((NPC*)target)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2109. else
  2110. lua_interface->LogError("%s: Error applying spell bonus on non entity.", lua_interface->GetScriptName(state));
  2111. }
  2112. }
  2113. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2114. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2115. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2116. }
  2117. else if (spawn && spawn->IsEntity()) {
  2118. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2119. LogWrite(LUA__DEBUG, 0, "LUA", "Applying Spell Bonus to Entity '%s'. Is a Group Member.", ((Entity*)spawn)->GetName());
  2120. if (spawn->IsPlayer())
  2121. ((Player*)spawn)->SetCharSheetChanged(true);
  2122. }
  2123. else
  2124. lua_interface->LogError("%s: Unable to apply spell bonus in AddSpellBonus.", lua_interface->GetScriptName(state));
  2125. }
  2126. else
  2127. lua_interface->LogError("%s: Invalid parameters for AddSpellBonus.", lua_interface->GetScriptName(state));
  2128. return 0;
  2129. }
  2130. int EQ2Emu_lua_AddSpawnSpellBonus(lua_State* state) {
  2131. if (!lua_interface)
  2132. return 0;
  2133. Spawn* spawn = lua_interface->GetSpawn(state);
  2134. int16 type = lua_interface->GetInt16Value(state, 2);
  2135. sint32 value = lua_interface->GetSInt32Value(state, 3);
  2136. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2137. if (!spawn) {
  2138. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2139. return 0;
  2140. }
  2141. if (!spawn->IsEntity()) {
  2142. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2143. return 0;
  2144. }
  2145. if (value == 0) {
  2146. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: value must be set", lua_interface->GetScriptName(state));
  2147. return 0;
  2148. }
  2149. if (!luaspell || !luaspell->spell) {
  2150. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2151. return 0;
  2152. }
  2153. if(luaspell->resisted) {
  2154. return 0;
  2155. }
  2156. int32 class_req = 0;
  2157. vector<int16> faction_req;
  2158. vector<int16> race_req;
  2159. int32 class_id = 0;
  2160. int32 i = 0;
  2161. int8 f = 0;
  2162. int8 r = 0;
  2163. while ((class_id = lua_interface->GetInt32Value(state, 4 + i))) {
  2164. if (class_id < 100) {
  2165. class_req += pow(2.0, double(class_id - 1));
  2166. }
  2167. else if (class_id > 100 && class_id < 1000) {
  2168. race_req.push_back(class_id);
  2169. r++;
  2170. }
  2171. else {
  2172. faction_req.push_back(class_id);
  2173. f++;
  2174. }
  2175. i++;
  2176. }
  2177. ((Entity*)spawn)->AddSpellBonus(luaspell, type, value, class_req, race_req, faction_req);
  2178. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SPELLBONUS))
  2179. luaspell->effect_bitmask += EFFECT_FLAG_SPELLBONUS;
  2180. if (spawn->IsPlayer())
  2181. ((Player*)spawn)->SetCharSheetChanged(true);
  2182. return 0;
  2183. }
  2184. int EQ2Emu_lua_RemoveSpawnSpellBonus(lua_State* state) {
  2185. if (!lua_interface)
  2186. return 0;
  2187. Spawn* spawn = lua_interface->GetSpawn(state);
  2188. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2189. if (!spawn) {
  2190. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not valid", lua_interface->GetScriptName(state));
  2191. return 0;
  2192. }
  2193. if (!spawn->IsEntity()) {
  2194. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: spawn is not an entity", lua_interface->GetScriptName(state));
  2195. return 0;
  2196. }
  2197. if (!luaspell || !luaspell->spell) {
  2198. lua_interface->LogError("%s: LUA AddSpawnSpellBonus command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  2199. return 0;
  2200. }
  2201. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2202. if (spawn->IsPlayer())
  2203. ((Player*)spawn)->SetCharSheetChanged(true);
  2204. return 0;
  2205. }
  2206. int EQ2Emu_lua_RemoveSpellBonus(lua_State* state) {
  2207. if (!lua_interface)
  2208. return 0;
  2209. Spawn* spawn = lua_interface->GetSpawn(state);
  2210. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2211. if (luaspell && luaspell->spell) {
  2212. ZoneServer* zone = luaspell->caster->GetZone();
  2213. Spawn* target = 0;
  2214. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2215. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2216. target = zone->GetSpawnByID(luaspell->targets[i]);
  2217. if (target && target->IsEntity()) {
  2218. ((Entity*)target)->RemoveSpellBonus(luaspell);
  2219. if (target->IsPlayer())
  2220. ((Player*)target)->SetCharSheetChanged(true);
  2221. }
  2222. }
  2223. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2224. }
  2225. else if (spawn && spawn->IsEntity()) {
  2226. ((Entity*)spawn)->RemoveSpellBonus(luaspell);
  2227. if (spawn->IsPlayer())
  2228. ((Player*)spawn)->SetCharSheetChanged(true);
  2229. }
  2230. return 0;
  2231. }
  2232. int EQ2Emu_lua_AddSkillBonus(lua_State* state) {
  2233. if (!lua_interface)
  2234. return 0;
  2235. Spawn* spawn = lua_interface->GetSpawn(state);
  2236. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  2237. float value = lua_interface->GetFloatValue(state, 3);
  2238. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2239. if (value != 0) {
  2240. int32 spell_id = 0;
  2241. if (luaspell && luaspell->spell && luaspell->caster) {
  2242. if(luaspell->resisted) {
  2243. return 0;
  2244. }
  2245. spell_id = luaspell->spell->GetSpellID();
  2246. ZoneServer* zone = luaspell->caster->GetZone();
  2247. Spawn* target = 0;
  2248. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2249. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2250. target = zone->GetSpawnByID(luaspell->targets[i]);
  2251. if (target && target->Alive()) {
  2252. if (target->IsPlayer()) {
  2253. ((Player*)target)->AddSkillBonus(spell_id, skill_id, value);
  2254. Client* client = target->GetZone()->GetClientBySpawn(target);
  2255. if (client) {
  2256. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2257. if (packet)
  2258. client->QueuePacket(packet);
  2259. }
  2260. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2261. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2262. }
  2263. else if (target->IsNPC()) {
  2264. ((NPC*)target)->AddSkillBonus(spell_id, skill_id, value);
  2265. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SKILLBONUS))
  2266. luaspell->effect_bitmask += EFFECT_FLAG_SKILLBONUS;
  2267. }
  2268. else
  2269. LogWrite(LUA__ERROR, 0, "LUA", "Error applying bonus buff on '%s'. Not a NPC or player.", target->GetName());
  2270. }
  2271. }
  2272. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2273. }
  2274. else if (spawn) {
  2275. if (spawn->IsPlayer()) {
  2276. ((Player*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2277. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2278. if (client) {
  2279. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2280. if (packet)
  2281. client->QueuePacket(packet);
  2282. }
  2283. }
  2284. else if (spawn->IsNPC())
  2285. ((NPC*)spawn)->AddSkillBonus(spell_id, skill_id, value);
  2286. else
  2287. LogWrite(LUA__ERROR, 0, "LUA", "Error applying skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2288. }
  2289. }
  2290. else
  2291. lua_interface->LogError("%s: Invalid parameters for AddSkillBonus.", lua_interface->GetScriptName(state));
  2292. return 0;
  2293. }
  2294. int EQ2Emu_lua_RemoveSkillBonus(lua_State* state) {
  2295. if (!lua_interface)
  2296. return 0;
  2297. Spawn* spawn = lua_interface->GetSpawn(state);
  2298. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2299. if (spawn && spawn->IsPlayer()) {
  2300. int32 spell_id = 0;
  2301. if (luaspell && luaspell->spell) {
  2302. if(luaspell->resisted) {
  2303. return 0;
  2304. }
  2305. spell_id = luaspell->spell->GetSpellID();
  2306. ZoneServer* zone = luaspell->caster->GetZone();
  2307. Spawn* target = 0;
  2308. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2309. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2310. target = zone->GetSpawnByID(luaspell->targets[i]);
  2311. if (target) {
  2312. if (target->IsPlayer()) {
  2313. ((Player*)target)->RemoveSkillBonus(spell_id);
  2314. Client* client = target->GetZone()->GetClientBySpawn(target);
  2315. if (client) {
  2316. EQ2Packet* packet = ((Player*)target)->GetSkills()->GetSkillPacket(client->GetVersion());
  2317. if (packet)
  2318. client->QueuePacket(packet);
  2319. }
  2320. }
  2321. else if (target->IsNPC())
  2322. ((NPC*)target)->RemoveSkillBonus(spell_id);
  2323. else
  2324. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2325. }
  2326. }
  2327. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2328. }
  2329. else if (spawn) {
  2330. if (spawn->IsPlayer()) {
  2331. ((Player*)spawn)->RemoveSkillBonus(spell_id);
  2332. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  2333. if (client) {
  2334. EQ2Packet* packet = ((Player*)spawn)->GetSkills()->GetSkillPacket(client->GetVersion());
  2335. if (packet)
  2336. client->QueuePacket(packet);
  2337. }
  2338. }
  2339. else if (spawn->IsNPC())
  2340. ((NPC*)spawn)->RemoveSkillBonus(spell_id);
  2341. else
  2342. LogWrite(LUA__ERROR, 0, "LUA", "Error removing skill bonus on '%s'. Not a NPC or player.", spawn->GetName());
  2343. }
  2344. }
  2345. return 0;
  2346. }
  2347. int EQ2Emu_lua_AddControlEffect(lua_State* state) {
  2348. if (!lua_interface)
  2349. return 0;
  2350. Spawn* spawn = lua_interface->GetSpawn(state);
  2351. int8 type = lua_interface->GetInt32Value(state, 2);
  2352. bool only_add_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2353. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2354. if(luaspell && luaspell->resisted) {
  2355. return 0;
  2356. }
  2357. if (!only_add_spawn && luaspell && luaspell->spell && luaspell->caster && type != 0) {
  2358. ZoneServer* zone = luaspell->caster->GetZone();
  2359. Spawn* target = 0;
  2360. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2361. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2362. target = zone->GetSpawnByID(luaspell->targets[i]);
  2363. if (target && target->IsEntity()) {
  2364. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2365. ((Entity*)target)->AddMezSpell(luaspell);
  2366. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2367. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2368. if (target->IsNPC())
  2369. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2370. }
  2371. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2372. ((Entity*)target)->AddStifleSpell(luaspell);
  2373. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2374. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2375. if (target->IsNPC())
  2376. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2377. }
  2378. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2379. ((Entity*)target)->AddDazeSpell(luaspell);
  2380. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2381. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2382. if (target->IsNPC())
  2383. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2384. }
  2385. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2386. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2387. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2388. ((Entity*)target)->AddStunSpell(luaspell);
  2389. if (target->IsNPC())
  2390. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2391. }
  2392. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2393. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2394. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2395. ((Entity*)target)->AddRootSpell(luaspell);
  2396. if (target->IsNPC())
  2397. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2398. }
  2399. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2400. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2401. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2402. ((Entity*)target)->AddFearSpell(luaspell);
  2403. if (target->IsNPC())
  2404. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2405. }
  2406. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2407. ((Entity*)target)->AddWaterwalkSpell(luaspell);
  2408. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2409. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2410. }
  2411. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2412. ((Entity*)target)->AddWaterjumpSpell(luaspell);
  2413. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2414. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2415. }
  2416. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2417. ((Entity*)target)->AddSnareSpell(luaspell);
  2418. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2419. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2420. if (target->IsNPC())
  2421. ((NPC*)target)->Brain()->AddHate(luaspell->caster, 5);
  2422. }
  2423. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2424. ((Entity*)target)->AddFlightSpell(luaspell);
  2425. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2426. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2427. }
  2428. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2429. ((Entity*)target)->AddGlideSpell(luaspell);
  2430. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2431. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2432. }
  2433. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2434. ((Entity*)target)->AddSafefallSpell(luaspell);
  2435. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2436. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2437. }
  2438. else
  2439. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2440. }
  2441. else
  2442. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (target != nullptr) ? target->GetName() : "NO_TARGET");
  2443. }
  2444. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2445. }
  2446. else if (only_add_spawn && spawn && spawn->IsEntity()) {
  2447. if (type == CONTROL_EFFECT_TYPE_MEZ) {
  2448. ((Entity*)spawn)->AddMezSpell(luaspell);
  2449. if (!(luaspell->effect_bitmask & EFFECT_FLAG_MEZ))
  2450. luaspell->effect_bitmask += EFFECT_FLAG_MEZ;
  2451. }
  2452. else if (type == CONTROL_EFFECT_TYPE_STIFLE) {
  2453. ((Entity*)spawn)->AddStifleSpell(luaspell);
  2454. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STIFLE))
  2455. luaspell->effect_bitmask += EFFECT_FLAG_STIFLE;
  2456. }
  2457. else if (type == CONTROL_EFFECT_TYPE_DAZE) {
  2458. ((Entity*)spawn)->AddDazeSpell(luaspell);
  2459. if (!(luaspell->effect_bitmask & EFFECT_FLAG_DAZE))
  2460. luaspell->effect_bitmask += EFFECT_FLAG_DAZE;
  2461. }
  2462. else if (type == CONTROL_EFFECT_TYPE_STUN) {
  2463. ((Entity*)spawn)->AddStunSpell(luaspell);
  2464. if (!(luaspell->effect_bitmask & EFFECT_FLAG_STUN))
  2465. luaspell->effect_bitmask += EFFECT_FLAG_STUN;
  2466. }
  2467. else if (type == CONTROL_EFFECT_TYPE_ROOT) {
  2468. ((Entity*)spawn)->AddRootSpell(luaspell);
  2469. if (!(luaspell->effect_bitmask & EFFECT_FLAG_ROOT))
  2470. luaspell->effect_bitmask += EFFECT_FLAG_ROOT;
  2471. }
  2472. else if (type == CONTROL_EFFECT_TYPE_FEAR) {
  2473. ((Entity*)spawn)->AddFearSpell(luaspell);
  2474. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FEAR))
  2475. luaspell->effect_bitmask += EFFECT_FLAG_FEAR;
  2476. }
  2477. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER) {
  2478. ((Entity*)spawn)->AddWaterwalkSpell(luaspell);
  2479. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERWALK))
  2480. luaspell->effect_bitmask += EFFECT_FLAG_WATERWALK;
  2481. }
  2482. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER) {
  2483. ((Entity*)spawn)->AddWaterjumpSpell(luaspell);
  2484. if (!(luaspell->effect_bitmask & EFFECT_FLAG_WATERJUMP))
  2485. luaspell->effect_bitmask += EFFECT_FLAG_WATERJUMP;
  2486. }
  2487. else if (type == CONTROL_EFFECT_TYPE_SNARE) {
  2488. ((Entity*)spawn)->AddSnareSpell(luaspell);
  2489. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SNARE))
  2490. luaspell->effect_bitmask += EFFECT_FLAG_SNARE;
  2491. }
  2492. else if (type == CONTROL_EFFECT_TYPE_FLIGHT) {
  2493. ((Entity*)spawn)->AddFlightSpell(luaspell);
  2494. if (!(luaspell->effect_bitmask & EFFECT_FLAG_FLIGHT))
  2495. luaspell->effect_bitmask += EFFECT_FLAG_FLIGHT;
  2496. }
  2497. else if (type == CONTROL_EFFECT_TYPE_GLIDE) {
  2498. ((Entity*)spawn)->AddGlideSpell(luaspell);
  2499. if (!(luaspell->effect_bitmask & EFFECT_FLAG_GLIDE))
  2500. luaspell->effect_bitmask += EFFECT_FLAG_GLIDE;
  2501. }
  2502. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL) {
  2503. ((Entity*)spawn)->AddSafefallSpell(luaspell);
  2504. if (!(luaspell->effect_bitmask & EFFECT_FLAG_SAFEFALL))
  2505. luaspell->effect_bitmask += EFFECT_FLAG_SAFEFALL;
  2506. }
  2507. else
  2508. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2509. }
  2510. else
  2511. lua_interface->LogError("%s: Error applying control effect on non entity '%s'.", lua_interface->GetScriptName(state), (spawn != nullptr) ? spawn->GetName() : "NO_SPAWN");
  2512. return 0;
  2513. }
  2514. int EQ2Emu_lua_RemoveControlEffect(lua_State* state) {
  2515. if (!lua_interface)
  2516. return 0;
  2517. Spawn* spawn = lua_interface->GetSpawn(state);
  2518. int8 type = lua_interface->GetInt8Value(state, 2);
  2519. bool only_remove_spawn = lua_interface->GetInt8Value(state, 3) == 1;
  2520. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  2521. if (spawn && spawn->IsEntity()) {
  2522. if (!only_remove_spawn && luaspell && luaspell->spell) {
  2523. ZoneServer* zone = luaspell->caster->GetZone();
  2524. Spawn* target = 0;
  2525. luaspell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  2526. for (int32 i = 0; i < luaspell->targets.size(); i++) {
  2527. target = zone->GetSpawnByID(luaspell->targets[i]);
  2528. if (target) {
  2529. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2530. ((Entity*)target)->RemoveMezSpell(luaspell);
  2531. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2532. ((Entity*)target)->RemoveStifleSpell(luaspell);
  2533. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2534. ((Entity*)target)->RemoveDazeSpell(luaspell);
  2535. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2536. ((Entity*)target)->RemoveStunSpell(luaspell);
  2537. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2538. ((Entity*)target)->RemoveRootSpell(luaspell);
  2539. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2540. ((Entity*)target)->RemoveFearSpell(luaspell);
  2541. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2542. ((Entity*)target)->RemoveWaterwalkSpell(luaspell);
  2543. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2544. ((Entity*)target)->RemoveWaterjumpSpell(luaspell);
  2545. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2546. ((Entity*)target)->RemoveSnareSpell(luaspell);
  2547. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2548. ((Entity*)target)->RemoveFlightSpell(luaspell);
  2549. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2550. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2551. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2552. ((Entity*)target)->RemoveGlideSpell(luaspell);
  2553. else
  2554. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2555. }
  2556. }
  2557. luaspell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  2558. }
  2559. else if (only_remove_spawn) {
  2560. if (type == CONTROL_EFFECT_TYPE_MEZ)
  2561. ((Entity*)spawn)->RemoveMezSpell(luaspell);
  2562. else if (type == CONTROL_EFFECT_TYPE_STIFLE)
  2563. ((Entity*)spawn)->RemoveStifleSpell(luaspell);
  2564. else if (type == CONTROL_EFFECT_TYPE_DAZE)
  2565. ((Entity*)spawn)->RemoveDazeSpell(luaspell);
  2566. else if (type == CONTROL_EFFECT_TYPE_STUN)
  2567. ((Entity*)spawn)->RemoveStunSpell(luaspell);
  2568. else if (type == CONTROL_EFFECT_TYPE_ROOT)
  2569. ((Entity*)spawn)->RemoveRootSpell(luaspell);
  2570. else if (type == CONTROL_EFFECT_TYPE_FEAR)
  2571. ((Entity*)spawn)->RemoveFearSpell(luaspell);
  2572. else if (type == CONTROL_EFFECT_TYPE_WALKUNDERWATER)
  2573. ((Entity*)spawn)->RemoveWaterwalkSpell(luaspell);
  2574. else if (type == CONTROL_EFFECT_TYPE_JUMPUNDERWATER)
  2575. ((Entity*)spawn)->RemoveWaterjumpSpell(luaspell);
  2576. else if (type == CONTROL_EFFECT_TYPE_SNARE)
  2577. ((Entity*)spawn)->RemoveSnareSpell(luaspell);
  2578. else if (type == CONTROL_EFFECT_TYPE_FLIGHT)
  2579. ((Entity*)spawn)->RemoveFlightSpell(luaspell);
  2580. else if (type == CONTROL_EFFECT_TYPE_GLIDE)
  2581. ((Entity*)spawn)->RemoveGlideSpell(luaspell);
  2582. else if (type == CONTROL_EFFECT_TYPE_SAFEFALL)
  2583. ((Entity*)spawn)->RemoveSafefallSpell(luaspell);
  2584. else
  2585. lua_interface->LogError("%s: Unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2586. }
  2587. }
  2588. return 0;
  2589. }
  2590. int EQ2Emu_lua_HasControlEffect(lua_State* state) {
  2591. if (!lua_interface)
  2592. return 0;
  2593. Spawn* spawn = lua_interface->GetSpawn(state);
  2594. int8 type = lua_interface->GetInt8Value(state, 2);
  2595. bool hasEffect = false;
  2596. if (!spawn)
  2597. lua_interface->LogError("%s: LUA HasControlEffect error: Could not find spawn.", lua_interface->GetScriptName(state));
  2598. else if (!spawn->IsEntity())
  2599. lua_interface->LogError("%s: LUA HasControlEffect error: spawn %s is not an entity!.", lua_interface->GetScriptName(state), spawn->GetName());
  2600. else if (type < CONTROL_MAX_EFFECTS)
  2601. hasEffect = ((Entity*)spawn)->HasControlEffect(type);
  2602. else
  2603. lua_interface->LogError("%s: LUA HasControlEffect unhandled control effect type of %u.", lua_interface->GetScriptName(state), type);
  2604. lua_interface->SetBooleanValue(state, hasEffect);
  2605. return 1;
  2606. }
  2607. int EQ2Emu_lua_GetBaseAggroRadius(lua_State* state) {
  2608. if (!lua_interface)
  2609. return 0;
  2610. Spawn* spawn = lua_interface->GetSpawn(state);
  2611. float distance = 0.0f;
  2612. if (!spawn)
  2613. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2614. else if (!spawn->IsNPC())
  2615. lua_interface->LogError("%s: LUA GetBaseAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2616. else
  2617. distance = ((NPC*)spawn)->GetBaseAggroRadius();
  2618. lua_interface->SetFloatValue(state, distance);
  2619. return 1;
  2620. }
  2621. int EQ2Emu_lua_GetAggroRadius(lua_State* state) {
  2622. if (!lua_interface)
  2623. return 0;
  2624. Spawn* spawn = lua_interface->GetSpawn(state);
  2625. float distance = 0.0f;
  2626. if (!spawn)
  2627. lua_interface->LogError("%s: LUA GetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2628. else if (!spawn->IsNPC())
  2629. lua_interface->LogError("%s: LUA GetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2630. else
  2631. distance = ((NPC*)spawn)->GetAggroRadius();
  2632. lua_interface->SetFloatValue(state, distance);
  2633. return 1;
  2634. }
  2635. int EQ2Emu_lua_SetAggroRadius(lua_State* state) {
  2636. if (!lua_interface)
  2637. return 0;
  2638. Spawn* spawn = lua_interface->GetSpawn(state);
  2639. float distance = lua_interface->GetFloatValue(state, 2);
  2640. bool override = lua_interface->GetBooleanValue(state, 3);
  2641. bool result = false;
  2642. lua_interface->ResetFunctionStack(state);
  2643. if (!spawn)
  2644. lua_interface->LogError("%s: LUA SetAggroRadius error: Could not find spawn.", lua_interface->GetScriptName(state));
  2645. else if (!spawn->IsNPC())
  2646. lua_interface->LogError("%s: LUA SetAggroRadius error: spawn %s is not an NPC!.", lua_interface->GetScriptName(state), spawn->GetName());
  2647. else
  2648. {
  2649. ((NPC*)spawn)->SetAggroRadius(distance, override);
  2650. result = true;
  2651. }
  2652. lua_interface->SetBooleanValue(state, result);
  2653. return 1;
  2654. }
  2655. int EQ2Emu_lua_SetIntBase(lua_State* state) {
  2656. if (!lua_interface)
  2657. return 0;
  2658. Spawn* spawn = lua_interface->GetSpawn(state);
  2659. int16 value = lua_interface->GetInt16Value(state, 2);
  2660. if (spawn && spawn->IsEntity()) {
  2661. ((Entity*)spawn)->GetInfoStruct()->set_intel_base(value);
  2662. if (spawn->IsPlayer())
  2663. ((Player*)spawn)->SetCharSheetChanged(true);
  2664. }
  2665. return 0;
  2666. }
  2667. int EQ2Emu_lua_SetAgiBase(lua_State* state) {
  2668. if (!lua_interface)
  2669. return 0;
  2670. Spawn* spawn = lua_interface->GetSpawn(state);
  2671. int16 value = lua_interface->GetInt16Value(state, 2);
  2672. if (spawn && spawn->IsEntity()) {
  2673. ((Entity*)spawn)->GetInfoStruct()->set_agi_base(value);
  2674. if (spawn->IsPlayer())
  2675. ((Player*)spawn)->SetCharSheetChanged(true);
  2676. }
  2677. return 0;
  2678. }
  2679. int EQ2Emu_lua_SetWisBase(lua_State* state) {
  2680. if (!lua_interface)
  2681. return 0;
  2682. Spawn* spawn = lua_interface->GetSpawn(state);
  2683. int16 value = lua_interface->GetInt16Value(state, 2);
  2684. if (spawn && spawn->IsEntity()) {
  2685. ((Entity*)spawn)->GetInfoStruct()->set_wis_base(value);
  2686. if (spawn->IsPlayer())
  2687. ((Player*)spawn)->SetCharSheetChanged(true);
  2688. }
  2689. return 0;
  2690. }
  2691. int EQ2Emu_lua_SetStaBase(lua_State* state) {
  2692. if (!lua_interface)
  2693. return 0;
  2694. Spawn* spawn = lua_interface->GetSpawn(state);
  2695. int16 value = lua_interface->GetInt16Value(state, 2);
  2696. if (spawn && spawn->IsEntity()) {
  2697. ((Entity*)spawn)->GetInfoStruct()->set_sta_base(value);
  2698. if (spawn->IsPlayer())
  2699. ((Player*)spawn)->SetCharSheetChanged(true);
  2700. }
  2701. return 0;
  2702. }
  2703. int EQ2Emu_lua_SetStrBase(lua_State* state) {
  2704. if (!lua_interface)
  2705. return 0;
  2706. Spawn* spawn = lua_interface->GetSpawn(state);
  2707. int16 value = lua_interface->GetInt16Value(state, 2);
  2708. if (spawn && spawn->IsEntity()) {
  2709. ((Entity*)spawn)->GetInfoStruct()->set_str_base(value);
  2710. if (spawn->IsPlayer())
  2711. ((Player*)spawn)->SetCharSheetChanged(true);
  2712. }
  2713. return 0;
  2714. }
  2715. int EQ2Emu_lua_SetDeity(lua_State* state) {
  2716. if (!lua_interface)
  2717. return 0;
  2718. Spawn* spawn = lua_interface->GetSpawn(state);
  2719. int8 value = lua_interface->GetInt8Value(state, 2);
  2720. if (spawn && spawn->IsEntity()) {
  2721. ((Entity*)spawn)->SetDeity(value);
  2722. if (spawn->IsPlayer())
  2723. ((Player*)spawn)->SetCharSheetChanged(true);
  2724. }
  2725. lua_interface->ResetFunctionStack(state);
  2726. return 0;
  2727. }
  2728. int EQ2Emu_lua_GetDeity(lua_State* state) {
  2729. if (!lua_interface)
  2730. return 0;
  2731. Spawn* spawn = lua_interface->GetSpawn(state);
  2732. if (spawn && spawn->IsEntity()) {
  2733. int8 deity = ((Entity*)spawn)->GetDeity();
  2734. lua_interface->SetInt32Value(state, deity);
  2735. return 1;
  2736. }
  2737. return 0;
  2738. }
  2739. int EQ2Emu_lua_SetInt(lua_State* state) {
  2740. if (!lua_interface)
  2741. return 0;
  2742. Spawn* spawn = lua_interface->GetSpawn(state);
  2743. sint32 value = lua_interface->GetSInt32Value(state, 2);
  2744. if (spawn && spawn->IsEntity()) {
  2745. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_INT, value);
  2746. if (spawn->IsPlayer())
  2747. ((Player*)spawn)->SetCharSheetChanged(true);
  2748. }
  2749. return 0;
  2750. }
  2751. int EQ2Emu_lua_SetWis(lua_State* state) {
  2752. if (!lua_interface)
  2753. return 0;
  2754. Spawn* spawn = lua_interface->GetSpawn(state);
  2755. float value = lua_interface->GetFloatValue(state, 2);
  2756. if (spawn && spawn->IsEntity()) {
  2757. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_WIS, value);
  2758. if (spawn->IsPlayer())
  2759. ((Player*)spawn)->SetCharSheetChanged(true);
  2760. }
  2761. return 0;
  2762. }
  2763. int EQ2Emu_lua_SetSta(lua_State* state) {
  2764. if (!lua_interface)
  2765. return 0;
  2766. Spawn* spawn = lua_interface->GetSpawn(state);
  2767. float value = lua_interface->GetFloatValue(state, 2);
  2768. if (spawn && spawn->IsEntity()) {
  2769. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STA, value);
  2770. if (spawn->IsPlayer())
  2771. ((Player*)spawn)->SetCharSheetChanged(true);
  2772. }
  2773. return 0;
  2774. }
  2775. int EQ2Emu_lua_SetStr(lua_State* state) {
  2776. if (!lua_interface)
  2777. return 0;
  2778. Spawn* spawn = lua_interface->GetSpawn(state);
  2779. float value = lua_interface->GetFloatValue(state, 2);
  2780. if (spawn && spawn->IsEntity()) {
  2781. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_STR, value);
  2782. if (spawn->IsPlayer())
  2783. ((Player*)spawn)->SetCharSheetChanged(true);
  2784. }
  2785. return 0;
  2786. }
  2787. int EQ2Emu_lua_SetAgi(lua_State* state) {
  2788. if (!lua_interface)
  2789. return 0;
  2790. Spawn* spawn = lua_interface->GetSpawn(state);
  2791. float value = lua_interface->GetFloatValue(state, 2);
  2792. if (spawn && spawn->IsEntity()) {
  2793. ((Entity*)spawn)->AddSpellBonus(0, ITEM_STAT_AGI, value);
  2794. if (spawn->IsPlayer())
  2795. ((Player*)spawn)->SetCharSheetChanged(true);
  2796. }
  2797. return 0;
  2798. }
  2799. int EQ2Emu_lua_GetCurrentHP(lua_State* state) {
  2800. if (!lua_interface)
  2801. return 0;
  2802. Spawn* spawn = lua_interface->GetSpawn(state);
  2803. if (spawn) {
  2804. lua_interface->SetInt32Value(state, spawn->GetHP());
  2805. return 1;
  2806. }
  2807. return 0;
  2808. }
  2809. int EQ2Emu_lua_GetMaxHP(lua_State* state) {
  2810. if (!lua_interface)
  2811. return 0;
  2812. Spawn* spawn = lua_interface->GetSpawn(state);
  2813. if (spawn) {
  2814. lua_interface->SetInt32Value(state, spawn->GetTotalHP());
  2815. return 1;
  2816. }
  2817. return 0;
  2818. }
  2819. int EQ2Emu_lua_GetMaxHPBase(lua_State* state) {
  2820. if (!lua_interface)
  2821. return 0;
  2822. Spawn* spawn = lua_interface->GetSpawn(state);
  2823. if (spawn) {
  2824. lua_interface->SetInt32Value(state, spawn->GetTotalHPBase());
  2825. return 1;
  2826. }
  2827. return 0;
  2828. }
  2829. int EQ2Emu_lua_GetName(lua_State* state) {
  2830. if (!lua_interface)
  2831. return 0;
  2832. Spawn* spawn = lua_interface->GetSpawn(state);
  2833. if (spawn) {
  2834. lua_interface->SetStringValue(state, spawn->GetName());
  2835. return 1;
  2836. }
  2837. return 0;
  2838. }
  2839. int EQ2Emu_lua_GetLevel(lua_State* state) {
  2840. Spawn* spawn = lua_interface->GetSpawn(state);
  2841. if (spawn) {
  2842. lua_interface->SetInt32Value(state, spawn->GetLevel());
  2843. return 1;
  2844. }
  2845. return 0;
  2846. }
  2847. int EQ2Emu_lua_GetCurrentPower(lua_State* state) {
  2848. if (!lua_interface)
  2849. return 0;
  2850. Spawn* spawn = lua_interface->GetSpawn(state);
  2851. if (spawn) {
  2852. lua_interface->SetInt32Value(state, spawn->GetPower());
  2853. return 1;
  2854. }
  2855. return 0;
  2856. }
  2857. int EQ2Emu_lua_GetMaxPower(lua_State* state) {
  2858. if (!lua_interface)
  2859. return 0;
  2860. Spawn* spawn = lua_interface->GetSpawn(state);
  2861. if (spawn) {
  2862. lua_interface->SetInt32Value(state, spawn->GetTotalPower());
  2863. return 1;
  2864. }
  2865. return 0;
  2866. }
  2867. int EQ2Emu_lua_GetMaxPowerBase(lua_State* state) {
  2868. if (!lua_interface)
  2869. return 0;
  2870. Spawn* spawn = lua_interface->GetSpawn(state);
  2871. if (spawn) {
  2872. lua_interface->SetInt32Value(state, spawn->GetTotalPowerBase());
  2873. return 1;
  2874. }
  2875. return 0;
  2876. }
  2877. int EQ2Emu_lua_GetDistance(lua_State* state) {
  2878. if (!lua_interface)
  2879. return 0;
  2880. Spawn* spawn = lua_interface->GetSpawn(state);
  2881. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  2882. bool include_radius = lua_interface->GetInt8Value(state, 3) == 1;
  2883. if (spawn && spawn2) {
  2884. float distance = spawn->GetDistance(spawn2, false, include_radius);
  2885. lua_interface->SetFloatValue(state, distance);
  2886. return 1;
  2887. }
  2888. return 0;
  2889. }
  2890. int EQ2Emu_lua_GetX(lua_State* state) {
  2891. if (!lua_interface)
  2892. return 0;
  2893. Spawn* spawn = lua_interface->GetSpawn(state);
  2894. if (spawn) {
  2895. lua_interface->SetFloatValue(state, spawn->GetX());
  2896. return 1;
  2897. }
  2898. return 0;
  2899. }
  2900. int EQ2Emu_lua_GetY(lua_State* state) {
  2901. if (!lua_interface)
  2902. return 0;
  2903. Spawn* spawn = lua_interface->GetSpawn(state);
  2904. if (spawn) {
  2905. lua_interface->SetFloatValue(state, spawn->GetY());
  2906. return 1;
  2907. }
  2908. return 0;
  2909. }
  2910. int EQ2Emu_lua_GetZ(lua_State* state) {
  2911. if (!lua_interface)
  2912. return 0;
  2913. Spawn* spawn = lua_interface->GetSpawn(state);
  2914. if (spawn) {
  2915. lua_interface->SetFloatValue(state, spawn->GetZ());
  2916. return 1;
  2917. }
  2918. return 0;
  2919. }
  2920. int EQ2Emu_lua_GetHeading(lua_State* state) {
  2921. if (!lua_interface)
  2922. return 0;
  2923. Spawn* spawn = lua_interface->GetSpawn(state);
  2924. if (spawn) {
  2925. lua_interface->SetFloatValue(state, spawn->GetHeading());
  2926. return 1;
  2927. }
  2928. return 0;
  2929. }
  2930. int EQ2Emu_lua_GetModelType(lua_State* state) {
  2931. if (!lua_interface)
  2932. return 0;
  2933. Spawn* spawn = lua_interface->GetSpawn(state);
  2934. if (spawn) {
  2935. lua_interface->SetInt32Value(state, spawn->GetModelType());
  2936. return 1;
  2937. }
  2938. return 0;
  2939. }
  2940. int EQ2Emu_lua_GetSpeed(lua_State* state) {
  2941. if (!lua_interface)
  2942. return 0;
  2943. Spawn* spawn = lua_interface->GetSpawn(state);
  2944. if (spawn) {
  2945. lua_interface->SetFloatValue(state, spawn->GetSpeed());
  2946. return 1;
  2947. }
  2948. return 0;
  2949. }
  2950. int EQ2Emu_lua_HasMoved(lua_State* state) {
  2951. if (!lua_interface)
  2952. return 0;
  2953. Spawn* spawn = lua_interface->GetSpawn(state);
  2954. if (spawn && spawn->IsEntity()) {
  2955. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->HasMoved(false));
  2956. return 1;
  2957. }
  2958. return 0;
  2959. }
  2960. int EQ2Emu_lua_GetInt(lua_State* state) {
  2961. if (!lua_interface)
  2962. return 0;
  2963. Spawn* spawn = lua_interface->GetSpawn(state);
  2964. if (spawn && spawn->IsEntity()) {
  2965. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetInt());
  2966. return 1;
  2967. }
  2968. return 0;
  2969. }
  2970. int EQ2Emu_lua_GetWis(lua_State* state) {
  2971. if (!lua_interface)
  2972. return 0;
  2973. Spawn* spawn = lua_interface->GetSpawn(state);
  2974. if (spawn && spawn->IsEntity()) {
  2975. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWis());
  2976. return 1;
  2977. }
  2978. return 0;
  2979. }
  2980. int EQ2Emu_lua_GetSta(lua_State* state) {
  2981. if (!lua_interface)
  2982. return 0;
  2983. Spawn* spawn = lua_interface->GetSpawn(state);
  2984. if (spawn && spawn->IsEntity()) {
  2985. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetSta());
  2986. return 1;
  2987. }
  2988. return 0;
  2989. }
  2990. int EQ2Emu_lua_GetStr(lua_State* state) {
  2991. if (!lua_interface)
  2992. return 0;
  2993. Spawn* spawn = lua_interface->GetSpawn(state);
  2994. if (spawn && spawn->IsEntity()) {
  2995. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStr());
  2996. return 1;
  2997. }
  2998. return 0;
  2999. }
  3000. int EQ2Emu_lua_GetAgi(lua_State* state) {
  3001. if (!lua_interface)
  3002. return 0;
  3003. Spawn* spawn = lua_interface->GetSpawn(state);
  3004. if (spawn && spawn->IsEntity()) {
  3005. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgi());
  3006. return 1;
  3007. }
  3008. return 0;
  3009. }
  3010. int EQ2Emu_lua_GetIntBase(lua_State* state) {
  3011. if (!lua_interface)
  3012. return 0;
  3013. Spawn* spawn = lua_interface->GetSpawn(state);
  3014. if (spawn && spawn->IsEntity()) {
  3015. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetIntBase());
  3016. return 1;
  3017. }
  3018. return 0;
  3019. }
  3020. int EQ2Emu_lua_GetWisBase(lua_State* state) {
  3021. if (!lua_interface)
  3022. return 0;
  3023. Spawn* spawn = lua_interface->GetSpawn(state);
  3024. if (spawn && spawn->IsEntity()) {
  3025. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetWisBase());
  3026. return 1;
  3027. }
  3028. return 0;
  3029. }
  3030. int EQ2Emu_lua_GetStaBase(lua_State* state) {
  3031. if (!lua_interface)
  3032. return 0;
  3033. Spawn* spawn = lua_interface->GetSpawn(state);
  3034. if (spawn && spawn->IsEntity()) {
  3035. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStaBase());
  3036. return 1;
  3037. }
  3038. return 0;
  3039. }
  3040. int EQ2Emu_lua_GetStrBase(lua_State* state) {
  3041. if (!lua_interface)
  3042. return 0;
  3043. Spawn* spawn = lua_interface->GetSpawn(state);
  3044. if (spawn && spawn->IsEntity()) {
  3045. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetStrBase());
  3046. return 1;
  3047. }
  3048. return 0;
  3049. }
  3050. int EQ2Emu_lua_GetAgiBase(lua_State* state) {
  3051. if (!lua_interface)
  3052. return 0;
  3053. Spawn* spawn = lua_interface->GetSpawn(state);
  3054. if (spawn && spawn->IsEntity()) {
  3055. lua_interface->SetInt32Value(state, ((Entity*)spawn)->GetAgiBase());
  3056. return 1;
  3057. }
  3058. return 0;
  3059. }
  3060. int EQ2Emu_lua_SetStepComplete(lua_State* state) {
  3061. if (!lua_interface)
  3062. return 0;
  3063. Spawn* player = lua_interface->GetSpawn(state);
  3064. if (!player || !player->IsPlayer()) {
  3065. lua_interface->LogError("%s: LUA SetStepComplete command error: player is not valid", lua_interface->GetScriptName(state));
  3066. return 0;
  3067. }
  3068. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3069. if (quest_id <= 0) {
  3070. lua_interface->LogError("%s: LUA SetStepComplete command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3071. return 0;
  3072. } else if ((((Player*)player)->player_quests.count(quest_id) <= 0)) {
  3073. lua_interface->LogError("%s: LUA SetStepComplete command error: player does not have quest", lua_interface->GetScriptName(state));
  3074. return 0;
  3075. }
  3076. int32 step = lua_interface->GetInt32Value(state, 3);
  3077. if (step > 0) {
  3078. Client* client = player->GetZone()->GetClientBySpawn(player);
  3079. if (client)
  3080. client->AddPendingQuestUpdate(quest_id, step);
  3081. } else {
  3082. lua_interface->LogError("%s: LUA SetStepComplete command error: step is not valid", lua_interface->GetScriptName(state));
  3083. }
  3084. return 0;
  3085. }
  3086. int EQ2Emu_lua_AddStepProgress(lua_State* state) {
  3087. Spawn* player = lua_interface->GetSpawn(state);
  3088. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3089. int32 step = lua_interface->GetInt32Value(state, 3);
  3090. int32 progress = lua_interface->GetInt32Value(state, 4);
  3091. if (player && player->IsPlayer() && quest_id > 0 && step > 0 && progress > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3092. Client* client = player->GetZone()->GetClientBySpawn(player);
  3093. if (client)
  3094. client->AddPendingQuestUpdate(quest_id, step, progress);
  3095. }
  3096. return 0;
  3097. }
  3098. int EQ2Emu_lua_GetTaskGroupStep(lua_State* state) {
  3099. if (!lua_interface)
  3100. return 0;
  3101. Spawn* player = lua_interface->GetSpawn(state);
  3102. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3103. if (player && player->IsPlayer() && quest_id > 0) {
  3104. lua_interface->SetInt32Value(state, ((Player*)player)->GetTaskGroupStep(quest_id));
  3105. return 1;
  3106. }
  3107. return 0;
  3108. }
  3109. int EQ2Emu_lua_QuestStepIsComplete(lua_State* state) {
  3110. if (!lua_interface)
  3111. return 0;
  3112. Spawn* player = lua_interface->GetSpawn(state);
  3113. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3114. int32 step_id = lua_interface->GetInt32Value(state, 3);
  3115. if (player && player->IsPlayer() && quest_id > 0) {
  3116. lua_interface->SetBooleanValue(state, ((Player*)player)->GetQuestStepComplete(quest_id, step_id));
  3117. return 1;
  3118. }
  3119. return 0;
  3120. }
  3121. int EQ2Emu_lua_GetQuestStep(lua_State* state) {
  3122. if (!lua_interface)
  3123. return 0;
  3124. Spawn* player = lua_interface->GetSpawn(state);
  3125. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3126. if (player && player->IsPlayer() && quest_id > 0) {
  3127. lua_interface->SetInt32Value(state, ((Player*)player)->GetQuestStep(quest_id));
  3128. return 1;
  3129. }
  3130. return 0;
  3131. }
  3132. int EQ2Emu_lua_RegisterQuest(lua_State* state) {
  3133. if (!lua_interface)
  3134. return 0;
  3135. Quest* quest = lua_interface->GetQuest(state);
  3136. string name = lua_interface->GetStringValue(state, 2);
  3137. string type = lua_interface->GetStringValue(state, 3);
  3138. string zone = lua_interface->GetStringValue(state, 4);
  3139. int16 level = lua_interface->GetInt16Value(state, 5);
  3140. string description = lua_interface->GetStringValue(state, 6);
  3141. bool load = true;
  3142. if (!quest) {
  3143. lua_interface->LogError("%s: Quest not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3144. load = false;
  3145. }
  3146. if (load && name.length() == 0) {
  3147. lua_interface->LogError("%s: Name not given in RegisterQuest!", lua_interface->GetScriptName(state));
  3148. load = false;
  3149. }
  3150. if (load && type.length() == 0) {
  3151. lua_interface->LogError("%s: Type not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3152. load = false;
  3153. }
  3154. if (load && zone.length() == 0) {
  3155. lua_interface->LogError("%s: Zone not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3156. load = false;
  3157. }
  3158. if (load && description.length() == 0) {
  3159. lua_interface->LogError("%s: Description not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3160. load = false;
  3161. }
  3162. if (load && level == 0) {
  3163. lua_interface->LogError("%s: Level not given in RegisterQuest for '%s'!", lua_interface->GetScriptName(state), name.c_str());
  3164. load = false;
  3165. }
  3166. if (load)
  3167. quest->RegisterQuest(name, type, zone, level, description);
  3168. return 0;
  3169. }
  3170. int EQ2Emu_lua_SetQuestPrereqLevel(lua_State* state) {
  3171. if (!lua_interface)
  3172. return 0;
  3173. Quest* quest = lua_interface->GetQuest(state);
  3174. if (quest) {
  3175. int8 level = lua_interface->GetInt16Value(state, 2);
  3176. quest->SetPrereqLevel(level);
  3177. }
  3178. return 0;
  3179. }
  3180. int EQ2Emu_lua_AddQuestPrereqQuest(lua_State* state) {
  3181. if (!lua_interface)
  3182. return 0;
  3183. Quest* quest = lua_interface->GetQuest(state);
  3184. if (quest) {
  3185. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3186. quest->AddPrereqQuest(quest_id);
  3187. }
  3188. return 0;
  3189. }
  3190. int EQ2Emu_lua_AddQuestPrereqItem(lua_State* state) {
  3191. if (!lua_interface)
  3192. return 0;
  3193. Quest* quest = lua_interface->GetQuest(state);
  3194. if (quest) {
  3195. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3196. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3197. if (quantity == 0)
  3198. quantity = 1;
  3199. Item* master_item = master_item_list.GetItem(item_id);
  3200. if (master_item) {
  3201. Item* item = new Item(master_item);
  3202. item->details.count = quantity;
  3203. quest->AddPrereqItem(item);
  3204. }
  3205. }
  3206. return 0;
  3207. }
  3208. int EQ2Emu_lua_HasQuest(lua_State* state) {
  3209. if (!lua_interface)
  3210. return 0;
  3211. Spawn* player = lua_interface->GetSpawn(state);
  3212. if(!player || !player->IsPlayer()) {
  3213. lua_interface->LogError("%s: LUA HasQuest command error: player is not valid", lua_interface->GetScriptName(state));
  3214. return 0;
  3215. }
  3216. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3217. if (quest_id > 0) {
  3218. lua_interface->SetBooleanValue(state, (((Player*)player)->player_quests.count(quest_id) > 0));
  3219. return 1;
  3220. } else {
  3221. lua_interface->LogError("%s: LUA HasQuest command error: quest_id is not valid", lua_interface->GetScriptName(state));
  3222. }
  3223. return 0;
  3224. }
  3225. int EQ2Emu_lua_QuestReturnNPC(lua_State* state) {
  3226. if (!lua_interface)
  3227. return 0;
  3228. Quest* quest = lua_interface->GetQuest(state);
  3229. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  3230. lua_interface->ResetFunctionStack(state);
  3231. if (quest && spawn_id > 0)
  3232. quest->SetQuestReturnNPC(spawn_id);
  3233. return 0;
  3234. }
  3235. int EQ2Emu_lua_AddTimer(lua_State* state) {
  3236. if (!lua_interface)
  3237. return 0;
  3238. Spawn* spawn = lua_interface->GetSpawn(state);
  3239. int32 time = lua_interface->GetInt32Value(state, 2);
  3240. string function = lua_interface->GetStringValue(state, 3);
  3241. int32 max_count = lua_interface->GetInt32Value(state, 4);
  3242. Spawn* player = lua_interface->GetSpawn(state, 5);
  3243. lua_interface->ResetFunctionStack(state);
  3244. if (!spawn) {
  3245. lua_interface->LogError("%s: LUA AddTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3246. return 0;
  3247. }
  3248. if (time <= 0) {
  3249. lua_interface->LogError("%s: LUA AddTimer command error: time is not set", lua_interface->GetScriptName(state));
  3250. return 0;
  3251. }
  3252. if (function.length() == 0) {
  3253. lua_interface->LogError("%s: LUA AddTimer command error: function is not set", lua_interface->GetScriptName(state));
  3254. return 0;
  3255. }
  3256. SpawnScriptTimer* timer = new SpawnScriptTimer;
  3257. if ( time < 10)
  3258. time = 10;
  3259. timer->timer = Timer::GetCurrentTime2() + time;
  3260. timer->function = function;
  3261. timer->spawn = spawn->GetID();
  3262. timer->player = player ? player->GetID() : 0;
  3263. if (max_count == 0)
  3264. max_count = 1;
  3265. timer->max_count = max_count;
  3266. timer->current_count = 0;
  3267. spawn->GetZone()->AddSpawnScriptTimer(timer);
  3268. return 0;
  3269. }
  3270. int EQ2Emu_lua_StopTimer(lua_State* state) {
  3271. if (!lua_interface)
  3272. return 0;
  3273. Spawn* spawn = lua_interface->GetSpawn(state);
  3274. string function = lua_interface->GetStringValue(state, 2);
  3275. lua_interface->ResetFunctionStack(state);
  3276. if (!spawn) {
  3277. lua_interface->LogError("%s: LUA StopTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  3278. return 0;
  3279. }
  3280. if(!spawn->GetZone()) {
  3281. lua_interface->LogError("%s: LUA StopTimer command error: spawn has no zone to check spawn timers", lua_interface->GetScriptName(state));
  3282. return 0;
  3283. }
  3284. spawn->GetZone()->StopSpawnScriptTimer(spawn, function);
  3285. return 0;
  3286. }
  3287. int EQ2Emu_lua_GetQuest(lua_State* state) {
  3288. if (!lua_interface)
  3289. return 0;
  3290. Spawn* player = lua_interface->GetSpawn(state);
  3291. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3292. lua_interface->ResetFunctionStack(state);
  3293. if (player && player->IsPlayer() && quest_id > 0) {
  3294. lua_interface->SetQuestValue(state, ((Player*)player)->player_quests[quest_id]);
  3295. return 1;
  3296. }
  3297. return 0;
  3298. }
  3299. int EQ2Emu_lua_QuestIsComplete(lua_State* state) {
  3300. if (!lua_interface)
  3301. return 0;
  3302. Spawn* player = lua_interface->GetSpawn(state);
  3303. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3304. lua_interface->ResetFunctionStack(state);
  3305. if (player && player->IsPlayer() && quest_id > 0 && (((Player*)player)->player_quests.count(quest_id) > 0)) {
  3306. Quest* quest = ((Player*)player)->player_quests[quest_id];
  3307. if (quest)
  3308. lua_interface->SetBooleanValue(state, quest->GetCompleted());
  3309. return 1;
  3310. }
  3311. return 0;
  3312. }
  3313. int EQ2Emu_lua_HasCompletedQuest(lua_State* state) {
  3314. if (!lua_interface)
  3315. return 0;
  3316. Spawn* player = lua_interface->GetSpawn(state);
  3317. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3318. lua_interface->ResetFunctionStack(state);
  3319. if (player && player->IsPlayer() && quest_id > 0) {
  3320. lua_interface->SetBooleanValue(state, (((Player*)player)->GetCompletedQuest(quest_id) != 0));
  3321. return 1;
  3322. }
  3323. return 0;
  3324. }
  3325. int EQ2Emu_lua_ProvidesQuest(lua_State* state) {
  3326. if (!lua_interface)
  3327. return 0;
  3328. Spawn* npc = lua_interface->GetSpawn(state);
  3329. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  3330. lua_interface->ResetFunctionStack(state);
  3331. if (npc && !npc->IsPlayer() && quest_id > 0)
  3332. npc->AddProvidedQuest(quest_id);
  3333. return 0;
  3334. }
  3335. int EQ2Emu_lua_OfferQuest(lua_State* state) {
  3336. if (!lua_interface)
  3337. return 0;
  3338. Spawn* npc = lua_interface->GetSpawn(state);
  3339. Spawn* player = lua_interface->GetSpawn(state, 2);
  3340. int32 quest_id = lua_interface->GetInt32Value(state, 3);
  3341. bool forced = lua_interface->GetBooleanValue(state, 4);
  3342. lua_interface->ResetFunctionStack(state);
  3343. /* NPC is allowed to be null */
  3344. if (player && player->IsPlayer() && quest_id > 0) {
  3345. Quest* master_quest = master_quest_list.GetQuest(quest_id, false);
  3346. if (master_quest) {
  3347. Client* client = player->GetZone()->GetClientBySpawn(player);
  3348. if (!client) {
  3349. lua_interface->LogError("%s: LUA OfferQuest command error: client is not set", lua_interface->GetScriptName(state));
  3350. }
  3351. Quest* quest = new Quest(master_quest);
  3352. if (!quest) {
  3353. lua_interface->LogError("%s: LUA OfferQuest command error: new Quest() failed.", lua_interface->GetScriptName(state));
  3354. }
  3355. if (client && quest) {
  3356. if (npc)
  3357. quest->SetQuestGiver(npc->GetDatabaseID());
  3358. else
  3359. quest->SetQuestGiver(0);
  3360. client->AddPendingQuest(quest, forced);
  3361. }
  3362. }
  3363. else {
  3364. lua_interface->LogError("%s: LUA OfferQuest command error: failed to get quest %d", lua_interface->GetScriptName(state), quest_id);
  3365. }
  3366. }
  3367. else {
  3368. 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);
  3369. }
  3370. return 0;
  3371. }
  3372. int EQ2Emu_lua_AddQuestPrereqClass(lua_State* state) {
  3373. if (!lua_interface)
  3374. return 0;
  3375. Quest* quest = lua_interface->GetQuest(state);
  3376. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3377. lua_interface->ResetFunctionStack(state);
  3378. if (quest) {
  3379. quest->AddPrereqClass(class_id);
  3380. }
  3381. return 0;
  3382. }
  3383. int EQ2Emu_lua_AddQuestPrereqRace(lua_State* state) {
  3384. if (!lua_interface)
  3385. return 0;
  3386. Quest* quest = lua_interface->GetQuest(state);
  3387. int8 race = lua_interface->GetInt8Value(state, 2);
  3388. lua_interface->ResetFunctionStack(state);
  3389. if (quest) {
  3390. quest->AddPrereqRace(race);
  3391. }
  3392. return 0;
  3393. }
  3394. int EQ2Emu_lua_AddQuestPrereqModelType(lua_State* state) {
  3395. if (!lua_interface)
  3396. return 0;
  3397. Quest* quest = lua_interface->GetQuest(state);
  3398. int16 model_type = lua_interface->GetInt16Value(state, 2);
  3399. lua_interface->ResetFunctionStack(state);
  3400. if (quest) {
  3401. quest->AddPrereqModelType(model_type);
  3402. }
  3403. return 0;
  3404. }
  3405. int EQ2Emu_lua_AddQuestPrereqTradeskillLevel(lua_State* state) {
  3406. if (!lua_interface)
  3407. return 0;
  3408. Quest* quest = lua_interface->GetQuest(state);
  3409. int8 level = lua_interface->GetInt8Value(state, 2);
  3410. lua_interface->ResetFunctionStack(state);
  3411. if (!quest) {
  3412. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillLevel command error: quest is not valid", lua_interface->GetScriptName(state));
  3413. return 0;
  3414. }
  3415. quest->SetPrereqTSLevel(level);
  3416. return 0;
  3417. }
  3418. int EQ2Emu_lua_AddQuestPrereqTradeskillClass(lua_State* state) {
  3419. if (!lua_interface)
  3420. return 0;
  3421. Quest* quest = lua_interface->GetQuest(state);
  3422. int8 class_id = lua_interface->GetInt8Value(state, 2);
  3423. lua_interface->ResetFunctionStack(state);
  3424. if (!quest) {
  3425. lua_interface->LogError("%s: LUA AddQuestPrereqTradeskillClass command error: quest is not valid", lua_interface->GetScriptName(state));
  3426. return 0;
  3427. }
  3428. quest->AddPrereqTradeskillClass(class_id);
  3429. return 0;
  3430. }
  3431. int EQ2Emu_lua_AddQuestPrereqFaction(lua_State* state) {
  3432. if (!lua_interface)
  3433. return 0;
  3434. Quest* quest = lua_interface->GetQuest(state);
  3435. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3436. sint32 min = lua_interface->GetSInt32Value(state, 3);
  3437. sint32 max = lua_interface->GetSInt32Value(state, 4);
  3438. lua_interface->ResetFunctionStack(state);
  3439. if (quest) {
  3440. quest->AddPrereqFaction(faction_id, min, max);
  3441. }
  3442. return 0;
  3443. }
  3444. int EQ2Emu_lua_AddQuestSelectableRewardItem(lua_State* state) {
  3445. if (!lua_interface)
  3446. return 0;
  3447. Quest* quest = lua_interface->GetQuest(state);
  3448. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3449. int8 quantity = lua_interface->GetInt8Value(state, 3);
  3450. lua_interface->ResetFunctionStack(state);
  3451. if (quest) {
  3452. if (quantity == 0)
  3453. quantity = 1;
  3454. Item* master_item = master_item_list.GetItem(item_id);
  3455. if (master_item) {
  3456. Item* item = new Item(master_item);
  3457. item->details.count = quantity;
  3458. quest->AddSelectableRewardItem(item);
  3459. }
  3460. }
  3461. return 0;
  3462. }
  3463. int EQ2Emu_lua_HasQuestRewardItem(lua_State* state) {
  3464. if (!lua_interface)
  3465. return 0;
  3466. Quest* quest = lua_interface->GetQuest(state);
  3467. if (quest) {
  3468. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3469. vector<Item*>* items = quest->GetRewardItems();
  3470. if (items) {
  3471. vector<Item*>::iterator itr;
  3472. for (itr = items->begin(); itr != items->end(); itr++) {
  3473. if (*itr && (*itr)->details.item_id == item_id) {
  3474. lua_interface->SetBooleanValue(state, true);
  3475. return 1;
  3476. }
  3477. }
  3478. }
  3479. }
  3480. lua_interface->SetBooleanValue(state, false);
  3481. return 1;
  3482. }
  3483. int EQ2Emu_lua_AddQuestRewardItem(lua_State* state) {
  3484. if (!lua_interface)
  3485. return 0;
  3486. Quest* quest = lua_interface->GetQuest(state);
  3487. int32 item_id = lua_interface->GetInt32Value(state, 2);
  3488. int8 quantity = lua_interface->GetInt32Value(state, 3);
  3489. lua_interface->ResetFunctionStack(state);
  3490. if (quest) {
  3491. if (quantity == 0)
  3492. quantity = 1;
  3493. Item* master_item = master_item_list.GetItem(item_id);
  3494. if (master_item) {
  3495. Item* item = new Item(master_item);
  3496. item->details.count = quantity;
  3497. quest->AddRewardItem(item);
  3498. }
  3499. }
  3500. return 0;
  3501. }
  3502. int EQ2Emu_lua_AddQuestRewardCoin(lua_State* state) {
  3503. if (!lua_interface)
  3504. return 0;
  3505. Quest* quest = lua_interface->GetQuest(state);
  3506. int32 copper = lua_interface->GetInt32Value(state, 2);
  3507. int32 silver = lua_interface->GetInt32Value(state, 3);
  3508. int32 gold = lua_interface->GetInt32Value(state, 4);
  3509. int32 plat = lua_interface->GetInt32Value(state, 5);
  3510. lua_interface->ResetFunctionStack(state);
  3511. if (quest) {
  3512. quest->AddRewardCoins(copper, silver, gold, plat);
  3513. }
  3514. return 0;
  3515. }
  3516. int EQ2Emu_lua_AddQuestRewardFaction(lua_State* state) {
  3517. if (!lua_interface)
  3518. return 0;
  3519. Quest* quest = lua_interface->GetQuest(state);
  3520. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  3521. sint32 amount = lua_interface->GetSInt32Value(state, 3);
  3522. lua_interface->ResetFunctionStack(state);
  3523. if (quest && faction_id > 0 && amount != 0)
  3524. quest->AddRewardFaction(faction_id, amount);
  3525. return 0;
  3526. }
  3527. int EQ2Emu_lua_SetQuestRewardStatus(lua_State* state) {
  3528. if (!lua_interface)
  3529. return 0;
  3530. Quest* quest = lua_interface->GetQuest(state);
  3531. int32 status = lua_interface->GetInt32Value(state, 2);
  3532. lua_interface->ResetFunctionStack(state);
  3533. if (quest) {
  3534. quest->SetRewardStatus(status);
  3535. }
  3536. return 0;
  3537. }
  3538. int EQ2Emu_lua_SetStatusTmpReward(lua_State* state) {
  3539. if (!lua_interface)
  3540. return 0;
  3541. Quest* quest = lua_interface->GetQuest(state);
  3542. int32 status = lua_interface->GetInt32Value(state, 2);
  3543. lua_interface->ResetFunctionStack(state);
  3544. if (quest) {
  3545. quest->SetStatusTmpReward(status);
  3546. }
  3547. return 0;
  3548. }
  3549. int EQ2Emu_lua_SetCoinTmpReward(lua_State* state) {
  3550. if (!lua_interface)
  3551. return 0;
  3552. Quest* quest = lua_interface->GetQuest(state);
  3553. int64 coins = lua_interface->GetInt64Value(state, 2);
  3554. lua_interface->ResetFunctionStack(state);
  3555. if (quest) {
  3556. quest->SetCoinTmpReward(coins);
  3557. }
  3558. return 0;
  3559. }
  3560. int EQ2Emu_lua_SetQuestRewardComment(lua_State* state) {
  3561. if (!lua_interface)
  3562. return 0;
  3563. Quest* quest = lua_interface->GetQuest(state);
  3564. string comment = lua_interface->GetStringValue(state, 2);
  3565. lua_interface->ResetFunctionStack(state);
  3566. if (quest) {
  3567. quest->SetRewardComment(comment);
  3568. }
  3569. return 0;
  3570. }
  3571. int EQ2Emu_lua_SetQuestRewardExp(lua_State* state) {
  3572. if (!lua_interface)
  3573. return 0;
  3574. Quest* quest = lua_interface->GetQuest(state);
  3575. int32 exp = lua_interface->GetInt32Value(state, 2);
  3576. lua_interface->ResetFunctionStack(state);
  3577. if (quest) {
  3578. quest->SetRewardXP(exp);
  3579. }
  3580. return 0;
  3581. }
  3582. int EQ2Emu_lua_AddQuestStep(lua_State* state) {
  3583. Quest* quest = lua_interface->GetQuest(state);
  3584. int32 step = lua_interface->GetInt32Value(state, 2);
  3585. string description = lua_interface->GetStringValue(state, 3);
  3586. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3587. float percentage = lua_interface->GetFloatValue(state, 5);
  3588. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3589. int16 icon = lua_interface->GetInt16Value(state, 7);
  3590. int32 usableitemid = lua_interface->GetInt32Value(state, 8);
  3591. if (quest) {
  3592. const char* taskgroup = 0;
  3593. if (str_taskgroup.length() > 0)
  3594. taskgroup = str_taskgroup.c_str();
  3595. int32 id = 0;
  3596. vector<int32>* ids = 0;
  3597. int i = 0;
  3598. while ((id = lua_interface->GetInt32Value(state, 9 + i))) {
  3599. if (ids == 0)
  3600. ids = new vector<int32>;
  3601. ids->push_back(id);
  3602. i++;
  3603. }
  3604. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_NORMAL, description, ids, quantity, taskgroup, 0, 0, percentage, usableitemid);
  3605. if (quest_step && icon && quantity > 0)
  3606. quest_step->SetIcon(icon);
  3607. if (quest->GetPlayer()) {
  3608. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3609. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3610. }
  3611. }
  3612. lua_interface->ResetFunctionStack(state);
  3613. return 0;
  3614. }
  3615. int EQ2Emu_lua_AddQuestStepKillLogic(lua_State* state, int8 type)
  3616. {
  3617. if (!lua_interface)
  3618. return 0;
  3619. Quest* quest = lua_interface->GetQuest(state);
  3620. int32 step = lua_interface->GetInt32Value(state, 2);
  3621. string description = lua_interface->GetStringValue(state, 3);
  3622. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3623. float percentage = lua_interface->GetFloatValue(state, 5);
  3624. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3625. int16 icon = lua_interface->GetInt16Value(state, 7);
  3626. if (quest) {
  3627. const char* taskgroup = 0;
  3628. if (str_taskgroup.length() > 0)
  3629. taskgroup = str_taskgroup.c_str();
  3630. int32 id = 0;
  3631. vector<int32>* ids = 0;
  3632. int i = 0;
  3633. while ((id = lua_interface->GetInt32Value(state, 8 + i))) {
  3634. if (ids == 0)
  3635. ids = new vector<int32>;
  3636. ids->push_back(id);
  3637. i++;
  3638. }
  3639. QuestStep* quest_step = quest->AddQuestStep(step, type, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3640. if (quest_step && icon > 0 && quantity > 0)
  3641. quest_step->SetIcon(icon);
  3642. if (quest->GetPlayer()) {
  3643. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3644. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3645. }
  3646. safe_delete(ids);
  3647. }
  3648. lua_interface->ResetFunctionStack(state);
  3649. return 0;
  3650. }
  3651. int EQ2Emu_lua_AddQuestStepKill(lua_State* state) {
  3652. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL);
  3653. }
  3654. int EQ2Emu_lua_AddQuestStepKillByRace(lua_State* state) {
  3655. return EQ2Emu_lua_AddQuestStepKillLogic(state, QUEST_STEP_TYPE_KILL_RACE_REQ);
  3656. }
  3657. int EQ2Emu_lua_AddQuestStepChat(lua_State* state) {
  3658. if (!lua_interface)
  3659. return 0;
  3660. Quest* quest = lua_interface->GetQuest(state);
  3661. int32 step = lua_interface->GetInt32Value(state, 2);
  3662. string description = lua_interface->GetStringValue(state, 3);
  3663. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3664. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3665. int16 icon = lua_interface->GetInt16Value(state, 6);
  3666. if (quest) {
  3667. const char* taskgroup = 0;
  3668. if (str_taskgroup.length() > 0)
  3669. taskgroup = str_taskgroup.c_str();
  3670. int32 npc_id = 0;
  3671. vector<int32>* ids = 0;
  3672. int i = 0;
  3673. while ((npc_id = lua_interface->GetInt32Value(state, 7 + i))) {
  3674. if (ids == 0)
  3675. ids = new vector<int32>;
  3676. ids->push_back(npc_id);
  3677. i++;
  3678. }
  3679. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CHAT, description, ids, quantity, taskgroup);
  3680. if (quest_step && icon > 0)
  3681. quest_step->SetIcon(icon);
  3682. if (quest->GetPlayer()) {
  3683. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3684. if(client)
  3685. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3686. }
  3687. safe_delete(ids);
  3688. }
  3689. lua_interface->ResetFunctionStack(state);
  3690. return 0;
  3691. }
  3692. int EQ2Emu_lua_AddQuestStepObtainItem(lua_State* state) {
  3693. if (!lua_interface)
  3694. return 0;
  3695. Quest* quest = lua_interface->GetQuest(state);
  3696. int32 step = lua_interface->GetInt32Value(state, 2);
  3697. string description = lua_interface->GetStringValue(state, 3);
  3698. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3699. float percentage = lua_interface->GetFloatValue(state, 5);
  3700. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3701. int16 icon = lua_interface->GetInt16Value(state, 7);
  3702. if (quest) {
  3703. const char* taskgroup = 0;
  3704. if (str_taskgroup.length() > 0)
  3705. taskgroup = str_taskgroup.c_str();
  3706. int32 item_id = 0;
  3707. vector<int32>* ids = 0;
  3708. int i = 0;
  3709. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3710. if (ids == 0)
  3711. ids = new vector<int32>;
  3712. ids->push_back(item_id);
  3713. i++;
  3714. }
  3715. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_OBTAIN_ITEM, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3716. if (quest_step && icon > 0 && quantity > 0)
  3717. quest_step->SetIcon(icon);
  3718. if (quest->GetPlayer()) {
  3719. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3720. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3721. }
  3722. safe_delete(ids);
  3723. }
  3724. lua_interface->ResetFunctionStack(state);
  3725. return 0;
  3726. }
  3727. int EQ2Emu_lua_AddQuestStepZoneLoc(lua_State* state) {
  3728. if (!lua_interface)
  3729. return 0;
  3730. Quest* quest = lua_interface->GetQuest(state);
  3731. int32 step = lua_interface->GetInt32Value(state, 2);
  3732. string description = lua_interface->GetStringValue(state, 3);
  3733. float max_variation = lua_interface->GetFloatValue(state, 4);
  3734. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3735. int16 icon = lua_interface->GetInt16Value(state, 6);
  3736. if (quest) {
  3737. const char* taskgroup = 0;
  3738. if (str_taskgroup.length() > 0)
  3739. taskgroup = str_taskgroup.c_str();
  3740. vector<Location>* locations = 0;
  3741. int8 i = 7;
  3742. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3743. while (true) {
  3744. Location loc;
  3745. loc.x = lua_interface->GetFloatValue(state, i);
  3746. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3747. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3748. loc.zone_id = lua_interface->GetInt32Value(state, i + 3);
  3749. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3750. break;
  3751. if (locations == 0)
  3752. locations = new vector<Location>;
  3753. locations->push_back(loc);
  3754. i += 4;
  3755. }
  3756. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3757. if (quest_step && icon > 0)
  3758. quest_step->SetIcon(icon);
  3759. if (quest->GetPlayer()) {
  3760. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3761. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3762. }
  3763. }
  3764. lua_interface->ResetFunctionStack(state);
  3765. return 0;
  3766. }
  3767. int EQ2Emu_lua_AddQuestStepLocation(lua_State* state) {
  3768. if (!lua_interface)
  3769. return 0;
  3770. Quest* quest = lua_interface->GetQuest(state);
  3771. int32 step = lua_interface->GetInt32Value(state, 2);
  3772. string description = lua_interface->GetStringValue(state, 3);
  3773. float max_variation = lua_interface->GetFloatValue(state, 4);
  3774. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3775. int16 icon = lua_interface->GetInt16Value(state, 6);
  3776. if (quest) {
  3777. const char* taskgroup = 0;
  3778. if (str_taskgroup.length() > 0)
  3779. taskgroup = str_taskgroup.c_str();
  3780. vector<Location>* locations = 0;
  3781. int8 i = 7;
  3782. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  3783. while (true) {
  3784. Location loc;
  3785. loc.x = lua_interface->GetFloatValue(state, i);
  3786. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3787. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3788. loc.zone_id = 0;
  3789. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3790. break;
  3791. if (locations == 0)
  3792. locations = new vector<Location>;
  3793. locations->push_back(loc);
  3794. i += 3;
  3795. }
  3796. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3797. if (quest_step && icon > 0)
  3798. quest_step->SetIcon(icon);
  3799. if (quest->GetPlayer()) {
  3800. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3801. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3802. }
  3803. }
  3804. lua_interface->ResetFunctionStack(state);
  3805. return 0;
  3806. }
  3807. int EQ2Emu_lua_AddQuestUsableItem(lua_State* state) {
  3808. if (!lua_interface)
  3809. return 0;
  3810. Quest* quest = lua_interface->GetQuest(state);
  3811. int32 step = lua_interface->GetInt32Value(state, 2);
  3812. string description = lua_interface->GetStringValue(state, 3);
  3813. float max_variation = lua_interface->GetFloatValue(state, 4);
  3814. string str_taskgroup = lua_interface->GetStringValue(state, 5);
  3815. int16 icon = lua_interface->GetInt16Value(state, 6);
  3816. if (quest) {
  3817. const char* taskgroup = 0;
  3818. if (str_taskgroup.length() > 0)
  3819. taskgroup = str_taskgroup.c_str();
  3820. vector<Location>* locations = 0;
  3821. int i = 7;
  3822. while (true) {
  3823. Location loc;
  3824. loc.x = lua_interface->GetFloatValue(state, i);
  3825. loc.y = lua_interface->GetFloatValue(state, i + 1);
  3826. loc.z = lua_interface->GetFloatValue(state, i + 2);
  3827. if (loc.x == 0 && loc.y == 0 && loc.z == 0)
  3828. break;
  3829. if (locations == 0)
  3830. locations = new vector<Location>;
  3831. locations->push_back(loc);
  3832. i += 3;
  3833. }
  3834. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_LOCATION, description, 0, 1, taskgroup, locations, max_variation);
  3835. if (quest_step && icon > 0)
  3836. quest_step->SetIcon(icon);
  3837. if (quest->GetPlayer()) {
  3838. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3839. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3840. }
  3841. }
  3842. lua_interface->ResetFunctionStack(state);
  3843. return 0;
  3844. }
  3845. int EQ2Emu_lua_AddQuestStepSpell(lua_State* state) {
  3846. Quest* quest = lua_interface->GetQuest(state);
  3847. int32 step = lua_interface->GetInt32Value(state, 2);
  3848. string description = lua_interface->GetStringValue(state, 3);
  3849. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3850. float percentage = lua_interface->GetFloatValue(state, 5);
  3851. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3852. int16 icon = lua_interface->GetInt16Value(state, 7);
  3853. if (quest) {
  3854. const char* taskgroup = 0;
  3855. if (str_taskgroup.length() > 0)
  3856. taskgroup = str_taskgroup.c_str();
  3857. int32 spell_id = 0;
  3858. vector<int32>* ids = 0;
  3859. int i = 0;
  3860. while ((spell_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3861. if (ids == 0)
  3862. ids = new vector<int32>;
  3863. ids->push_back(spell_id);
  3864. i++;
  3865. }
  3866. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_SPELL, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3867. if (quest_step && icon > 0 && quantity > 0)
  3868. quest_step->SetIcon(icon);
  3869. if (quest->GetPlayer()) {
  3870. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3871. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3872. }
  3873. safe_delete(ids);
  3874. }
  3875. lua_interface->ResetFunctionStack(state);
  3876. return 0;
  3877. }
  3878. int EQ2Emu_lua_AddQuestStepCraft(lua_State* state) {
  3879. if (!lua_interface)
  3880. return 0;
  3881. Quest* quest = lua_interface->GetQuest(state);
  3882. int32 step = lua_interface->GetInt32Value(state, 2);
  3883. string description = lua_interface->GetStringValue(state, 3);
  3884. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3885. float percentage = lua_interface->GetFloatValue(state, 5);
  3886. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3887. int16 icon = lua_interface->GetInt16Value(state, 7);
  3888. if (quest) {
  3889. const char* taskgroup = 0;
  3890. if (str_taskgroup.length() > 0)
  3891. taskgroup = str_taskgroup.c_str();
  3892. int32 item_id = 0;
  3893. vector<int32>* ids = 0;
  3894. int i = 0;
  3895. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3896. if (ids == 0)
  3897. ids = new vector<int32>;
  3898. ids->push_back(item_id);
  3899. i++;
  3900. }
  3901. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_CRAFT, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3902. if (quest_step && icon > 0 && quantity > 0)
  3903. quest_step->SetIcon(icon);
  3904. if (quest->GetPlayer()) {
  3905. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3906. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3907. }
  3908. safe_delete(ids);
  3909. }
  3910. lua_interface->ResetFunctionStack(state);
  3911. return 0;
  3912. }
  3913. int EQ2Emu_lua_AddQuestStepHarvest(lua_State* state) {
  3914. if (!lua_interface)
  3915. return 0;
  3916. Quest* quest = lua_interface->GetQuest(state);
  3917. int32 step = lua_interface->GetInt32Value(state, 2);
  3918. string description = lua_interface->GetStringValue(state, 3);
  3919. int32 quantity = lua_interface->GetInt32Value(state, 4);
  3920. float percentage = lua_interface->GetFloatValue(state, 5);
  3921. string str_taskgroup = lua_interface->GetStringValue(state, 6);
  3922. int16 icon = lua_interface->GetInt16Value(state, 7);
  3923. if (quest) {
  3924. const char* taskgroup = 0;
  3925. if (str_taskgroup.length() > 0)
  3926. taskgroup = str_taskgroup.c_str();
  3927. int32 item_id = 0;
  3928. vector<int32>* ids = 0;
  3929. int i = 0;
  3930. while ((item_id = lua_interface->GetInt32Value(state, 8 + i))) {
  3931. if (ids == 0)
  3932. ids = new vector<int32>;
  3933. ids->push_back(item_id);
  3934. i++;
  3935. }
  3936. QuestStep* quest_step = quest->AddQuestStep(step, QUEST_STEP_TYPE_HARVEST, description, ids, quantity, taskgroup, 0, 0, percentage, 0);
  3937. if (quest_step && icon > 0 && quantity > 0)
  3938. quest_step->SetIcon(icon);
  3939. if (quest->GetPlayer()) {
  3940. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  3941. quest->GetPlayer()->GetZone()->SendQuestUpdates(client);
  3942. }
  3943. safe_delete(ids);
  3944. }
  3945. lua_interface->ResetFunctionStack(state);
  3946. return 0;
  3947. }
  3948. int EQ2Emu_lua_SetQuestCompleteAction(lua_State* state) {
  3949. if (!lua_interface)
  3950. return 0;
  3951. Quest* quest = lua_interface->GetQuest(state);
  3952. string action = lua_interface->GetStringValue(state, 2);
  3953. lua_interface->ResetFunctionStack(state);
  3954. if (quest) {
  3955. if (action.length() > 0)
  3956. quest->SetCompleteAction(action);
  3957. }
  3958. return 0;
  3959. }
  3960. int EQ2Emu_lua_AddQuestStepCompleteAction(lua_State* state) {
  3961. if (!lua_interface)
  3962. return 0;
  3963. Quest* quest = lua_interface->GetQuest(state);
  3964. int32 step = lua_interface->GetInt32Value(state, 2);
  3965. string action = lua_interface->GetStringValue(state, 3);
  3966. lua_interface->ResetFunctionStack(state);
  3967. if (quest) {
  3968. if (step > 0 && action.length() > 0)
  3969. quest->AddCompleteAction(step, action);
  3970. }
  3971. return 0;
  3972. }
  3973. int EQ2Emu_lua_AddQuestStepProgressAction(lua_State* state) {
  3974. if (!lua_interface)
  3975. return 0;
  3976. Quest* quest = lua_interface->GetQuest(state);
  3977. int32 step = lua_interface->GetInt32Value(state, 2);
  3978. string action = lua_interface->GetStringValue(state, 3);
  3979. lua_interface->ResetFunctionStack(state);
  3980. if (quest) {
  3981. if (step > 0 && action.length() > 0)
  3982. quest->AddProgressAction(step, action);
  3983. }
  3984. return 0;
  3985. }
  3986. int EQ2Emu_lua_UpdateQuestDescription(lua_State* state) {
  3987. if (!lua_interface)
  3988. return 0;
  3989. Quest* quest = lua_interface->GetQuest(state);
  3990. string description = lua_interface->GetStringValue(state, 2);
  3991. lua_interface->ResetFunctionStack(state);
  3992. if (quest && description.length() > 0)
  3993. quest->SetDescription(description);
  3994. return 0;
  3995. }
  3996. int EQ2Emu_lua_SetCompletedDescription(lua_State* state) {
  3997. if (!lua_interface)
  3998. return 0;
  3999. Quest* quest = lua_interface->GetQuest(state);
  4000. string description = lua_interface->GetStringValue(state, 2);
  4001. lua_interface->ResetFunctionStack(state);
  4002. if (quest && description.length() > 0)
  4003. quest->SetCompletedDescription(description);
  4004. return 0;
  4005. }
  4006. int EQ2Emu_lua_UpdateQuestTaskGroupDescription(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. bool display_bullets = (lua_interface->GetInt8Value(state, 4) == 1);
  4013. lua_interface->ResetFunctionStack(state);
  4014. if (quest && step > 0 && description.length() > 0) {
  4015. quest->SetTaskGroupDescription(step, description, display_bullets);
  4016. /* if (quest->GetPlayer()) {
  4017. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4018. if (client)
  4019. client->SendQuestUpdateStep(quest, step, false);
  4020. }*/
  4021. }
  4022. return 0;
  4023. }
  4024. int EQ2Emu_lua_UpdateQuestStepDescription(lua_State* state) {
  4025. if (!lua_interface)
  4026. return 0;
  4027. Quest* quest = lua_interface->GetQuest(state);
  4028. int32 step = lua_interface->GetInt32Value(state, 2);
  4029. string description = lua_interface->GetStringValue(state, 3);
  4030. lua_interface->ResetFunctionStack(state);
  4031. if (quest && step > 0 && description.length() > 0) {
  4032. quest->SetStepDescription(step, description);
  4033. /*if (quest->GetPlayer()) {
  4034. Client* client = quest->GetPlayer()->GetZone()->GetClientBySpawn(quest->GetPlayer());
  4035. if (client)
  4036. client->SendQuestUpdateStepImmediately(quest, step);
  4037. }*/
  4038. }
  4039. return 0;
  4040. }
  4041. int EQ2Emu_lua_UpdateQuestZone(lua_State* state) {
  4042. Quest* quest = lua_interface->GetQuest(state);
  4043. string zone = lua_interface->GetStringValue(state, 2);
  4044. lua_interface->ResetFunctionStack(state);
  4045. if (quest && zone.length() > 0)
  4046. quest->SetZone(zone);
  4047. return 0;
  4048. }
  4049. int EQ2Emu_lua_GiveQuestReward(lua_State* state) {
  4050. if (!lua_interface)
  4051. return 0;
  4052. Quest* quest = lua_interface->GetQuest(state);
  4053. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4054. lua_interface->ResetFunctionStack(state);
  4055. if (quest && spawn) {
  4056. if (spawn->IsPlayer()) {
  4057. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4058. if (client)
  4059. {
  4060. client->AddPendingQuestAcceptReward(quest);
  4061. client->AddPendingQuestReward(quest);
  4062. }
  4063. }
  4064. }
  4065. return 0;
  4066. }
  4067. int EQ2Emu_lua_Harvest(lua_State* state) {
  4068. if (!lua_interface)
  4069. return 0;
  4070. Spawn* player = lua_interface->GetSpawn(state);
  4071. Spawn* node = lua_interface->GetSpawn(state, 2);
  4072. if (player && node && player->IsPlayer() && node->IsGroundSpawn()) {
  4073. Client* client = player->GetZone()->GetClientBySpawn(player);
  4074. if (client) {
  4075. LogWrite(MISC__TODO, 1, "TODO", "Cancel harvest if skill insufficient; Func: %s, Line: %i", __FUNCTION__, __LINE__);
  4076. ((GroundSpawn*)node)->ProcessHarvest(client);
  4077. if (((GroundSpawn*)node)->GetNumberHarvests() == 0) {
  4078. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4079. player->GetZone()->RemoveSpawn(node, true, true, true, true, (spell != nullptr) ? false : true);
  4080. }
  4081. }
  4082. }
  4083. else if (player && player->IsPlayer()) {
  4084. Client* client = player->GetZone()->GetClientBySpawn(player);
  4085. if (client)
  4086. client->Message(CHANNEL_COLOR_RED, "Invalid target for this spell.");
  4087. }
  4088. lua_interface->ResetFunctionStack(state);
  4089. return 0;
  4090. }
  4091. int EQ2Emu_lua_Bind(lua_State* state) {
  4092. if (!lua_interface)
  4093. return 0;
  4094. Spawn* spawn = lua_interface->GetSpawn(state);
  4095. int32 zone_id = lua_interface->GetInt32Value(state, 2);
  4096. float x = lua_interface->GetFloatValue(state, 3);
  4097. float y = lua_interface->GetFloatValue(state, 4);
  4098. float z = lua_interface->GetFloatValue(state, 5);
  4099. float h = lua_interface->GetFloatValue(state, 6);
  4100. lua_interface->ResetFunctionStack(state);
  4101. if (!spawn) {
  4102. lua_interface->LogError("%s: LUA Bind command error: spawn is not valid", lua_interface->GetScriptName(state));
  4103. return 0;
  4104. }
  4105. if (!spawn->IsPlayer()) {
  4106. lua_interface->LogError("%s: LUA Bind command error: spawn is not a player", lua_interface->GetScriptName(state));
  4107. return 0;
  4108. }
  4109. if (zone_id == 0) {
  4110. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4111. if (!client) {
  4112. lua_interface->LogError("%s: LUA Bind command error: unable to get client from spawn", lua_interface->GetScriptName(state));
  4113. return 0;
  4114. }
  4115. if (!client->Bind())
  4116. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to set bind point.");
  4117. }
  4118. else {
  4119. Player* player = (Player*)spawn;
  4120. player->GetPlayerInfo()->SetBindZone(zone_id);
  4121. player->GetPlayerInfo()->SetBindX(x);
  4122. player->GetPlayerInfo()->SetBindY(y);
  4123. player->GetPlayerInfo()->SetBindZ(z);
  4124. player->GetPlayerInfo()->SetBindHeading(h);
  4125. }
  4126. return 0;
  4127. }
  4128. int EQ2Emu_lua_Gate(lua_State* state) {
  4129. if (!lua_interface)
  4130. return 0;
  4131. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  4132. Spawn* spawn = lua_interface->GetSpawn(state);
  4133. lua_interface->ResetFunctionStack(state);
  4134. if (spawn) {
  4135. if (spawn->IsPlayer()) {
  4136. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4137. if (client) {
  4138. if (!client->Gate((spell != nullptr) ? true : false))
  4139. client->SimpleMessage(CHANNEL_COLOR_RED, "Unable to gate.");
  4140. }
  4141. }
  4142. }
  4143. return 0;
  4144. }
  4145. int EQ2Emu_lua_IsBindAllowed(lua_State* state) {
  4146. if (!lua_interface)
  4147. return 0;
  4148. bool ret = false;
  4149. Spawn* spawn = lua_interface->GetSpawn(state);
  4150. lua_interface->ResetFunctionStack(state);
  4151. if (spawn) {
  4152. if (spawn->IsPlayer()) {
  4153. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4154. if (client)
  4155. ret = client->BindAllowed();
  4156. }
  4157. }
  4158. lua_interface->SetBooleanValue(state, ret);
  4159. return 1;
  4160. }
  4161. int EQ2Emu_lua_IsGateAllowed(lua_State* state) {
  4162. if (!lua_interface)
  4163. return 0;
  4164. bool ret = false;
  4165. Spawn* spawn = lua_interface->GetSpawn(state);
  4166. lua_interface->ResetFunctionStack(state);
  4167. if (spawn) {
  4168. if (spawn->IsPlayer()) {
  4169. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4170. ZoneServer* zone = lua_interface->GetZone(state);
  4171. if (client && zone){
  4172. ret = zone->GetCanGate();
  4173. }
  4174. }
  4175. }
  4176. lua_interface->SetBooleanValue(state, ret);
  4177. return 1;
  4178. }
  4179. int EQ2Emu_lua_IsAlive(lua_State* state) {
  4180. Spawn* spawn = lua_interface->GetSpawn(state);
  4181. lua_interface->ResetFunctionStack(state);
  4182. if (spawn) {
  4183. lua_interface->SetBooleanValue(state, spawn->Alive());
  4184. return 1;
  4185. }
  4186. return 0;
  4187. }
  4188. int EQ2Emu_lua_IsInCombat(lua_State* state) {
  4189. if (!lua_interface)
  4190. return 0;
  4191. Spawn* spawn = lua_interface->GetSpawn(state);
  4192. lua_interface->ResetFunctionStack(state);
  4193. if (spawn && spawn->IsEntity()) {
  4194. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->EngagedInCombat());
  4195. return 1;
  4196. }
  4197. return 0;
  4198. }
  4199. int EQ2Emu_lua_SendMessage(lua_State* state) {
  4200. Spawn* spawn = lua_interface->GetSpawn(state);
  4201. string message = lua_interface->GetStringValue(state, 2);
  4202. string color_str = lua_interface->GetStringValue(state, 3);
  4203. lua_interface->ResetFunctionStack(state);
  4204. int8 color = CHANNEL_NARRATIVE;
  4205. if (spawn && spawn->IsPlayer() && message.length() > 0) {
  4206. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4207. if (client) {
  4208. if (color_str.length() > 0) {
  4209. // leave for backwards compat, but all future should just use the number
  4210. if (strncasecmp(color_str.c_str(), "red", 3) == 0)
  4211. color = CHANNEL_COLOR_RED;
  4212. else if (strncasecmp(color_str.c_str(), "yellow", 6) == 0)
  4213. color = CHANNEL_COLOR_YELLOW;
  4214. else
  4215. {
  4216. // use a number to specify the channel as per Commands/Commands.h defines
  4217. color = (int8)atoul(color_str.c_str());
  4218. }
  4219. }
  4220. client->SimpleMessage(color, message.c_str());
  4221. }
  4222. }
  4223. return 0;
  4224. }
  4225. int EQ2Emu_lua_SendPopUpMessage(lua_State* state) {
  4226. Spawn* spawn = lua_interface->GetSpawn(state);
  4227. string message = lua_interface->GetStringValue(state, 2);
  4228. int8 red = lua_interface->GetInt8Value(state, 3);
  4229. int8 green = lua_interface->GetInt8Value(state, 4);
  4230. int8 blue = lua_interface->GetInt8Value(state, 5);
  4231. lua_interface->ResetFunctionStack(state);
  4232. if (!spawn) {
  4233. lua_interface->LogError("%s: LUA SendPopUpMessage command error: Spawn is not valid.", lua_interface->GetScriptName(state));
  4234. return 0;
  4235. }
  4236. int32 words = ::CountWordsInString(message.c_str());
  4237. if (words < 5)
  4238. words = 5;
  4239. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4240. if (client)
  4241. client->SendPopupMessage(10, message.c_str(), "ui_harvested_normal", words, red, green, blue);
  4242. return 0;
  4243. }
  4244. int EQ2Emu_lua_SetServerControlFlag(lua_State* state) {
  4245. Spawn* spawn = lua_interface->GetSpawn(state);
  4246. int8 param = lua_interface->GetInt8Value(state, 2);
  4247. int8 param_value = lua_interface->GetInt8Value(state, 3);
  4248. int8 value = lua_interface->GetInt8Value(state, 4);
  4249. lua_interface->ResetFunctionStack(state);
  4250. if (spawn && spawn->IsPlayer() && (param >= 1 && param <= 5)) {
  4251. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4252. if (client) {
  4253. PacketStruct* packet = configReader.getStruct("WS_ServerControlFlags", client->GetVersion());
  4254. switch (param) {
  4255. case 1: {
  4256. packet->setDataByName("parameter1", param_value);
  4257. break;
  4258. }
  4259. case 2: {
  4260. packet->setDataByName("parameter2", param_value);
  4261. break;
  4262. }
  4263. case 3: {
  4264. packet->setDataByName("parameter3", param_value);
  4265. break;
  4266. }
  4267. case 4: {
  4268. packet->setDataByName("parameter4", param_value);
  4269. break;
  4270. }
  4271. case 5: {
  4272. packet->setDataByName("parameter5", param_value);
  4273. break;
  4274. }
  4275. }
  4276. packet->setDataByName("value", value);
  4277. client->QueuePacket(packet->serialize());
  4278. safe_delete(packet);
  4279. }
  4280. }
  4281. return 0;
  4282. }
  4283. int EQ2Emu_lua_ToggleTracking(lua_State* state) {
  4284. Spawn* spawn = lua_interface->GetSpawn(state);
  4285. lua_interface->ResetFunctionStack(state);
  4286. if (spawn && spawn->IsPlayer()) {
  4287. if (((Player*)spawn)->GetIsTracking())
  4288. spawn->GetZone()->AddPlayerTracking((Player*)spawn);
  4289. else
  4290. spawn->GetZone()->RemovePlayerTracking((Player*)spawn, TRACKING_STOP);
  4291. }
  4292. return 0;
  4293. }
  4294. int EQ2Emu_lua_AddPrimaryEntityCommand(lua_State* state) {
  4295. Spawn* player = lua_interface->GetSpawn(state);
  4296. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  4297. string name = lua_interface->GetStringValue(state, 3);
  4298. float distance = lua_interface->GetFloatValue(state, 4);
  4299. string command = lua_interface->GetStringValue(state, 5);
  4300. string error_text = lua_interface->GetStringValue(state, 6);
  4301. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  4302. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  4303. bool denyListDefault = (lua_interface->GetInt8Value(state, 9) == 1);
  4304. lua_interface->ResetFunctionStack(state);
  4305. if (spawn) {
  4306. if (distance == 0)
  4307. distance = 10.0f;
  4308. if (command.length() == 0)
  4309. command = name;
  4310. if (command.length() < 1 && name.length() < 1)
  4311. {
  4312. // have to run this first to send a 'blank' default command, then remove all commands from the list
  4313. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  4314. spawn->RemovePrimaryCommands();
  4315. }
  4316. else
  4317. {
  4318. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual, denyListDefault, (player && player->IsPlayer()) ? (Player*)player : NULL);
  4319. }
  4320. }
  4321. return 0;
  4322. }
  4323. int EQ2Emu_lua_HasSpell(lua_State* state) {
  4324. if (!lua_interface)
  4325. return 0;
  4326. Spawn* player = lua_interface->GetSpawn(state);
  4327. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4328. int16 tier = lua_interface->GetInt16Value(state, 3);
  4329. lua_interface->ResetFunctionStack(state);
  4330. if (player && player->IsPlayer()) {
  4331. lua_interface->SetBooleanValue(state, ((Player*)player)->HasSpell(spellid, tier, true));
  4332. return 1;
  4333. }
  4334. return 0;
  4335. }
  4336. int EQ2Emu_lua_AddSpellBookEntry(lua_State* state) {
  4337. if (!lua_interface)
  4338. return 0;
  4339. Spawn* player = lua_interface->GetSpawn(state);
  4340. int32 spellid = lua_interface->GetInt32Value(state, 2);
  4341. int16 tier = lua_interface->GetInt16Value(state, 3);
  4342. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  4343. bool add_silently = lua_interface->GetBooleanValue(state, 4);
  4344. bool add_to_hotbar = true;
  4345. if (num_args > 4) {
  4346. add_to_hotbar = lua_interface->GetBooleanValue(state, 5);
  4347. }
  4348. lua_interface->ResetFunctionStack(state);
  4349. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4350. if (player && spell && player->IsPlayer()) {
  4351. Client* client = player->GetClient();
  4352. if (client) {
  4353. if (!client->GetPlayer()->HasSpell(spellid, tier - 1, true))
  4354. {
  4355. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4356. client->GetPlayer()->AddSpellBookEntry(spellid, 1, client->GetPlayer()->GetFreeSpellBookSlot(spell->GetSpellData()->spell_book_type), spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4357. client->GetPlayer()->UnlockSpell(spell);
  4358. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4359. }
  4360. else
  4361. {
  4362. Spell* spell = master_spell_list.GetSpell(spellid, tier);
  4363. int8 old_slot = client->GetPlayer()->GetSpellSlot(spell->GetSpellID());
  4364. client->GetPlayer()->RemoveSpellBookEntry(spell->GetSpellID());
  4365. client->GetPlayer()->AddSpellBookEntry(spell->GetSpellID(), spell->GetSpellTier(), old_slot, spell->GetSpellData()->spell_book_type, spell->GetSpellData()->linked_timer, true);
  4366. client->GetPlayer()->UnlockSpell(spell);
  4367. client->SendSpellUpdate(spell, add_silently, add_to_hotbar);
  4368. }
  4369. //if (client ) {
  4370. // ((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);
  4371. EQ2Packet* outapp = ((Player*)player)->GetSpellBookUpdatePacket(client->GetVersion());
  4372. if (outapp)
  4373. client->QueuePacket(outapp);
  4374. }
  4375. }
  4376. return 0;
  4377. }
  4378. int EQ2Emu_lua_HasFreeSlot(lua_State* state) {
  4379. if (!lua_interface)
  4380. return 0;
  4381. Spawn* player = lua_interface->GetSpawn(state);
  4382. lua_interface->ResetFunctionStack(state);
  4383. if (player && player->IsPlayer()) {
  4384. lua_interface->SetBooleanValue(state, ((Player*)player)->item_list.HasFreeSlot());
  4385. return 1;
  4386. }
  4387. return 0;
  4388. }
  4389. int EQ2Emu_lua_Attack(lua_State* state) {
  4390. if (lua_interface) {
  4391. Spawn* npc = lua_interface->GetSpawn(state);
  4392. Spawn* player = lua_interface->GetSpawn(state, 2);
  4393. lua_interface->ResetFunctionStack(state);
  4394. if (npc && player && npc->IsNPC() && player->IsPlayer())
  4395. ((NPC*)npc)->AddHate((Entity*)player, 100);
  4396. }
  4397. return 0;
  4398. }
  4399. int EQ2Emu_lua_ApplySpellVisual(lua_State* state) {
  4400. if (lua_interface) {
  4401. Spawn* target = lua_interface->GetSpawn(state);
  4402. int32 spell_visual = lua_interface->GetInt32Value(state, 2);
  4403. lua_interface->ResetFunctionStack(state);
  4404. if (target && target->GetZone())
  4405. target->GetZone()->SendCastSpellPacket(spell_visual, target);
  4406. }
  4407. return 0;
  4408. }
  4409. int EQ2Emu_lua_HasCollectionsToHandIn(lua_State* state) {
  4410. Spawn* player;
  4411. if (lua_interface) {
  4412. player = lua_interface->GetSpawn(state);
  4413. lua_interface->ResetFunctionStack(state);
  4414. if (player && player->IsPlayer()) {
  4415. lua_interface->SetBooleanValue(state, ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn());
  4416. return 1;
  4417. }
  4418. }
  4419. return 0;
  4420. }
  4421. int EQ2Emu_lua_HandInCollections(lua_State* state) {
  4422. Spawn* player;
  4423. Client* client;
  4424. if (lua_interface) {
  4425. player = lua_interface->GetSpawn(state);
  4426. lua_interface->ResetFunctionStack(state);
  4427. if (player && ((Player*)player)->IsPlayer() && ((Player*)player)->GetCollectionList()->HasCollectionsToHandIn())
  4428. if ((client = player->GetZone()->GetClientBySpawn(player)))
  4429. client->HandInCollections();
  4430. }
  4431. return 0;
  4432. }
  4433. int EQ2Emu_lua_UseWidget(lua_State* state) {
  4434. Spawn* widget;
  4435. if (lua_interface) {
  4436. widget = lua_interface->GetSpawn(state);
  4437. lua_interface->ResetFunctionStack(state);
  4438. if (widget && widget->IsWidget())
  4439. ((Widget*)widget)->HandleUse(nullptr, "");
  4440. }
  4441. return 0;
  4442. }
  4443. int EQ2Emu_lua_SetSpellList(lua_State* state) {
  4444. Spawn* spawn = 0;
  4445. int32 primary_list = 0;
  4446. int32 secondary_list = 0;
  4447. if (lua_interface) {
  4448. spawn = lua_interface->GetSpawn(state);
  4449. primary_list = lua_interface->GetInt32Value(state, 2);
  4450. secondary_list = lua_interface->GetInt32Value(state, 3);
  4451. lua_interface->ResetFunctionStack(state);
  4452. if (!spawn->IsNPC()) {
  4453. lua_interface->LogError("%s: LUA SetSpellList command error: Spawn was not a valid NPC", lua_interface->GetScriptName(state));
  4454. return 0;
  4455. }
  4456. NPC* npc = (NPC*)spawn;
  4457. npc->SetPrimarySpellList(primary_list);
  4458. npc->SetSecondarySpellList(secondary_list);
  4459. npc->SetSpells(npc->GetZone()->GetNPCSpells(npc->GetPrimarySpellList(), npc->GetSecondarySpellList()));
  4460. }
  4461. return 0;
  4462. }
  4463. int EQ2Emu_lua_GetPet(lua_State* state) {
  4464. if (!lua_interface)
  4465. return 0;
  4466. Spawn* spawn = lua_interface->GetSpawn(state);
  4467. lua_interface->ResetFunctionStack(state);
  4468. if (spawn) {
  4469. if (spawn->IsEntity() && ((Entity*)spawn)->GetPet()) {
  4470. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetPet());
  4471. return 1;
  4472. }
  4473. }
  4474. return 0;
  4475. }
  4476. int EQ2Emu_lua_GetCharmedPet(lua_State* state) {
  4477. if (!lua_interface)
  4478. return 0;
  4479. Spawn* spawn = lua_interface->GetSpawn(state);
  4480. lua_interface->ResetFunctionStack(state);
  4481. if (spawn) {
  4482. if (spawn->IsEntity() && ((Entity*)spawn)->GetCharmedPet()) {
  4483. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCharmedPet());
  4484. return 1;
  4485. }
  4486. }
  4487. return 0;
  4488. }
  4489. int EQ2Emu_lua_GetDeityPet(lua_State* state) {
  4490. if (!lua_interface)
  4491. return 0;
  4492. Spawn* spawn = lua_interface->GetSpawn(state);
  4493. lua_interface->ResetFunctionStack(state);
  4494. if (spawn) {
  4495. if (spawn->IsEntity() && ((Entity*)spawn)->GetDeityPet()) {
  4496. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetDeityPet());
  4497. return 1;
  4498. }
  4499. }
  4500. return 0;
  4501. }
  4502. int EQ2Emu_lua_GetCosmeticPet(lua_State* state) {
  4503. if (!lua_interface)
  4504. return 0;
  4505. Spawn* spawn = lua_interface->GetSpawn(state);
  4506. lua_interface->ResetFunctionStack(state);
  4507. if (spawn) {
  4508. if (spawn->IsEntity() && ((Entity*)spawn)->GetCosmeticPet()) {
  4509. lua_interface->SetSpawnValue(state, ((Entity*)spawn)->GetCosmeticPet());
  4510. return 1;
  4511. }
  4512. }
  4513. return 0;
  4514. }
  4515. int EQ2Emu_lua_Charm(lua_State* state) {
  4516. if (!lua_interface)
  4517. return 0;
  4518. Spawn* owner = lua_interface->GetSpawn(state);
  4519. Spawn* pet = lua_interface->GetSpawn(state, 2);
  4520. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4521. lua_interface->ResetFunctionStack(state);
  4522. if (!luaspell) {
  4523. lua_interface->LogError("%s: LUA Charm command error: Spell is not valid, charm can only be used in spell scripts.", lua_interface->GetScriptName(state));
  4524. return 0;
  4525. }
  4526. if(luaspell->resisted) {
  4527. return 0;
  4528. }
  4529. if (owner && pet && owner->IsEntity() && pet->IsNPC()) {
  4530. ((Entity*)owner)->SetCharmedPet((Entity*)pet);
  4531. pet->SetPet(true);
  4532. ((NPC*)pet)->SetPetType(PET_TYPE_CHARMED);
  4533. ((NPC*)pet)->SetOwner((Entity*)owner);
  4534. // If owner is player and player does not have a summoned pet set the players charsheet
  4535. if (owner->IsPlayer() && !((Entity*)owner)->GetPet()) {
  4536. Player* player = (Player*)owner;
  4537. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4538. player->GetInfoStruct()->set_pet_name(std::string(pet->GetName()));
  4539. player->GetInfoStruct()->set_pet_movement(2);
  4540. player->GetInfoStruct()->set_pet_behavior(3);
  4541. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4542. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4543. // Make sure the values get sent to the client
  4544. player->SetCharSheetChanged(true);
  4545. }
  4546. // Clear the spawns script so the charmed mob doesn't try to do anything like random walks
  4547. pet->SetSpawnScript("");
  4548. // Set faction to the same as the owner
  4549. pet->SetFactionID(owner->GetFactionID());
  4550. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4551. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4552. // Clear hate list
  4553. ((NPC*)pet)->Brain()->ClearHate();
  4554. // Set the brain to a pet brain
  4555. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4556. }
  4557. return 0;
  4558. }
  4559. int EQ2Emu_lua_GetGroup(lua_State* state) {
  4560. if (!lua_interface)
  4561. return 0;
  4562. Spawn* spawn = lua_interface->GetSpawn(state);
  4563. lua_interface->ResetFunctionStack(state);
  4564. if (!spawn) {
  4565. lua_interface->LogError("%s: LUA GetGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  4566. return 0;
  4567. }
  4568. vector<Spawn*> groupMembers;
  4569. if (!spawn->IsPlayer() && spawn->HasSpawnGroup()) {
  4570. groupMembers = *spawn->GetSpawnGroup();
  4571. }
  4572. else if (spawn->IsPlayer() && ((Player*)spawn)->GetGroupMemberInfo()) {
  4573. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  4574. deque<GroupMemberInfo*>::iterator itr;
  4575. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Player*)spawn)->GetGroupMemberInfo()->group_id);
  4576. if (group)
  4577. {
  4578. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  4579. deque<GroupMemberInfo*>* members = group->GetMembers();
  4580. GroupMemberInfo* info = 0;
  4581. for (itr = members->begin(); itr != members->end(); itr++) {
  4582. info = *itr;
  4583. if (info->client)
  4584. groupMembers.push_back(info->client->GetPlayer());
  4585. }
  4586. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  4587. }
  4588. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  4589. }
  4590. else
  4591. return 0;
  4592. lua_createtable(state, groupMembers.size(), 0);
  4593. int newTable = lua_gettop(state);
  4594. for (int32 i = 0; i < groupMembers.size(); i++) {
  4595. lua_interface->SetSpawnValue(state, groupMembers.at(i));
  4596. lua_rawseti(state, newTable, i + 1);
  4597. }
  4598. return 1;
  4599. }
  4600. int EQ2Emu_lua_CreateOptionWindow(lua_State* state) {
  4601. if (!lua_interface)
  4602. return 0;
  4603. vector<OptionWindowOption>* option_window = new vector<OptionWindowOption>();
  4604. lua_interface->SetOptionWindowValue(state, option_window);
  4605. return 1;
  4606. }
  4607. int EQ2Emu_lua_AddOptionWindowOption(lua_State* state) {
  4608. if (!lua_interface)
  4609. return 0;
  4610. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4611. if (option_window) {
  4612. OptionWindowOption option_window_option;
  4613. option_window_option.optionName = lua_interface->GetStringValue(state, 2);
  4614. option_window_option.optionDescription = lua_interface->GetStringValue(state, 3);
  4615. option_window_option.optionIconSheet = lua_interface->GetInt32Value(state, 4);
  4616. option_window_option.optionIconID = lua_interface->GetInt16Value(state, 5);
  4617. option_window_option.optionCommand = lua_interface->GetStringValue(state, 6);
  4618. option_window_option.optionConfirmTitle = lua_interface->GetStringValue(state, 7);
  4619. if (option_window_option.optionName.length() > 0 && option_window_option.optionDescription.length() > 0)
  4620. option_window->push_back(option_window_option);
  4621. }
  4622. return 0;
  4623. }
  4624. int EQ2Emu_lua_SendOptionWindow(lua_State* state) {
  4625. if (!lua_interface)
  4626. return 0;
  4627. vector<OptionWindowOption>* option_window = lua_interface->GetOptionWindow(state);
  4628. Spawn* player = lua_interface->GetSpawn(state, 2);
  4629. string window_title = lua_interface->GetStringValue(state, 3);
  4630. string cancel_command = lua_interface->GetStringValue(state, 4);
  4631. Client* client = player->GetZone()->GetClientBySpawn(player);
  4632. if (option_window && window_title.length() > 0 && client) {
  4633. PacketStruct* packet = configReader.getStruct("WS_SelectTradeskill", client->GetVersion());
  4634. if (!packet)
  4635. return 0;
  4636. packet->setDataByName("title_text", window_title.c_str());
  4637. if (cancel_command.length() > 0)
  4638. packet->setDataByName("command_text_cancel", cancel_command.c_str());
  4639. packet->setArrayLengthByName("num_selections", option_window->size());
  4640. vector<OptionWindowOption>::iterator itr;
  4641. int8 i = 0;
  4642. for (itr = option_window->begin(); itr != option_window->end(); itr++) {
  4643. OptionWindowOption opt = *itr;
  4644. packet->setArrayDataByName("tradeskill_name", opt.optionName.c_str(), i);
  4645. packet->setArrayDataByName("tradeskill_description", opt.optionDescription.c_str(), i);
  4646. packet->setArrayDataByName("icon_sheet", opt.optionIconSheet, i);
  4647. packet->setArrayDataByName("icon_id", opt.optionIconID, i);
  4648. if (opt.optionCommand.length() > 0)
  4649. packet->setArrayDataByName("command_text", opt.optionCommand.c_str(), i);
  4650. if (opt.optionConfirmTitle.length() > 0)
  4651. packet->setArrayDataByName("confirm_window_title", opt.optionConfirmTitle.c_str(), i);
  4652. i++;
  4653. }
  4654. client->QueuePacket(packet->serialize());
  4655. safe_delete(option_window);
  4656. safe_delete(packet);
  4657. }
  4658. return 0;
  4659. }
  4660. int EQ2Emu_lua_GetTradeskillClass(lua_State* state) {
  4661. if (!lua_interface)
  4662. return 0;
  4663. Spawn* spawn = lua_interface->GetSpawn(state);
  4664. if (spawn) {
  4665. lua_interface->SetInt32Value(state, spawn->GetTradeskillClass());
  4666. return 1;
  4667. }
  4668. else
  4669. lua_interface->LogError("%s: LUA GetTradeskillClass command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4670. return 0;
  4671. }
  4672. int EQ2Emu_lua_GetTradeskillLevel(lua_State* state) {
  4673. if (!lua_interface)
  4674. return 0;
  4675. Spawn* spawn = lua_interface->GetSpawn(state);
  4676. if (spawn) {
  4677. lua_interface->SetInt32Value(state, spawn->GetTSLevel());
  4678. return 1;
  4679. }
  4680. else
  4681. lua_interface->LogError("%s: LUA GetTradeskillLevel command error: Spawns was not valid", lua_interface->GetScriptName(state));
  4682. return 0;
  4683. }
  4684. int EQ2Emu_lua_GetTradeskillClassName(lua_State* state) {
  4685. if (!lua_interface)
  4686. return 0;
  4687. Spawn* spawn = lua_interface->GetSpawn(state);
  4688. if (spawn) {
  4689. int8 class_id = spawn->GetTradeskillClass();
  4690. // Need to add 42 for the offset in the array
  4691. class_id += 44;
  4692. lua_interface->SetStringValue(state, classes.GetClassNameCase(class_id).c_str());
  4693. return 1;
  4694. }
  4695. else
  4696. lua_interface->LogError("%s: LUA GetTradeskillClassName command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4697. return 0;
  4698. }
  4699. int EQ2Emu_lua_SetTradeskillLevel(lua_State* state) {
  4700. if (!lua_interface)
  4701. return 0;
  4702. Spawn* spawn = lua_interface->GetSpawn(state);
  4703. int16 level = lua_interface->GetInt8Value(state, 2);
  4704. if (spawn) {
  4705. if (spawn->IsPlayer())
  4706. spawn->GetZone()->GetClientBySpawn(spawn)->ChangeTSLevel(spawn->GetTSLevel(), level);
  4707. else
  4708. spawn->SetTSLevel(level);
  4709. }
  4710. else
  4711. lua_interface->LogError("%s: LUA SetTradeskillLevel command error: Spawn was not valid", lua_interface->GetScriptName(state));
  4712. return 0;
  4713. }
  4714. int EQ2Emu_lua_SetAttackable(lua_State* state) {
  4715. if (!lua_interface)
  4716. return 0;
  4717. Spawn* spawn = lua_interface->GetSpawn(state);
  4718. int8 attackable = lua_interface->GetInt8Value(state, 2);
  4719. if (spawn) {
  4720. spawn->SetAttackable(attackable);
  4721. spawn->vis_changed = true; //some clients store this in vis instead of info, need to make sense both are updated
  4722. }
  4723. return 0;
  4724. }
  4725. int EQ2Emu_lua_SummonPet(lua_State* state) {
  4726. // Check to see if we have a valid lua_interface
  4727. if (!lua_interface)
  4728. return 0;
  4729. // Get the spawn that is getting the pet
  4730. Spawn* spawn = lua_interface->GetSpawn(state);
  4731. // Get the DB ID of the pet
  4732. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4733. // The max level the pet can gain
  4734. int8 max_level = lua_interface->GetInt8Value(state, 3);
  4735. // Get the spell that this command was called from
  4736. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4737. // Check to make sure the spawn pointer is valid
  4738. if (!spawn) {
  4739. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4740. return 0;
  4741. }
  4742. // Check to make sure the spawn is an entity
  4743. if (!spawn->IsEntity()) {
  4744. lua_interface->LogError("%s: LUA SummonPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4745. return 0;
  4746. }
  4747. // Check to make sure the spawn doesn't already have a pet of this type
  4748. if (((Entity*)spawn)->GetPet()) {
  4749. if (spawn->IsPlayer()) {
  4750. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4751. if (client)
  4752. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a pet.");
  4753. }
  4754. lua_interface->LogError("%s: LUA SummonPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4755. return 0;
  4756. }
  4757. // Check to see if the DB ID for the pet is set
  4758. if (pet_id == 0) {
  4759. lua_interface->LogError("%s: LUA SummonPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4760. return 0;
  4761. }
  4762. // Check to see if the pointer to the spell is valid
  4763. if (!luaspell) {
  4764. lua_interface->LogError("%s: LUA SummonPet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4765. return 0;
  4766. }
  4767. if(luaspell->resisted) {
  4768. return 0;
  4769. }
  4770. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  4771. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4772. if (!pet) {
  4773. lua_interface->LogError("%s: LUA SummonPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4774. return 0;
  4775. }
  4776. // Check to make sure the pet is an npc
  4777. if (!pet->IsNPC()) {
  4778. lua_interface->LogError("%s: LUA SummonPet command error: id (%u) did not point to a npc", lua_interface->GetScriptName(state), pet_id);
  4779. return 0;
  4780. }
  4781. // Spawn the pet at the same location as the owner
  4782. pet->SetX(spawn->GetX());
  4783. pet->SetY(spawn->GetY());
  4784. pet->SetZ(spawn->GetZ());
  4785. pet->SetLocation(spawn->GetLocation());
  4786. pet->SetHeading(spawn->GetHeading());
  4787. spawn->GetZone()->AddSpawn(pet);
  4788. /*
  4789. const char* spawn_script = world.GetSpawnScript(pet_id);
  4790. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  4791. spawn->SetSpawnScript(string(spawn_script));
  4792. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  4793. }*/
  4794. // Get a random pet name
  4795. string random_pet_name;
  4796. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4797. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4798. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4799. // If player set various values for the char sheet (pet window)
  4800. if (spawn->IsPlayer()) {
  4801. Player* player = (Player*)spawn;
  4802. player->GetInfoStruct()->set_pet_id(player->GetIDWithPlayerSpawn(pet));
  4803. player->GetInfoStruct()->set_pet_name(random_pet_name);
  4804. player->GetInfoStruct()->set_pet_movement(2);
  4805. player->GetInfoStruct()->set_pet_behavior(3);
  4806. player->GetInfoStruct()->set_pet_health_pct(1.0f);
  4807. player->GetInfoStruct()->set_pet_power_pct(1.0f);
  4808. // Make sure the values get sent to the client
  4809. player->SetCharSheetChanged(true);
  4810. }
  4811. // Set the pets name
  4812. pet->SetName(random_pet_name.c_str());
  4813. // Set the level of the pet to the owners level or max level(if set) if owners level is greater
  4814. if (max_level > 0)
  4815. pet->SetLevel(spawn->GetLevel() >= max_level ? max_level : spawn->GetLevel());
  4816. else
  4817. pet->SetLevel(spawn->GetLevel());
  4818. // Set the max level this pet can reach
  4819. ((NPC*)pet)->SetMaxPetLevel(max_level);
  4820. // Set the faction of the pet to the same faction as the owner
  4821. pet->SetFactionID(spawn->GetFactionID());
  4822. // Set the spawn as a pet
  4823. pet->SetPet(true);
  4824. // Give a pointer of the owner to the pet
  4825. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4826. // Give a pointer of the pet to the owner
  4827. ((Entity*)spawn)->SetCombatPet((Entity*)pet);
  4828. // Set the pet type
  4829. ((NPC*)pet)->SetPetType(PET_TYPE_COMBAT);
  4830. // Set the spell id used to create this pet
  4831. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4832. // Set the spell tier used to create this pet
  4833. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4834. // Set the pets spawn type to 6
  4835. pet->SetSpawnType(6);
  4836. // Set the pets brain
  4837. ((NPC*)pet)->SetBrain(new CombatPetBrain((NPC*)pet));
  4838. // Check to see if the pet has a subtitle
  4839. if (strlen(pet->GetSubTitle()) > 0) {
  4840. // Add the players name to the front of the sub title
  4841. string pet_subtitle;
  4842. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4843. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4844. // Set the pets subtitle to the new one
  4845. pet->SetSubTitle(pet_subtitle.c_str());
  4846. }
  4847. // Add the "Pet Options" entity command to the pet
  4848. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4849. // Set the pet as the return value for this function
  4850. lua_interface->SetSpawnValue(state, pet);
  4851. return 1;
  4852. }
  4853. int EQ2Emu_lua_SummonDeityPet(lua_State* state) {
  4854. if (!lua_interface)
  4855. return 0;
  4856. Spawn* spawn = lua_interface->GetSpawn(state);
  4857. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4858. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4859. if (!spawn) {
  4860. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4861. return 0;
  4862. }
  4863. if (!spawn->IsEntity()) {
  4864. lua_interface->LogError("%s: LUA SummonDeityPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4865. return 0;
  4866. }
  4867. if (((Entity*)spawn)->GetDeityPet()) {
  4868. if (spawn->IsPlayer()) {
  4869. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4870. if (client)
  4871. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a deity pet.");
  4872. }
  4873. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4874. return 0;
  4875. }
  4876. if (pet_id == 0) {
  4877. lua_interface->LogError("%s: LUA SummonDeityPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4878. return 0;
  4879. }
  4880. if (!luaspell) {
  4881. lua_interface->LogError("%s: LUA SummonDeityPet command error: valid spell not found, SummonDeityPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4882. return 0;
  4883. }
  4884. if(luaspell->resisted) {
  4885. return 0;
  4886. }
  4887. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4888. if (!pet) {
  4889. lua_interface->LogError("%s: LUA SummonDeityPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4890. return 0;
  4891. }
  4892. if (!pet->IsNPC()) {
  4893. lua_interface->LogError("%s: LUA SummonDeityPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4894. return 0;
  4895. }
  4896. pet->SetX(spawn->GetX());
  4897. pet->SetY(spawn->GetY());
  4898. pet->SetZ(spawn->GetZ());
  4899. pet->SetLocation(spawn->GetLocation());
  4900. pet->SetHeading(spawn->GetHeading());
  4901. spawn->GetZone()->AddSpawn(pet);
  4902. string random_pet_name;
  4903. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4904. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4905. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4906. pet->SetName(random_pet_name.c_str());
  4907. pet->SetLevel(spawn->GetLevel());
  4908. pet->SetFactionID(spawn->GetFactionID());
  4909. pet->SetPet(true);
  4910. ((NPC*)pet)->SetPetType(PET_TYPE_DEITY);
  4911. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4912. ((Entity*)spawn)->SetDeityPet((Entity*)pet);
  4913. pet->SetSpawnType(6);
  4914. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4915. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4916. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4917. if (strlen(pet->GetSubTitle()) > 0) {
  4918. string pet_subtitle;
  4919. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4920. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4921. pet->SetSubTitle(pet_subtitle.c_str());
  4922. }
  4923. // deity and cosmetic pets are not attackable
  4924. pet->SetAttackable(false);
  4925. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  4926. lua_interface->SetSpawnValue(state, pet);
  4927. return 1;
  4928. }
  4929. int EQ2Emu_lua_SummonCosmeticPet(lua_State* state) {
  4930. if (!lua_interface)
  4931. return 0;
  4932. Spawn* spawn = lua_interface->GetSpawn(state);
  4933. int32 pet_id = lua_interface->GetInt32Value(state, 2);
  4934. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  4935. if (!spawn) {
  4936. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  4937. return 0;
  4938. }
  4939. if (!spawn->IsEntity()) {
  4940. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  4941. return 0;
  4942. }
  4943. if (((Entity*)spawn)->GetCosmeticPet()) {
  4944. if (spawn->IsPlayer()) {
  4945. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  4946. if (client)
  4947. client->SimpleMessage(CHANNEL_COLOR_YELLOW, "You already have a cosmetic pet.");
  4948. }
  4949. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn already has a pet of this type", lua_interface->GetScriptName(state));
  4950. return 0;
  4951. }
  4952. if (pet_id == 0) {
  4953. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  4954. return 0;
  4955. }
  4956. if (!luaspell) {
  4957. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: valid spell not found, SummonCosmeticPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  4958. return 0;
  4959. }
  4960. if(luaspell->resisted) {
  4961. return 0;
  4962. }
  4963. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  4964. if (!pet) {
  4965. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: Could not find spawn with id of %u.", lua_interface->GetScriptName(state), pet_id);
  4966. return 0;
  4967. }
  4968. if (!pet->IsNPC()) {
  4969. lua_interface->LogError("%s: LUA SummonCosmeticPet command error: spawn with id of %u is not a npc", lua_interface->GetScriptName(state), pet_id);
  4970. return 0;
  4971. }
  4972. pet->SetX(spawn->GetX());
  4973. pet->SetY(spawn->GetY());
  4974. pet->SetZ(spawn->GetZ());
  4975. pet->SetLocation(spawn->GetLocation());
  4976. pet->SetHeading(spawn->GetHeading());
  4977. spawn->GetZone()->AddSpawn(pet);
  4978. string random_pet_name;
  4979. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  4980. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  4981. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  4982. pet->SetName(random_pet_name.c_str());
  4983. pet->SetLevel(spawn->GetLevel());
  4984. pet->SetFactionID(spawn->GetFactionID());
  4985. pet->SetPet(true);
  4986. ((NPC*)pet)->SetPetType(PET_TYPE_COSMETIC);
  4987. ((NPC*)pet)->SetOwner((Entity*)spawn);
  4988. ((Entity*)spawn)->SetCosmeticPet((Entity*)pet);
  4989. pet->SetSpawnType(6);
  4990. ((NPC*)pet)->SetBrain(new NonCombatPetBrain((NPC*)pet));
  4991. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  4992. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  4993. if (strlen(pet->GetSubTitle()) > 0) {
  4994. string pet_subtitle;
  4995. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  4996. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  4997. pet->SetSubTitle(pet_subtitle.c_str());
  4998. }
  4999. pet->SetAttackable(false);
  5000. pet->AddSecondaryEntityCommand("Pet Options", 10.0f, "petoptions", "", 0, 0);
  5001. lua_interface->SetSpawnValue(state, pet);
  5002. return 1;
  5003. }
  5004. int EQ2Emu_lua_DismissPet(lua_State* state) {
  5005. if (!lua_interface)
  5006. return 0;
  5007. Spawn* spawn = lua_interface->GetSpawn(state);
  5008. if (!spawn) {
  5009. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  5010. return 0;
  5011. }
  5012. if (!spawn->IsPet()) {
  5013. lua_interface->LogError("%s: LUA DismissPet command error: spawn is not a pet", lua_interface->GetScriptName(state));
  5014. return 0;
  5015. }
  5016. if (!((NPC*)spawn)->IsDismissing())
  5017. ((NPC*)spawn)->GetOwner()->DismissPet((NPC*)spawn, false, true);
  5018. return 0;
  5019. }
  5020. int EQ2Emu_lua_SetQuestFeatherColor(lua_State* state) {
  5021. if (!lua_interface)
  5022. return 0;
  5023. Quest* quest = lua_interface->GetQuest(state);
  5024. if (!quest) {
  5025. 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));
  5026. return 0;
  5027. }
  5028. int8 feather_color = lua_interface->GetInt8Value(state, 2);
  5029. if (feather_color > 0)
  5030. quest->SetFeatherColor(feather_color);
  5031. return 0;
  5032. }
  5033. int EQ2Emu_lua_RemoveSpawnAccess(lua_State* state) {
  5034. if (!lua_interface)
  5035. return 0;
  5036. Spawn* spawn = lua_interface->GetSpawn(state);
  5037. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  5038. if (!spawn) {
  5039. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: first spawn is not valid", lua_interface->GetScriptName(state));
  5040. return 0;
  5041. }
  5042. if (!spawn2) {
  5043. lua_interface->LogError("%s: LUA RemoveSpawnAccess command error: second spawn is not valid", lua_interface->GetScriptName(state));
  5044. return 0;
  5045. }
  5046. spawn->RemoveSpawnAccess(spawn2);
  5047. return 0;
  5048. }
  5049. int EQ2Emu_lua_SpawnByLocationID(lua_State* state) {
  5050. if (!lua_interface)
  5051. return 0;
  5052. ZoneServer* zone = lua_interface->GetZone(state);
  5053. int32 location_id = lua_interface->GetInt32Value(state, 2);
  5054. if (!zone) {
  5055. lua_interface->LogError("%s: LUA SpawnByLocationID command error: zone is not valid", lua_interface->GetScriptName(state));
  5056. return 0;
  5057. }
  5058. if (location_id == 0) {
  5059. lua_interface->LogError("%s: LUA SpawnByLocationID command error: location id can not be 0", lua_interface->GetScriptName(state));
  5060. return 0;
  5061. }
  5062. SpawnLocation* location = zone->GetSpawnLocation(location_id);
  5063. if (!location) {
  5064. lua_interface->LogError("%s: LUA SpawnByLocationID command error: no location found for the given ID (%u)", lua_interface->GetScriptName(state), location_id);
  5065. return 0;
  5066. }
  5067. Spawn* spawn = 0;
  5068. if (location->entities[0]) {
  5069. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  5070. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  5071. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  5072. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  5073. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  5074. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  5075. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  5076. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  5077. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  5078. spawn = zone->AddSignSpawn(location, location->entities[0]);
  5079. if(spawn && spawn->IsOmittedByDBFlag())
  5080. {
  5081. LogWrite(SPAWN__WARNING, 0, "Spawn", "Spawn (%u) was skipped due to a missing expansion / holiday flag being met.", location->entities[0]->spawn_id);
  5082. safe_delete(spawn);
  5083. spawn = 0;
  5084. return 0;
  5085. }
  5086. if (spawn) {
  5087. const char* script = 0;
  5088. for (int x = 0; x < 3; x++) {
  5089. switch (x) {
  5090. case 0:
  5091. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  5092. break;
  5093. case 1:
  5094. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  5095. break;
  5096. case 2:
  5097. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  5098. break;
  5099. }
  5100. if (script && lua_interface->GetSpawnScript(script) != 0) {
  5101. spawn->SetSpawnScript(string(script));
  5102. break;
  5103. }
  5104. }
  5105. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  5106. lua_interface->SetSpawnValue(state, spawn);
  5107. return 1;
  5108. }
  5109. else {
  5110. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by location id to zone %s with location id %u.", zone->GetZoneName(), location_id);
  5111. safe_delete(spawn);
  5112. }
  5113. }
  5114. return 0;
  5115. }
  5116. int EQ2Emu_lua_CastEntityCommand(lua_State* state) {
  5117. if (!lua_interface)
  5118. return 0;
  5119. Spawn* caster = lua_interface->GetSpawn(state);
  5120. Spawn* target = lua_interface->GetSpawn(state, 2);
  5121. int32 id = lua_interface->GetInt32Value(state, 3);
  5122. string command = lua_interface->GetStringValue(state, 4);
  5123. if (!caster) {
  5124. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not valid", lua_interface->GetScriptName(state));
  5125. return 0;
  5126. }
  5127. if (!target) {
  5128. lua_interface->LogError("%s: LUA CastEntityCommand command error: target is not valid", lua_interface->GetScriptName(state));
  5129. return 0;
  5130. }
  5131. if (!caster->IsPlayer()) {
  5132. lua_interface->LogError("%s: LUA CastEntityCommand command error: caster is not a player", lua_interface->GetScriptName(state));
  5133. return 0;
  5134. }
  5135. EntityCommand* entity_command = caster->GetZone()->GetEntityCommand(id, command);
  5136. if (!entity_command) {
  5137. 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());
  5138. return 0;
  5139. }
  5140. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  5141. if (!client) {
  5142. lua_interface->LogError("%s: LUA CastEntityCommand command error: unable to get a valid client for the given caster", lua_interface->GetScriptName(state));
  5143. return 0;
  5144. }
  5145. client->GetCurrentZone()->ProcessEntityCommand(entity_command, (Player*)caster, target);
  5146. return 0;
  5147. }
  5148. int EQ2Emu_lua_SetLuaBrain(lua_State* state) {
  5149. if (!lua_interface)
  5150. return 0;
  5151. Spawn* spawn = lua_interface->GetSpawn(state);
  5152. if (!spawn) {
  5153. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not valid", lua_interface->GetScriptName(state));
  5154. return 0;
  5155. }
  5156. if (!spawn->IsNPC()) {
  5157. lua_interface->LogError("%s: LUA SetLuaBrain command error: spawn is not a npc", lua_interface->GetScriptName(state));
  5158. return 0;
  5159. }
  5160. ((NPC*)spawn)->SetBrain(new LuaBrain((NPC*)spawn));
  5161. return 0;
  5162. }
  5163. int EQ2Emu_lua_SetBrainTick(lua_State* state) {
  5164. if (!lua_interface)
  5165. return 0;
  5166. Spawn* spawn = lua_interface->GetSpawn(state);
  5167. int16 tick = lua_interface->GetInt16Value(state, 2);
  5168. if (!spawn) {
  5169. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not valid", lua_interface->GetScriptName(state));
  5170. return 0;
  5171. }
  5172. if (!spawn->IsNPC()) {
  5173. lua_interface->LogError("%s: LUA SetBrainTick command error: spawn is not a valid npc", lua_interface->GetScriptName(state));
  5174. return 0;
  5175. }
  5176. if (tick < 20) {
  5177. lua_interface->LogError("%s: LUA SetBrainTick command error: tick can not be set below 20 milliseconds", lua_interface->GetScriptName(state));
  5178. return 0;
  5179. }
  5180. ((NPC*)spawn)->Brain()->SetTick(tick);
  5181. return 0;
  5182. }
  5183. int EQ2Emu_lua_SetFollowTarget(lua_State* state) {
  5184. if (!lua_interface)
  5185. return 0;
  5186. Spawn* spawn = lua_interface->GetSpawn(state);
  5187. Spawn* target = lua_interface->GetSpawn(state, 2);
  5188. int32 follow_distance = lua_interface->GetInt32Value(state, 3);
  5189. if (!spawn) {
  5190. lua_interface->LogError("%s: LUA SetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5191. return 0;
  5192. }
  5193. // Target can be null, setting follow target to 0 clears it and will cancel follow, so no need to check it
  5194. spawn->SetFollowTarget(target, follow_distance);
  5195. return 0;
  5196. }
  5197. int EQ2Emu_lua_GetFollowTarget(lua_State* state) {
  5198. if (!lua_interface)
  5199. return 0;
  5200. Spawn* spawn = lua_interface->GetSpawn(state);
  5201. if (!spawn) {
  5202. lua_interface->LogError("%s: LUA GetFollowTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  5203. return 0;
  5204. }
  5205. Spawn* target = spawn->GetFollowTarget();
  5206. if (target) {
  5207. lua_interface->SetSpawnValue(state, target);
  5208. return 1;
  5209. }
  5210. return 0;
  5211. }
  5212. int EQ2Emu_lua_ToggleFollow(lua_State* state) {
  5213. if (!lua_interface)
  5214. return 0;
  5215. Spawn* spawn = lua_interface->GetSpawn(state);
  5216. if (!spawn) {
  5217. lua_interface->LogError("%s: LUA ToggleFollow command error: spawn is not valid", lua_interface->GetScriptName(state));
  5218. return 0;
  5219. }
  5220. if (spawn->following)
  5221. spawn->following = false;
  5222. else
  5223. spawn->following = true;
  5224. return 0;
  5225. }
  5226. int EQ2Emu_lua_IsFollowing(lua_State* state) {
  5227. if (!lua_interface)
  5228. return 0;
  5229. Spawn* spawn = lua_interface->GetSpawn(state);
  5230. if (!spawn) {
  5231. lua_interface->LogError("%s: LUA IsFollowing command error: spawn is not valid", lua_interface->GetScriptName(state));
  5232. return 0;
  5233. }
  5234. lua_interface->SetBooleanValue(state, spawn->following);
  5235. return 1;
  5236. }
  5237. int EQ2Emu_lua_SetTempVariable(lua_State* state) {
  5238. // As this is unique among the rest of our lua functions as the 3rd param can be of multiple types
  5239. // I will attempt to explain how this function works for future refrence
  5240. // Fist lets make sure lua_interface is valid, if not return out
  5241. if (!lua_interface)
  5242. return 0;
  5243. // Next we grab the first 2 params same as we usually would
  5244. Spawn* spawn = lua_interface->GetSpawn(state);
  5245. string var = lua_interface->GetStringValue(state, 2);
  5246. // 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
  5247. // 1 = Spawn
  5248. // 2 = Zone
  5249. // 3 = Item
  5250. // 4 = Quest
  5251. // 5 = String
  5252. // 6 = nil (null)
  5253. int8 dataType = 0;
  5254. // Define pointers for each potential type
  5255. Spawn* spawnVal = 0;
  5256. ZoneServer* zone = 0;
  5257. Item* item = 0;
  5258. Quest* quest = 0;
  5259. string val;
  5260. // Finally we get to grabbing the third param, we will first check to see if it is light user data
  5261. // which is custom data types, in this case it can be Spawn, Zone, Item, or Quest. Conversation and
  5262. // options window are also light user data be we do not handle those.
  5263. // We check with lua_islightuserdata(lua_State*, index)
  5264. if (lua_islightuserdata(state, 3)) {
  5265. // It is light user data so we will grab the param with lua_touserdata(lua_State*, index)
  5266. // and convert it to LUAUserData*
  5267. LUAUserData* data = (LUAUserData*)lua_touserdata(state, 3);
  5268. // Check to make sure the data we got is valid, if not give an error
  5269. if (!data || !data->IsCorrectlyInitialized()) {
  5270. lua_interface->LogError("%s: LUA SetTempVariable command error while processing %s", lua_interface->GetScriptName(state), lua_tostring(state, -1));
  5271. }
  5272. // Check if data is a Spawn, if so set our Spawn pointer and the dataType variable
  5273. else if (data->IsSpawn()) {
  5274. spawnVal = data->spawn;
  5275. dataType = 1;
  5276. }
  5277. // Check if data is a Zone, if so set our Zone pointer and the dataType variable
  5278. else if (data->IsZone()) {
  5279. zone = data->zone;
  5280. dataType = 2;
  5281. }
  5282. // Check if data is a Item, if so set our Item pointer and the dataType variable
  5283. else if (data->IsItem()) {
  5284. item = data->item;
  5285. dataType = 3;
  5286. }
  5287. // Check if data is a Ques, if so set our Quest pointer and the dataType variable
  5288. else if (data->IsQuest()) {
  5289. quest = data->quest;
  5290. dataType = 4;
  5291. }
  5292. }
  5293. // Wasn't light user data, check if it is nil(null)
  5294. else if (lua_isnil(state, 3)) {
  5295. // It is nil (null) set the dataType variable, no need to set a pointer in this case
  5296. dataType = 6;
  5297. }
  5298. // Wasn't light user data or nil (null), must be a string
  5299. else {
  5300. // Set the string and dataType variable
  5301. val = lua_interface->GetStringValue(state, 3);
  5302. dataType = 5;
  5303. }
  5304. // We now have all the params, lets check to make sure they are valid
  5305. if (!spawn) {
  5306. lua_interface->LogError("%s: LUA SetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5307. return 0;
  5308. }
  5309. if (var.length() == 0) {
  5310. lua_interface->LogError("%s: LUA SetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5311. return 0;
  5312. }
  5313. if (dataType == 0) {
  5314. lua_interface->LogError("%s: LUA SetTempVariable command error: unknown data type", lua_interface->GetScriptName(state));
  5315. return 0;
  5316. }
  5317. // All params are valid, lets set the spawns temp variable, this is where dataType variable comes in.
  5318. // AddTempVariable has overloads for all the types of data we support, we need to make sure the third
  5319. // param gets sent to the correct list so we check the value of dataType to know where it should go.
  5320. switch (dataType) {
  5321. case 1:
  5322. // 1 = Spawn
  5323. spawn->AddTempVariable(var, spawnVal);
  5324. break;
  5325. case 2:
  5326. // 2 = Zone
  5327. spawn->AddTempVariable(var, zone);
  5328. break;
  5329. case 3:
  5330. // 3 = Item
  5331. spawn->AddTempVariable(var, item);
  5332. break;
  5333. case 4:
  5334. // 4 = Quest
  5335. spawn->AddTempVariable(var, quest);
  5336. break;
  5337. case 5:
  5338. // 5 = String
  5339. spawn->AddTempVariable(var, val);
  5340. break;
  5341. case 6:
  5342. // 6 = nil (null) so the variable is no longer set, lets remove it from the spawn
  5343. spawn->DeleteTempVariable(var);
  5344. break;
  5345. }
  5346. // And we are done so return out
  5347. return 0;
  5348. }
  5349. int EQ2Emu_lua_GetTempVariable(lua_State* state) {
  5350. if (!lua_interface)
  5351. return 0;
  5352. Spawn* spawn = lua_interface->GetSpawn(state);
  5353. string var = lua_interface->GetStringValue(state, 2);
  5354. if (!spawn) {
  5355. lua_interface->LogError("%s: LUA GetTempVariable command error: spawn is not valid", lua_interface->GetScriptName(state));
  5356. return 0;
  5357. }
  5358. if (var.length() == 0) {
  5359. lua_interface->LogError("%s: LUA GetTempVariable command error: var must be set", lua_interface->GetScriptName(state));
  5360. return 0;
  5361. }
  5362. // This will tell us the type of data this variable contains, uses the same values as the previous function
  5363. int8 type = spawn->GetTempVariableType(var);
  5364. Spawn* spawn2 = 0;
  5365. ZoneServer* zone = 0;
  5366. Item* item = 0;
  5367. Quest* quest = 0;
  5368. // Set the lua function return value based on the type of data the variable contains
  5369. switch (type) {
  5370. case 1:
  5371. spawn2 = spawn->GetTempVariableSpawn(var);
  5372. if (!spawn2)
  5373. return 0;
  5374. lua_interface->SetSpawnValue(state, spawn2);
  5375. break;
  5376. case 2:
  5377. zone = spawn->GetTempVariableZone(var);
  5378. if (!zone)
  5379. return 0;
  5380. lua_interface->SetZoneValue(state, zone);
  5381. break;
  5382. case 3:
  5383. item = spawn->GetTempVariableItem(var);
  5384. if (!item)
  5385. return 0;
  5386. lua_interface->SetItemValue(state, item);
  5387. break;
  5388. case 4:
  5389. quest = spawn->GetTempVariableQuest(var);
  5390. if (!quest)
  5391. return 0;
  5392. lua_interface->SetQuestValue(state, quest);
  5393. break;
  5394. case 5:
  5395. lua_interface->SetStringValue(state, spawn->GetTempVariable(var).c_str());
  5396. break;
  5397. default:
  5398. // Not a valid type then the variable was not set so return out
  5399. return 0;
  5400. }
  5401. // Return value was set so return out
  5402. return 1;
  5403. }
  5404. int EQ2Emu_lua_GiveQuestItem(lua_State* state)
  5405. {
  5406. if (!lua_interface)
  5407. return 0;
  5408. Quest* quest = lua_interface->GetQuest(state);
  5409. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5410. string description = lua_interface->GetStringValue(state, 3);
  5411. int32 item_id = lua_interface->GetInt32Value(state, 4);
  5412. if (!quest) {
  5413. lua_interface->LogError("%s: LUA GiveQuestItem command error: quest is not valid", lua_interface->GetScriptName(state));
  5414. lua_interface->SetBooleanValue(state, false);
  5415. return 1;
  5416. }
  5417. if (!spawn) {
  5418. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5419. lua_interface->SetBooleanValue(state, false);
  5420. return 1;
  5421. }
  5422. if (!spawn->IsPlayer()) {
  5423. lua_interface->LogError("%s: LUA GiveQuestItem command error: spawn must be a player", lua_interface->GetScriptName(state));
  5424. lua_interface->SetBooleanValue(state, false);
  5425. return 1;
  5426. }
  5427. if (item_id == 0) {
  5428. lua_interface->LogError("%s: LUA GiveQuestItem command error: item_id is not valid", lua_interface->GetScriptName(state));
  5429. lua_interface->SetBooleanValue(state, false);
  5430. return 1;
  5431. }
  5432. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  5433. if (!client) {
  5434. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get a valid client from the given spawn", lua_interface->GetScriptName(state));
  5435. lua_interface->SetBooleanValue(state, false);
  5436. return 1;
  5437. }
  5438. Item* item = master_item_list.GetItem(item_id);
  5439. if (!item) {
  5440. lua_interface->LogError("%s: LUA GiveQuestItem command error: unable to get an item from the given id (%u)", lua_interface->GetScriptName(state), item_id);
  5441. lua_interface->SetBooleanValue(state, false);
  5442. return 1;
  5443. }
  5444. Item* firstItem = new Item(item);
  5445. quest->AddTmpRewardItem(firstItem);
  5446. int8 num_args = (int8)lua_interface->GetNumberOfArgs(state);
  5447. bool itemsAddedSuccessfully = true;
  5448. if(num_args > 4)
  5449. {
  5450. for(int8 n=5;n<num_args+1;n++)
  5451. {
  5452. int32 new_item = lua_interface->GetInt32Value(state, n);
  5453. Item* tmpItem = master_item_list.GetItem(new_item);
  5454. if(tmpItem)
  5455. {
  5456. Item* newTmpItem = new Item(tmpItem);
  5457. quest->AddTmpRewardItem(newTmpItem);
  5458. }
  5459. else
  5460. itemsAddedSuccessfully = false;
  5461. }
  5462. }
  5463. client->AddPendingQuestAcceptReward(quest);
  5464. client->DisplayQuestComplete(quest, true, description);
  5465. lua_interface->SetBooleanValue(state, itemsAddedSuccessfully);
  5466. return 1;
  5467. }
  5468. int EQ2Emu_lua_SetQuestRepeatable(lua_State* state) {
  5469. if (!lua_interface)
  5470. return 0;
  5471. Quest* quest = lua_interface->GetQuest(state);
  5472. if (!quest) {
  5473. lua_interface->LogError("%s: LUA SetQuestRepeatable command error: quest is not valid", lua_interface->GetScriptName(state));
  5474. return 0;
  5475. }
  5476. quest->SetRepeatable(true);
  5477. return 0;
  5478. }
  5479. int EQ2Emu_lua_GetArchetypeName(lua_State* state) {
  5480. if (!lua_interface)
  5481. return 0;
  5482. Spawn* spawn = lua_interface->GetSpawn(state);
  5483. if (!spawn) {
  5484. lua_interface->LogError("%s: LUA GetArchetypeName command error: spawn is not valid", lua_interface->GetScriptName(state));
  5485. return 0;
  5486. }
  5487. int8 base_class = classes.GetBaseClass(spawn->GetAdventureClass());
  5488. string ret = classes.GetClassNameCase(base_class);
  5489. if (ret.length() > 0) {
  5490. lua_interface->SetStringValue(state, ret.c_str());
  5491. return 1;
  5492. }
  5493. return 0;
  5494. }
  5495. int EQ2Emu_lua_SendWaypoints(lua_State* state) {
  5496. if (!lua_interface)
  5497. return 0;
  5498. Spawn* player = lua_interface->GetSpawn(state);
  5499. if (player && player->IsPlayer()) {
  5500. Client* client = player->GetClient();
  5501. if (client)
  5502. client->SendWaypoints();
  5503. }
  5504. return 0;
  5505. }
  5506. int EQ2Emu_lua_AddWaypoint(lua_State* state) {
  5507. if (!lua_interface)
  5508. return 0;
  5509. Spawn* player = lua_interface->GetSpawn(state);
  5510. string name = lua_interface->GetStringValue(state, 2);
  5511. int32 type = lua_interface->GetInt32Value(state, 3);
  5512. if (type == 0)
  5513. type = 2;
  5514. if (name.length() > 0) {
  5515. if (player && player->IsPlayer()) {
  5516. Client* client = player->GetClient();
  5517. if (client)
  5518. client->AddWaypoint(name, type);
  5519. }
  5520. }
  5521. return 0;
  5522. }
  5523. int EQ2Emu_lua_RemoveWaypoint(lua_State* state) {
  5524. if (!lua_interface)
  5525. return 0;
  5526. Spawn* player = lua_interface->GetSpawn(state);
  5527. string name = lua_interface->GetStringValue(state, 2);
  5528. if (name.length() > 0) {
  5529. if (player && player->IsPlayer()) {
  5530. Client* client = player->GetClient();
  5531. if (client)
  5532. client->RemoveWaypoint(name);
  5533. }
  5534. }
  5535. return 0;
  5536. }
  5537. int EQ2Emu_lua_AddWard(lua_State* state) {
  5538. if (!lua_interface)
  5539. return 0;
  5540. int32 damage = lua_interface->GetInt32Value(state);
  5541. bool keepWard = (lua_interface->GetInt8Value(state, 2) == 1);
  5542. int8 wardType = lua_interface->GetInt8Value(state, 3);
  5543. int8 damageTypes = lua_interface->GetInt8Value(state, 4);
  5544. int32 damageAbsorptionPercent = lua_interface->GetInt32Value(state, 5);
  5545. int32 damageAbsorptionMaxHealthPercent = lua_interface->GetInt32Value(state, 6);
  5546. int32 redirectDamagePercent = lua_interface->GetInt32Value(state, 7);
  5547. int32 maxHitCount = lua_interface->GetInt32Value(state, 8);
  5548. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5549. if(!spell || spell->resisted) {
  5550. return 0;
  5551. }
  5552. bool ward_was_added = false;
  5553. ZoneServer* zone = spell->caster->GetZone();
  5554. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5555. for (int32 i = 0; i < spell->targets.size(); i++) {
  5556. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  5557. if (!target)
  5558. continue;
  5559. if (target->IsEntity()) {
  5560. // If the ward is already active remove it
  5561. if (((Entity*)target)->GetWard(spell->spell->GetSpellID()))
  5562. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5563. // Create new ward info
  5564. WardInfo* ward = new WardInfo;
  5565. ward->Spell = spell;
  5566. ward->BaseDamage = damage;
  5567. ward->DamageLeft = damage;
  5568. ward->AbsorbAllDamage = (damage == 0) ? true : false;
  5569. ward->keepWard = keepWard;
  5570. ward->WardType = wardType;
  5571. if (damageAbsorptionPercent > 100)
  5572. damageAbsorptionPercent = 100;
  5573. ward->DamageAbsorptionPercentage = damageAbsorptionPercent;
  5574. if (damageAbsorptionMaxHealthPercent > 100)
  5575. damageAbsorptionMaxHealthPercent = 100;
  5576. ward->DamageAbsorptionMaxHealthPercent = damageAbsorptionMaxHealthPercent;
  5577. ward->RedirectDamagePercent = redirectDamagePercent;
  5578. ward->LastRedirectDamage = 0;
  5579. ward->LastAbsorbedDamage = 0;
  5580. ward->HitCount = 0;
  5581. spell->num_triggers = maxHitCount;
  5582. spell->had_triggers = true;
  5583. spell->cancel_after_all_triggers = false;
  5584. ward->MaxHitCount = maxHitCount;
  5585. if (wardType == WARD_TYPE_MAGICAL)
  5586. ward->DamageType = damageTypes;
  5587. // Add the ward to the entity
  5588. ((Entity*)target)->AddWard(spell->spell->GetSpellID(), ward);
  5589. ward_was_added = true;
  5590. }
  5591. }
  5592. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5593. if (ward_was_added && spell->caster->IsPlayer()) {
  5594. spell->had_dmg_remaining = true;
  5595. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, damage, 1);
  5596. }
  5597. return 0;
  5598. }
  5599. int EQ2Emu_lua_AddToWard(lua_State* state) {
  5600. if (!lua_interface)
  5601. return 0;
  5602. int32 amount = lua_interface->GetInt32Value(state);
  5603. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5604. WardInfo* ward = 0;
  5605. if(!spell || spell->resisted) {
  5606. return 0;
  5607. }
  5608. ZoneServer* zone = spell->caster->GetZone();
  5609. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5610. if (zone->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5611. Entity* target = (Entity*)zone->GetSpawnByID(spell->targets.at(0));
  5612. ward = target->GetWard(spell->spell->GetSpellID());
  5613. if (target && ward) {
  5614. ward->DamageLeft += amount;
  5615. if (ward->DamageLeft > ward->BaseDamage)
  5616. ward->DamageLeft = ward->BaseDamage;
  5617. for (int32 i = 0; i < spell->targets.size(); i++) {
  5618. if (Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i)))
  5619. zone->SendHealPacket(ward->Spell->caster, spawn, HEAL_PACKET_TYPE_REGEN_ABSORB, amount, ward->Spell->spell->GetName());
  5620. }
  5621. }
  5622. }
  5623. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5624. if (ward && spell->caster->IsPlayer())
  5625. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, ward->DamageLeft, 1);
  5626. return 0;
  5627. }
  5628. int EQ2Emu_lua_GetWardAmountLeft(lua_State* state) {
  5629. if (!lua_interface)
  5630. return 0;
  5631. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5632. if (!spell) {
  5633. lua_interface->LogError("%s: LUA GetWardAmountLeft command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5634. return 0;
  5635. }
  5636. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5637. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5638. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5639. if (ward) {
  5640. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5641. return 1;
  5642. }
  5643. }
  5644. return 0;
  5645. }
  5646. int EQ2Emu_lua_GetWardValue(lua_State* state) {
  5647. if (!lua_interface)
  5648. return 0;
  5649. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5650. if (!spell) {
  5651. lua_interface->LogError("%s: LUA GetWardValue command error: this command can only be used in a spell script", lua_interface->GetScriptName(state));
  5652. return 0;
  5653. }
  5654. string type = lua_interface->GetStringValue(state, 2);
  5655. if (spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0))->IsEntity()) {
  5656. Entity* target = (Entity*)spell->caster->GetZone()->GetSpawnByID(spell->targets.at(0));
  5657. WardInfo* ward = target->GetWard(spell->spell->GetSpellID());
  5658. if (ward) {
  5659. if (boost::iequals(type, "damageleft"))
  5660. lua_interface->SetInt32Value(state, ward->DamageLeft);
  5661. else if (boost::iequals(type, "basedamage"))
  5662. lua_interface->SetInt32Value(state, ward->BaseDamage);
  5663. else if (boost::iequals(type, "keepward"))
  5664. lua_interface->SetBooleanValue(state, ward->keepWard);
  5665. else if (boost::iequals(type, "wardtype"))
  5666. lua_interface->SetInt32Value(state, ward->WardType);
  5667. else if (boost::iequals(type, "dmgabsorptionpct"))
  5668. lua_interface->SetInt32Value(state, ward->DamageAbsorptionPercentage);
  5669. else if (boost::iequals(type, "dmgabsorptionmaxhealthpct"))
  5670. lua_interface->SetInt32Value(state, ward->DamageAbsorptionMaxHealthPercent);
  5671. else if (boost::iequals(type, "redirectdamagepercent"))
  5672. lua_interface->SetInt32Value(state, ward->RedirectDamagePercent);
  5673. else if (boost::iequals(type, "lastredirectdamage"))
  5674. lua_interface->SetInt32Value(state, ward->LastRedirectDamage);
  5675. else if (boost::iequals(type, "lastabsorbeddamage"))
  5676. lua_interface->SetInt32Value(state, ward->LastAbsorbedDamage);
  5677. else if (boost::iequals(type, "hitcount"))
  5678. lua_interface->SetInt32Value(state, ward->HitCount);
  5679. else if (boost::iequals(type, "maxhitcount"))
  5680. lua_interface->SetInt32Value(state, ward->MaxHitCount);
  5681. else
  5682. lua_interface->LogError("%s: LUA GetWardValue command argument type '%s' did not match any options", lua_interface->GetScriptName(state), type);
  5683. return 1;
  5684. }
  5685. }
  5686. return 0;
  5687. }
  5688. int EQ2Emu_lua_RemoveWard(lua_State* state) {
  5689. if (!lua_interface)
  5690. return 0;
  5691. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5692. if(!spell) {
  5693. return 0;
  5694. }
  5695. ZoneServer* zone = spell->caster->GetZone();
  5696. Spawn* target = 0;
  5697. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5698. for (int32 i = 0; i < spell->targets.size(); i++) {
  5699. target = zone->GetSpawnByID(spell->targets.at(i));
  5700. if (target && target->IsEntity()) {
  5701. ((Entity*)target)->RemoveWard(spell->spell->GetSpellID());
  5702. }
  5703. }
  5704. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5705. return 0;
  5706. }
  5707. int EQ2Emu_lua_Interrupt(lua_State* state)
  5708. {
  5709. if (!lua_interface)
  5710. return 0;
  5711. Spawn* caster = lua_interface->GetSpawn(state); // Second param in lua_interface->get functions defaults to 1
  5712. Spawn* target = lua_interface->GetSpawn(state, 2);
  5713. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5714. if (!caster)
  5715. {
  5716. lua_interface->LogError("%s: LUA Interrupt command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  5717. return 0;
  5718. }
  5719. if (!target)
  5720. {
  5721. lua_interface->LogError("%s: LUA Interrupt command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  5722. return 0;
  5723. }
  5724. if (!spell) {
  5725. lua_interface->LogError("%s: LUA Interrupt command error: spell is not a valid spawn", lua_interface->GetScriptName(state));
  5726. return 0;
  5727. }
  5728. if (!target->IsEntity() && !spell)
  5729. {
  5730. lua_interface->LogError("%s: LUA Interrupt command error: Target is not an entity", lua_interface->GetScriptName(state));
  5731. return 0;
  5732. }
  5733. if (!target && spell) {
  5734. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5735. for (int8 i = 0; i < spell->targets.size(); i++) {
  5736. target = caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  5737. if (!target || !target->IsEntity())
  5738. continue;
  5739. ((Entity*)target)->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5740. }
  5741. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5742. }
  5743. else
  5744. caster->GetZone()->GetSpellProcess()->Interrupted((Entity*)target, caster, SPELL_ERROR_INTERRUPTED);
  5745. return 0;
  5746. }
  5747. int EQ2Emu_lua_Stealth(lua_State* state) {
  5748. if (!lua_interface)
  5749. return 0;
  5750. int8 type = lua_interface->GetInt8Value(state);
  5751. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  5752. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  5753. if (!spell) {
  5754. lua_interface->LogError("%s: LUA Stealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  5755. return 0;
  5756. }
  5757. ZoneServer* zone = spell->caster->GetZone();
  5758. if (spawn) {
  5759. if (spawn->IsEntity()) {
  5760. if (type == 1) {
  5761. ((Entity*)spawn)->AddStealthSpell(spell);
  5762. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5763. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5764. }
  5765. else if (type == 2) {
  5766. ((Entity*)spawn)->AddInvisSpell(spell);
  5767. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5768. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5769. }
  5770. return 0;
  5771. }
  5772. else {
  5773. lua_interface->LogError("%s: LUA Stealth command error: target override is not Entity", lua_interface->GetScriptName(state));
  5774. return 0;
  5775. }
  5776. }
  5777. else {
  5778. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  5779. for (int32 i = 0; i < spell->targets.size(); i++) {
  5780. spawn = zone->GetSpawnByID(spell->targets.at(i));
  5781. if (!spawn || !spawn->IsEntity())
  5782. continue;
  5783. if (type == 1) {
  5784. ((Entity*)spawn)->AddStealthSpell(spell);
  5785. if (!(spell->effect_bitmask & EFFECT_FLAG_STEALTH))
  5786. spell->effect_bitmask += EFFECT_FLAG_STEALTH;
  5787. }
  5788. else if (type == 2) {
  5789. ((Entity*)spawn)->AddInvisSpell(spell);
  5790. if (!(spell->effect_bitmask & EFFECT_FLAG_INVIS))
  5791. spell->effect_bitmask += EFFECT_FLAG_INVIS;
  5792. }
  5793. else {
  5794. lua_interface->LogError("%s: LUA Stealth command error: invalid stealth type given", lua_interface->GetScriptName(state));
  5795. break;
  5796. }
  5797. }
  5798. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  5799. }
  5800. return 0;
  5801. }
  5802. int EQ2Emu_lua_IsStealthed(lua_State* state) {
  5803. if (!lua_interface)
  5804. return 0;
  5805. Spawn* spawn = lua_interface->GetSpawn(state);
  5806. if (!spawn) {
  5807. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not valid", lua_interface->GetScriptName(state));
  5808. return 0;
  5809. }
  5810. if (spawn->IsEntity()) {
  5811. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStealthed());
  5812. return 1;
  5813. }
  5814. else
  5815. lua_interface->LogError("%s: LUA IsStealthed command error: spawn is not entity", lua_interface->GetScriptName(state));
  5816. return 0;
  5817. }
  5818. int EQ2Emu_lua_IsInvis(lua_State* state) {
  5819. if (!lua_interface)
  5820. return 0;
  5821. Spawn* spawn = lua_interface->GetSpawn(state);
  5822. if (!spawn) {
  5823. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not valid", lua_interface->GetScriptName(state));
  5824. return 0;
  5825. }
  5826. if (spawn->IsEntity()) {
  5827. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsInvis());
  5828. return 1;
  5829. }
  5830. else
  5831. lua_interface->LogError("%s: LUA IsInvis command error: spawn is not entity", lua_interface->GetScriptName(state));
  5832. return 0;
  5833. }
  5834. int EQ2Emu_lua_HasItemEquipped(lua_State* state) {
  5835. if (!lua_interface)
  5836. return 0;
  5837. Spawn* player = lua_interface->GetSpawn(state);
  5838. int32 item_id = lua_interface->GetInt32Value(state, 2);
  5839. lua_interface->ResetFunctionStack(state);
  5840. if (!player->IsPlayer()) {
  5841. lua_interface->LogError("%s: LUA HasItemEquipped command error: spawn is not player", lua_interface->GetScriptName(state));
  5842. return 0;
  5843. }
  5844. lua_interface->SetBooleanValue(state, ((Player*)player)->GetEquipmentList()->HasItem(item_id));
  5845. return 1;
  5846. }
  5847. int EQ2Emu_lua_GetEquippedItemBySlot(lua_State* state) {
  5848. if (!lua_interface)
  5849. return 0;
  5850. Spawn* player = lua_interface->GetSpawn(state);
  5851. int8 slot = lua_interface->GetInt8Value(state, 2);
  5852. lua_interface->ResetFunctionStack(state);
  5853. if (!player) {
  5854. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5855. return 0;
  5856. }
  5857. if (!player->IsPlayer()) {
  5858. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: spawn is not player", lua_interface->GetScriptName(state));
  5859. return 0;
  5860. }
  5861. Item* item = ((Player*)player)->GetEquipmentList()->GetItem(slot);
  5862. if (!item) {
  5863. lua_interface->LogError("%s: LUA GetEquippedItemBySlot command error: item was not found in slot", lua_interface->GetScriptName(state));
  5864. return 0;
  5865. }
  5866. lua_interface->SetItemValue(state, item);
  5867. return 1;
  5868. }
  5869. int EQ2Emu_lua_GetEquippedItemByID(lua_State* state) {
  5870. if (!lua_interface)
  5871. return 0;
  5872. Spawn* player = lua_interface->GetSpawn(state);
  5873. int32 id = lua_interface->GetInt32Value(state, 2);
  5874. lua_interface->ResetFunctionStack(state);
  5875. if (!player) {
  5876. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5877. return 0;
  5878. }
  5879. if (!player->IsPlayer()) {
  5880. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  5881. return 0;
  5882. }
  5883. Item* item = ((Player*)player)->GetEquipmentList()->GetItemFromItemID(id);
  5884. if (!item) {
  5885. lua_interface->LogError("%s: LUA GetEquippedItemByID command error: equipped item with used id not found", lua_interface->GetScriptName(state));
  5886. return 0;
  5887. }
  5888. lua_interface->SetItemValue(state, item);
  5889. return 1;
  5890. }
  5891. int EQ2Emu_lua_SetEquippedItemByID(lua_State* state) {
  5892. if (!lua_interface)
  5893. return 0;
  5894. Spawn* spawn = lua_interface->GetSpawn(state);
  5895. int8 slot = lua_interface->GetInt8Value(state, 2);
  5896. int32 item_id = lua_interface->GetInt32Value(state, 3);
  5897. lua_interface->ResetFunctionStack(state);
  5898. if (!spawn) {
  5899. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  5900. return 0;
  5901. }
  5902. if (!spawn->IsEntity()) {
  5903. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5904. return 0;
  5905. }
  5906. Item* item = master_item_list.GetItem(item_id);
  5907. if (!item) {
  5908. lua_interface->LogError("%s: LUA SetEquippedItemByID command error: equipped item with used id %u not found", item_id, lua_interface->GetScriptName(state));
  5909. return 0;
  5910. }
  5911. Item* copy = new Item(item);
  5912. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, copy);
  5913. if(result)
  5914. {
  5915. ((Entity*)spawn)->SetEquipment(copy, slot);
  5916. spawn->vis_changed = true;
  5917. if(spawn->IsPlayer())
  5918. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5919. }
  5920. else
  5921. {
  5922. safe_delete(copy);
  5923. }
  5924. lua_interface->SetBooleanValue(state, result);
  5925. return 1;
  5926. }
  5927. int EQ2Emu_lua_SetEquippedItem(lua_State* state) {
  5928. if (!lua_interface)
  5929. return 0;
  5930. Spawn* spawn = lua_interface->GetSpawn(state);
  5931. int8 slot = lua_interface->GetInt8Value(state, 2);
  5932. Item* item = lua_interface->GetItem(state, 3);
  5933. lua_interface->ResetFunctionStack(state);
  5934. if (!spawn) {
  5935. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not valid", lua_interface->GetScriptName(state));
  5936. return 0;
  5937. }
  5938. if (!spawn->IsEntity()) {
  5939. lua_interface->LogError("%s: LUA SetEquippedItem command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5940. return 0;
  5941. }
  5942. if (!item) {
  5943. lua_interface->LogError("%s: LUA SetEquippedItem command error: passed item not found", lua_interface->GetScriptName(state));
  5944. return 0;
  5945. }
  5946. bool result = ((Entity*)spawn)->GetEquipmentList()->AddItem(slot, item);
  5947. if(result)
  5948. {
  5949. ((Entity*)spawn)->SetEquipment(item, slot);
  5950. spawn->vis_changed = true;
  5951. if(spawn->IsPlayer())
  5952. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5953. }
  5954. lua_interface->SetBooleanValue(state, result);
  5955. return 1;
  5956. }
  5957. int EQ2Emu_lua_UnequipSlot(lua_State* state) {
  5958. if (!lua_interface)
  5959. return 0;
  5960. Spawn* spawn = lua_interface->GetSpawn(state);
  5961. int8 slot = lua_interface->GetInt8Value(state, 2);
  5962. 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
  5963. lua_interface->ResetFunctionStack(state);
  5964. if (!spawn) {
  5965. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not valid", lua_interface->GetScriptName(state));
  5966. return 0;
  5967. }
  5968. if (!spawn->IsEntity()) {
  5969. lua_interface->LogError("%s: LUA UnequipSlot command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5970. return 0;
  5971. }
  5972. ((Entity*)spawn)->GetEquipmentList()->RemoveItem(slot, no_delete_item);
  5973. ((Entity*)spawn)->SetEquipment(nullptr, slot);
  5974. spawn->vis_changed = true;
  5975. if(spawn->IsPlayer())
  5976. ((Player*)spawn)->GetClient()->SendEquipOrInvUpdateBySlot(slot);
  5977. lua_interface->SetBooleanValue(state, true);
  5978. return 1;
  5979. }
  5980. int EQ2Emu_lua_SetEquipment(lua_State* state) {
  5981. if (!lua_interface)
  5982. return 0;
  5983. Spawn* spawn = lua_interface->GetSpawn(state);
  5984. int8 slot = lua_interface->GetInt8Value(state, 2);
  5985. int16 type = lua_interface->GetInt16Value(state, 3);
  5986. int8 r = lua_interface->GetInt8Value(state, 4);
  5987. int8 g = lua_interface->GetInt8Value(state, 5);
  5988. int8 b = lua_interface->GetInt8Value(state, 6);
  5989. int8 h_r = lua_interface->GetInt8Value(state, 7);
  5990. int8 h_g = lua_interface->GetInt8Value(state, 8);
  5991. int8 h_b = lua_interface->GetInt8Value(state, 9);
  5992. lua_interface->ResetFunctionStack(state);
  5993. if (!spawn) {
  5994. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not valid", lua_interface->GetScriptName(state));
  5995. return 0;
  5996. }
  5997. if (!spawn->IsEntity()) {
  5998. lua_interface->LogError("%s: LUA SetEquipment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  5999. return 0;
  6000. }
  6001. ((Entity*)spawn)->SetEquipment(slot, type, r, g, b, h_r, h_g, h_b);
  6002. spawn->vis_changed = true;
  6003. lua_interface->SetBooleanValue(state, true);
  6004. return 1;
  6005. }
  6006. int EQ2Emu_lua_GetItemByID(lua_State* state) {
  6007. if (!lua_interface)
  6008. return 0;
  6009. Spawn* player = lua_interface->GetSpawn(state);
  6010. int32 id = lua_interface->GetInt32Value(state, 2);
  6011. int8 count = lua_interface->GetInt8Value(state, 3);
  6012. bool include_bank = lua_interface->GetInt8Value(state, 4);
  6013. lua_interface->ResetFunctionStack(state);
  6014. if (!player) {
  6015. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not valid", lua_interface->GetScriptName(state));
  6016. return 0;
  6017. }
  6018. if (!player->IsPlayer()) {
  6019. lua_interface->LogError("%s: LUA GetItemByID command error: spawn is not player", lua_interface->GetScriptName(state));
  6020. return 0;
  6021. }
  6022. if (!count)
  6023. count = 1;
  6024. Item* item = ((Player*)player)->GetPlayerItemList()->GetItemFromID(id, count, include_bank);
  6025. if (!item) {
  6026. lua_interface->LogError("%s: LUA GetItemByID command error: item with used id not found", lua_interface->GetScriptName(state));
  6027. return 0;
  6028. }
  6029. lua_interface->SetItemValue(state, item);
  6030. return 1;
  6031. }
  6032. int EQ2Emu_lua_PlayAnimation(lua_State* state) {
  6033. if (!lua_interface)
  6034. return 0;
  6035. Spawn* spawn = lua_interface->GetSpawn(state);
  6036. int32 anim = lua_interface->GetInt32Value(state, 2);
  6037. Spawn* spawn2 = lua_interface->GetSpawn(state, 3);
  6038. int8 type = lua_interface->GetInt8Value(state, 4);
  6039. if (!spawn) {
  6040. lua_interface->LogError("%s: LUA PlayAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  6041. return 0;
  6042. }
  6043. if (spawn2) {
  6044. if (spawn2->IsPlayer()) {
  6045. if (type != 1 && type != 2)
  6046. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2);
  6047. else
  6048. spawn->GetZone()->PlayAnimation(spawn, anim, spawn2, type);
  6049. return 0;
  6050. }
  6051. else {
  6052. lua_interface->LogError("%s: LUA PlayAnimation command error: second spawn not a player", lua_interface->GetScriptName(state));
  6053. return 0;
  6054. }
  6055. }
  6056. else
  6057. spawn->GetZone()->PlayAnimation(spawn, anim);
  6058. return 0;
  6059. }
  6060. int EQ2Emu_lua_IsPet(lua_State* state) {
  6061. if (!lua_interface)
  6062. return 0;
  6063. Spawn* spawn = lua_interface->GetSpawn(state);
  6064. if (!spawn) {
  6065. lua_interface->LogError("%s: LUA IsPet command error: spawn is not valid", lua_interface->GetScriptName(state));
  6066. return 0;
  6067. }
  6068. lua_interface->SetBooleanValue(state, spawn->IsPet());
  6069. return 1;
  6070. }
  6071. int EQ2Emu_lua_GetOwner(lua_State* state) {
  6072. if (!lua_interface)
  6073. return 0;
  6074. Spawn* spawn = lua_interface->GetSpawn(state);
  6075. if (!spawn) {
  6076. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not valid", lua_interface->GetScriptName(state));
  6077. return 0;
  6078. }
  6079. if (!spawn->IsNPC()) {
  6080. lua_interface->LogError("%s: LUA GetOwner command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6081. return 0;
  6082. }
  6083. if (((NPC*)spawn)->GetOwner()) {
  6084. lua_interface->SetSpawnValue(state, ((NPC*)spawn)->GetOwner());
  6085. return 1;
  6086. }
  6087. return 0;
  6088. }
  6089. int EQ2Emu_lua_SetTarget(lua_State* state) {
  6090. if (!lua_interface)
  6091. return 0;
  6092. Spawn* spawn = lua_interface->GetSpawn(state);
  6093. Spawn* target = lua_interface->GetSpawn(state, 2);
  6094. if (!spawn) {
  6095. lua_interface->LogError("%s: LUA SetTarget command error: spawn is not valid", lua_interface->GetScriptName(state));
  6096. return 0;
  6097. }
  6098. if (!spawn) {
  6099. lua_interface->LogError("%s: LUA SetTarget command error: target is not valid", lua_interface->GetScriptName(state));
  6100. return 0;
  6101. }
  6102. spawn->SetTarget(target);
  6103. return 0;
  6104. }
  6105. int EQ2Emu_lua_SetInCombat(lua_State* state) {
  6106. if (!lua_interface)
  6107. return 0;
  6108. Spawn* spawn = lua_interface->GetSpawn(state);
  6109. bool val = lua_interface->GetBooleanValue(state, 2);
  6110. if (!spawn) {
  6111. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not valid", lua_interface->GetScriptName(state));
  6112. return 0;
  6113. }
  6114. if (!spawn->IsEntity()) {
  6115. lua_interface->LogError("%s: LUA SetInCombat command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6116. return 0;
  6117. }
  6118. ((Entity*)spawn)->InCombat(val);
  6119. if (val) {
  6120. spawn->ClearRunningLocations();
  6121. spawn->CalculateRunningLocation(true);
  6122. }
  6123. return 0;
  6124. }
  6125. int EQ2Emu_lua_CompareSpawns(lua_State* state) {
  6126. if (!lua_interface)
  6127. return 0;
  6128. Spawn* spawn1 = lua_interface->GetSpawn(state);
  6129. Spawn* spawn2 = lua_interface->GetSpawn(state, 2);
  6130. if (!spawn1) {
  6131. lua_interface->LogError("%s: LUA CompareSpawns command error: first spawn is not valid", lua_interface->GetScriptName(state));
  6132. return 0;
  6133. }
  6134. if (!spawn2) {
  6135. lua_interface->LogError("%s: LUA CompareSpawns command error: second spawn is not valid", lua_interface->GetScriptName(state));
  6136. return 0;
  6137. }
  6138. lua_interface->SetBooleanValue(state, (spawn1 == spawn2));
  6139. return 1;
  6140. }
  6141. int EQ2Emu_lua_ClearRunback(lua_State* state){
  6142. if (!lua_interface)
  6143. return 0;
  6144. Spawn* spawn = lua_interface->GetSpawn(state);
  6145. if (!spawn) {
  6146. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6147. return 0;
  6148. }
  6149. if (!spawn->IsNPC()) {
  6150. lua_interface->LogError("%s: LUA ClearRunback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6151. return 0;
  6152. }
  6153. ((NPC*)spawn)->ClearRunback();
  6154. return 0;
  6155. }
  6156. int EQ2Emu_lua_Runback(lua_State* state) {
  6157. if (!lua_interface)
  6158. return 0;
  6159. Spawn* spawn = lua_interface->GetSpawn(state);
  6160. if (!spawn) {
  6161. lua_interface->LogError("%s: LUA Runback command error: spawn is not valid", lua_interface->GetScriptName(state));
  6162. return 0;
  6163. }
  6164. if (!spawn->IsNPC()) {
  6165. lua_interface->LogError("%s: LUA Runback command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6166. return 0;
  6167. }
  6168. ((NPC*)spawn)->Runback();
  6169. return 0;
  6170. }
  6171. int EQ2Emu_lua_GetRunbackDistance(lua_State* state) {
  6172. if (!lua_interface)
  6173. return 0;
  6174. Spawn* spawn = lua_interface->GetSpawn(state);
  6175. if (!spawn) {
  6176. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not valid", lua_interface->GetScriptName(state));
  6177. return 0;
  6178. }
  6179. if (!spawn->IsNPC()) {
  6180. lua_interface->LogError("%s: LUA GetRunbackDistance command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6181. return 0;
  6182. }
  6183. lua_interface->SetFloatValue(state, ((NPC*)spawn)->GetRunbackDistance());
  6184. return 1;
  6185. }
  6186. int EQ2Emu_lua_IsCasting(lua_State* state) {
  6187. if (!lua_interface)
  6188. return 0;
  6189. Spawn* spawn = lua_interface->GetSpawn(state);
  6190. if (!spawn) {
  6191. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not valid", lua_interface->GetScriptName(state));
  6192. return 0;
  6193. }
  6194. if (!spawn->IsEntity()) {
  6195. lua_interface->LogError("%s: LUA IsCasting command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6196. return 0;
  6197. }
  6198. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsCasting());
  6199. return 1;
  6200. }
  6201. int EQ2Emu_lua_IsMezzed(lua_State* state) {
  6202. if (!lua_interface)
  6203. return 0;
  6204. Spawn* spawn = lua_interface->GetSpawn(state);
  6205. if (!spawn) {
  6206. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not valid", lua_interface->GetScriptName(state));
  6207. return 0;
  6208. }
  6209. if (!spawn->IsEntity()) {
  6210. lua_interface->LogError("%s: LUA IsMezzed command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6211. return 0;
  6212. }
  6213. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzed());
  6214. return 1;
  6215. }
  6216. int EQ2Emu_lua_IsStunned(lua_State* state) {
  6217. if (!lua_interface)
  6218. return 0;
  6219. Spawn* spawn = lua_interface->GetSpawn(state);
  6220. if (!spawn) {
  6221. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6222. return 0;
  6223. }
  6224. if (!spawn->IsEntity()) {
  6225. lua_interface->LogError("%s: LUA IsStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6226. return 0;
  6227. }
  6228. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsStunned());
  6229. return 1;
  6230. }
  6231. int EQ2Emu_lua_IsMezzedOrStunned(lua_State* state) {
  6232. if (!lua_interface)
  6233. return 0;
  6234. Spawn* spawn = lua_interface->GetSpawn(state);
  6235. if (!spawn) {
  6236. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not valid", lua_interface->GetScriptName(state));
  6237. return 0;
  6238. }
  6239. if (!spawn->IsEntity()) {
  6240. lua_interface->LogError("%s: LUA IsMezzedOrStunned command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6241. return 0;
  6242. }
  6243. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsMezzedOrStunned());
  6244. return 1;
  6245. }
  6246. int EQ2Emu_lua_ProcessSpell(lua_State* state) {
  6247. if (!lua_interface)
  6248. return 0;
  6249. Spawn* spawn = lua_interface->GetSpawn(state);
  6250. Spawn* target = lua_interface->GetSpawn(state, 2);
  6251. float distance = lua_interface->GetFloatValue(state, 3);
  6252. if (!spawn) {
  6253. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not valid", lua_interface->GetScriptName(state));
  6254. return 0;
  6255. }
  6256. if (!target) {
  6257. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6258. return 0;
  6259. }
  6260. if (!spawn->IsNPC()) {
  6261. lua_interface->LogError("%s: LUA ProcessSpell command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6262. return 0;
  6263. }
  6264. if (!target->IsEntity()) {
  6265. lua_interface->LogError("%s: LUA ProcessSpell command error: target is not an entity", lua_interface->GetScriptName(state));
  6266. return 0;
  6267. }
  6268. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->ProcessSpell(((Entity*)target), distance));
  6269. return 1;
  6270. }
  6271. int EQ2Emu_lua_ProcessMelee(lua_State* state) {
  6272. if (!lua_interface)
  6273. return 0;
  6274. Spawn* spawn = lua_interface->GetSpawn(state);
  6275. Spawn* target = lua_interface->GetSpawn(state, 2);
  6276. float distance = lua_interface->GetFloatValue(state, 3);
  6277. if (!spawn) {
  6278. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not valid", lua_interface->GetScriptName(state));
  6279. return 0;
  6280. }
  6281. if (!target) {
  6282. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not valid", lua_interface->GetScriptName(state));
  6283. return 0;
  6284. }
  6285. if (!spawn->IsNPC()) {
  6286. lua_interface->LogError("%s: LUA ProcessMelee command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6287. return 0;
  6288. }
  6289. if (!target->IsEntity()) {
  6290. lua_interface->LogError("%s: LUA ProcessMelee command error: target is not an entity", lua_interface->GetScriptName(state));
  6291. return 0;
  6292. }
  6293. ((NPC*)spawn)->Brain()->ProcessMelee(((Entity*)target), distance);
  6294. return 0;
  6295. }
  6296. int EQ2Emu_lua_HasRecovered(lua_State* state) {
  6297. if (!lua_interface)
  6298. return 0;
  6299. Spawn* spawn = lua_interface->GetSpawn(state);
  6300. if (!spawn) {
  6301. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not valid", lua_interface->GetScriptName(state));
  6302. return 0;
  6303. }
  6304. if (!spawn->IsNPC()) {
  6305. lua_interface->LogError("%s: LUA HasRecovered command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6306. return 0;
  6307. }
  6308. lua_interface->SetBooleanValue(state, ((NPC*)spawn)->Brain()->HasRecovered());
  6309. return 1;
  6310. }
  6311. int EQ2Emu_lua_GetEncounterSize(lua_State* state) {
  6312. if (!lua_interface)
  6313. return 0;
  6314. Spawn* spawn = lua_interface->GetSpawn(state);
  6315. if (!spawn) {
  6316. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not valid", lua_interface->GetScriptName(state));
  6317. return 0;
  6318. }
  6319. if (!spawn->IsNPC()) {
  6320. lua_interface->LogError("%s: LUA GetEncounterSize command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6321. return 0;
  6322. }
  6323. lua_interface->SetInt32Value(state, ((NPC*)spawn)->Brain()->GetEncounterSize());
  6324. return 1;
  6325. }
  6326. int EQ2Emu_lua_GetMostHated(lua_State* state) {
  6327. if (!lua_interface)
  6328. return 0;
  6329. Spawn* spawn = lua_interface->GetSpawn(state);
  6330. if (!spawn) {
  6331. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not valid", lua_interface->GetScriptName(state));
  6332. return 0;
  6333. }
  6334. if (!spawn->IsNPC()) {
  6335. lua_interface->LogError("%s: LUA GetMostHated command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6336. return 0;
  6337. }
  6338. Entity* hated = ((NPC*)spawn)->Brain()->GetMostHated();
  6339. if (hated) {
  6340. lua_interface->SetSpawnValue(state, hated);
  6341. return 1;
  6342. }
  6343. return 0;
  6344. }
  6345. int EQ2Emu_lua_ClearHate(lua_State* state) {
  6346. if (!lua_interface)
  6347. return 0;
  6348. Spawn* spawn = lua_interface->GetSpawn(state);
  6349. Spawn* hated = lua_interface->GetSpawn(state, 2);
  6350. if (!spawn) {
  6351. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not valid", lua_interface->GetScriptName(state));
  6352. return 0;
  6353. }
  6354. if (!spawn->IsNPC()) {
  6355. lua_interface->LogError("%s: LUA ClearHate command error: spawn is not NPC", lua_interface->GetScriptName(state));
  6356. return 0;
  6357. }
  6358. if (!hated) {
  6359. ((NPC*)spawn)->Brain()->ClearHate();
  6360. return 0;
  6361. }
  6362. else
  6363. {
  6364. if (!hated->IsEntity()) {
  6365. lua_interface->LogError("%s: LUA ClearHate command error: second param is not entity", lua_interface->GetScriptName(state));
  6366. return 0;
  6367. }
  6368. ((NPC*)spawn)->Brain()->ClearHate(((Entity*)hated));
  6369. return 0;
  6370. }
  6371. return 0;
  6372. }
  6373. int EQ2Emu_lua_ClearEncounter(lua_State* state) {
  6374. if (!lua_interface)
  6375. return 0;
  6376. Spawn* spawn = lua_interface->GetSpawn(state);
  6377. if (!spawn) {
  6378. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not valid", lua_interface->GetScriptName(state));
  6379. return 0;
  6380. }
  6381. if (!spawn->IsNPC()) {
  6382. lua_interface->LogError("%s: LUA ClearEncounter command error: spawn is not an NPC", lua_interface->GetScriptName(state));
  6383. return 0;
  6384. }
  6385. ((NPC*)spawn)->Brain()->ClearEncounter();
  6386. return 0;
  6387. }
  6388. int EQ2Emu_lua_GetEncounter(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 GetEncounter command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6394. return 0;
  6395. }
  6396. if (!spawn->IsNPC()) {
  6397. lua_interface->LogError("%s: LUA GetEncounter command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6398. return 0;
  6399. }
  6400. // Temp list to store hate list
  6401. vector<int32>* encounterList = ((NPC*)spawn)->Brain()->GetEncounter();
  6402. if (encounterList->size() == 0) {
  6403. safe_delete(encounterList);
  6404. return 0;
  6405. }
  6406. lua_createtable(state, encounterList->size(), 0);
  6407. int newTable = lua_gettop(state);
  6408. for (int32 i = 0; i < encounterList->size(); i++) {
  6409. Spawn* temp = spawn->GetZone()->GetSpawnByID(encounterList->at(i));
  6410. if (temp)
  6411. lua_interface->SetSpawnValue(state, temp);
  6412. lua_rawseti(state, newTable, i + 1);
  6413. }
  6414. safe_delete(encounterList);
  6415. return 1;
  6416. }
  6417. int EQ2Emu_lua_GetHateList(lua_State* state) {
  6418. if (!lua_interface)
  6419. return 0;
  6420. Spawn* spawn = lua_interface->GetSpawn(state);
  6421. if (!spawn) {
  6422. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not valid", lua_interface->GetScriptName(state));
  6423. return 0;
  6424. }
  6425. if (!spawn->IsNPC()) {
  6426. lua_interface->LogError("%s: LUA GetHateList command error: spawn is not a NPC", lua_interface->GetScriptName(state));
  6427. return 0;
  6428. }
  6429. // Temp list to store hate list
  6430. vector<Entity*>* hateList = ((NPC*)spawn)->Brain()->GetHateList();
  6431. if (hateList->size() == 0) {
  6432. safe_delete(hateList);
  6433. return 0;
  6434. }
  6435. lua_createtable(state, hateList->size(), 0);
  6436. int newTable = lua_gettop(state);
  6437. for (int32 i = 0; i < hateList->size(); i++) {
  6438. lua_interface->SetSpawnValue(state, hateList->at(i));
  6439. lua_rawseti(state, newTable, i + 1);
  6440. }
  6441. safe_delete(hateList);
  6442. return 1;
  6443. }
  6444. int EQ2Emu_lua_HasGroup(lua_State* state) {
  6445. if (!lua_interface)
  6446. return 0;
  6447. Spawn* spawn = lua_interface->GetSpawn(state);
  6448. if (!spawn) {
  6449. lua_interface->LogError("%s: LUA HasGroup command error: spawn is not valid", lua_interface->GetScriptName(state));
  6450. return 0;
  6451. }
  6452. if (spawn->IsPlayer()) {
  6453. if (((Player*)spawn)->GetGroupMemberInfo() && world.GetGroupManager()->GetGroupSize(((Player*)spawn)->GetGroupMemberInfo()->group_id) > 1)
  6454. lua_interface->SetBooleanValue(state, true);
  6455. else
  6456. lua_interface->SetBooleanValue(state, false);
  6457. return 1;
  6458. }
  6459. else {
  6460. lua_interface->SetBooleanValue(state, spawn->HasSpawnGroup());
  6461. return 1;
  6462. }
  6463. }
  6464. int EQ2Emu_lua_SetCompleteFlag(lua_State* state) {
  6465. if (!lua_interface)
  6466. return 0;
  6467. Quest* quest = lua_interface->GetQuest(state);
  6468. if (!quest) {
  6469. lua_interface->LogError("%s: LUA SetCompleteFlag command error: quest is not valid", lua_interface->GetScriptName(state));
  6470. return 0;
  6471. }
  6472. quest->SetCompletedFlag(true);
  6473. return 0;
  6474. }
  6475. int EQ2Emu_lua_HasSpellEffect(lua_State* state) {
  6476. if (!lua_interface)
  6477. return 0;
  6478. Spawn* spawn = lua_interface->GetSpawn(state);
  6479. int32 spellID = lua_interface->GetInt32Value(state, 2);
  6480. int8 tier = lua_interface->GetInt8Value(state, 3);
  6481. if (!spawn) {
  6482. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not valid", lua_interface->GetScriptName(state));
  6483. return 0;
  6484. }
  6485. if (!spawn->IsEntity()) {
  6486. lua_interface->LogError("%s: LUA HasSpellEffect command error: spawn is not an entity", lua_interface->GetScriptName(state));
  6487. return 0;
  6488. }
  6489. if (spellID == 0) {
  6490. lua_interface->LogError("%s: LUA HasSpellEffect command error: spell id is not valid", lua_interface->GetScriptName(state));
  6491. return 0;
  6492. }
  6493. SpellEffects* effect = ((Entity*)spawn)->GetSpellEffect(spellID);
  6494. if (effect) {
  6495. if (tier > 0) {
  6496. // If a tier was passed chec to see if it is the same as the effect
  6497. if (tier == effect->tier)
  6498. lua_interface->SetBooleanValue(state, true);
  6499. else
  6500. lua_interface->SetBooleanValue(state, false);
  6501. return 1;
  6502. }
  6503. else {
  6504. // Have an effect but no tier was passed so return true
  6505. lua_interface->SetBooleanValue(state, true);
  6506. }
  6507. return 1;
  6508. }
  6509. // no effect so return false
  6510. lua_interface->SetBooleanValue(state, false);
  6511. return 1;
  6512. }
  6513. int EQ2Emu_lua_AddSpawnIDAccess(lua_State* state) {
  6514. if (!lua_interface)
  6515. return 0;
  6516. Spawn* spawn = lua_interface->GetSpawn(state);
  6517. int32 id = lua_interface->GetInt32Value(state, 2);
  6518. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6519. Spawn* spawn2 = 0;
  6520. vector<Spawn*> list;
  6521. if (!spawn) {
  6522. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6523. return 0;
  6524. }
  6525. //If zone not provided, use spawn's zone
  6526. if (!zone)
  6527. zone = spawn->GetZone();
  6528. list = zone->GetSpawnsByID(id);
  6529. if (list.size() == 0) {
  6530. lua_interface->LogError("%s: LUA AddSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6531. return 0;
  6532. }
  6533. vector<Spawn*>::iterator itr = list.begin();
  6534. for (int8 i = 0; i < list.size(); i++) {
  6535. spawn2 = itr[i];
  6536. if (spawn2)
  6537. spawn2->AddAllowAccessSpawn(spawn);
  6538. }
  6539. return 0;
  6540. }
  6541. int EQ2Emu_lua_RemoveSpawnIDAccess(lua_State* state) {
  6542. if (!lua_interface)
  6543. return 0;
  6544. Spawn* spawn = lua_interface->GetSpawn(state);
  6545. int32 id = lua_interface->GetInt32Value(state, 2);
  6546. ZoneServer* zone = lua_interface->GetZone(state, 3);
  6547. Spawn* spawn2 = 0;
  6548. if (!spawn) {
  6549. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: spawn is not valid", lua_interface->GetScriptName(state));
  6550. return 0;
  6551. }
  6552. //If zone not provided, use spawn's zone
  6553. if (!zone)
  6554. zone = spawn->GetZone();
  6555. vector<Spawn*> list = zone->GetSpawnsByID(id);
  6556. vector<Spawn*>::iterator itr = list.begin();
  6557. if (list.size() == 0) {
  6558. lua_interface->LogError("%s: LUA RemoveSpawnIDAccess command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  6559. return 0;
  6560. }
  6561. for (int8 i = 0; i < list.size(); i++) {
  6562. spawn2 = itr[i];
  6563. if (spawn2)
  6564. spawn2->RemoveSpawnAccess(spawn);
  6565. }
  6566. return 0;
  6567. }
  6568. int EQ2Emu_lua_SetQuestYellow(lua_State* state) {
  6569. if (!lua_interface)
  6570. return 0;
  6571. Quest* quest = lua_interface->GetQuest(state);
  6572. if (!quest) {
  6573. lua_interface->LogError("%s: LUA SetQuestYellow command error: quest is not valid", lua_interface->GetScriptName(state));
  6574. return 0;
  6575. }
  6576. quest->SetYellowName(true);
  6577. return 0;
  6578. }
  6579. int EQ2Emu_lua_CanReceiveQuest(lua_State* state) {
  6580. if (!lua_interface)
  6581. return 0;
  6582. Spawn* spawn = lua_interface->GetSpawn(state);
  6583. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  6584. if (!spawn) {
  6585. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not valid", lua_interface->GetScriptName(state));
  6586. return 0;
  6587. }
  6588. if (!spawn->IsPlayer()) {
  6589. lua_interface->LogError("%s: LUA CanReceieveQuest command error: spawn is not player", lua_interface->GetScriptName(state));
  6590. return 0;
  6591. }
  6592. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanReceiveQuest(quest_id));
  6593. return 1;
  6594. }
  6595. int EQ2Emu_lua_SetSuccessTimer(lua_State* state) {
  6596. if (!lua_interface)
  6597. return 0;
  6598. Spawn* spawn = lua_interface->GetSpawn(state);
  6599. if (!spawn) {
  6600. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6601. return 0;
  6602. }
  6603. if (!spawn->IsPlayer()) {
  6604. lua_interface->LogError("%s: LUA SetSuccessTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6605. return 0;
  6606. }
  6607. ZoneServer* zone = spawn->GetZone();
  6608. if (!zone) {
  6609. lua_interface->LogError("%s: LUA SetSuccessTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6610. return 0;
  6611. }
  6612. Instance_Type iType = zone->GetInstanceType();
  6613. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6614. iType == GROUP_LOCKOUT_INSTANCE ||
  6615. iType == RAID_LOCKOUT_INSTANCE ||
  6616. iType == SOLO_PERSIST_INSTANCE ||
  6617. iType == GROUP_PERSIST_INSTANCE ||
  6618. iType == RAID_PERSIST_INSTANCE) {
  6619. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6620. if (data) {
  6621. // Check to see if the timer has already been set, if it has return out.
  6622. if (Timer::GetUnixTimeStamp() <= data->last_success_timestamp + data->success_lockout_time)
  6623. return 0;
  6624. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 1, Timer::GetUnixTimeStamp());
  6625. data->last_success_timestamp = Timer::GetUnixTimeStamp();
  6626. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6627. if (client) {
  6628. string time_msg = "";
  6629. int32 time = data->success_lockout_time;
  6630. int16 hour;
  6631. int8 min;
  6632. int8 sec;
  6633. hour = time / 3600;
  6634. time = time % 3600;
  6635. min = time / 60;
  6636. time = time % 60;
  6637. sec = time;
  6638. if (hour > 0) {
  6639. char temp[10];
  6640. sprintf(temp, " %i", hour);
  6641. time_msg.append(temp);
  6642. time_msg.append(" hour");
  6643. time_msg.append((hour > 1) ? "s" : "");
  6644. }
  6645. if (min > 0) {
  6646. char temp[5];
  6647. sprintf(temp, " %i", min);
  6648. time_msg.append(temp);
  6649. time_msg.append(" minute");
  6650. time_msg.append((min > 1) ? "s" : "");
  6651. }
  6652. // Only add seconds if minutes and hours are 0
  6653. if (hour == 0 && min == 0 && sec > 0) {
  6654. char temp[5];
  6655. sprintf(temp, " %i", sec);
  6656. time_msg.append(temp);
  6657. time_msg.append(" second");
  6658. time_msg.append((sec > 1) ? "s" : "");
  6659. }
  6660. 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());
  6661. }
  6662. }
  6663. else
  6664. lua_interface->LogError("LUA SetSuccessTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6665. }
  6666. else
  6667. lua_interface->LogError("%s: LUA SetSuccessTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6668. return 0;
  6669. }
  6670. int EQ2Emu_lua_SetFailureTimer(lua_State* state) {
  6671. if (!lua_interface)
  6672. return 0;
  6673. Spawn* spawn = lua_interface->GetSpawn(state);
  6674. if (!spawn) {
  6675. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not valid", lua_interface->GetScriptName(state));
  6676. return 0;
  6677. }
  6678. if (!spawn->IsPlayer()) {
  6679. lua_interface->LogError("%s: LUA SetFailureTimer command error: spawn is not a player", lua_interface->GetScriptName(state));
  6680. return 0;
  6681. }
  6682. ZoneServer* zone = spawn->GetZone();
  6683. if (!zone) {
  6684. lua_interface->LogError("%s: LUA SetFailureTimer command error: unable to get a valid zone for the given spawn", lua_interface->GetScriptName(state));
  6685. return 0;
  6686. }
  6687. Instance_Type iType = zone->GetInstanceType();
  6688. if (iType == SOLO_LOCKOUT_INSTANCE ||
  6689. iType == GROUP_LOCKOUT_INSTANCE ||
  6690. iType == RAID_LOCKOUT_INSTANCE ||
  6691. iType == SOLO_PERSIST_INSTANCE ||
  6692. iType == GROUP_PERSIST_INSTANCE ||
  6693. iType == RAID_PERSIST_INSTANCE) {
  6694. InstanceData* data = ((Player*)spawn)->GetCharacterInstances()->FindInstanceByZoneID(spawn->GetZone()->GetZoneID());
  6695. if (data) {
  6696. // Check to see if the timer has already been set, if it has return out.
  6697. if (Timer::GetUnixTimeStamp() <= data->last_failure_timestamp + data->failure_lockout_time)
  6698. return 0;
  6699. database.UpdateCharacterInstance(((Player*)spawn)->GetCharacterID(), string(spawn->GetZone()->GetZoneName()), spawn->GetZone()->GetInstanceID(), 2, Timer::GetUnixTimeStamp());
  6700. data->last_failure_timestamp = Timer::GetUnixTimeStamp();
  6701. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  6702. if (client) {
  6703. string time_msg = "";
  6704. int32 time = data->failure_lockout_time;
  6705. int16 hour;
  6706. int8 min;
  6707. int8 sec;
  6708. hour = time / 3600;
  6709. time = time % 3600;
  6710. min = time / 60;
  6711. time = time % 60;
  6712. sec = time;
  6713. if (hour > 0) {
  6714. char temp[10];
  6715. sprintf(temp, " %i", hour);
  6716. time_msg.append(temp);
  6717. time_msg.append(" hour");
  6718. time_msg.append((hour > 1) ? "s" : "");
  6719. }
  6720. if (min > 0) {
  6721. char temp[5];
  6722. sprintf(temp, " %i", min);
  6723. time_msg.append(temp);
  6724. time_msg.append(" minute");
  6725. time_msg.append((min > 1) ? "s" : "");
  6726. }
  6727. // Only add seconds if minutes and hours are 0
  6728. if (hour == 0 && min == 0 && sec > 0) {
  6729. char temp[5];
  6730. sprintf(temp, " %i", sec);
  6731. time_msg.append(temp);
  6732. time_msg.append(" second");
  6733. time_msg.append((sec > 1) ? "s" : "");
  6734. }
  6735. 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());
  6736. }
  6737. }
  6738. else
  6739. lua_interface->LogError("LUA SetFailureTimer command error: unable to get instance data for instance %u for player %s", spawn->GetZone()->GetInstanceID(), spawn->GetName());
  6740. }
  6741. else
  6742. lua_interface->LogError("%s: LUA SetFailureTimer command error: current zone for given spawn is not a lockout or persistent instance", lua_interface->GetScriptName(state));
  6743. return 0;
  6744. }
  6745. int EQ2Emu_lua_IsGroundSpawn(lua_State* state) {
  6746. if (!lua_interface)
  6747. return 0;
  6748. Spawn* spawn = lua_interface->GetSpawn(state);
  6749. if (!spawn) {
  6750. lua_interface->LogError("%s: LUA IsGroundSpawn command error: not a valid spawn", lua_interface->GetScriptName(state));
  6751. return 0;
  6752. }
  6753. lua_interface->SetBooleanValue(state, spawn->IsGroundSpawn());
  6754. return 1;
  6755. }
  6756. int EQ2Emu_lua_CanHarvest(lua_State* state) {
  6757. if (!lua_interface)
  6758. return 0;
  6759. Spawn* player = lua_interface->GetSpawn(state);
  6760. Spawn* ground = lua_interface->GetSpawn(state, 2);
  6761. if (!player) {
  6762. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6763. return 0;
  6764. }
  6765. if (!player->IsPlayer()) {
  6766. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a player", lua_interface->GetScriptName(state));
  6767. return 0;
  6768. }
  6769. if (!ground) {
  6770. lua_interface->LogError("%s: LUA CanHarvest command error: not a valid spawn", lua_interface->GetScriptName(state));
  6771. return 0;
  6772. }
  6773. if (!ground->IsGroundSpawn()) {
  6774. lua_interface->LogError("%s: LUA CanHarvest command error: spawn is not a ground spawn", lua_interface->GetScriptName(state));
  6775. return 0;
  6776. }
  6777. vector<GroundSpawnEntry*>* groundspawn_entries = player->GetZone()->GetGroundSpawnEntries(((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6778. if (!groundspawn_entries) {
  6779. lua_interface->LogError("LUA CanHarvest command error: No groundspawn entries assigned to groundspawn id: %u", ((GroundSpawn*)ground)->GetGroundSpawnEntryID());
  6780. return 0;
  6781. }
  6782. Skill* skill = 0;
  6783. string collection_skill = string(((GroundSpawn*)ground)->GetCollectionSkill());
  6784. if (collection_skill == "Collecting")
  6785. skill = ((Player*)player)->GetSkillByName("Gathering");
  6786. else
  6787. skill = ((Player*)player)->GetSkillByName(collection_skill.c_str());
  6788. if (!skill) {
  6789. lua_interface->LogError("LUA CanHarvest command error: Player '%s' lacks the skill: '%s'", player->GetName(), collection_skill.c_str());
  6790. return 0;
  6791. }
  6792. vector<GroundSpawnEntry*>::iterator itr;
  6793. GroundSpawnEntry* entry = 0;
  6794. bool can_harvest = false;
  6795. sint32 min_skill = -1;
  6796. int16 totalSkill = skill->current_val;
  6797. int32 skillID = master_item_list.GetItemStatIDByName(collection_skill);
  6798. if(skillID != 0xFFFFFFFF)
  6799. {
  6800. ((Entity*)player)->MStats.lock();
  6801. totalSkill += ((Entity*)player)->stats[skillID];
  6802. ((Entity*)player)->MStats.unlock();
  6803. }
  6804. // first, iterate through groundspawn_entries, discard tables player cannot use
  6805. for (itr = groundspawn_entries->begin(); itr != groundspawn_entries->end(); itr++)
  6806. {
  6807. entry = *itr;
  6808. if (min_skill == -1 || entry->min_skill_level < min_skill)
  6809. min_skill = entry->min_skill_level;
  6810. // if player lacks skill, skip table
  6811. if (entry->min_skill_level > totalSkill)
  6812. continue;
  6813. // if bonus, but player lacks level, skip table
  6814. if (entry->bonus_table && (player->GetLevel() < entry->min_adventure_level))
  6815. continue;
  6816. can_harvest = true;
  6817. break;
  6818. }
  6819. lua_interface->SetBooleanValue(state, can_harvest);
  6820. // If false, send the message to the client
  6821. if (!can_harvest) {
  6822. Client* client = player->GetZone()->GetClientBySpawn(player);
  6823. if (client) {
  6824. string msg = "You do not have enough skill to ";
  6825. if (collection_skill == "Gathering" || collection_skill == "Collecting")
  6826. msg.append("gather");
  6827. else if (collection_skill == "Mining")
  6828. msg.append("mine");
  6829. else if (collection_skill == "Trapping")
  6830. msg.append("trap");
  6831. else if (collection_skill == "Foresting")
  6832. msg.append("forest");
  6833. else if (collection_skill == "Fishing")
  6834. msg.append("catch");
  6835. msg.append(" the %s. It requires %i %s skill, and your skill is %i.");
  6836. client->Message(CHANNEL_HARVESTING_WARNINGS, msg.c_str(), ground->GetName(), min_skill, skill->name.data.c_str(), totalSkill);
  6837. // You do not have enough skill to catch the band of fish. It requires 20 Fishing skill, and your skill is 12.
  6838. }
  6839. }
  6840. return 1;
  6841. }
  6842. int EQ2Emu_lua_HasRecipeBook(lua_State* state) {
  6843. if (!lua_interface)
  6844. return 0;
  6845. Spawn* player = lua_interface->GetSpawn(state);
  6846. int32 recipe_id = lua_interface->GetInt32Value(state, 2);
  6847. if (!player) {
  6848. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not valid", lua_interface->GetScriptName(state));
  6849. return 0;
  6850. }
  6851. if (!player->IsPlayer()) {
  6852. lua_interface->LogError("%s: LUA HasRecipeBook command error, Spawn is not a player", lua_interface->GetScriptName(state));
  6853. return 0;
  6854. }
  6855. bool ret = ((Player*)player)->HasRecipeBook(recipe_id);
  6856. lua_interface->SetBooleanValue(state, ret);
  6857. return 1;
  6858. }
  6859. int EQ2Emu_lua_SummonDumbFirePet(lua_State* state) {
  6860. // Check to see if we have a valid lua_interface
  6861. if (!lua_interface)
  6862. return 0;
  6863. // Get the spawn that is getting the pet
  6864. Spawn* spawn = lua_interface->GetSpawn(state);
  6865. Spawn* target = lua_interface->GetSpawn(state, 2);
  6866. // Get the DB ID of the pet
  6867. int32 pet_id = lua_interface->GetInt32Value(state, 3);
  6868. float x = lua_interface->GetFloatValue(state, 4);
  6869. float y = lua_interface->GetFloatValue(state, 5);
  6870. float z = lua_interface->GetFloatValue(state, 6);
  6871. // Get the spell that this command was called from
  6872. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  6873. // Check to make sure the spawn pointer is valid
  6874. if (!spawn) {
  6875. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not valid", lua_interface->GetScriptName(state));
  6876. return 0;
  6877. }
  6878. // Check to make sure the spawn is an entity
  6879. if (!spawn->IsEntity()) {
  6880. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: Spawn is not an entity", lua_interface->GetScriptName(state));
  6881. return 0;
  6882. }
  6883. if (!target) {
  6884. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not valid", lua_interface->GetScriptName(state));
  6885. return 0;
  6886. }
  6887. if (!target->IsEntity()) {
  6888. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: target is not an entity", lua_interface->GetScriptName(state));
  6889. return 0;
  6890. }
  6891. // Check to see if the DB ID for the pet is set
  6892. if (pet_id == 0) {
  6893. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: pet_id can not be set to 0", lua_interface->GetScriptName(state));
  6894. return 0;
  6895. }
  6896. // Check to see if the pointer to the spell is valid
  6897. if (!luaspell) {
  6898. lua_interface->LogError("%s: LUA SummonDumbFirePet command error: valid spell not found, SummonPet can only be used in spell scripts", lua_interface->GetScriptName(state));
  6899. return 0;
  6900. }
  6901. if(luaspell->resisted) {
  6902. return 0;
  6903. }
  6904. // Get a pointer to a spawn with the given DB ID and check if the pointer is valid
  6905. Spawn* pet = spawn->GetZone()->GetSpawn(pet_id);
  6906. if (!pet) {
  6907. lua_interface->LogError("LUA SummonDumbFirePet command error: Could not find spawn with id of %u.", pet_id);
  6908. return 0;
  6909. }
  6910. // Check to make sure the pet is an npc
  6911. if (!pet->IsNPC()) {
  6912. lua_interface->LogError("LUA SummonDumbFirePet command error: id (%u) did not point to a npc", pet_id);
  6913. return 0;
  6914. }
  6915. if (x == 0)
  6916. x = spawn->GetX();
  6917. if (y == 0)
  6918. y = spawn->GetY();
  6919. if (z == 0)
  6920. z = spawn->GetZ();
  6921. // Spawn the pet at the same location as the owner
  6922. pet->SetX(x);
  6923. pet->SetY(y);
  6924. pet->SetZ(z);
  6925. pet->SetLocation(spawn->GetLocation());
  6926. pet->SetHeading(spawn->GetHeading());
  6927. spawn->GetZone()->AddSpawn(pet);
  6928. /*
  6929. const char* spawn_script = world.GetSpawnScript(pet_id);
  6930. if(spawn_script && lua_interface->GetSpawnScript(spawn_script) != 0){
  6931. spawn->SetSpawnScript(string(spawn_script));
  6932. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  6933. }*/
  6934. // Get a random pet name
  6935. string random_pet_name;
  6936. int16 rand_index = MakeRandomInt(0, spawn->GetZone()->pet_names.size() - 1);
  6937. random_pet_name = spawn->GetZone()->pet_names.at(rand_index);
  6938. LogWrite(PET__DEBUG, 0, "Pets", "Randomize Pet Name: '%s' (rand: %i)", random_pet_name.c_str(), rand_index);
  6939. // Set the pets name
  6940. pet->SetName(random_pet_name.c_str());
  6941. // Set the level of the pet to the owners level
  6942. pet->SetLevel(spawn->GetLevel());
  6943. // Set the faction of the pet to the same faction as the owner
  6944. pet->SetFactionID(spawn->GetFactionID());
  6945. // Set the spawn as a pet
  6946. pet->SetPet(true);
  6947. // Give a pointer of the owner to the pet
  6948. ((NPC*)pet)->SetOwner((Entity*)spawn);
  6949. // Set the pet type
  6950. ((NPC*)pet)->SetPetType(PET_TYPE_DUMBFIRE);
  6951. // Set the spell id used to create this pet
  6952. ((NPC*)pet)->SetPetSpellID(luaspell->spell->GetSpellData()->id);
  6953. // Set the spell tier used to create this pet
  6954. ((NPC*)pet)->SetPetSpellTier(luaspell->spell->GetSpellData()->tier);
  6955. // Set the pets spawn type to 6
  6956. pet->SetSpawnType(6);
  6957. // Set the pets brain
  6958. ((NPC*)pet)->SetBrain(new DumbFirePetBrain((NPC*)pet, (Entity*)target, luaspell->spell->GetSpellDuration() * 100));
  6959. // Check to see if the pet has a subtitle
  6960. if (strlen(pet->GetSubTitle()) > 0) {
  6961. // Add the players name to the front of the sub title
  6962. string pet_subtitle;
  6963. pet_subtitle.append(spawn->GetName()).append("'s ").append(pet->GetSubTitle());
  6964. LogWrite(PET__DEBUG, 0, "Pets", "Pet Subtitle: '%s'", pet_subtitle.c_str());
  6965. // Set the pets subtitle to the new one
  6966. pet->SetSubTitle(pet_subtitle.c_str());
  6967. }
  6968. // Set the pet as the return value for this function
  6969. lua_interface->SetSpawnValue(state, pet);
  6970. return 1;
  6971. }
  6972. int EQ2Emu_lua_SpawnMove(lua_State* state) {
  6973. if (!lua_interface)
  6974. return 0;
  6975. Spawn* spawn = lua_interface->GetSpawn(state);
  6976. Spawn* player = lua_interface->GetSpawn(state, 2);
  6977. float max_distance = lua_interface->GetFloatValue(state, 3);
  6978. string type = lua_interface->GetStringValue(state, 4);
  6979. if (!spawn || (spawn && spawn->IsPlayer())) {
  6980. lua_interface->LogError("%s: LUA SpawnMove command error: first param spawn is not valid or is player", lua_interface->GetScriptName(state));
  6981. return 0;
  6982. }
  6983. if (!player || (player && !player->IsPlayer())) {
  6984. lua_interface->LogError("%s: LUA SpawnMove command error: second param is not player", lua_interface->GetScriptName(state));
  6985. return 0;
  6986. }
  6987. Client* client = 0;
  6988. if (player->GetZone())
  6989. client = player->GetZone()->GetClientBySpawn(player);
  6990. if (!client) {
  6991. lua_interface->LogError("%s: LUA SpawnMove command error: could not find client", lua_interface->GetScriptName(state));
  6992. return 0;
  6993. }
  6994. //Set max_distance to default if not set or not proper value
  6995. if (max_distance <= 0)
  6996. max_distance = 500;
  6997. PacketStruct* packet = configReader.getStruct("WS_MoveObjectMode", client->GetVersion());
  6998. if (packet) {
  6999. float unknown2_3 = 0;
  7000. int8 placement_mode = 0;
  7001. if (type == "wall") {
  7002. placement_mode = 2;
  7003. unknown2_3 = 150;
  7004. }
  7005. else if (type == "ceiling")
  7006. placement_mode = 1;
  7007. packet->setDataByName("placement_mode", placement_mode);
  7008. packet->setDataByName("spawn_id", ((Player*)player)->GetIDWithPlayerSpawn(spawn));
  7009. packet->setDataByName("model_type", spawn->GetModelType());
  7010. packet->setDataByName("unknown", 1); //size
  7011. packet->setDataByName("unknown2", 1); //size 2
  7012. packet->setDataByName("unknown2", .5, 1); //size 3
  7013. packet->setDataByName("unknown2", 3, 2);
  7014. packet->setDataByName("unknown2", unknown2_3, 3);
  7015. packet->setDataByName("max_distance", max_distance);
  7016. packet->setDataByName("CoEunknown", 0xFFFFFFFF);
  7017. client->QueuePacket(packet->serialize());
  7018. safe_delete(packet);
  7019. }
  7020. return 0;
  7021. }
  7022. int EQ2Emu_lua_GetItemType(lua_State* state) {
  7023. if (!lua_interface)
  7024. return 0;
  7025. Item* item = lua_interface->GetItem(state);
  7026. if (!item) {
  7027. lua_interface->LogError("%s: LUA GetItemType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7028. return 0;
  7029. }
  7030. lua_interface->SetInt32Value(state, item->generic_info.item_type);
  7031. return 1;
  7032. }
  7033. int EQ2Emu_lua_GetItemEffectType(lua_State* state) {
  7034. if (!lua_interface)
  7035. return 0;
  7036. Item* item = lua_interface->GetItem(state);
  7037. if (!item) {
  7038. lua_interface->LogError("%s: LUA GetItemEffectType command error: item pointer is not valid", lua_interface->GetScriptName(state));
  7039. return 0;
  7040. }
  7041. lua_interface->SetInt32Value(state, item->effect_type);
  7042. return 1;
  7043. }
  7044. int EQ2Emu_lua_AddTransportSpawn(lua_State* state) {
  7045. if (!lua_interface)
  7046. return 0;
  7047. Spawn* spawn = lua_interface->GetSpawn(state);
  7048. if (!spawn) {
  7049. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7050. return 0;
  7051. }
  7052. if (spawn->GetZone())
  7053. spawn->GetZone()->AddTransportSpawn(spawn);
  7054. return 0;
  7055. }
  7056. int EQ2Emu_lua_IsTransportSpawn(lua_State* state) {
  7057. if (!lua_interface)
  7058. return 0;
  7059. Spawn* spawn = lua_interface->GetSpawn(state);
  7060. if (!spawn) {
  7061. lua_interface->LogError("%s: LUA AddTransportSpawn command error: spawn is not valid", lua_interface->GetScriptName(state));
  7062. return 0;
  7063. }
  7064. lua_interface->SetBooleanValue(state, spawn->IsTransportSpawn());
  7065. return 1;
  7066. }
  7067. int EQ2Emu_lua_GetSkillValue(lua_State* state) {
  7068. if (!lua_interface)
  7069. return 0;
  7070. Skill* skill = lua_interface->GetSkill(state);
  7071. if (!skill) {
  7072. lua_interface->LogError("%s: LUA GetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7073. return 0;
  7074. }
  7075. lua_interface->SetInt32Value(state, skill->current_val);
  7076. return 1;
  7077. }
  7078. int EQ2Emu_lua_GetSkillMaxValue(lua_State* state) {
  7079. if (!lua_interface)
  7080. return 0;
  7081. Skill* skill = lua_interface->GetSkill(state);
  7082. if (!skill) {
  7083. lua_interface->LogError("%s: LUA GetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7084. return 0;
  7085. }
  7086. lua_interface->SetInt32Value(state, skill->max_val);
  7087. return 1;
  7088. }
  7089. int EQ2Emu_lua_GetSkillName(lua_State* state) {
  7090. if (!lua_interface)
  7091. return 0;
  7092. Skill* skill = lua_interface->GetSkill(state);
  7093. if (!skill) {
  7094. lua_interface->LogError("%s: LUA GetSkillName command error: skill is not valid", lua_interface->GetScriptName(state));
  7095. return 0;
  7096. }
  7097. lua_interface->SetStringValue(state, skill->name.data.c_str());
  7098. return 1;
  7099. }
  7100. int EQ2Emu_lua_SetSkillMaxValue(lua_State* state) {
  7101. if (!lua_interface)
  7102. return 0;
  7103. Skill* skill = lua_interface->GetSkill(state);
  7104. int16 value = lua_interface->GetInt16Value(state, 2);
  7105. if (!skill) {
  7106. lua_interface->LogError("%s: LUA SetSkillMaxValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7107. return 0;
  7108. }
  7109. skill->max_val = value;
  7110. if (skill->max_val < skill->current_val)
  7111. skill->current_val = skill->max_val;
  7112. return 0;
  7113. }
  7114. int EQ2Emu_lua_SetSkillValue(lua_State* state) {
  7115. if (!lua_interface)
  7116. return 0;
  7117. Skill* skill = lua_interface->GetSkill(state);
  7118. int16 value = lua_interface->GetInt16Value(state, 2);
  7119. if (!skill) {
  7120. lua_interface->LogError("%s: LUA SetSkillValue command error: skill is not valid", lua_interface->GetScriptName(state));
  7121. return 0;
  7122. }
  7123. if (value > skill->max_val)
  7124. skill->current_val = skill->max_val;
  7125. else
  7126. skill->current_val = value;
  7127. return 0;
  7128. }
  7129. int EQ2Emu_lua_HasSkill(lua_State* state) {
  7130. if (!lua_interface)
  7131. return 0;
  7132. Spawn* player = lua_interface->GetSpawn(state);
  7133. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7134. if (skill_id > 0 && player && player->IsPlayer()) {
  7135. lua_interface->SetBooleanValue(state, ((Player*)player)->skill_list.HasSkill(skill_id));
  7136. return 1;
  7137. }
  7138. return 0;
  7139. }
  7140. int EQ2Emu_lua_AddSkill(lua_State* state) {
  7141. if (!lua_interface)
  7142. return 0;
  7143. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7144. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7145. int16 current_val = lua_interface->GetInt16Value(state, 3);
  7146. int16 max_val = lua_interface->GetInt16Value(state, 4);
  7147. bool more_to_add = lua_interface->GetBooleanValue(state, 5);
  7148. if (skill_id > 0 && current_val > 0 && max_val > 0) {
  7149. if (player_spawn && player_spawn->IsPlayer()) {
  7150. Player* player = (Player*)player_spawn;
  7151. bool added = false;
  7152. if (!player->skill_list.HasSkill(skill_id)) {
  7153. player->AddSkill(skill_id, current_val, max_val, true);
  7154. added = true;
  7155. }
  7156. 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
  7157. Client* client = player->GetClient();
  7158. if (client) {
  7159. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7160. if (packet)
  7161. client->QueuePacket(packet);
  7162. }
  7163. }
  7164. if (added) {
  7165. lua_interface->SetBooleanValue(state, true);
  7166. return 1;
  7167. }
  7168. }
  7169. else {
  7170. lua_interface->LogError("%s: LUA AddSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7171. }
  7172. }
  7173. else {
  7174. lua_interface->LogError("%s: LUA AddSkill command error: Required parameters not set", lua_interface->GetScriptName(state));
  7175. }
  7176. lua_interface->SetBooleanValue(state, false);
  7177. return 1;
  7178. }
  7179. int EQ2Emu_lua_RemoveSkill(lua_State* state) {
  7180. if (!lua_interface)
  7181. return 0;
  7182. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7183. int32 skill_id = lua_interface->GetInt32Value(state, 2);
  7184. bool more_to_remove = lua_interface->GetBooleanValue(state, 3);
  7185. if (skill_id > 0) {
  7186. if (player_spawn && player_spawn->IsPlayer()) {
  7187. Player* player = (Player*)player_spawn;
  7188. if (player->skill_list.HasSkill(skill_id)) {
  7189. player->RemovePlayerSkill(skill_id);
  7190. if (!more_to_remove) {
  7191. Client* client = player->GetClient();
  7192. if (client) {
  7193. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7194. if (packet)
  7195. client->QueuePacket(packet);
  7196. }
  7197. }
  7198. }
  7199. }
  7200. else {
  7201. lua_interface->LogError("%s: LUA RemoveSkill command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7202. }
  7203. }
  7204. else {
  7205. lua_interface->LogError("%s: LUA RemoveSkill command error: skill_id not set", lua_interface->GetScriptName(state));
  7206. }
  7207. return 0;
  7208. }
  7209. int EQ2Emu_lua_IncreaseSkillCapsByType(lua_State* state) {
  7210. if (!lua_interface)
  7211. return 0;
  7212. Spawn* player_spawn = lua_interface->GetSpawn(state);
  7213. int8 skill_type = lua_interface->GetInt8Value(state, 2);
  7214. int16 amount = lua_interface->GetInt8Value(state, 3);
  7215. bool more_to_increase = lua_interface->GetBooleanValue(state, 4);
  7216. if (amount > 0 && skill_type < 100) {
  7217. if (player_spawn && player_spawn->IsPlayer()) {
  7218. Player* player = (Player*)player_spawn;
  7219. player->skill_list.IncreaseSkillCapsByType(skill_type, amount);
  7220. if (!more_to_increase) {
  7221. Client* client = player->GetClient();
  7222. if (client) {
  7223. EQ2Packet* packet = player->GetSkills()->GetSkillPacket(client->GetVersion());
  7224. if (packet)
  7225. client->QueuePacket(packet);
  7226. }
  7227. }
  7228. }
  7229. else {
  7230. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Given spawn is not a player", lua_interface->GetScriptName(state));
  7231. }
  7232. }
  7233. else {
  7234. lua_interface->LogError("%s: LUA IncreaseSkillCapsByType command error: Invalid parameters", lua_interface->GetScriptName(state));
  7235. }
  7236. return 0;
  7237. }
  7238. int EQ2Emu_lua_GetSkill(lua_State* state) {
  7239. if (!lua_interface)
  7240. return 0;
  7241. Spawn* spawn = lua_interface->GetSpawn(state);
  7242. string name = lua_interface->GetStringValue(state, 2);
  7243. if (!spawn) {
  7244. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not valid", lua_interface->GetScriptName(state));
  7245. return 0;
  7246. }
  7247. if (!spawn->IsEntity()) {
  7248. lua_interface->LogError("%s: LUA GetSkill command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7249. return 0;
  7250. }
  7251. Skill* skill = ((Entity*)spawn)->GetSkillByName(name.c_str());
  7252. if (skill) {
  7253. lua_interface->SetSkillValue(state, skill);
  7254. return 1;
  7255. }
  7256. return 0;
  7257. }
  7258. int EQ2Emu_lua_AddProc(lua_State* state) {
  7259. if (!lua_interface)
  7260. return 0;
  7261. Spawn* spawn = lua_interface->GetSpawn(state);
  7262. int8 type = lua_interface->GetInt8Value(state, 2);
  7263. float chance = lua_interface->GetFloatValue(state, 3);
  7264. Item* item = lua_interface->GetItem(state, 4);
  7265. bool use_all_spelltargets = (lua_interface->GetInt8Value(state, 5) == 1);
  7266. LuaSpell* spell = 0;
  7267. if (!spawn && (!spell || !use_all_spelltargets)) {
  7268. lua_interface->LogError("%s: LUA AddProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7269. return 0;
  7270. }
  7271. if ((!spell || use_all_spelltargets) && spawn && !spawn->IsEntity()) {
  7272. lua_interface->LogError("%s: LUA AddProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7273. return 0;
  7274. }
  7275. if (!item)
  7276. spell = lua_interface->GetCurrentSpell(state);
  7277. if (!item && !spell) {
  7278. lua_interface->LogError("%s: LUA AddProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7279. return 0;
  7280. }
  7281. if(spell && spell->resisted) {
  7282. return 0;
  7283. }
  7284. if (spell && use_all_spelltargets) {
  7285. Spawn* target;
  7286. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7287. for (int8 i = 0; i < spell->targets.size(); i++) {
  7288. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7289. if (!target || !target->IsEntity())
  7290. continue;
  7291. ((Entity*)target)->AddProc(type, chance, item, spell);
  7292. }
  7293. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7294. }
  7295. else
  7296. ((Entity*)spawn)->AddProc(type, chance, item, spell);
  7297. return 0;
  7298. }
  7299. int EQ2Emu_lua_RemoveProc(lua_State* state) {
  7300. if (!lua_interface)
  7301. return 0;
  7302. Spawn* spawn = lua_interface->GetSpawn(state);
  7303. Item* item = lua_interface->GetItem(state, 2);
  7304. LuaSpell* spell = 0;
  7305. if (!spawn) {
  7306. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not valid", lua_interface->GetScriptName(state));
  7307. return 0;
  7308. }
  7309. if (!spawn->IsEntity()) {
  7310. lua_interface->LogError("%s: LUA RemoveProc command error: spawn is not a valid entity", lua_interface->GetScriptName(state));
  7311. return 0;
  7312. }
  7313. if (!item)
  7314. spell = lua_interface->GetCurrentSpell(state);
  7315. if (!item && !spell) {
  7316. lua_interface->LogError("%s: LUA RemoveProc command error: can only use with an item provided or inside a spell script", lua_interface->GetScriptName(state));
  7317. return 0;
  7318. }
  7319. if (spell) {
  7320. Spawn* target;
  7321. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7322. for (int8 i = 0; i < spell->targets.size(); i++) {
  7323. target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  7324. if (!target || !target->IsEntity())
  7325. continue;
  7326. ((Entity*)target)->RemoveProc(item, spell);
  7327. }
  7328. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7329. spell->caster->RemoveProc(item, spell);
  7330. }
  7331. else
  7332. ((Entity*)spawn)->RemoveProc(item, spell);
  7333. return 0;
  7334. }
  7335. int EQ2Emu_lua_Knockback(lua_State* state) {
  7336. if (!lua_interface)
  7337. return 0;
  7338. Spawn* target_spawn = lua_interface->GetSpawn(state);
  7339. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  7340. int32 duration = lua_interface->GetInt32Value(state, 3);
  7341. float vertical = lua_interface->GetFloatValue(state, 4);
  7342. float horizontal = lua_interface->GetFloatValue(state, 5);
  7343. bool use_heading = lua_interface->GetInt8Value(state, 6) == 1 ? true : false;
  7344. if (!target_spawn) {
  7345. lua_interface->LogError("%s: LUA Knockback command error: target_spawn is not valid", lua_interface->GetScriptName(state));
  7346. return 0;
  7347. }
  7348. if (!spawn) {
  7349. lua_interface->LogError("%s: LUA Knockback command error: spawn is not valid", lua_interface->GetScriptName(state));
  7350. return 0;
  7351. }
  7352. if (spawn->IsPlayer() && (vertical != 0 || horizontal != 0)) {
  7353. Client* client = spawn->GetZone()->GetClientBySpawn(spawn);
  7354. PacketStruct* packet = configReader.getStruct("WS_PlayerKnockback", client->GetVersion());
  7355. if (packet) {
  7356. packet->setDataByName("target_x", target_spawn->GetX());
  7357. packet->setDataByName("target_y", target_spawn->GetY());
  7358. packet->setDataByName("target_z", target_spawn->GetZ());
  7359. packet->setDataByName("vertical_movement", vertical);
  7360. packet->setDataByName("horizontal_movement", horizontal);
  7361. if (use_heading)
  7362. packet->setDataByName("use_player_heading", 1);
  7363. client->QueuePacket(packet->serialize());
  7364. }
  7365. safe_delete(packet);
  7366. }
  7367. return 0;
  7368. }
  7369. int EQ2Emu_lua_IsEpic(lua_State* state) {
  7370. if (!lua_interface)
  7371. return 0;
  7372. Spawn* spawn = lua_interface->GetSpawn(state);
  7373. if (!spawn) {
  7374. lua_interface->LogError("%s: LUA IsEpic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7375. return 0;
  7376. }
  7377. lua_interface->SetBooleanValue(state, (spawn->GetHeroic() >= 2));
  7378. return 1;
  7379. }
  7380. int EQ2Emu_lua_ProcDamage(lua_State* state) {
  7381. if (!lua_interface)
  7382. return 0;
  7383. Spawn* caster = lua_interface->GetSpawn(state);
  7384. Spawn* target = lua_interface->GetSpawn(state, 2);
  7385. string name = lua_interface->GetStringValue(state, 3);
  7386. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  7387. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  7388. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  7389. string success_msg = lua_interface->GetStringValue(state, 7);
  7390. string effect_msg = lua_interface->GetStringValue(state, 8);
  7391. if (!caster) {
  7392. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7393. return 0;
  7394. }
  7395. if (!caster->IsEntity()) {
  7396. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  7397. return 0;
  7398. }
  7399. if (!target) {
  7400. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7401. return 0;
  7402. }
  7403. if (!target->IsEntity()) {
  7404. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  7405. return 0;
  7406. }
  7407. if (name.length() == 0) {
  7408. lua_interface->LogError("%s: LUA ProcDamage command error: name is empty", lua_interface->GetScriptName(state));
  7409. return 0;
  7410. }
  7411. ((Entity*)caster)->ProcAttack(target, dmg_type, low_damage, high_damage, name, success_msg, effect_msg);
  7412. return 0;
  7413. }
  7414. int EQ2Emu_lua_GetSkillIDByName(lua_State* state) {
  7415. if (!lua_interface)
  7416. return 0;
  7417. string name = lua_interface->GetStringValue(state);
  7418. if (name.length() == 0) {
  7419. lua_interface->LogError("%s: LUA GetSkillIDByName command error: name param was not set", lua_interface->GetScriptName(state));
  7420. return 0;
  7421. }
  7422. Skill* skill = master_skill_list.GetSkillByName(name.c_str());
  7423. if (!skill) {
  7424. lua_interface->LogError("LUA GetSkillIDByName command error: skill with name of %s not found", name.c_str());
  7425. return 0;
  7426. }
  7427. lua_interface->SetInt32Value(state, skill->skill_id);
  7428. return 1;
  7429. }
  7430. int EQ2Emu_lua_IsHeroic(lua_State* state) {
  7431. if (!lua_interface)
  7432. return 0;
  7433. Spawn* spawn = lua_interface->GetSpawn(state);
  7434. if (!spawn) {
  7435. lua_interface->LogError("%s: LUA IsHeroic command error: spawn is not valid", lua_interface->GetScriptName(state));
  7436. return 0;
  7437. }
  7438. lua_interface->SetBooleanValue(state, spawn->GetHeroic() == 1);
  7439. return 1;
  7440. }
  7441. int EQ2Emu_lua_LastSpellAttackHit(lua_State* state) {
  7442. if (!lua_interface)
  7443. return 0;
  7444. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  7445. if (!luaspell) {
  7446. lua_interface->LogError("%s: LUA LastSpellAttackHit command error: this must be called from a spellscript", lua_interface->GetScriptName(state));
  7447. return 0;
  7448. }
  7449. lua_interface->SetBooleanValue(state, luaspell->last_spellattack_hit);
  7450. return 1;
  7451. }
  7452. int EQ2Emu_lua_IsBehind(lua_State* state) {
  7453. if (!lua_interface)
  7454. return 0;
  7455. Spawn* spawn = lua_interface->GetSpawn(state);
  7456. Spawn* target = lua_interface->GetSpawn(state, 2);
  7457. if (!spawn) {
  7458. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not valid", lua_interface->GetScriptName(state));
  7459. return 0;
  7460. }
  7461. if (!spawn->IsEntity()) {
  7462. lua_interface->LogError("%s: LUA IsBehind command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7463. return 0;
  7464. }
  7465. if (!target) {
  7466. lua_interface->LogError("%s: LUA IsBehind command error: target is not valid", lua_interface->GetScriptName(state));
  7467. return 0;
  7468. }
  7469. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->BehindTarget(target));
  7470. return 1;
  7471. }
  7472. int EQ2Emu_lua_IsFlanking(lua_State* state) {
  7473. if (!lua_interface)
  7474. return 0;
  7475. Spawn* spawn = lua_interface->GetSpawn(state);
  7476. Spawn* target = lua_interface->GetSpawn(state, 2);
  7477. if (!spawn) {
  7478. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not valid", lua_interface->GetScriptName(state));
  7479. return 0;
  7480. }
  7481. if (!spawn->IsEntity()) {
  7482. lua_interface->LogError("%s: LUA IsFlanking command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7483. return 0;
  7484. }
  7485. if (!target) {
  7486. lua_interface->LogError("%s: LUA IsFlanking command error: target is not valid", lua_interface->GetScriptName(state));
  7487. return 0;
  7488. }
  7489. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->FlankingTarget(target));
  7490. return 1;
  7491. }
  7492. int EQ2Emu_lua_GetItemCount(lua_State* state) {
  7493. if (!lua_interface)
  7494. return 0;
  7495. Item* item = lua_interface->GetItem(state);
  7496. if (!item) {
  7497. lua_interface->LogError("%s: LUA GetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7498. return 0;
  7499. }
  7500. lua_interface->SetInt32Value(state, item->details.count);
  7501. return 1;
  7502. }
  7503. int EQ2Emu_lua_SetItemCount(lua_State* state) {
  7504. if (!lua_interface)
  7505. return 0;
  7506. Item* item = lua_interface->GetItem(state);
  7507. Spawn* owner = lua_interface->GetSpawn(state, 2);
  7508. int16 new_count = lua_interface->GetInt32Value(state, 3);
  7509. if (!item) {
  7510. lua_interface->LogError("%s: LUA SetItemCount command error: item not valid", lua_interface->GetScriptName(state));
  7511. return 0;
  7512. }
  7513. if (!owner) {
  7514. lua_interface->LogError("%s: LUA SetItemCount command error: spawn not valid", lua_interface->GetScriptName(state));
  7515. return 0;
  7516. }
  7517. if (!owner->IsPlayer()) {
  7518. lua_interface->LogError("%s: LUA SetItemCount command error: spawn is not a player", lua_interface->GetScriptName(state));
  7519. return 0;
  7520. }
  7521. if (item->stack_count < new_count) {
  7522. lua_interface->LogError("%s: LUA SetItemCount command error: new item count cannot be more than max stack count", lua_interface->GetScriptName(state));
  7523. return 0;
  7524. }
  7525. if (new_count > 0) {
  7526. item->details.count = new_count;
  7527. item->save_needed = true;
  7528. }
  7529. else if (((Player*)owner)->GetEquipmentList()->GetItem(item->details.slot_id) == item)
  7530. ((Player*)owner)->GetEquipmentList()->RemoveItem(item->details.slot_id, true);
  7531. else if (((Player*)owner)->GetPlayerItemList()->GetItemFromUniqueID(item->details.unique_id) == item)
  7532. ((Player*)owner)->GetPlayerItemList()->RemoveItem(item, true);
  7533. else
  7534. {
  7535. lua_interface->LogError("%s: LUA SetItemCount command error: could not remove item from player", lua_interface->GetScriptName(state));
  7536. return 0;
  7537. }
  7538. Client* client = owner->GetZone()->GetClientBySpawn(owner);
  7539. if (!client)
  7540. return 0;
  7541. ((Player*)owner)->SendInventoryUpdate(client->GetVersion());
  7542. EQ2Packet* app = ((Player*)owner)->GetEquipmentList()->serialize(client->GetVersion(), client->GetPlayer());
  7543. if (app)
  7544. client->QueuePacket(app);
  7545. return 0;
  7546. }
  7547. int EQ2Emu_lua_AddSpellTimer(lua_State* state) {
  7548. if (!lua_interface)
  7549. return 0;
  7550. int32 time = lua_interface->GetInt32Value(state);
  7551. string function = lua_interface->GetStringValue(state, 2);
  7552. Spawn* caster = lua_interface->GetSpawn(state, 3);
  7553. Spawn* target = lua_interface->GetSpawn(state, 4);
  7554. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7555. if (time == 0) {
  7556. lua_interface->LogError("%s: LUA AddSpellTimer command error: time must be set", lua_interface->GetScriptName(state));
  7557. return 0;
  7558. }
  7559. if (function.length() == 0) {
  7560. lua_interface->LogError("%s: LUA AddSpellTimer command error: function name must be set", lua_interface->GetScriptName(state));
  7561. return 0;
  7562. }
  7563. if (!spell) {
  7564. lua_interface->LogError("%s: LUA AddSpellTimer command error: spell not found, AddSpellTimer must be used in a spell script", lua_interface->GetScriptName(state));
  7565. return 0;
  7566. }
  7567. SpellScriptTimer* timer = new SpellScriptTimer;
  7568. /* //Google tells me memsetting a string is bad, manually setting just in case - Foof
  7569. #ifdef WIN32
  7570. ZeroMemory(timer, sizeof(SpellScriptTimer));
  7571. #else
  7572. bzero(timer, sizeof(SpellScriptTimer));
  7573. #endif*/
  7574. timer->caster = 0;
  7575. timer->deleteWhenDone = false;
  7576. timer->target = 0;
  7577. timer->time = Timer::GetCurrentTime2() + time;
  7578. timer->customFunction = function;
  7579. timer->spell = spell;
  7580. if (caster)
  7581. timer->caster = caster->GetID();
  7582. if (target)
  7583. timer->target = target->GetID();
  7584. spell->caster->GetZone()->GetSpellProcess()->AddSpellScriptTimer(timer);
  7585. return 0;
  7586. }
  7587. int EQ2Emu_lua_Resurrect(lua_State* state) {
  7588. if (!lua_interface)
  7589. return 0;
  7590. float hp_perc = lua_interface->GetFloatValue(state);
  7591. float power_perc = lua_interface->GetFloatValue(state, 2);
  7592. bool send_window = lua_interface->GetInt32Value(state, 3) == 1;
  7593. Spawn* target = lua_interface->GetSpawn(state, 4);
  7594. string heal_name = lua_interface->GetStringValue(state, 5);
  7595. int8 crit_mod = lua_interface->GetInt32Value(state, 6);
  7596. bool no_calcs = lua_interface->GetInt32Value(state, 7) == 1;
  7597. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7598. if (!spell) {
  7599. lua_interface->LogError("%s: LUA command error: this function must be used in a spellscript", lua_interface->GetScriptName(state));
  7600. return 0;
  7601. }
  7602. Entity* caster = spell->caster;
  7603. if (!caster) {
  7604. lua_interface->LogError("%s: LUA command error: could not find caster", lua_interface->GetScriptName(state));
  7605. return 0;
  7606. }
  7607. Client* client = 0;
  7608. PendingResurrection* rez = 0;
  7609. ZoneServer* zone = spell->caster->GetZone();
  7610. if (!target) {
  7611. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7612. if (spell->targets.size() > 0) {
  7613. vector<int32> spell_targets = spell->targets;
  7614. for (int8 i = 0; i < spell_targets.size(); i++) {
  7615. target = zone->GetSpawnByID(spell_targets.at(i));
  7616. if (!target)
  7617. continue;
  7618. if (!target->IsPlayer())
  7619. continue;
  7620. client = target->GetZone()->GetClientBySpawn(target);
  7621. if (!client)
  7622. continue;
  7623. rez = client->GetCurrentRez();
  7624. if (rez->active)
  7625. continue;
  7626. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7627. rez->active = true;
  7628. rez->caster = caster;
  7629. rez->expire_timer = new Timer;
  7630. int32 duration = spell->spell->GetSpellDuration();
  7631. rez->expire_timer->Start(duration * 100);
  7632. rez->hp_perc = hp_perc;
  7633. rez->mp_perc = power_perc;
  7634. rez->range = spell->spell->GetSpellData()->range;
  7635. rez->spell_name = spell->spell->GetName();
  7636. if (heal_name.length() > 0)
  7637. rez->heal_name = heal_name;
  7638. else
  7639. rez->heal_name = rez->spell_name;
  7640. rez->no_calcs = no_calcs;
  7641. rez->crit_mod = crit_mod;
  7642. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7643. if (send_window)
  7644. client->SendResurrectionWindow();
  7645. else {
  7646. target->GetZone()->ResurrectSpawn(target, client);
  7647. rez->should_delete = true;
  7648. }
  7649. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7650. }
  7651. }
  7652. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7653. }
  7654. else {
  7655. client = target->GetZone()->GetClientBySpawn(target);
  7656. if (!client)
  7657. return 0;
  7658. rez = client->GetCurrentRez();
  7659. if (rez->active)
  7660. return 0;
  7661. client->GetResurrectMutex()->writelock(__FUNCTION__, __LINE__);
  7662. rez->active = true;
  7663. rez->caster = caster;
  7664. rez->expire_timer = new Timer;
  7665. int32 duration = spell->spell->GetSpellDuration();
  7666. rez->expire_timer->Start(duration * 100);
  7667. rez->hp_perc = hp_perc;
  7668. rez->mp_perc = power_perc;
  7669. rez->range = spell->spell->GetSpellData()->range;
  7670. rez->spell_name = spell->spell->GetName();
  7671. if (heal_name.length() > 0)
  7672. rez->heal_name = heal_name;
  7673. else
  7674. rez->heal_name = rez->spell_name;
  7675. rez->no_calcs = no_calcs;
  7676. rez->crit_mod = crit_mod;
  7677. rez->spell_visual = spell->spell->GetSpellData()->spell_visual;
  7678. if (send_window)
  7679. client->SendResurrectionWindow();
  7680. else {
  7681. target->GetZone()->ResurrectSpawn(target, client);
  7682. rez->should_delete = true;
  7683. }
  7684. client->GetResurrectMutex()->releasewritelock(__FUNCTION__, __LINE__);
  7685. }
  7686. return 0;
  7687. }
  7688. int EQ2Emu_lua_SetVision(lua_State* state) {
  7689. if (!lua_interface)
  7690. return 0;
  7691. Spawn* spawn = lua_interface->GetSpawn(state);
  7692. int8 vision = lua_interface->GetInt8Value(state, 2);
  7693. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7694. if (!spawn) {
  7695. lua_interface->LogError("%s: LUA SetVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7696. return 0;
  7697. }
  7698. if (!spawn->IsEntity()) {
  7699. lua_interface->LogError("%s: LUA SetVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7700. return 0;
  7701. }
  7702. if (spell && spell->targets.size() > 0) {
  7703. ZoneServer* zone = spell->caster->GetZone();
  7704. for (int8 i = 0; i < spell->targets.size(); i++) {
  7705. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7706. if (target && target->IsEntity()) {
  7707. ((Entity*)target)->GetInfoStruct()->set_vision(vision);
  7708. if (target->IsPlayer())
  7709. ((Player*)target)->SetCharSheetChanged(true);
  7710. }
  7711. }
  7712. }
  7713. else {
  7714. ((Entity*)spawn)->GetInfoStruct()->set_vision(vision);
  7715. if (spawn->IsPlayer())
  7716. ((Player*)spawn)->SetCharSheetChanged(true);
  7717. }
  7718. return 0;
  7719. }
  7720. int EQ2Emu_lua_BlurVision(lua_State* state) {
  7721. if (!lua_interface)
  7722. return 0;
  7723. Spawn* spawn = lua_interface->GetSpawn(state);
  7724. float intensity = lua_interface->GetFloatValue(state, 2);
  7725. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7726. if (!spawn) {
  7727. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not valid", lua_interface->GetScriptName(state));
  7728. return 0;
  7729. }
  7730. if (!spawn->IsEntity()) {
  7731. lua_interface->LogError("%s: LUA BlurVision command error: spawn is not an entity", lua_interface->GetScriptName(state));
  7732. return 0;
  7733. }
  7734. if (spell && spell->targets.size() > 0) {
  7735. ZoneServer* zone = spell->caster->GetZone();
  7736. for (int8 i = 0; i < spell->targets.size(); i++) {
  7737. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7738. if (target && target->IsEntity()) {
  7739. ((Entity*)target)->GetInfoStruct()->set_drunk(intensity);
  7740. if (target->IsPlayer())
  7741. ((Player*)target)->SetCharSheetChanged(true);
  7742. }
  7743. }
  7744. }
  7745. else {
  7746. ((Entity*)spawn)->GetInfoStruct()->set_drunk(intensity);
  7747. if (spawn->IsPlayer())
  7748. ((Player*)spawn)->SetCharSheetChanged(true);
  7749. }
  7750. return 0;
  7751. }
  7752. int EQ2Emu_lua_BreatheUnderwater(lua_State* state) {
  7753. if (!lua_interface)
  7754. return 0;
  7755. Spawn* spawn = lua_interface->GetSpawn(state);
  7756. bool breatheUnderwater = lua_interface->GetBooleanValue(state, 2);
  7757. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7758. if (!spawn) {
  7759. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not valid", lua_interface->GetScriptName(state));
  7760. return 0;
  7761. }
  7762. if (!spawn->IsEntity()) {
  7763. lua_interface->LogError("%s: LUA BreathUnderwater command error: spawn is not en entity", lua_interface->GetScriptName(state));
  7764. return 0;
  7765. }
  7766. if (spell && spell->targets.size() > 0) {
  7767. ZoneServer* zone = spell->caster->GetZone();
  7768. for (int8 i = 0; i < spell->targets.size(); i++) {
  7769. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7770. if (target && target->IsEntity()) {
  7771. ((Entity*)target)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7772. if (target->IsPlayer())
  7773. ((Player*)target)->SetCharSheetChanged(true);
  7774. }
  7775. }
  7776. }
  7777. else {
  7778. ((Entity*)spawn)->GetInfoStruct()->set_breathe_underwater(breatheUnderwater);
  7779. if (spawn->IsPlayer())
  7780. ((Player*)spawn)->SetCharSheetChanged(true);
  7781. }
  7782. return 0;
  7783. }
  7784. int EQ2Emu_lua_GetItemSkillReq(lua_State* state) {
  7785. if (!lua_interface)
  7786. return 0;
  7787. Item* item = lua_interface->GetItem(state);
  7788. int8 type = lua_interface->GetInt32Value(state, 2);
  7789. if (!item) {
  7790. lua_interface->LogError("%s: LUA GetItemSkillReq command error: item not valid", lua_interface->GetScriptName(state));
  7791. return 0;
  7792. }
  7793. if (type == 1)
  7794. lua_interface->SetInt32Value(state, item->generic_info.skill_req1);
  7795. else if (type == 2)
  7796. lua_interface->SetInt32Value(state, item->generic_info.skill_req2);
  7797. return 1;
  7798. }
  7799. int EQ2Emu_lua_SetSpeedMultiplier(lua_State* state) {
  7800. if (!lua_interface)
  7801. return 0;
  7802. Spawn* target = lua_interface->GetSpawn(state);
  7803. float val = lua_interface->GetFloatValue(state, 2);
  7804. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7805. // Added from Gangrenous post
  7806. if (spell && spell->resisted)
  7807. return 0;
  7808. // if its a percentage of 100 its a slow, we want to go at a fraction of the speed
  7809. if (val > 1.0f)
  7810. val = 1.0f - (val / 100.0f);
  7811. if (spell && spell->spell && spell->targets.size() > 0) {
  7812. ZoneServer* zone = spell->caster->GetZone();
  7813. for (int32 i = 0; i != spell->targets.size(); i++) {
  7814. Spawn* spawn = zone->GetSpawnByID(spell->targets.at(i));
  7815. if (spawn && spawn->IsEntity()) {
  7816. ((Entity*)spawn)->SetSpeedMultiplier(val);
  7817. if (spawn->IsPlayer())
  7818. ((Player*)spawn)->SetCharSheetChanged(true);
  7819. }
  7820. }
  7821. }
  7822. else {
  7823. if (target && target->IsEntity()) {
  7824. ((Entity*)target)->SetSpeedMultiplier(val);
  7825. if (target->IsPlayer())
  7826. ((Player*)target)->SetCharSheetChanged(true);
  7827. }
  7828. }
  7829. return 0;
  7830. }
  7831. int EQ2Emu_lua_SetIllusion(lua_State* state) {
  7832. if (!lua_interface)
  7833. return 0;
  7834. Spawn* spawn = lua_interface->GetSpawn(state);
  7835. int16 model = lua_interface->GetInt16Value(state, 2);
  7836. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7837. if (spell && spell->spell && spell->targets.size() > 0) {
  7838. ZoneServer* zone = spell->caster->GetZone();
  7839. for (int32 i = 0; i < spell->targets.size(); i++) {
  7840. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7841. if (target)
  7842. target->SetIllusionModel(model);
  7843. }
  7844. }
  7845. else {
  7846. if (!spawn) {
  7847. lua_interface->LogError("%s: LUA SetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7848. return 0;
  7849. }
  7850. spawn->SetIllusionModel(model);
  7851. }
  7852. return 0;
  7853. }
  7854. int EQ2Emu_lua_ResetIllusion(lua_State* state) {
  7855. if (!lua_interface)
  7856. return 0;
  7857. Spawn* spawn = lua_interface->GetSpawn(state);
  7858. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7859. if (spell && spell->spell && spell->targets.size() > 0) {
  7860. ZoneServer* zone = spell->caster->GetZone();
  7861. for (int32 i = 0; i < spell->targets.size(); i++) {
  7862. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  7863. if (target)
  7864. target->SetIllusionModel(0);
  7865. }
  7866. }
  7867. else {
  7868. if (!spawn) {
  7869. lua_interface->LogError("%s: LUA ResetIllusion command error: spawn is not valid", lua_interface->GetScriptName(state));
  7870. return 0;
  7871. }
  7872. spawn->SetIllusionModel(0);
  7873. }
  7874. return 0;
  7875. }
  7876. int EQ2Emu_lua_AddThreatTransfer(lua_State* state) {
  7877. if (!lua_interface)
  7878. return 0;
  7879. Spawn* caster = lua_interface->GetSpawn(state);
  7880. Spawn* target = lua_interface->GetSpawn(state, 2);
  7881. float chance = lua_interface->GetFloatValue(state, 3);
  7882. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7883. if (!caster) {
  7884. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  7885. return 0;
  7886. }
  7887. if (!caster->IsEntity()) {
  7888. lua_interface->LogError("%s: LUA AddThreatTransfer command error: caster is not an entity", lua_interface->GetScriptName(state));
  7889. return 0;
  7890. }
  7891. if (!target) {
  7892. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  7893. return 0;
  7894. }
  7895. if (!target->IsEntity()) {
  7896. lua_interface->LogError("%s: LUA AddThreatTransfer command error: target is not an entity", lua_interface->GetScriptName(state));
  7897. return 0;
  7898. }
  7899. if (chance <= 0) {
  7900. lua_interface->LogError("%s: LUA AddThreatTransfer command error: chance must be greater then 0%", lua_interface->GetScriptName(state));
  7901. return 0;
  7902. }
  7903. if (!spell) {
  7904. lua_interface->LogError("%s: LUA AddThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7905. return 0;
  7906. }
  7907. if(spell->resisted) {
  7908. return 0;
  7909. }
  7910. if (((Entity*)caster)->GetThreatTransfer()) {
  7911. return 0;
  7912. }
  7913. ThreatTransfer* transfer = new ThreatTransfer;
  7914. transfer->Target = target->GetID();
  7915. transfer->Amount = chance;
  7916. transfer->Spell = spell;
  7917. ((Entity*)caster)->SetThreatTransfer(transfer);
  7918. return 0;
  7919. }
  7920. int EQ2Emu_lua_RemoveThreatTransfer(lua_State* state) {
  7921. if (!lua_interface)
  7922. return 0;
  7923. Spawn* spawn = lua_interface->GetSpawn(state);
  7924. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7925. if (!spawn) {
  7926. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: spawn is not valid", lua_interface->GetScriptName(state));
  7927. return 0;
  7928. }
  7929. if (!spell) {
  7930. lua_interface->LogError("%s: LUA RemoveThreatTransfer command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7931. return 0;
  7932. }
  7933. if (((Entity*)spawn)->GetThreatTransfer() && ((Entity*)spawn)->GetThreatTransfer()->Spell == spell) {
  7934. ThreatTransfer* transfer = ((Entity*)spawn)->GetThreatTransfer();
  7935. if(transfer && transfer->Spell != spell) {
  7936. lua_interface->LogError("%s: LUA RemoveThreatTransfer called, but there was a different spell set for the threat transfer.", lua_interface->GetScriptName(state));
  7937. return 0;
  7938. }
  7939. ((Entity*)spawn)->SetThreatTransfer(nullptr);
  7940. }
  7941. return 0;
  7942. }
  7943. int EQ2Emu_lua_CureByType(lua_State* state) {
  7944. if (!lua_interface)
  7945. return 0;
  7946. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7947. int8 cure_count = lua_interface->GetInt8Value(state);
  7948. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  7949. string cure_name = lua_interface->GetStringValue(state, 3);
  7950. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  7951. Spawn* target = lua_interface->GetSpawn(state, 5);
  7952. Spawn* caster = lua_interface->GetSpawn(state, 6); // optional
  7953. if(spell && spell->resisted) {
  7954. return 0;
  7955. }
  7956. if (target) {
  7957. if (!target->IsEntity()) {
  7958. lua_interface->LogError("%s: LUA CureByType command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  7959. return 0;
  7960. }
  7961. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  7962. std::string alternate_name = "item";
  7963. if(spell)
  7964. alternate_name = std::string(spell->spell->GetName());
  7965. if(!caster && spell)
  7966. caster = (Spawn*)spell->caster;
  7967. ((Entity*)target)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : alternate_name, (Entity*)caster, cure_level);
  7968. }
  7969. }
  7970. else {
  7971. ZoneServer* zone = spell->caster->GetZone();
  7972. vector<int32> targets = spell->targets;
  7973. vector<Entity*> targets_to_cure;
  7974. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  7975. for (int8 i = 0; i < targets.size(); i++) {
  7976. target = zone->GetSpawnByID(targets.at(i));
  7977. if (!target || !target->IsEntity())
  7978. continue;
  7979. if (((Entity*)target)->GetDetTypeCount(cure_type) > 0) {
  7980. targets_to_cure.push_back((Entity*)target);
  7981. }
  7982. }
  7983. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  7984. vector<Entity*>::iterator itr;
  7985. for(itr = targets_to_cure.begin(); itr != targets_to_cure.end(); itr++) {
  7986. ((Entity*)*itr)->CureDetrimentByType(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  7987. }
  7988. }
  7989. return 0;
  7990. }
  7991. int EQ2Emu_lua_CureByControlEffect(lua_State* state) {
  7992. if (!lua_interface)
  7993. return 0;
  7994. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  7995. if (!spell) {
  7996. lua_interface->LogError("%s: LUA CureByControlEffect command error: can only be used in a spell script", lua_interface->GetScriptName(state));
  7997. return 0;
  7998. }
  7999. if(spell->resisted) {
  8000. return 0;
  8001. }
  8002. int8 cure_count = lua_interface->GetInt8Value(state);
  8003. int8 cure_type = lua_interface->GetInt8Value(state, 2);
  8004. string cure_name = lua_interface->GetStringValue(state, 3);
  8005. int8 cure_level = lua_interface->GetInt8Value(state, 4);
  8006. Spawn* target = lua_interface->GetSpawn(state, 5);
  8007. if (target) {
  8008. if (!target->IsEntity()) {
  8009. lua_interface->LogError("%s: LUA CureByControlEffect command error: spawn override must be entity if used", lua_interface->GetScriptName(state));
  8010. return 0;
  8011. }
  8012. if (((Entity*)target)->GetDetCount() > 0)
  8013. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8014. }
  8015. else {
  8016. ZoneServer* zone = spell->caster->GetZone();
  8017. vector<int32> targets = spell->targets;
  8018. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8019. for (int8 i = 0; i < targets.size(); i++) {
  8020. target = zone->GetSpawnByID(targets.at(i));
  8021. if (!target || !target->IsEntity())
  8022. continue;
  8023. if (((Entity*)target)->GetDetCount() > 0)
  8024. ((Entity*)target)->CureDetrimentByControlEffect(cure_count, cure_type, cure_name.length() > 0 ? cure_name : (string)spell->spell->GetName(), spell->caster, cure_level);
  8025. }
  8026. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8027. }
  8028. return 0;
  8029. }
  8030. int EQ2Emu_lua_CancelSpell(lua_State* state) {
  8031. if (!lua_interface)
  8032. return 0;
  8033. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8034. if (!spell) {
  8035. lua_interface->LogError("%s: LUA CancelSpell command error: can only be use in a spell script", lua_interface->GetScriptName(state));
  8036. return 0;
  8037. }
  8038. if (!spell->caster) {
  8039. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the caster of the spell", lua_interface->GetScriptName(state));
  8040. return 0;
  8041. }
  8042. if (!spell->caster->GetZone()) {
  8043. lua_interface->LogError("%s: LUA CancelSpell command error: unable to get the zone of the caster", lua_interface->GetScriptName(state));
  8044. return 0;
  8045. }
  8046. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8047. return 0;
  8048. }
  8049. int EQ2Emu_lua_RemoveStealth(lua_State* state) {
  8050. if (!lua_interface)
  8051. return 0;
  8052. Spawn* spawn = lua_interface->GetSpawn(state);
  8053. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8054. if (!spell) {
  8055. lua_interface->LogError("%s: LUA RemoveStealth command error: must be used from spell script", lua_interface->GetScriptName(state));
  8056. return 0;
  8057. }
  8058. if (spawn && spawn->IsEntity())
  8059. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8060. else {
  8061. ZoneServer* zone = spell->caster->GetZone();
  8062. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8063. for (int32 i = 0; i < spell->targets.size(); i++) {
  8064. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8065. if (!spawn || !spawn->IsEntity())
  8066. continue;
  8067. ((Entity*)spawn)->RemoveStealthSpell(spell);
  8068. }
  8069. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8070. }
  8071. return 0;
  8072. }
  8073. int EQ2Emu_lua_RemoveInvis(lua_State* state) {
  8074. if (!lua_interface)
  8075. return 0;
  8076. Spawn* spawn = lua_interface->GetSpawn(state);
  8077. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8078. if (!spell) {
  8079. lua_interface->LogError("%s: LUA RemoveInvis command error: must be used from spell script", lua_interface->GetScriptName(state));
  8080. return 0;
  8081. }
  8082. if (spawn && spawn->IsEntity())
  8083. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8084. else {
  8085. ZoneServer* zone = spell->caster->GetZone();
  8086. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8087. for (int32 i = 0; i < spell->targets.size(); i++) {
  8088. spawn = zone->GetSpawnByID(spell->targets.at(i));
  8089. if (!spawn || !spawn->IsEntity())
  8090. continue;
  8091. ((Entity*)spawn)->RemoveInvisSpell(spell);
  8092. }
  8093. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8094. }
  8095. return 0;
  8096. }
  8097. int EQ2Emu_lua_StartHeroicOpportunity(lua_State* state) {
  8098. if (!lua_interface)
  8099. return 0;
  8100. Spawn* caster = lua_interface->GetSpawn(state);
  8101. int8 class_id = lua_interface->GetInt8Value(state, 2);
  8102. if (!caster) {
  8103. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster is not valid", lua_interface->GetScriptName(state));
  8104. return 0;
  8105. }
  8106. if (!caster->IsPlayer()) {
  8107. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: caster must be a player", lua_interface->GetScriptName(state));
  8108. return 0;
  8109. }
  8110. Spawn* target = caster->GetTarget();
  8111. if (!target) {
  8112. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: target is not valid", lua_interface->GetScriptName(state));
  8113. return 0;
  8114. }
  8115. Client* client = caster->GetZone()->GetClientBySpawn(caster);
  8116. if (!client) {
  8117. lua_interface->LogError("%s: LUA StartHeroicOpportunity command error: unable to get a client for the given caster", lua_interface->GetScriptName(state));
  8118. return 0;
  8119. }
  8120. HeroicOP* ho = master_ho_list.GetHeroicOP(class_id);
  8121. if (ho) {
  8122. ho->SetTarget(target->GetID());
  8123. LogWrite(SPELL__ERROR, 0, "HO", "caster: %u", caster->GetID());
  8124. LogWrite(SPELL__ERROR, 0, "HO", "target: %u", target->GetID());
  8125. if (((Entity*)caster)->GetGroupMemberInfo()) {
  8126. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8127. world.GetGroupManager()->GroupLock(__FUNCTION__, __LINE__);
  8128. deque<GroupMemberInfo*>::iterator itr;
  8129. PlayerGroup* group = world.GetGroupManager()->GetGroup(((Entity*)caster)->GetGroupMemberInfo()->group_id);
  8130. if (group)
  8131. {
  8132. group->MGroupMembers.readlock(__FUNCTION__, __LINE__);
  8133. deque<GroupMemberInfo*>* members = group->GetMembers();
  8134. for (itr = members->begin(); itr != members->end(); itr++) {
  8135. if ((*itr)->client)
  8136. ClientPacketFunctions::SendHeroicOPUpdate((*itr)->client, ho);
  8137. }
  8138. group->MGroupMembers.releasereadlock(__FUNCTION__, __LINE__);
  8139. }
  8140. world.GetGroupManager()->ReleaseGroupLock(__FUNCTION__, __LINE__);
  8141. }
  8142. else
  8143. safe_delete(ho);
  8144. }
  8145. else {
  8146. if (caster->GetZone()->GetSpellProcess()->AddHO(client, ho)) {
  8147. ClientPacketFunctions::SendHeroicOPUpdate(client, ho);
  8148. }
  8149. else
  8150. safe_delete(ho);
  8151. }
  8152. }
  8153. return 0;
  8154. }
  8155. int EQ2Emu_lua_SetSpellTriggerCount(lua_State* state) {
  8156. if (!lua_interface)
  8157. return 0;
  8158. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8159. if (!spell) {
  8160. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8161. return 0;
  8162. }
  8163. int16 triggerCount = lua_interface->GetInt16Value(state);
  8164. bool cancel_after_triggers = (lua_interface->GetInt8Value(state, 2) == 1);
  8165. if (!triggerCount) {
  8166. lua_interface->LogError("%s: LUA SetSpellTriggerCount command error: used trigger value equals zero!", lua_interface->GetScriptName(state));
  8167. return 0;
  8168. }
  8169. spell->num_triggers = triggerCount;
  8170. spell->had_triggers = true;
  8171. spell->cancel_after_all_triggers = cancel_after_triggers;
  8172. return 0;
  8173. }
  8174. int EQ2Emu_lua_GetSpellTriggerCount(lua_State* state) {
  8175. if (!lua_interface)
  8176. return 0;
  8177. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8178. if (!spell) {
  8179. lua_interface->LogError("%s: LUA GetSpellTriggerCount command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8180. return 0;
  8181. }
  8182. lua_interface->SetInt32Value(state, spell->num_triggers);
  8183. return 1;
  8184. }
  8185. int EQ2Emu_lua_RemoveTriggerFromSpell(lua_State* state) {
  8186. if (!lua_interface)
  8187. return 0;
  8188. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8189. if (!spell) {
  8190. lua_interface->LogError("%s: LUA RemoveTriggerFromSpell command error: you must use this function in a spellscript!", lua_interface->GetScriptName(state));
  8191. return 0;
  8192. }
  8193. int16 remove_count = lua_interface->GetInt16Value(state);
  8194. if (!remove_count)
  8195. remove_count = 1;
  8196. if (remove_count >= spell->num_triggers) {
  8197. spell->num_triggers = 0;
  8198. if (spell->cancel_after_all_triggers)
  8199. spell->caster->GetZone()->GetSpellProcess()->AddSpellCancel(spell);
  8200. }
  8201. else {
  8202. spell->num_triggers -= remove_count;
  8203. ClientPacketFunctions::SendMaintainedExamineUpdate(spell->caster->GetZone()->GetClientBySpawn(spell->caster), spell->slot_pos, spell->num_triggers, 0);
  8204. }
  8205. return 0;
  8206. }
  8207. int EQ2Emu_lua_CopySpawnAppearance(lua_State* state) {
  8208. if (!lua_interface)
  8209. return 0;
  8210. Spawn* spawn = lua_interface->GetSpawn(state);
  8211. Spawn* copy_spawn = lua_interface->GetSpawn(state, 2);
  8212. if (!spawn) {
  8213. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the first spawn used was not valid!", lua_interface->GetScriptName(state));
  8214. return 0;
  8215. }
  8216. if (!copy_spawn) {
  8217. lua_interface->LogError("%s: LUA CopySpawnAppearance command error: the second spawn used was not valid!", lua_interface->GetScriptName(state));
  8218. return 0;
  8219. }
  8220. spawn->CopySpawnAppearance(copy_spawn);
  8221. return 0;
  8222. }
  8223. int EQ2Emu_lua_HasSpellImmunity(lua_State* state) {
  8224. Spawn* spawn = lua_interface->GetSpawn(state);
  8225. int8 type = lua_interface->GetInt8Value(state, 2);
  8226. if (!spawn) {
  8227. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn does not exist.", lua_interface->GetScriptName(state));
  8228. return 0;
  8229. }
  8230. else if (!spawn->IsEntity()) {
  8231. lua_interface->LogError("%s: LUA HasSpellImmunity command error: spawn %s is not an entity.", lua_interface->GetScriptName(state), spawn->GetName());
  8232. return 0;
  8233. }
  8234. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->IsImmune(type));
  8235. return 1;
  8236. }
  8237. int EQ2Emu_lua_AddImmunitySpell(lua_State* state) {
  8238. if (!lua_interface)
  8239. return 0;
  8240. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8241. int8 type = lua_interface->GetInt8Value(state);
  8242. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8243. if (!spell) {
  8244. lua_interface->LogError("%s: LUA AddImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8245. return 0;
  8246. }
  8247. if(spell->resisted) {
  8248. return 0;
  8249. }
  8250. if (spawn) {
  8251. if (!spawn->IsEntity()) {
  8252. lua_interface->LogError("%s: LUA AddImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8253. return 0;
  8254. }
  8255. Entity* entity = ((Entity*)spawn);
  8256. entity->AddImmunity(spell, type);
  8257. }
  8258. else {
  8259. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8260. for (int8 i = 0; i < spell->targets.size(); i++) {
  8261. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8262. if (!spawn || !spawn->IsEntity())
  8263. continue;
  8264. Entity* entity = ((Entity*)spawn);
  8265. entity->AddImmunity(spell, type);
  8266. }
  8267. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8268. }
  8269. return 0;
  8270. }
  8271. int EQ2Emu_lua_RemoveImmunitySpell(lua_State* state) {
  8272. if (!lua_interface)
  8273. return 0;
  8274. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8275. int8 type = lua_interface->GetInt8Value(state);
  8276. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8277. if (!spell) {
  8278. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: This must be used in a spellscript", lua_interface->GetScriptName(state));
  8279. return 0;
  8280. }
  8281. if (spawn) {
  8282. if (!spawn->IsEntity()) {
  8283. lua_interface->LogError("%s: LUA RemoveImmunitySpell command error: The spawn provided is not an entity", lua_interface->GetScriptName(state));
  8284. return 0;
  8285. }
  8286. Entity* entity = ((Entity*)spawn);
  8287. entity->RemoveImmunity(spell, type);
  8288. }
  8289. else {
  8290. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8291. for (int8 i = 0; i < spell->targets.size(); i++) {
  8292. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8293. if (!spawn || !spawn->IsEntity())
  8294. continue;
  8295. Entity* entity = ((Entity*)spawn);
  8296. entity->RemoveImmunity(spell, type);
  8297. }
  8298. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8299. }
  8300. return 0;
  8301. }
  8302. int EQ2Emu_lua_SetSpellSnareValue(lua_State* state) {
  8303. if (!lua_interface)
  8304. return 0;
  8305. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8306. if (!spell) {
  8307. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: This can only be used in a spell script!", lua_interface->GetScriptName(state));
  8308. return 0;
  8309. }
  8310. if(spell->resisted) {
  8311. return 0;
  8312. }
  8313. float snare = lua_interface->GetFloatValue(state);
  8314. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  8315. // convert the val to the speed multipler value (100 - val)
  8316. float val = 100.0 - snare;
  8317. val /= 100.0;
  8318. if (spawn) {
  8319. if (!spawn->IsEntity()) {
  8320. lua_interface->LogError("%s: LUA SetSpellSnareValue command error: spawn must be an entity.", lua_interface->GetScriptName(state));
  8321. return 0;
  8322. }
  8323. ((Entity*)spawn)->SetSnareValue(spell, val);
  8324. }
  8325. else {
  8326. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  8327. for (int8 i = 0; i < spell->targets.size(); i++) {
  8328. spawn = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  8329. if (!spawn || !spawn->IsEntity())
  8330. continue;
  8331. ((Entity*)spawn)->SetSnareValue(spell, val);
  8332. }
  8333. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  8334. }
  8335. return 0;
  8336. }
  8337. int EQ2Emu_lua_CheckRaceType(lua_State* state) {
  8338. if (!lua_interface)
  8339. return 0;
  8340. Spawn* spawn = lua_interface->GetSpawn(state);
  8341. int16 race_id = lua_interface->GetInt16Value(state, 2);
  8342. if (!spawn) {
  8343. lua_interface->LogError("%s: LUA CheckRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8344. return 0;
  8345. }
  8346. if (race_id == 0) {
  8347. lua_interface->LogError("%s: LUA CheckRaceType command error: race id must be set", lua_interface->GetScriptName(state));
  8348. return 0;
  8349. }
  8350. lua_interface->SetBooleanValue(state, (race_id == race_types_list.GetRaceType(spawn->GetModelType()) || race_id == race_types_list.GetRaceBaseType(spawn->GetModelType())));
  8351. return 1;
  8352. }
  8353. int EQ2Emu_lua_GetRaceType(lua_State* state) {
  8354. if (!lua_interface)
  8355. return 0;
  8356. Spawn* spawn = lua_interface->GetSpawn(state);
  8357. if (!spawn) {
  8358. lua_interface->LogError("%s: LUA GetRaceType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8359. return 0;
  8360. }
  8361. lua_interface->SetInt32Value(state, race_types_list.GetRaceType(spawn->GetModelType()));
  8362. return 1;
  8363. }
  8364. int EQ2Emu_lua_GetRaceBaseType(lua_State* state) {
  8365. if (!lua_interface)
  8366. return 0;
  8367. Spawn* spawn = lua_interface->GetSpawn(state);
  8368. if (!spawn) {
  8369. lua_interface->LogError("%s: LUA GetRaceBaseType command error: spawn is not valid", lua_interface->GetScriptName(state));
  8370. return 0;
  8371. }
  8372. lua_interface->SetInt32Value(state, race_types_list.GetRaceBaseType(spawn->GetModelType()));
  8373. return 1;
  8374. }
  8375. int EQ2Emu_lua_GetSpellName(lua_State* state) {
  8376. if (!lua_interface)
  8377. return 0;
  8378. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  8379. if (!spell) {
  8380. lua_interface->LogError("%s: LUA GetSpellName command error: this function must be used from a spell script!", lua_interface->GetScriptName(state));
  8381. return 0;
  8382. }
  8383. lua_interface->SetStringValue(state, spell->spell->GetName());
  8384. return 1;
  8385. }
  8386. int EQ2Emu_lua_GetQuestFlags(lua_State* state) {
  8387. if (!lua_interface)
  8388. return 0;
  8389. Quest* quest = lua_interface->GetQuest(state);
  8390. if (!quest) {
  8391. lua_interface->LogError("%s: LUA GetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8392. return 0;
  8393. }
  8394. lua_interface->SetInt32Value(state, quest->GetQuestFlags());
  8395. return 1;
  8396. }
  8397. int EQ2Emu_lua_SetQuestFlags(lua_State* state) {
  8398. if (!lua_interface)
  8399. return 0;
  8400. Quest* quest = lua_interface->GetQuest(state);
  8401. int32 flags = lua_interface->GetInt32Value(state, 2);
  8402. if (!quest) {
  8403. lua_interface->LogError("%s: LUA SetQuestFlags command error: quest is not valid.", lua_interface->GetScriptName(state));
  8404. return 0;
  8405. }
  8406. quest->SetQuestFlags(flags);
  8407. return 0;
  8408. }
  8409. int EQ2Emu_lua_SetQuestTimer(lua_State* state) {
  8410. if (!lua_interface)
  8411. return 0;
  8412. Quest* quest = lua_interface->GetQuest(state);
  8413. Spawn* player = lua_interface->GetSpawn(state, 2);
  8414. int32 step = lua_interface->GetInt32Value(state, 3);
  8415. int32 duration = lua_interface->GetInt32Value(state, 4);
  8416. string action = lua_interface->GetStringValue(state, 5);
  8417. if (!quest) {
  8418. lua_interface->LogError("%s: LUA SetQuestTimer command error: quest is not valid.", lua_interface->GetScriptName(state));
  8419. return 0;
  8420. }
  8421. if (!player) {
  8422. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8423. return 0;
  8424. }
  8425. if (!player->IsPlayer()) {
  8426. lua_interface->LogError("%s: LUA SetQuestTimer command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8427. return 0;
  8428. }
  8429. if (step == 0) {
  8430. lua_interface->LogError("%s: LUA SetQuestTimer command error: step must be set.", lua_interface->GetScriptName(state));
  8431. return 0;
  8432. }
  8433. if (duration == 0) {
  8434. lua_interface->LogError("%s: LUA SetQuestTimer command error: duration must be set.", lua_interface->GetScriptName(state));
  8435. return 0;
  8436. }
  8437. if (action.length() == 0) {
  8438. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed action must be set.", lua_interface->GetScriptName(state));
  8439. return 0;
  8440. }
  8441. Client* client = player->GetZone()->GetClientBySpawn(player);
  8442. if (!client) {
  8443. lua_interface->LogError("%s: LUA SetQuestTimer command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8444. return 0;
  8445. }
  8446. quest->SetTimerStep(step);
  8447. quest->AddFailedAction(step, action);
  8448. quest->SetStepTimer(duration);
  8449. client->AddQuestTimer(quest->GetQuestID());
  8450. return 0;
  8451. }
  8452. int EQ2Emu_lua_SetQuestTimerComplete(lua_State* state) {
  8453. if (!lua_interface)
  8454. return 0;
  8455. Quest* quest = lua_interface->GetQuest(state);
  8456. Spawn* player = lua_interface->GetSpawn(state, 2);
  8457. if (!quest) {
  8458. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: quest is not valid.", lua_interface->GetScriptName(state));
  8459. return 0;
  8460. }
  8461. if (!player) {
  8462. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8463. return 0;
  8464. }
  8465. if (!player->IsPlayer()) {
  8466. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8467. return 0;
  8468. }
  8469. Client* client = player->GetZone()->GetClientBySpawn(player);
  8470. if (!client) {
  8471. lua_interface->LogError("%s: LUA SetQuestTimerComplete command error: failed to get a valid client pointer for the given player", lua_interface->GetScriptName(state));
  8472. return 0;
  8473. }
  8474. quest->SetTimerStep(0);
  8475. quest->SetStepTimer(0);
  8476. client->RemoveQuestTimer(quest->GetQuestID());
  8477. return 0;
  8478. }
  8479. int EQ2Emu_lua_RemoveQuestStep(lua_State* state) {
  8480. if (!lua_interface)
  8481. return 0;
  8482. Spawn* player = lua_interface->GetSpawn(state);
  8483. Quest* quest = lua_interface->GetQuest(state, 2);
  8484. int32 step = lua_interface->GetInt32Value(state, 3);
  8485. if (!player) {
  8486. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8487. return 0;
  8488. }
  8489. if (!player->IsPlayer()) {
  8490. lua_interface->LogError("%s: LUA RemoveQuestStep command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8491. return 0;
  8492. }
  8493. if (!quest) {
  8494. lua_interface->LogError("%s: LUA RemoveQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8495. return 0;
  8496. }
  8497. if (step == 0) {
  8498. lua_interface->LogError("%s: LUA RemoveQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8499. return 0;
  8500. }
  8501. Client* client = player->GetZone()->GetClientBySpawn(player);
  8502. if (!client) {
  8503. lua_interface->LogError("%s: LUA RemoveQuestStep command error: unable to get a valid client pointer from the given player.", lua_interface->GetScriptName(state));
  8504. return 0;
  8505. }
  8506. if (quest->RemoveQuestStep(step, client)) {
  8507. client->QueuePacket(quest->QuestJournalReply(client->GetVersion(), client->GetNameCRC(), (Player*)player, 0, 0, 0, true));
  8508. client->GetCurrentZone()->SendQuestUpdates(client);
  8509. }
  8510. else
  8511. lua_interface->LogError("LUA RemoveQuestStep command error: unable to remove the step (%u) from the quest (%s).", step, quest->GetName());
  8512. return 0;
  8513. }
  8514. int EQ2Emu_lua_ResetQuestStep(lua_State* state) {
  8515. if (!lua_interface)
  8516. return 0;
  8517. Quest* quest = lua_interface->GetQuest(state, 1);
  8518. int32 step = lua_interface->GetInt32Value(state, 2);
  8519. string desc = lua_interface->GetStringValue(state, 3);
  8520. string task_group = lua_interface->GetStringValue(state, 4);
  8521. if (!quest) {
  8522. lua_interface->LogError("%s: LUA ResetQuestStep command error: quest is not valid.", lua_interface->GetScriptName(state));
  8523. return 0;
  8524. }
  8525. if (step == 0) {
  8526. lua_interface->LogError("%s: LUA ResetQuestStep command error: step must be set.", lua_interface->GetScriptName(state));
  8527. return 0;
  8528. }
  8529. QuestStep* quest_step = quest->GetQuestStep(step);
  8530. if (!quest_step) {
  8531. lua_interface->LogError("%s: LUA ResetQuestStep command error: unable to get a valid quest step.", lua_interface->GetScriptName(state));
  8532. return 0;
  8533. }
  8534. quest_step->SetStepProgress(0);
  8535. quest_step->SetTaskGroup(task_group);
  8536. quest_step->SetDescription(desc);
  8537. return 0;
  8538. }
  8539. int EQ2Emu_lua_AddQuestStepFailureAction(lua_State* state) {
  8540. if (!lua_interface)
  8541. return 0;
  8542. Quest* quest = lua_interface->GetQuest(state);
  8543. int32 step = lua_interface->GetInt32Value(state, 2);
  8544. string action = lua_interface->GetStringValue(state, 3);
  8545. if (!quest) {
  8546. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: quest is not valid.", lua_interface->GetScriptName(state));
  8547. return 0;
  8548. }
  8549. if (step == 0) {
  8550. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: step must be set.", lua_interface->GetScriptName(state));
  8551. return 0;
  8552. }
  8553. if (action.length() == 0) {
  8554. lua_interface->LogError("%s: LUA AddQuestStepFailureAction command error: action must be set.", lua_interface->GetScriptName(state));
  8555. return 0;
  8556. }
  8557. quest->AddFailedAction(step, action);
  8558. return 0;
  8559. }
  8560. int EQ2Emu_lua_SetStepFailed(lua_State* state) {
  8561. if (!lua_interface)
  8562. return 0;
  8563. Spawn* player = lua_interface->GetSpawn(state);
  8564. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8565. int32 step = lua_interface->GetInt32Value(state, 3);
  8566. if (!player) {
  8567. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid spawn.", lua_interface->GetScriptName(state));
  8568. return 0;
  8569. }
  8570. if (!player->IsPlayer()) {
  8571. lua_interface->LogError("%s: LUA SetStepFailed command error: player is not a valid player.", lua_interface->GetScriptName(state));
  8572. return 0;
  8573. }
  8574. if (quest_id == 0) {
  8575. lua_interface->LogError("%s: LUA SetStepFailed command error: quest_id must be set.", lua_interface->GetScriptName(state));
  8576. return 0;
  8577. }
  8578. if (step == 0) {
  8579. lua_interface->LogError("%s: LUA SetStepFailed command error: step must be set.", lua_interface->GetScriptName(state));
  8580. return 0;
  8581. }
  8582. Quest* quest = ((Player*)player)->GetQuest(quest_id);
  8583. if (!quest) {
  8584. lua_interface->LogError("LUA SetStepFailed command error: unable to get a valid quest from the given id (%u).", quest_id);
  8585. return 0;
  8586. }
  8587. quest->StepFailed(step);
  8588. return 0;
  8589. }
  8590. int EQ2Emu_lua_GetQuestCompleteCount(lua_State* state) {
  8591. if (!lua_interface)
  8592. return 0;
  8593. Spawn* player = lua_interface->GetSpawn(state);
  8594. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8595. if (!player) {
  8596. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid spawn", lua_interface->GetScriptName(state));
  8597. return 0;
  8598. }
  8599. if (!player->IsPlayer()) {
  8600. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: player is not a valid player", lua_interface->GetScriptName(state));
  8601. return 0;
  8602. }
  8603. if (quest_id == 0) {
  8604. lua_interface->LogError("%s: LUA GetQuestCompleteCount command error: quest id is not valid", lua_interface->GetScriptName(state));
  8605. return 0;
  8606. }
  8607. Quest* quest = ((Player*)player)->GetCompletedQuest(quest_id);
  8608. if (!quest) {
  8609. lua_interface->SetInt32Value(state, 0);
  8610. return 1;
  8611. }
  8612. lua_interface->SetInt32Value(state, quest->GetCompleteCount());
  8613. return 1;
  8614. }
  8615. int EQ2Emu_lua_SetServerVariable(lua_State* state) {
  8616. if (!lua_interface)
  8617. return 0;
  8618. string name = lua_interface->GetStringValue(state);
  8619. string value = lua_interface->GetStringValue(state, 2);
  8620. string comment = lua_interface->GetStringValue(state, 3);
  8621. if (name.length() == 0) {
  8622. lua_interface->LogError("%s: LUA SetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8623. return 0;
  8624. }
  8625. if (value.length() == 0) {
  8626. lua_interface->LogError("%s: LUA SetServerVariable command error: value is not valid", lua_interface->GetScriptName(state));
  8627. return 0;
  8628. }
  8629. string varname = string("lua_").append(name);
  8630. Variable* var = variables.FindVariable(varname);
  8631. if (var)
  8632. var->SetValue(value.c_str());
  8633. else {
  8634. var = new Variable(varname.c_str(), value.c_str(), comment.c_str());
  8635. variables.AddVariable(var);
  8636. }
  8637. database.SaveVariable(var->GetName(), var->GetValue(), var->GetComment());
  8638. return 0;
  8639. }
  8640. int EQ2Emu_lua_GetServerVariable(lua_State* state) {
  8641. if (!lua_interface)
  8642. return 0;
  8643. string name = lua_interface->GetStringValue(state);
  8644. if (name.length() == 0) {
  8645. lua_interface->LogError("%s: LUA GetServerVariable command error: name is not valid", lua_interface->GetScriptName(state));
  8646. return 0;
  8647. }
  8648. string varname = string("lua_").append(name);
  8649. Variable* var = variables.FindVariable(varname);
  8650. if (var)
  8651. lua_interface->SetStringValue(state, var->GetValue());
  8652. else
  8653. lua_interface->SetStringValue(state, "NULL");
  8654. return 1;
  8655. }
  8656. int EQ2Emu_lua_HasLanguage(lua_State* state) {
  8657. if (!lua_interface)
  8658. return 0;
  8659. Spawn* player = lua_interface->GetSpawn(state);
  8660. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8661. if (!player) {
  8662. lua_interface->LogError("%s: LUA HasLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8663. return 0;
  8664. }
  8665. if (!player->IsPlayer()) {
  8666. lua_interface->LogError("%s: LUA HasLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8667. return 0;
  8668. }
  8669. lua_interface->SetBooleanValue(state, ((Player*)player)->HasLanguage(language_id));
  8670. return 1;
  8671. }
  8672. int EQ2Emu_lua_AddLanguage(lua_State* state) {
  8673. if (!lua_interface)
  8674. return 0;
  8675. Spawn* player = lua_interface->GetSpawn(state);
  8676. int32 language_id = lua_interface->GetInt32Value(state, 2);
  8677. if (!player) {
  8678. lua_interface->LogError("%s: LUA AddLanguage command error: player is not valid", lua_interface->GetScriptName(state));
  8679. return 0;
  8680. }
  8681. if (!player->IsPlayer()) {
  8682. lua_interface->LogError("%s: LUA AddLanguage command error: player is not a valid player", lua_interface->GetScriptName(state));
  8683. return 0;
  8684. }
  8685. Language* language = master_languages_list.GetLanguage(language_id);
  8686. if (language)
  8687. {
  8688. ((Player*)player)->AddLanguage(language->GetID(), language->GetName(), true);
  8689. ((Player*)player)->GetClient()->SendLanguagesUpdate(language->GetID());
  8690. }
  8691. return 0;
  8692. }
  8693. int EQ2Emu_lua_IsNight(lua_State* state) {
  8694. if (!lua_interface)
  8695. return 0;
  8696. ZoneServer* zone = lua_interface->GetZone(state);
  8697. if (!zone) {
  8698. lua_interface->LogError("%s: LUA IsNight command error: zone is not valid", lua_interface->GetScriptName(state));
  8699. return 0;
  8700. }
  8701. lua_interface->SetBooleanValue(state, zone->IsDusk());
  8702. return 1;
  8703. }
  8704. int EQ2Emu_lua_AddMultiFloorLift(lua_State* state) {
  8705. if (!lua_interface)
  8706. return 0;
  8707. Spawn* spawn = lua_interface->GetSpawn(state);
  8708. if (!spawn) {
  8709. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not valid", lua_interface->GetScriptName(state));
  8710. return 0;
  8711. }
  8712. if (!spawn->IsWidget()) {
  8713. lua_interface->LogError("%s: LUA AddMultiFloorLift command error: spawn is not a widget", lua_interface->GetScriptName(state));
  8714. return 0;
  8715. }
  8716. ((Widget*)spawn)->SetMultiFloorLift(true);
  8717. if (spawn->GetZone())
  8718. spawn->GetZone()->AddTransportSpawn(spawn);
  8719. return 0;
  8720. }
  8721. int EQ2Emu_lua_StartAutoMount(lua_State* state) {
  8722. if (!lua_interface)
  8723. return 0;
  8724. Spawn* player = lua_interface->GetSpawn(state);
  8725. int32 path = lua_interface->GetInt32Value(state, 2);
  8726. if (!player) {
  8727. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8728. return 0;
  8729. }
  8730. if (!player->IsPlayer()) {
  8731. lua_interface->LogError("%s: LUA StartAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8732. return 0;
  8733. }
  8734. if (path == 0) {
  8735. lua_interface->LogError("%s: LUA StartAutoMount command error: path must be greater then zero", lua_interface->GetScriptName(state));
  8736. return 0;
  8737. }
  8738. Client* client = player->GetZone()->GetClientBySpawn(player);
  8739. if (!client) {
  8740. lua_interface->LogError("%s: LUA StartAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8741. return 0;
  8742. }
  8743. client->SendFlightAutoMount(path);
  8744. return 0;
  8745. }
  8746. int EQ2Emu_lua_EndAutoMount(lua_State* state) {
  8747. if (!lua_interface)
  8748. return 0;
  8749. Spawn* player = lua_interface->GetSpawn(state);
  8750. if (!player) {
  8751. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not valid", lua_interface->GetScriptName(state));
  8752. return 0;
  8753. }
  8754. if (!player->IsPlayer()) {
  8755. lua_interface->LogError("%s: LUA EndAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8756. return 0;
  8757. }
  8758. Client* client = player->GetZone()->GetClientBySpawn(player);
  8759. if (!client) {
  8760. lua_interface->LogError("%s: LUA EndAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8761. return 0;
  8762. }
  8763. client->EndAutoMount();
  8764. return 0;
  8765. }
  8766. int EQ2Emu_lua_IsOnAutoMount(lua_State* state) {
  8767. if (!lua_interface)
  8768. return 0;
  8769. Spawn* player = lua_interface->GetSpawn(state);
  8770. if (!player) {
  8771. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn in not valid", lua_interface->GetScriptName(state));
  8772. return 0;
  8773. }
  8774. if (!player->IsPlayer()) {
  8775. lua_interface->LogError("%s: LUA IsOnAutoMount command error: spawn is not a player", lua_interface->GetScriptName(state));
  8776. return 0;
  8777. }
  8778. Client* client = player->GetZone()->GetClientBySpawn(player);
  8779. if (!client) {
  8780. lua_interface->LogError("%s: LUA IsOnAutoMount command error: unable to get a client from the given player", lua_interface->GetScriptName(state));
  8781. return 0;
  8782. }
  8783. lua_interface->SetBooleanValue(state, client->GetOnAutoMount());
  8784. return 1;
  8785. }
  8786. int EQ2Emu_lua_SetPlayerHistory(lua_State* state) {
  8787. if (!lua_interface)
  8788. return 0;
  8789. Spawn* player = lua_interface->GetSpawn(state);
  8790. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8791. int32 value = lua_interface->GetInt32Value(state, 3);
  8792. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8793. if (!player) {
  8794. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8795. return 0;
  8796. }
  8797. if (!player->IsPlayer()) {
  8798. lua_interface->LogError("%s: LUA SetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8799. return 0;
  8800. }
  8801. ((Player*)player)->UpdateLUAHistory(event_id, value, value2);
  8802. return 0;
  8803. }
  8804. int EQ2Emu_lua_GetPlayerHistory(lua_State* state) {
  8805. if (!lua_interface)
  8806. return 0;
  8807. Spawn* player = lua_interface->GetSpawn(state);
  8808. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8809. if (!player) {
  8810. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8811. return 0;
  8812. }
  8813. if (!player->IsPlayer()) {
  8814. lua_interface->LogError("%s: LUA GetPlayerHistory command error: spawn is not a player", lua_interface->GetScriptName(state));
  8815. return 0;
  8816. }
  8817. LUAHistory* hd = ((Player*)player)->GetLUAHistory(event_id);
  8818. if (!hd)
  8819. return 0;
  8820. lua_interface->SetInt32Value(state, hd->Value);
  8821. lua_interface->SetInt32Value(state, hd->Value2);
  8822. return 2;
  8823. }
  8824. int EQ2Emu_lua_SetGridID(lua_State* state) {
  8825. if (!lua_interface)
  8826. return 0;
  8827. Spawn* spawn = lua_interface->GetSpawn(state);
  8828. int32 grid = lua_interface->GetInt32Value(state, 2);
  8829. if (!spawn) {
  8830. lua_interface->LogError("%s: LUA SetGridID command error: spawn is not valid", lua_interface->GetScriptName(state));
  8831. return 0;
  8832. }
  8833. if (grid == 0) {
  8834. lua_interface->LogError("%s: LUA SetGridID command error: grid is not valid", lua_interface->GetScriptName(state));
  8835. return 0;
  8836. }
  8837. spawn->SetPos(&(spawn->appearance.pos.grid_id), grid);
  8838. return 0;
  8839. }
  8840. int EQ2Emu_lua_SetRequiredHistory(lua_State* state) {
  8841. if (!lua_interface)
  8842. return 0;
  8843. Spawn* spawn = lua_interface->GetSpawn(state);
  8844. int32 event_id = lua_interface->GetInt32Value(state, 2);
  8845. int32 value1 = lua_interface->GetInt32Value(state, 3);
  8846. int32 value2 = lua_interface->GetInt32Value(state, 4);
  8847. bool private_spawn = (lua_interface->GetInt8Value(state, 5) == 1);
  8848. int16 flag_override = lua_interface->GetInt16Value(state, 6);
  8849. if (!spawn) {
  8850. lua_interface->LogError("%s: LUA SetRequiredHistory command error: spawn is not valid", lua_interface->GetScriptName(state));
  8851. return 0;
  8852. }
  8853. //Add this quest to the list of required quests for this spawn
  8854. spawn->SetRequiredHistory(event_id, value1, value2);
  8855. //If private spawn value set
  8856. if (private_spawn) {
  8857. //Set the spawn to be private when not granted access via history
  8858. spawn->AddAllowAccessSpawn(spawn);
  8859. spawn->SetPrivateQuestSpawn(true);
  8860. }
  8861. //This value will override vis_flags in the vis packet
  8862. if (flag_override > 0)
  8863. spawn->SetQuestsRequiredOverride(flag_override);
  8864. return 0;
  8865. }
  8866. int EQ2Emu_lua_GetQuestStepProgress(lua_State* state) {
  8867. if (!lua_interface)
  8868. return 0;
  8869. Spawn* player = lua_interface->GetSpawn(state);
  8870. int32 quest_id = lua_interface->GetInt32Value(state, 2);
  8871. int32 step_id = lua_interface->GetInt32Value(state, 3);
  8872. if (!player) {
  8873. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not valid", lua_interface->GetScriptName(state));
  8874. return 0;
  8875. }
  8876. if (!player->IsPlayer()) {
  8877. lua_interface->LogError("%s: LUA GetQuestStepProgress command error: spawn is not a player", lua_interface->GetScriptName(state));
  8878. return 0;
  8879. }
  8880. lua_interface->SetInt32Value(state, ((Player*)player)->GetStepProgress(quest_id, step_id));
  8881. return 1;
  8882. }
  8883. int EQ2Emu_lua_SetPlayerLevel(lua_State* state) {
  8884. if (!lua_interface)
  8885. return 0;
  8886. Spawn* player = lua_interface->GetSpawn(state);
  8887. int8 level = lua_interface->GetInt8Value(state, 2);
  8888. if (!player) {
  8889. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not valid", lua_interface->GetScriptName(state));
  8890. return 0;
  8891. }
  8892. if (!player->IsPlayer()) {
  8893. lua_interface->LogError("%s: LUA SetPlayerLevel command error: spawn is not a player", lua_interface->GetScriptName(state));
  8894. return 0;
  8895. }
  8896. if (level == 0) {
  8897. lua_interface->LogError("%s: LUA SetPlayerLevel command error: new level can't be 0", lua_interface->GetScriptName(state));
  8898. return 0;
  8899. }
  8900. Client* client = player->GetZone()->GetClientBySpawn(player);
  8901. if (!client) {
  8902. lua_interface->LogError("%s: LUA SetPlayerLevel command error: unable to get a client from the given spawn", lua_interface->GetScriptName(state));
  8903. return 0;
  8904. }
  8905. client->ChangeLevel(client->GetPlayer()->GetLevel(), level);
  8906. return 0;
  8907. }
  8908. int EQ2Emu_lua_AddCoin(lua_State* state) {
  8909. if (!lua_interface)
  8910. return 0;
  8911. Spawn* player = lua_interface->GetSpawn(state);
  8912. int32 amount = lua_interface->GetInt32Value(state, 2);
  8913. if (!player) {
  8914. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8915. return 0;
  8916. }
  8917. if (!player->IsPlayer()) {
  8918. lua_interface->LogError("%s: LUA AddCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8919. return 0;
  8920. }
  8921. if (amount == 0) {
  8922. lua_interface->LogError("%s: LUA AddCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8923. return 0;
  8924. }
  8925. ((Player*)player)->AddCoins(amount);
  8926. return 0;
  8927. }
  8928. int EQ2Emu_lua_RemoveCoin(lua_State* state) {
  8929. if (!lua_interface)
  8930. return 0;
  8931. Spawn* player = lua_interface->GetSpawn(state);
  8932. int32 amount = lua_interface->GetInt32Value(state, 2);
  8933. if (!player) {
  8934. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not valid", lua_interface->GetScriptName(state));
  8935. return 0;
  8936. }
  8937. if (!player->IsPlayer()) {
  8938. lua_interface->LogError("%s: LUA RemoveCoin command error: spawn is not a player", lua_interface->GetScriptName(state));
  8939. return 0;
  8940. }
  8941. if (amount == 0) {
  8942. lua_interface->LogError("%s: LUA RemoveCoin command error: amount must be greater then 0", lua_interface->GetScriptName(state));
  8943. return 0;
  8944. }
  8945. lua_interface->SetBooleanValue(state, ((Player*)player)->RemoveCoins(amount));
  8946. return 1;
  8947. }
  8948. int EQ2Emu_lua_GetPlayersInZone(lua_State* state) {
  8949. if (!lua_interface)
  8950. return 0;
  8951. ZoneServer* zone = lua_interface->GetZone(state);
  8952. if (!zone) {
  8953. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8954. return 0;
  8955. }
  8956. vector<Entity*> players = zone->GetPlayers();
  8957. if (players.size() == 0)
  8958. return 0;
  8959. lua_createtable(state, players.size(), 0);
  8960. int newTable = lua_gettop(state);
  8961. for (int32 i = 0; i < players.size(); i++) {
  8962. lua_interface->SetSpawnValue(state, players.at(i));
  8963. lua_rawseti(state, newTable, i + 1);
  8964. }
  8965. return 1;
  8966. }
  8967. int EQ2Emu_lua_SpawnGroupByID(lua_State* state) {
  8968. if (!lua_interface)
  8969. return 0;
  8970. ZoneServer* zone = lua_interface->GetZone(state, 1);
  8971. if (!zone) {
  8972. lua_interface->LogError("%s: LUA GetPlayersInZone command error: zone is not valid", lua_interface->GetScriptName(state));
  8973. return 0;
  8974. }
  8975. int32 group_id = lua_interface->GetInt32Value(state, 2);
  8976. //Map of <placement_id, location_id>
  8977. map<int32, int32>* locs = zone->GetSpawnLocationsByGroup(group_id);
  8978. map<int32, int32>::iterator itr;
  8979. vector<Spawn*> group;
  8980. for (itr = locs->begin(); itr != locs->end(); itr++) {
  8981. SpawnLocation* location = zone->GetSpawnLocation(itr->second);
  8982. if (!location) {
  8983. lua_interface->LogError("LUA SpawnByLocationID command error: no location found for the given ID (%u)", itr->second);
  8984. return 0;
  8985. }
  8986. Spawn* spawn = 0;
  8987. if (location->entities[0]) {
  8988. if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_NPC)
  8989. spawn = zone->AddNPCSpawn(location, location->entities[0]);
  8990. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_GROUNDSPAWN)
  8991. spawn = zone->AddGroundSpawn(location, location->entities[0]);
  8992. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_OBJECT)
  8993. spawn = zone->AddObjectSpawn(location, location->entities[0]);
  8994. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_WIDGET)
  8995. spawn = zone->AddWidgetSpawn(location, location->entities[0]);
  8996. else if (location->entities[0]->spawn_type == SPAWN_ENTRY_TYPE_SIGN)
  8997. spawn = zone->AddSignSpawn(location, location->entities[0]);
  8998. if(spawn && spawn->IsOmittedByDBFlag())
  8999. {
  9000. 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);
  9001. safe_delete(spawn);
  9002. continue;
  9003. }
  9004. if (spawn) {
  9005. const char* script = 0;
  9006. for (int x = 0; x < 3; x++) {
  9007. switch (x) {
  9008. case 0:
  9009. script = world.GetSpawnEntryScript(location->entities[0]->spawn_entry_id);
  9010. break;
  9011. case 1:
  9012. script = world.GetSpawnLocationScript(location->entities[0]->spawn_location_id);
  9013. break;
  9014. case 2:
  9015. script = world.GetSpawnScript(location->entities[0]->spawn_id);
  9016. break;
  9017. }
  9018. if (script && lua_interface->GetSpawnScript(script) != 0) {
  9019. spawn->SetSpawnScript(string(script));
  9020. break;
  9021. }
  9022. }
  9023. zone->CallSpawnScript(spawn, SPAWN_SCRIPT_SPAWN);
  9024. lua_interface->SetSpawnValue(state, spawn);
  9025. group.push_back(spawn);
  9026. }
  9027. else {
  9028. LogWrite(ZONE__ERROR, 0, "Zone", "Error adding spawn by group id to zone %s with location id %u.", zone->GetZoneName(), group_id);
  9029. safe_delete(spawn);
  9030. }
  9031. }
  9032. }
  9033. if (!group.empty()) {
  9034. lua_createtable(state, group.size(), 0);
  9035. int newTable = lua_gettop(state);
  9036. for (int32 i = 0; i < group.size(); i++) {
  9037. lua_interface->SetSpawnValue(state, group[i]);
  9038. lua_rawseti(state, newTable, i + 1);
  9039. }
  9040. }
  9041. else
  9042. lua_pushnil(state);
  9043. return 1;
  9044. }
  9045. int EQ2Emu_lua_SetSpawnAnimation(lua_State* state) {
  9046. if (!lua_interface)
  9047. return 0;
  9048. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9049. int32 anim_id = lua_interface->GetInt32Value(state, 2);
  9050. int16 leeway = lua_interface->GetInt16Value(state, 3);
  9051. if (!spawn) {
  9052. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: spawn is not valid", lua_interface->GetScriptName(state));
  9053. return 0;
  9054. }
  9055. if (anim_id == 0) {
  9056. lua_interface->LogError("%s: LUA SetSpawnAnimation command error: anim_id is not valid", lua_interface->GetScriptName(state));
  9057. return 0;
  9058. }
  9059. if (leeway == 0)
  9060. leeway = 5000;
  9061. spawn->SetSpawnAnim(anim_id);
  9062. spawn->SetSpawnAnimLeeway(leeway);
  9063. return 0;
  9064. }
  9065. int EQ2Emu_lua_GetClientVersion(lua_State* state) {
  9066. if (!lua_interface)
  9067. return 0;
  9068. Spawn* player = lua_interface->GetSpawn(state);
  9069. if (!player) {
  9070. return 0;
  9071. }
  9072. Client* client = player->GetZone()->GetClientBySpawn(player);
  9073. if (!client) {
  9074. return 0;
  9075. }
  9076. lua_interface->SetInt32Value(state, client->GetVersion());
  9077. return 1;
  9078. }
  9079. int EQ2Emu_lua_GetItemID(lua_State* state) {
  9080. if (!lua_interface)
  9081. return 0;
  9082. Item* item = lua_interface->GetItem(state);
  9083. if (!item) {
  9084. lua_interface->LogError("%s: LUA GetItemID command error: item is not valid", lua_interface->GetScriptName(state));
  9085. return 0;
  9086. }
  9087. lua_interface->SetInt32Value(state, item->details.item_id);
  9088. return 1;
  9089. }
  9090. int EQ2Emu_lua_IsEntity(lua_State* state) {
  9091. if (!lua_interface)
  9092. return 0;
  9093. Spawn* spawn = lua_interface->GetSpawn(state);
  9094. if (!spawn) {
  9095. lua_interface->LogError("%s: LUA IsEntity command error: spawn is not valid", lua_interface->GetScriptName(state));
  9096. return 0;
  9097. }
  9098. lua_interface->SetBooleanValue(state, spawn->IsEntity());
  9099. return 1;
  9100. }
  9101. int EQ2Emu_lua_GetOrigX(lua_State* state) {
  9102. if (!lua_interface)
  9103. return 0;
  9104. Spawn* spawn = lua_interface->GetSpawn(state);
  9105. if (!spawn) {
  9106. lua_interface->LogError("%s: LUA GetOrigX command error: spawn is not valid", lua_interface->GetScriptName(state));
  9107. return 0;
  9108. }
  9109. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigX());
  9110. return 1;
  9111. }
  9112. int EQ2Emu_lua_GetOrigY(lua_State* state) {
  9113. if (!lua_interface)
  9114. return 0;
  9115. Spawn* spawn = lua_interface->GetSpawn(state);
  9116. if (!spawn) {
  9117. lua_interface->LogError("%s: LUA GetOrigY command error: spawn is not valid", lua_interface->GetScriptName(state));
  9118. return 0;
  9119. }
  9120. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigY());
  9121. return 1;
  9122. }
  9123. int EQ2Emu_lua_GetOrigZ(lua_State* state) {
  9124. if (!lua_interface)
  9125. return 0;
  9126. Spawn* spawn = lua_interface->GetSpawn(state);
  9127. if (!spawn) {
  9128. lua_interface->LogError("%s: LUA GetOrigZ command error: spawn is not valid", lua_interface->GetScriptName(state));
  9129. return 0;
  9130. }
  9131. lua_interface->SetFloatValue(state, spawn->GetSpawnOrigZ());
  9132. return 1;
  9133. }
  9134. int EQ2Emu_lua_GetPCTOfHP(lua_State* state) {
  9135. if (!lua_interface)
  9136. return 0;
  9137. Spawn* spawn = lua_interface->GetSpawn(state);
  9138. float pct = lua_interface->GetFloatValue(state, 2);
  9139. if (!spawn) {
  9140. lua_interface->LogError("%s: LUA GetPCTOfHP command error: spawn is not valid", lua_interface->GetScriptName(state));
  9141. return 0;
  9142. }
  9143. if (pct == 0) {
  9144. lua_interface->LogError("%s: LUA GetPCTOfHP command error: pct is not valid", lua_interface->GetScriptName(state));
  9145. return 0;
  9146. }
  9147. int32 amount = std::round(spawn->GetTotalHP() * (pct / 100));
  9148. lua_interface->SetInt32Value(state, amount);
  9149. return 1;
  9150. }
  9151. int EQ2Emu_lua_GetPCTOfPower(lua_State* state) {
  9152. if (!lua_interface)
  9153. return 0;
  9154. Spawn* spawn = lua_interface->GetSpawn(state);
  9155. float pct = lua_interface->GetFloatValue(state, 2);
  9156. if (!spawn) {
  9157. lua_interface->LogError("%s: LUA GetPCTOfPower command error: spawn is not valid", lua_interface->GetScriptName(state));
  9158. return 0;
  9159. }
  9160. if (pct == 0) {
  9161. lua_interface->LogError("%s: LUA GetPCTOfPower command error: pct is not valid", lua_interface->GetScriptName(state));
  9162. return 0;
  9163. }
  9164. int32 amount = std::round(spawn->GetTotalPower() * (pct / 100));
  9165. lua_interface->SetInt32Value(state, amount);
  9166. return 1;
  9167. }
  9168. int EQ2Emu_lua_GetBoundZoneID(lua_State* state) {
  9169. if (!lua_interface)
  9170. return 0;
  9171. Spawn* spawn = lua_interface->GetSpawn(state);
  9172. if (!spawn) {
  9173. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not valid", lua_interface->GetScriptName(state));
  9174. return 0;
  9175. }
  9176. if (!spawn->IsPlayer()) {
  9177. lua_interface->LogError("%s: LUA GetBoundZoneID command error: spawn is not a player", lua_interface->GetScriptName(state));
  9178. return 0;
  9179. }
  9180. lua_interface->SetInt32Value(state, ((Player*)spawn)->GetPlayerInfo()->GetBindZoneID());
  9181. return 1;
  9182. }
  9183. int EQ2Emu_lua_Evac(lua_State* state) {
  9184. if (!lua_interface)
  9185. return 0;
  9186. Spawn* target = lua_interface->GetSpawn(state);
  9187. if (target) {
  9188. float x = target->GetZone()->GetSafeX();
  9189. float y = target->GetZone()->GetSafeY();
  9190. float z = target->GetZone()->GetSafeZ();
  9191. float h = target->GetZone()->GetSafeHeading();
  9192. target->SetX(x);
  9193. target->SetY(y);
  9194. target->SetZ(z);
  9195. target->SetHeading(h);
  9196. target->SetSpawnOrigX(x);
  9197. target->SetSpawnOrigY(y);
  9198. target->SetSpawnOrigZ(z);
  9199. target->SetSpawnOrigHeading(h);
  9200. if (target->IsPlayer()) {
  9201. Client* client = target->GetZone()->GetClientBySpawn(target);
  9202. if (client) {
  9203. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9204. int numargs = lua_interface->GetNumberOfArgs(state);
  9205. if(numargs == 4) {
  9206. x = lua_interface->GetFloatValue(state,1);
  9207. y = lua_interface->GetFloatValue(state,2);
  9208. z = lua_interface->GetFloatValue(state,3);
  9209. h = lua_interface->GetFloatValue(state,4);
  9210. }
  9211. client->SetReloadingZone(true);
  9212. target->SetX(x);
  9213. target->SetY(y);
  9214. target->SetZ(z);
  9215. target->SetHeading(h);
  9216. target->SetSpawnOrigX(x);
  9217. target->SetSpawnOrigY(y);
  9218. target->SetSpawnOrigZ(z);
  9219. target->SetSpawnOrigHeading(h);
  9220. target->SetAppearancePosition(x,y,z);
  9221. client->SetZoningCoords(x,y,z,h);
  9222. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9223. if (packet)
  9224. {
  9225. packet->setDataByName("x", x);
  9226. packet->setDataByName("y", y);
  9227. packet->setDataByName("z", z);
  9228. client->QueuePacket(packet->serialize());
  9229. safe_delete(packet);
  9230. }
  9231. client->GetCurrentZone()->RemoveSpawn(target, false, false, true, true);
  9232. client->GetPlayer()->SetSpawnSentState(target, SpawnState::SPAWN_STATE_SENT);
  9233. }
  9234. }
  9235. }
  9236. else {
  9237. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9238. if(!spell)
  9239. return 0;
  9240. ZoneServer* zone = spell->caster->GetZone();
  9241. float x = spell->caster->GetZone()->GetSafeX();
  9242. float y = spell->caster->GetZone()->GetSafeY();
  9243. float z = spell->caster->GetZone()->GetSafeZ();
  9244. float h = spell->caster->GetZone()->GetSafeHeading();
  9245. int numargs = lua_interface->GetNumberOfArgs(state);
  9246. if(numargs == 4) {
  9247. x = lua_interface->GetFloatValue(state,1);
  9248. y = lua_interface->GetFloatValue(state,2);
  9249. z = lua_interface->GetFloatValue(state,3);
  9250. h = lua_interface->GetFloatValue(state,4);
  9251. }
  9252. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  9253. for (int32 i = 0; i < spell->targets.size(); i++) {
  9254. Spawn* target2 = zone->GetSpawnByID(spell->targets.at(i));
  9255. if (!target2)
  9256. continue;
  9257. if (target2->IsPlayer()) {
  9258. Client* client = target2->GetZone()->GetClientBySpawn(target2);
  9259. if (client) {
  9260. client->GetCurrentZone()->ClearHate(client->GetPlayer());
  9261. client->SetReloadingZone(true);
  9262. target2->SetX(x);
  9263. target2->SetY(y);
  9264. target2->SetZ(z);
  9265. target2->SetHeading(h);
  9266. target2->SetSpawnOrigX(x);
  9267. target2->SetSpawnOrigY(y);
  9268. target2->SetSpawnOrigZ(z);
  9269. target2->SetSpawnOrigHeading(h);
  9270. target2->SetAppearancePosition(x,y,z);
  9271. client->SetZoningCoords(x,y,z,h);
  9272. PacketStruct* packet = configReader.getStruct("WS_TeleportWithinZone", client->GetVersion());
  9273. if (packet)
  9274. {
  9275. packet->setDataByName("x", x);
  9276. packet->setDataByName("y", y);
  9277. packet->setDataByName("z", z);
  9278. client->QueuePacket(packet->serialize());
  9279. safe_delete(packet);
  9280. }
  9281. client->GetCurrentZone()->RemoveSpawn(target2, false, false, true, true);
  9282. client->GetPlayer()->SetSpawnSentState(target2, SpawnState::SPAWN_STATE_SENT);
  9283. }
  9284. }
  9285. }
  9286. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  9287. }
  9288. return 0;
  9289. }
  9290. int EQ2Emu_lua_GetSpellTier(lua_State* state) {
  9291. if (!lua_interface)
  9292. return 0;
  9293. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9294. if (!luaspell) {
  9295. lua_interface->LogError("%s: LUA GetSpellTier command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9296. return 0;
  9297. }
  9298. int8 tier = luaspell->spell->GetSpellTier();
  9299. lua_interface->SetInt32Value(state, tier);
  9300. return 1;
  9301. }
  9302. int EQ2Emu_lua_GetSpellID(lua_State* state) {
  9303. if (!lua_interface)
  9304. return 0;
  9305. LuaSpell* luaspell = lua_interface->GetCurrentSpell(state);
  9306. if (!luaspell) {
  9307. lua_interface->LogError("%s: LUA GetSpellID command error: must be used in a spell script", lua_interface->GetScriptName(state));
  9308. return 0;
  9309. }
  9310. int32 spell_id = luaspell->spell->GetSpellID();
  9311. lua_interface->SetInt32Value(state, spell_id);
  9312. return 1;
  9313. }
  9314. int EQ2Emu_lua_StartTransmute(lua_State* state) {
  9315. if (!lua_interface)
  9316. return 0;
  9317. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9318. if (!spawn) {
  9319. lua_interface->LogError("%s: Lua StartTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9320. return 0;
  9321. }
  9322. if (!spawn->IsPlayer()) {
  9323. lua_interface->LogError("%s: Lua StartTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9324. return 0;
  9325. }
  9326. ZoneServer* zone = spawn->GetZone();
  9327. if (!zone) {
  9328. return 0;
  9329. }
  9330. Client* client = zone->GetClientBySpawn(spawn);
  9331. if (!client) {
  9332. return 0;
  9333. }
  9334. Transmute::CreateItemRequest(client, static_cast<Player*>(spawn));
  9335. return 0;
  9336. }
  9337. int EQ2Emu_lua_CompleteTransmute(lua_State* state) {
  9338. if (!lua_interface)
  9339. return 0;
  9340. Spawn* spawn = lua_interface->GetSpawn(state, 1);
  9341. if (!spawn) {
  9342. lua_interface->LogError("%s: Lua CompleteTransmute command error: no spawn", lua_interface->GetScriptName(state));
  9343. return 0;
  9344. }
  9345. if (!spawn->IsPlayer()) {
  9346. lua_interface->LogError("%s: Lua CompleteTransmute command error: spawn is not a player", lua_interface->GetScriptName(state));
  9347. return 0;
  9348. }
  9349. ZoneServer* zone = spawn->GetZone();
  9350. if (!zone) {
  9351. return 0;
  9352. }
  9353. Client* client = zone->GetClientBySpawn(spawn);
  9354. if (!client) {
  9355. return 0;
  9356. }
  9357. Transmute::CompleteTransmutation(client, static_cast<Player*>(spawn));
  9358. return 0;
  9359. }
  9360. int EQ2Emu_lua_ProcHate(lua_State* state) {
  9361. if (!lua_interface)
  9362. return 0;
  9363. Spawn* caster = lua_interface->GetSpawn(state);
  9364. Spawn* target = lua_interface->GetSpawn(state, 2);
  9365. int32 threat_amt = lua_interface->GetInt32Value(state, 3);
  9366. string spell_name = lua_interface->GetStringValue(state, 4);
  9367. if (!caster) {
  9368. lua_interface->LogError("%s: LUA ProcHate command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  9369. return 0;
  9370. }
  9371. if (!caster->IsEntity()) {
  9372. lua_interface->LogError("%s: LUA ProcHate command error: caster is not an entity", lua_interface->GetScriptName(state));
  9373. return 0;
  9374. }
  9375. if (!target) {
  9376. lua_interface->LogError("%s: LUA ProcHate command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  9377. return 0;
  9378. }
  9379. if (!target->IsEntity()) {
  9380. lua_interface->LogError("%s: LUA ProcHate command error: target is not an entity", lua_interface->GetScriptName(state));
  9381. return 0;
  9382. }
  9383. static_cast<Entity*>(target)->AddHate(static_cast<Entity*>(caster), threat_amt);
  9384. caster->GetZone()->SendThreatPacket(static_cast<Entity*>(caster), target, threat_amt, spell_name.c_str());
  9385. return 0;
  9386. }
  9387. int EQ2Emu_lua_GiveExp(lua_State* state) {
  9388. if (!lua_interface)
  9389. return 0;
  9390. Spawn* player = lua_interface->GetSpawn(state);
  9391. int32 amount = lua_interface->GetInt32Value(state, 2);
  9392. if (player && player->IsPlayer() && amount > 0) {
  9393. ((Player*)player)->AddXP(amount);
  9394. ((Player*)player)->SetCharSheetChanged(true);
  9395. Client* client = player->GetZone()->GetClientBySpawn(player);
  9396. if (client) {
  9397. client->SimpleMessage(CHANNEL_REWARD, "You gain experience!");
  9398. }
  9399. }
  9400. return 0;
  9401. }
  9402. int EQ2Emu_lua_DisplayText(lua_State* state) {
  9403. if (!lua_interface)
  9404. return 0;
  9405. Spawn* player = lua_interface->GetSpawn(state);
  9406. int8 type = lua_interface->GetInt8Value(state, 2);
  9407. string text = lua_interface->GetStringValue(state, 3);
  9408. Client* client = 0;
  9409. if (player && player->IsPlayer())
  9410. client = player->GetZone()->GetClientBySpawn(player);
  9411. if (!client || text.length() == 0) {
  9412. lua_interface->LogError("%s: LUA DisplayText required parameters not given", lua_interface->GetScriptName(state));
  9413. return 0;
  9414. }
  9415. client->SimpleMessage(type, text.c_str());
  9416. return 0;
  9417. }
  9418. int EQ2Emu_lua_ShowLootWindow(lua_State* state) {
  9419. if (!lua_interface)
  9420. return 0;
  9421. Spawn* player = lua_interface->GetSpawn(state);
  9422. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9423. Client* client = 0;
  9424. if (player && player->IsPlayer())
  9425. client = player->GetZone()->GetClientBySpawn(player);
  9426. if (!client || !spawn) {
  9427. lua_interface->LogError("%s: LUA ShowLootWindow required parameters not given", lua_interface->GetScriptName(state));
  9428. return 0;
  9429. }
  9430. vector<Item*>* items = ((Player*)player)->GetPendingLootItems(spawn->GetID());
  9431. if (!items) {
  9432. lua_interface->LogError("%s: LUA ShowLootWindow has no items", lua_interface->GetScriptName(state));
  9433. return 0;
  9434. }
  9435. client->Loot(spawn->GetLootCoins(), items, spawn);
  9436. return 0;
  9437. }
  9438. int EQ2Emu_lua_GetRandomSpawnByID(lua_State* state) {
  9439. if (!lua_interface)
  9440. return 0;
  9441. Spawn* spawnref = lua_interface->GetSpawn(state);
  9442. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9443. if (spawn_id > 0 && spawnref) {
  9444. vector<Spawn*> spawns = spawnref->GetZone()->GetSpawnsByID(spawn_id);
  9445. if (spawns.size() == 0) {
  9446. lua_interface->LogError("%s: LUA EQ2Emu_lua_GetRandomSpawnByID command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9447. return 0;
  9448. }
  9449. Spawn* spawn = 0;
  9450. int16 index = MakeRandomInt(0, spawns.size());
  9451. if (index >= spawns.size() || index < 0)
  9452. index = 0;
  9453. spawn = spawns[index];
  9454. lua_interface->SetSpawnValue(state, spawn);
  9455. return 1;
  9456. }
  9457. else {
  9458. lua_interface->LogError("%s: LUA GetRandomSpawnByID required parameters not given", lua_interface->GetScriptName(state));
  9459. }
  9460. return 0;
  9461. }
  9462. int EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns(lua_State* state) {
  9463. Spawn* player = lua_interface->GetSpawn(state);
  9464. int32 spawn_id = lua_interface->GetInt32Value(state, 2);
  9465. string name = lua_interface->GetStringValue(state, 3);
  9466. float distance = lua_interface->GetFloatValue(state, 4);
  9467. string command = lua_interface->GetStringValue(state, 5);
  9468. string error_text = lua_interface->GetStringValue(state, 6);
  9469. int16 cast_time = lua_interface->GetInt16Value(state, 7);
  9470. int32 spell_visual = lua_interface->GetInt32Value(state, 8);
  9471. if (spawn_id && player && player->IsPlayer() && name.length() > 0) {
  9472. if (distance == 0)
  9473. distance = 10.0f;
  9474. if (command.length() == 0)
  9475. command = name;
  9476. vector<Spawn*> spawns = player->GetZone()->GetSpawnsByID(spawn_id);
  9477. if (spawns.size() == 0) {
  9478. lua_interface->LogError("%s: LUA AddPrimaryEntityCommandAllSpawns command error: GetSpawnsByID returned no spawns", lua_interface->GetScriptName(state));
  9479. return 0;
  9480. }
  9481. Spawn* spawn = 0;
  9482. for (vector<Spawn*>::iterator itr = spawns.begin(); itr != spawns.end(); itr++) {
  9483. spawn = *itr;
  9484. if (spawn) {
  9485. spawn->AddPrimaryEntityCommand(name.c_str(), distance, command.c_str(), error_text.c_str(), cast_time, spell_visual);
  9486. player->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance);
  9487. }
  9488. }
  9489. }
  9490. return 0;
  9491. }
  9492. int EQ2Emu_lua_InstructionWindowGoal(lua_State* state) {
  9493. if (!lua_interface)
  9494. return 0;
  9495. Client* client = 0;
  9496. Spawn* player = lua_interface->GetSpawn(state);
  9497. int8 goal_num = lua_interface->GetInt8Value(state, 2);
  9498. if (player && player->IsPlayer() && player->GetZone())
  9499. client = player->GetZone()->GetClientBySpawn(player);
  9500. else{
  9501. lua_interface->LogError("LUA InstructionWindowGoal command error: player is not valid");
  9502. return 0;
  9503. }
  9504. if (client) {
  9505. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9506. if (packet) {
  9507. packet->setDataByName("goal_num", goal_num);
  9508. client->QueuePacket(packet->serialize());
  9509. safe_delete(packet);
  9510. }
  9511. }
  9512. return 0;
  9513. }
  9514. int EQ2Emu_lua_InstructionWindowClose(lua_State* state) {
  9515. if (!lua_interface)
  9516. return 0;
  9517. Client* client = 0;
  9518. Spawn* player = lua_interface->GetSpawn(state);
  9519. if (player && player->IsPlayer() && player->GetZone())
  9520. client = player->GetZone()->GetClientBySpawn(player);
  9521. else {
  9522. lua_interface->LogError("LUA InstructionWindowClose command error: player is not valid");
  9523. return 0;
  9524. }
  9525. if (client) {
  9526. client->QueuePacket(new EQ2Packet(OP_EqInstructionWindowCloseCmd, 0, 0));
  9527. }
  9528. return 0;
  9529. }
  9530. int EQ2Emu_lua_InstructionWindow(lua_State* state) {
  9531. if (!lua_interface)
  9532. return 0;
  9533. Client* client = 0;
  9534. Spawn* player = lua_interface->GetSpawn(state);
  9535. float duration = lua_interface->GetFloatValue(state, 2);
  9536. string text = lua_interface->GetStringValue(state, 3);
  9537. string voice = lua_interface->GetStringValue(state, 4);
  9538. int32 voice_key1 = lua_interface->GetInt32Value(state, 5);
  9539. int32 voice_key2 = lua_interface->GetInt32Value(state, 6);
  9540. string signal = lua_interface->GetStringValue(state, 7);
  9541. string goal1 = lua_interface->GetStringValue(state, 8);
  9542. string task1 = lua_interface->GetStringValue(state, 9);
  9543. string goal2 = lua_interface->GetStringValue(state, 10);
  9544. string task2 = lua_interface->GetStringValue(state, 11);
  9545. string goal3 = lua_interface->GetStringValue(state, 12);
  9546. string task3 = lua_interface->GetStringValue(state, 13);
  9547. string goal4 = lua_interface->GetStringValue(state, 14);
  9548. string task4 = lua_interface->GetStringValue(state, 15);
  9549. if (!player) {
  9550. lua_interface->LogError("LUA InstructionWindow command error: spawn is not valid");
  9551. return 0;
  9552. }
  9553. if (!player->IsPlayer()) {
  9554. lua_interface->LogError("LUA InstructionWindow command error: spawn is not a player");
  9555. return 0;
  9556. }
  9557. else
  9558. client = ((Player*)player)->GetClient();
  9559. if (!client) {
  9560. lua_interface->LogError("LUA InstructionWindow command error: could not find client");
  9561. return 0;
  9562. }
  9563. if (text.length() == 0) {
  9564. lua_interface->LogError("LUA InstructionWindow required parameters not given");
  9565. return 0;
  9566. }
  9567. if (duration >= 0 && duration < 2)
  9568. duration = 2;
  9569. PacketStruct* packet = configReader.getStruct("WS_InstructionWindow", client->GetVersion());
  9570. if (packet) {
  9571. packet->setDataByName("open_seconds_max", duration);
  9572. packet->setDataByName("text", text.c_str());
  9573. packet->setDataByName("voice", voice.c_str());
  9574. int8 num_goals = 1;
  9575. if (task2.length() > 0)
  9576. num_goals++;
  9577. if (task3.length() > 0)
  9578. num_goals++;
  9579. if (task4.length() > 0)
  9580. num_goals++;
  9581. packet->setArrayLengthByName("num_goals", num_goals);
  9582. for (int8 i = 0; i < num_goals; i++) {
  9583. packet->setSubArrayLengthByName("num_tasks", 1, i);
  9584. }
  9585. if (goal1.length() > 0)
  9586. packet->setArrayDataByName("goal_text", goal1.c_str());
  9587. if (goal2.length() > 0)
  9588. packet->setArrayDataByName("goal_text", goal2.c_str(), 1);
  9589. if (goal3.length() > 0)
  9590. packet->setArrayDataByName("goal_text", goal3.c_str(), 2);
  9591. if (goal4.length() > 0)
  9592. packet->setArrayDataByName("goal_text", goal4.c_str(), 3);
  9593. packet->setSubArrayDataByName("task_text", task1.c_str());
  9594. if (task2.length() > 0)
  9595. packet->setSubArrayDataByName("task_text", task2.c_str(), 1);
  9596. if (task3.length() > 0)
  9597. packet->setSubArrayDataByName("task_text", task3.c_str(), 2);
  9598. if (task4.length() > 0)
  9599. packet->setSubArrayDataByName("task_text", task4.c_str(), 3);
  9600. packet->setDataByName("complete_sound", "click");
  9601. packet->setDataByName("signal", signal.c_str());
  9602. packet->setDataByName("voice_key1", voice_key1);
  9603. packet->setDataByName("voice_key2", voice_key2);
  9604. client->QueuePacket(packet->serialize());
  9605. safe_delete(packet);
  9606. }
  9607. return 0;
  9608. }
  9609. int EQ2Emu_lua_ShowWindow(lua_State* state) {
  9610. if (!lua_interface)
  9611. return 0;
  9612. Client* client = 0;
  9613. Spawn* player = lua_interface->GetSpawn(state);
  9614. string window = lua_interface->GetStringValue(state, 2);
  9615. int8 show = lua_interface->GetInt8Value(state, 3);
  9616. if (!player) {
  9617. lua_interface->LogError("LUA ShowWindow command error: spawn is not valid");
  9618. return 0;
  9619. }
  9620. if (!player->IsPlayer()) {
  9621. lua_interface->LogError("LUA ShowWindow command error: spawn is not a player");
  9622. return 0;
  9623. }
  9624. else
  9625. client = ((Player*)player)->GetClient();
  9626. if (!client) {
  9627. lua_interface->LogError("LUA ShowWindow command error: could not find client");
  9628. return 0;
  9629. }
  9630. if (window.length() == 0) {
  9631. lua_interface->LogError("LUA ShowWindow required parameters not given");
  9632. return 0;
  9633. }
  9634. PacketStruct* packet = configReader.getStruct("WS_ShowWindow", client->GetVersion());
  9635. if (packet) {
  9636. packet->setDataByName("window", window.c_str());
  9637. packet->setDataByName("show", show);
  9638. client->QueuePacket(packet->serialize());
  9639. safe_delete(packet);
  9640. }
  9641. return 0;
  9642. }
  9643. int EQ2Emu_lua_EnableGameEvent(lua_State* state) {
  9644. //See GameEvents.txt for options that can be used for this function
  9645. if (!lua_interface)
  9646. return 0;
  9647. Client* client = 0;
  9648. Spawn* player = lua_interface->GetSpawn(state);
  9649. string event_name = lua_interface->GetStringValue(state, 2);
  9650. int8 enabled = lua_interface->GetInt8Value(state, 3);
  9651. if (!player || !player->IsPlayer()) {
  9652. lua_interface->LogError("LUA EnableGameEvent error: player is not valid");
  9653. return 0;
  9654. }
  9655. if (player->GetZone())
  9656. client = player->GetZone()->GetClientBySpawn(player);
  9657. if (!client) {
  9658. lua_interface->LogError("LUA EnableGameEvent error: could not find client");
  9659. return 0;
  9660. }
  9661. PacketStruct* packet = configReader.getStruct("WS_EnableGameEvent", client->GetVersion());
  9662. if (packet) {
  9663. packet->setDataByName("event_name", event_name.c_str());
  9664. packet->setDataByName("enabled", enabled);
  9665. client->QueuePacket(packet->serialize());
  9666. safe_delete(packet);
  9667. }
  9668. return 0;
  9669. }
  9670. int EQ2Emu_lua_GetTutorialStep(lua_State* state) {
  9671. if (!lua_interface)
  9672. return 0;
  9673. Spawn* player = lua_interface->GetSpawn(state);
  9674. if (player && player->IsPlayer()) {
  9675. lua_interface->SetInt32Value(state, ((Player*)player)->GetTutorialStep());
  9676. return 1;
  9677. }
  9678. return 0;
  9679. }
  9680. int EQ2Emu_lua_SetTutorialStep(lua_State* state) {
  9681. if (!lua_interface)
  9682. return 0;
  9683. Spawn* player = lua_interface->GetSpawn(state);
  9684. int8 step = lua_interface->GetInt8Value(state, 2);
  9685. if (player && player->IsPlayer() && step > 0) {
  9686. ((Player*)player)->SetTutorialStep(step);
  9687. }
  9688. return 0;
  9689. }
  9690. int EQ2Emu_lua_FlashWindow(lua_State* state) {
  9691. if (!lua_interface)
  9692. return 0;
  9693. Client* client = 0;
  9694. Spawn* player = lua_interface->GetSpawn(state);
  9695. string window = lua_interface->GetStringValue(state, 2);
  9696. float flash_seconds = lua_interface->GetFloatValue(state, 3);
  9697. if (!player) {
  9698. lua_interface->LogError("LUA FlashWindow command error: spawn is not valid");
  9699. return 0;
  9700. }
  9701. if (!player->IsPlayer()) {
  9702. lua_interface->LogError("LUA FlashWindow command error: spawn is not a player");
  9703. return 0;
  9704. }
  9705. else
  9706. client = ((Player*)player)->GetClient();
  9707. if (!client) {
  9708. lua_interface->LogError("LUA FlashWindow command error: could not find client");
  9709. return 0;
  9710. }
  9711. if (window.length() == 0) {
  9712. lua_interface->LogError("LUA FlashWindow required parameters not given");
  9713. return 0;
  9714. }
  9715. PacketStruct* packet = configReader.getStruct("WS_FlashWindow", client->GetVersion());
  9716. if (packet) {
  9717. packet->setDataByName("window", window.c_str());
  9718. packet->setDataByName("flash_seconds", flash_seconds);
  9719. client->QueuePacket(packet->serialize());
  9720. safe_delete(packet);
  9721. }
  9722. return 0;
  9723. }
  9724. int EQ2Emu_lua_CheckLOS(lua_State* state) {
  9725. if (!lua_interface)
  9726. return 0;
  9727. Spawn* spawn = lua_interface->GetSpawn(state);
  9728. Spawn* target = lua_interface->GetSpawn(state, 2);
  9729. if (spawn && target)
  9730. return spawn->CheckLoS(target);
  9731. return 0;
  9732. }
  9733. int EQ2Emu_lua_CheckLOSByCoordinates(lua_State* state) {
  9734. if (!lua_interface)
  9735. return 0;
  9736. Spawn* spawn = lua_interface->GetSpawn(state);
  9737. float x = lua_interface->GetFloatValue(state, 2);
  9738. float y = lua_interface->GetFloatValue(state, 3);
  9739. float z = lua_interface->GetFloatValue(state, 4);
  9740. if (spawn)
  9741. return spawn->CheckLoS(glm::vec3(spawn->GetX(), spawn->GetZ(), spawn->GetY() + 1.0f), glm::vec3(x, z, y+1.0f));
  9742. return 0;
  9743. }
  9744. int EQ2Emu_lua_SetZoneExpansionFlag(lua_State* state) {
  9745. if (!lua_interface)
  9746. return 0;
  9747. ZoneServer* zone = lua_interface->GetZone(state);
  9748. int32 xpackFlag = lua_interface->GetInt32Value(state, 2);
  9749. if (zone)
  9750. zone->SetExpansionFlag(xpackFlag);
  9751. return 0;
  9752. }
  9753. int EQ2Emu_lua_GetZoneExpansionFlag(lua_State* state) {
  9754. if (!lua_interface)
  9755. return 0;
  9756. ZoneServer* zone = lua_interface->GetZone(state);
  9757. if (zone) {
  9758. lua_interface->SetInt32Value(state, zone->GetExpansionFlag());
  9759. return 1;
  9760. }
  9761. return 0;
  9762. }
  9763. int EQ2Emu_lua_SetZoneHolidayFlag(lua_State* state) {
  9764. if (!lua_interface)
  9765. return 0;
  9766. ZoneServer* zone = lua_interface->GetZone(state);
  9767. int32 holidayFlag = lua_interface->GetInt32Value(state, 2);
  9768. if (zone)
  9769. zone->SetHolidayFlag(holidayFlag);
  9770. return 0;
  9771. }
  9772. int EQ2Emu_lua_GetZoneHolidayFlag(lua_State* state) {
  9773. if (!lua_interface)
  9774. return 0;
  9775. ZoneServer* zone = lua_interface->GetZone(state);
  9776. if (zone) {
  9777. lua_interface->SetInt32Value(state, zone->GetHolidayFlag());
  9778. return 1;
  9779. }
  9780. return 0;
  9781. }
  9782. int EQ2Emu_lua_SetCanBind(lua_State* state) {
  9783. if (!lua_interface)
  9784. return 0;
  9785. Spawn* player = lua_interface->GetSpawn(state);
  9786. ZoneServer* zone = player->GetZone();
  9787. bool canbind = lua_interface->GetInt32Value(state, 2);
  9788. if (zone)
  9789. zone->SetCanBind(canbind);
  9790. return 0;
  9791. }
  9792. int EQ2Emu_lua_GetCanBind(lua_State* state) {
  9793. if (!lua_interface)
  9794. return 0;
  9795. Spawn* player = lua_interface->GetSpawn(state);
  9796. ZoneServer* zone = player->GetZone();
  9797. if (zone) {
  9798. lua_interface->SetInt32Value(state, zone->GetCanBind());
  9799. return 1;
  9800. }
  9801. return 0;
  9802. }
  9803. int EQ2Emu_lua_SetCanGate(lua_State* state) {
  9804. if (!lua_interface)
  9805. return 0;
  9806. Spawn* player = lua_interface->GetSpawn(state);
  9807. ZoneServer* zone = player->GetZone();
  9808. bool cangate = lua_interface->GetInt32Value(state, 2);
  9809. if (zone)
  9810. zone->SetCanGate(cangate);
  9811. return 0;
  9812. }
  9813. int EQ2Emu_lua_GetCanGate(lua_State* state) {
  9814. if (!lua_interface)
  9815. return 0;
  9816. Spawn* player = lua_interface->GetSpawn(state);
  9817. ZoneServer* zone = player->GetZone();
  9818. if (zone) {
  9819. lua_interface->SetInt32Value(state, zone->GetCanGate());
  9820. return 1;
  9821. }
  9822. return 0;
  9823. }
  9824. int EQ2Emu_lua_AddSpawnProximity(lua_State* state) {
  9825. if (!lua_interface)
  9826. return 0;
  9827. Spawn* spawn = lua_interface->GetSpawn(state);
  9828. int32 spawn_value = lua_interface->GetInt32Value(state, 2);
  9829. int8 spawn_type = lua_interface->GetInt8Value(state, 3);
  9830. float distance = lua_interface->GetFloatValue(state, 4);
  9831. string in_range_function = lua_interface->GetStringValue(state, 5);
  9832. string leaving_range_function = lua_interface->GetStringValue(state, 6);
  9833. if (spawn && distance > 0 && in_range_function.length() > 0)
  9834. spawn->AddLUASpawnProximity(spawn_value, (Spawn::SpawnProximityType)spawn_type, distance, in_range_function, leaving_range_function);
  9835. return 0;
  9836. }
  9837. int EQ2Emu_lua_CanSeeInvis(lua_State* state) {
  9838. if (!lua_interface)
  9839. return 0;
  9840. Spawn* spawn = lua_interface->GetSpawn(state);
  9841. Spawn* target = lua_interface->GetSpawn(state, 2);
  9842. if (spawn && target)
  9843. {
  9844. if (spawn->IsPlayer() && target->IsEntity())
  9845. {
  9846. lua_interface->SetBooleanValue(state, ((Player*)spawn)->CanSeeInvis((Entity*)target));
  9847. return 1;
  9848. }
  9849. else if (spawn->IsEntity() && target->IsEntity())
  9850. {
  9851. lua_interface->SetBooleanValue(state, ((Entity*)spawn)->CanSeeInvis((Entity*)target));
  9852. return 1;
  9853. }
  9854. }
  9855. return 0;
  9856. }
  9857. int EQ2Emu_lua_SetSeeInvis(lua_State* state) {
  9858. if (!lua_interface)
  9859. return 0;
  9860. Spawn* spawn = lua_interface->GetSpawn(state);
  9861. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9862. if (spawn && spawn->IsEntity())
  9863. {
  9864. ((Entity*)spawn)->SetSeeInvisSpell(val);
  9865. if (spawn->IsPlayer())
  9866. {
  9867. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9868. if (client)
  9869. ((Player*)spawn)->GetZone()->SendAllSpawnsForSeeInvisChange(client);
  9870. }
  9871. }
  9872. return 0;
  9873. }
  9874. int EQ2Emu_lua_SetSeeHide(lua_State* state) {
  9875. if (!lua_interface)
  9876. return 0;
  9877. Spawn* spawn = lua_interface->GetSpawn(state);
  9878. bool val = (lua_interface->GetInt8Value(state, 2) == 1);
  9879. if (spawn && spawn->IsEntity())
  9880. {
  9881. ((Entity*)spawn)->SetSeeHideSpell(val);
  9882. if (spawn->IsPlayer())
  9883. {
  9884. Client* client = spawn->GetZone()->GetClientBySpawn((Player*)spawn);
  9885. if (client)
  9886. ((Player*)spawn)->GetZone()->SendAllSpawnsForVisChange(client);
  9887. }
  9888. }
  9889. return 0;
  9890. }
  9891. int EQ2Emu_lua_SetAccessToEntityCommand(lua_State* state)
  9892. {
  9893. if (!lua_interface)
  9894. return 0;
  9895. Spawn* player = lua_interface->GetSpawn(state);
  9896. Spawn* spawn = lua_interface->GetSpawn(state, 2);
  9897. string command = lua_interface->GetStringValue(state, 3);
  9898. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9899. lua_interface->ResetFunctionStack(state);
  9900. if (spawn && player && player->IsPlayer())
  9901. {
  9902. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9903. bool res = false;
  9904. if (cmd)
  9905. res = spawn->SetPermissionToEntityCommand(cmd, (Player*)player, val);
  9906. lua_interface->SetBooleanValue(state, res);
  9907. return 1;
  9908. }
  9909. return 0;
  9910. }
  9911. int EQ2Emu_lua_SetAccessToEntityCommandByCharID(lua_State* state)
  9912. {
  9913. if (!lua_interface)
  9914. return 0;
  9915. Spawn* spawn = lua_interface->GetSpawn(state);
  9916. int32 charID = lua_interface->GetInt32Value(state, 2);
  9917. string command = lua_interface->GetStringValue(state, 3);
  9918. bool val = (lua_interface->GetInt8Value(state, 4) == 1);
  9919. lua_interface->ResetFunctionStack(state);
  9920. if (spawn && charID)
  9921. {
  9922. EntityCommand* cmd = spawn->FindEntityCommand(string(command), true);
  9923. bool res = false;
  9924. if (cmd)
  9925. res = spawn->SetPermissionToEntityCommandByCharID(cmd, charID, val);
  9926. lua_interface->SetBooleanValue(state, res);
  9927. return 1;
  9928. }
  9929. return 0;
  9930. }
  9931. int EQ2Emu_lua_RemovePrimaryEntityCommand(lua_State* state)
  9932. {
  9933. if (!lua_interface)
  9934. return 0;
  9935. Spawn* spawn = lua_interface->GetSpawn(state);
  9936. string command = lua_interface->GetStringValue(state, 2);
  9937. lua_interface->ResetFunctionStack(state);
  9938. if (spawn && command.length() > 0)
  9939. spawn->RemovePrimaryEntityCommand(command.c_str());
  9940. return 0;
  9941. }
  9942. int EQ2Emu_lua_SendUpdateDefaultCommand(lua_State* state) {
  9943. if (!lua_interface)
  9944. return 0;
  9945. Spawn* spawn = lua_interface->GetSpawn(state);
  9946. float distance = lua_interface->GetFloatValue(state, 2);
  9947. string command = lua_interface->GetStringValue(state, 3);
  9948. Spawn* player = lua_interface->GetSpawn(state, 4);
  9949. lua_interface->ResetFunctionStack(state);
  9950. if (spawn) {
  9951. spawn->GetZone()->SendUpdateDefaultCommand(spawn, command.c_str(), distance, player);
  9952. }
  9953. return 0;
  9954. }
  9955. int EQ2Emu_lua_SendTransporters(lua_State* state) {
  9956. if (!lua_interface)
  9957. return 0;
  9958. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  9959. Spawn* spawn = lua_interface->GetSpawn(state);
  9960. Spawn* player = lua_interface->GetSpawn(state, 2);
  9961. int32 transport_id = lua_interface->GetInt32Value(state, 3);
  9962. lua_interface->ResetFunctionStack(state);
  9963. if (spawn && player && transport_id && player->IsPlayer()) {
  9964. Client* client = 0;
  9965. if (player && player->IsPlayer())
  9966. client = player->GetZone()->GetClientBySpawn(player);
  9967. if (!client)
  9968. return 0;
  9969. vector<TransportDestination*> destinations;
  9970. player->GetZone()->GetTransporters(&destinations, client, transport_id);
  9971. if (destinations.size())
  9972. {
  9973. client->SetTemporaryTransportID(transport_id);
  9974. client->ProcessTeleport(spawn, &destinations, transport_id, (spell != nullptr) ? true : false);
  9975. }
  9976. else
  9977. client->Message(CHANNEL_COLOR_RED, "There are no transporters available (ID: %u)", transport_id);
  9978. }
  9979. return 0;
  9980. }
  9981. int EQ2Emu_lua_SetTemporaryTransportID(lua_State* state) {
  9982. if (!lua_interface)
  9983. return 0;
  9984. Spawn* player = lua_interface->GetSpawn(state);
  9985. int32 transport_id = lua_interface->GetInt32Value(state, 2);
  9986. lua_interface->ResetFunctionStack(state);
  9987. if (player && player->IsPlayer()) {
  9988. Client* client = 0;
  9989. if (player && player->IsPlayer())
  9990. client = player->GetZone()->GetClientBySpawn(player);
  9991. if (!client)
  9992. return 0;
  9993. client->SetTemporaryTransportID(transport_id);
  9994. }
  9995. return 0;
  9996. }
  9997. int EQ2Emu_lua_GetTemporaryTransportID(lua_State* state) {
  9998. if (!lua_interface)
  9999. return 0;
  10000. Spawn* player = lua_interface->GetSpawn(state);
  10001. lua_interface->ResetFunctionStack(state);
  10002. if (player && player->IsPlayer()) {
  10003. Client* client = 0;
  10004. if (player && player->IsPlayer())
  10005. client = player->GetZone()->GetClientBySpawn(player);
  10006. if (!client)
  10007. return 0;
  10008. lua_interface->SetInt32Value(state, client->GetTemporaryTransportID());
  10009. return 1;
  10010. }
  10011. return 0;
  10012. }
  10013. int EQ2Emu_lua_SetAlignment(lua_State* state) {
  10014. if (!lua_interface)
  10015. return 0;
  10016. Spawn* spawn = lua_interface->GetSpawn(state);
  10017. sint32 alignment = lua_interface->GetSInt32Value(state, 2);
  10018. LuaSpell* spell = lua_interface->GetCurrentSpell(state);
  10019. if (!spawn) {
  10020. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10021. return 0;
  10022. }
  10023. if (!spawn->IsEntity()) {
  10024. lua_interface->LogError("%s: LUA SetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10025. return 0;
  10026. }
  10027. if (alignment < SCHAR_MIN || alignment > SCHAR_MAX)
  10028. {
  10029. 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);
  10030. return 0;
  10031. }
  10032. lua_interface->ResetFunctionStack(state);
  10033. if (spell && spell->targets.size() > 0) {
  10034. ZoneServer* zone = spell->caster->GetZone();
  10035. for (int8 i = 0; i < spell->targets.size(); i++) {
  10036. Spawn* target = zone->GetSpawnByID(spell->targets.at(i));
  10037. if (target && target->IsEntity()) {
  10038. ((Entity*)target)->GetInfoStruct()->set_alignment((sint8)alignment);
  10039. if (target->IsPlayer())
  10040. ((Player*)target)->SetCharSheetChanged(true);
  10041. }
  10042. }
  10043. }
  10044. else {
  10045. ((Entity*)spawn)->GetInfoStruct()->set_alignment((sint8)alignment);
  10046. if (spawn->IsPlayer())
  10047. ((Player*)spawn)->SetCharSheetChanged(true);
  10048. }
  10049. return 0;
  10050. }
  10051. int EQ2Emu_lua_GetAlignment(lua_State* state) {
  10052. if (!lua_interface)
  10053. return 0;
  10054. Spawn* spawn = lua_interface->GetSpawn(state);
  10055. lua_interface->ResetFunctionStack(state);
  10056. if (!spawn) {
  10057. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not valid", lua_interface->GetScriptName(state));
  10058. return 0;
  10059. }
  10060. if (!spawn->IsEntity()) {
  10061. lua_interface->LogError("%s: LUA GetAlignment command error: spawn is not an entity", lua_interface->GetScriptName(state));
  10062. return 0;
  10063. }
  10064. lua_interface->SetSInt32Value(state, ((Entity*)spawn)->GetAlignment());
  10065. return 1;
  10066. }
  10067. int EQ2Emu_lua_GetSpell(lua_State* state) {
  10068. if (!lua_interface)
  10069. return 0;
  10070. int32 spell_id = lua_interface->GetInt32Value(state);
  10071. int8 spell_tier = lua_interface->GetInt8Value(state, 2);
  10072. string custom_lua_script = lua_interface->GetStringValue(state, 3);
  10073. if (spell_id > 0) {
  10074. if (spell_tier == 0)
  10075. spell_tier = 1;
  10076. Spell* spell = master_spell_list.GetSpell(spell_id, spell_tier);
  10077. LuaSpell* lua_spell = 0;
  10078. if(custom_lua_script.size() > 0)
  10079. {
  10080. // attempt to load the custom script since it isn't already loaded
  10081. // we will re-obtain the lua_spell further below
  10082. if((lua_spell = lua_interface->GetSpell(custom_lua_script.c_str())) == nullptr)
  10083. {
  10084. 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());
  10085. lua_interface->LoadLuaSpell(custom_lua_script);
  10086. }
  10087. }
  10088. else
  10089. custom_lua_script = spell->GetSpellData()->lua_script;
  10090. if (!lua_spell && lua_interface)
  10091. lua_spell = lua_interface->GetSpell(custom_lua_script.c_str());
  10092. if (!lua_spell)
  10093. {
  10094. LogWrite(LUA__ERROR, 0, "LUA", "GetSpell(%u, %u, '%s') spell could not be loaded.", spell_id, spell_tier, custom_lua_script.c_str());
  10095. return 0;
  10096. }
  10097. lua_spell->spell = new Spell(spell);
  10098. lua_interface->AddCustomSpell(lua_spell);
  10099. lua_interface->SetSpellValue(state, lua_spell);
  10100. return 1;
  10101. }
  10102. return 0;
  10103. }
  10104. int EQ2Emu_lua_GetSpellData(lua_State* state) {
  10105. if (!lua_interface)
  10106. return 0;
  10107. LuaSpell* spell = lua_interface->GetSpell(state);
  10108. string field = lua_interface->GetStringValue(state, 2);
  10109. if (!spell) {
  10110. lua_interface->LogError("%s: Spell not given in GetSpellData!", lua_interface->GetScriptName(state));
  10111. return 0;
  10112. }
  10113. if (!spell->spell || !spell->spell->GetSpellData()) {
  10114. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellData!", lua_interface->GetScriptName(state));
  10115. return 0;
  10116. }
  10117. boost::to_lower(field);
  10118. return spell->spell->GetSpellData(state, field);
  10119. }
  10120. int EQ2Emu_lua_SetSpellData(lua_State* state) {
  10121. if (!lua_interface)
  10122. return 0;
  10123. LuaSpell* spell = lua_interface->GetSpell(state);
  10124. string field = lua_interface->GetStringValue(state, 2);
  10125. int8 fieldArg = 3; // field value after the initial set
  10126. if (!spell) {
  10127. lua_interface->LogError("%s: Spell not given in SetSpellData!", lua_interface->GetScriptName(state));
  10128. return 0;
  10129. }
  10130. if (!spell->spell || !spell->spell->GetSpellData()) {
  10131. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellData!", lua_interface->GetScriptName(state));
  10132. return 0;
  10133. }
  10134. boost::to_lower(field);
  10135. bool valSet = false;
  10136. spell->spell->SetSpellData(state, field, fieldArg);
  10137. return valSet;
  10138. }
  10139. int EQ2Emu_lua_SetSpellDataIndex(lua_State* state) {
  10140. if (!lua_interface)
  10141. return 0;
  10142. LuaSpell* spell = lua_interface->GetSpell(state);
  10143. int8 idx = lua_interface->GetInt32Value(state, 2);
  10144. if (!spell) {
  10145. lua_interface->LogError("%s: Spell not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10146. return 0;
  10147. }
  10148. if (!spell->spell || !spell->spell->GetSpellData()) {
  10149. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDataIndex!", lua_interface->GetScriptName(state));
  10150. return 0;
  10151. }
  10152. if (spell->spell->lua_data.size() <= idx)
  10153. {
  10154. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10155. return 0;
  10156. }
  10157. bool setVal = true;
  10158. LUAData* data = spell->spell->lua_data[idx];
  10159. switch (data->type)
  10160. {
  10161. case 0:
  10162. {
  10163. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10164. sint32 value2 = lua_interface->GetSInt32Value(state, 4);
  10165. data->int_value = value;
  10166. data->int_value2 = value2;
  10167. break;
  10168. }
  10169. case 1:
  10170. {
  10171. float value = lua_interface->GetFloatValue(state, 3);
  10172. float value2 = lua_interface->GetFloatValue(state, 4);
  10173. data->float_value = value;
  10174. data->float_value2 = value2;
  10175. break;
  10176. }
  10177. case 2:
  10178. {
  10179. bool value = lua_interface->GetBooleanValue(state, 3);
  10180. data->bool_value = value;
  10181. break;
  10182. }
  10183. case 3:
  10184. {
  10185. string value = lua_interface->GetStringValue(state, 3);
  10186. string value2 = lua_interface->GetStringValue(state, 4);
  10187. data->string_value = value;
  10188. data->string_value2 = value2;
  10189. break;
  10190. }
  10191. default:
  10192. setVal = false;
  10193. }
  10194. return setVal;
  10195. }
  10196. int EQ2Emu_lua_GetSpellDataIndex(lua_State* state) {
  10197. if (!lua_interface)
  10198. return 0;
  10199. LuaSpell* spell = lua_interface->GetSpell(state);
  10200. int8 idx = lua_interface->GetInt32Value(state, 2);
  10201. bool secondfield = lua_interface->GetBooleanValue(state, 3);
  10202. if (!spell) {
  10203. lua_interface->LogError("%s: Spell not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10204. return 0;
  10205. }
  10206. if (!spell->spell || !spell->spell->GetSpellData()) {
  10207. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDataIndex!", lua_interface->GetScriptName(state));
  10208. return 0;
  10209. }
  10210. if (spell->spell->lua_data.size() <= idx)
  10211. {
  10212. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDataIndex!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10213. return 0;
  10214. }
  10215. bool setVal = true;
  10216. LUAData* data = spell->spell->lua_data[idx];
  10217. switch (data->type)
  10218. {
  10219. case 0:
  10220. {
  10221. if(!secondfield)
  10222. lua_interface->SetSInt32Value(state, data->int_value);
  10223. else
  10224. lua_interface->SetSInt32Value(state, data->int_value2);
  10225. break;
  10226. }
  10227. case 1:
  10228. {
  10229. if (!secondfield)
  10230. lua_interface->SetFloatValue(state, data->float_value);
  10231. else
  10232. lua_interface->SetFloatValue(state, data->float_value2);
  10233. break;
  10234. }
  10235. case 2:
  10236. {
  10237. lua_interface->SetBooleanValue(state, data->bool_value);
  10238. break;
  10239. }
  10240. case 3:
  10241. {
  10242. if (!secondfield)
  10243. lua_interface->SetStringValue(state, data->string_value.c_str());
  10244. else
  10245. lua_interface->SetStringValue(state, data->string_value2.c_str());
  10246. break;
  10247. }
  10248. default:
  10249. setVal = false;
  10250. }
  10251. return setVal;
  10252. }
  10253. int EQ2Emu_lua_SetSpellDisplayEffect(lua_State* state) {
  10254. if (!lua_interface)
  10255. return 0;
  10256. LuaSpell* spell = lua_interface->GetSpell(state);
  10257. int8 idx = lua_interface->GetInt32Value(state, 2);
  10258. string field = lua_interface->GetStringValue(state, 3);
  10259. boost::to_lower(field);
  10260. if (!spell) {
  10261. lua_interface->LogError("%s: Spell not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10262. return 0;
  10263. }
  10264. if (!spell->spell || !spell->spell->GetSpellData()) {
  10265. lua_interface->LogError("%s: Inner Spell or SpellData not given in SetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10266. return 0;
  10267. }
  10268. if (spell->spell->effects.size() <= idx)
  10269. {
  10270. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) SetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10271. return 0;
  10272. }
  10273. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10274. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10275. if (field == "description")
  10276. effect->description = string(lua_interface->GetStringValue(state, 4));
  10277. else if (field == "bullet")
  10278. effect->subbullet = lua_interface->GetInt8Value(state, 4);
  10279. else if (field == "percentage")
  10280. effect->percentage = lua_interface->GetInt8Value(state, 4);
  10281. else // no match
  10282. return 0;
  10283. return 1;
  10284. }
  10285. int EQ2Emu_lua_GetSpellDisplayEffect(lua_State* state) {
  10286. if (!lua_interface)
  10287. return 0;
  10288. LuaSpell* spell = lua_interface->GetSpell(state);
  10289. int8 idx = lua_interface->GetInt32Value(state, 2);
  10290. string field = lua_interface->GetStringValue(state, 3);
  10291. boost::to_lower(field);
  10292. if (!spell) {
  10293. lua_interface->LogError("%s: Spell not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10294. return 0;
  10295. }
  10296. if (!spell->spell || !spell->spell->GetSpellData()) {
  10297. lua_interface->LogError("%s: Inner Spell or SpellData not given in GetSpellDisplayEffect!", lua_interface->GetScriptName(state));
  10298. return 0;
  10299. }
  10300. if (spell->spell->effects.size() <= idx)
  10301. {
  10302. lua_interface->LogError("%s: lua_data size %i <= %i (idx passed) GetSpellDisplayEffect!", lua_interface->GetScriptName(state), spell->spell->lua_data.size(), idx);
  10303. return 0;
  10304. }
  10305. // do we need to lock? eh probably not this should only be used before use of the custom spell
  10306. SpellDisplayEffect* effect = spell->spell->effects[idx];
  10307. if (field == "description")
  10308. lua_interface->SetStringValue(state, effect->description.c_str());
  10309. else if (field == "bullet")
  10310. lua_interface->SetInt32Value(state, effect->subbullet);
  10311. else if (field == "percentage")
  10312. lua_interface->SetInt32Value(state, effect->percentage);
  10313. else // no match
  10314. return 0;
  10315. return 1;
  10316. }
  10317. int EQ2Emu_lua_CastCustomSpell(lua_State* state) {
  10318. if (!lua_interface)
  10319. return 0;
  10320. LuaSpell* spell = lua_interface->GetSpell(state);
  10321. Spawn* caster = lua_interface->GetSpawn(state, 2);
  10322. Spawn* target = lua_interface->GetSpawn(state, 3);
  10323. if (!target) {
  10324. lua_interface->LogError("%s: LUA CastCustomSpell command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10325. return 0;
  10326. }
  10327. if (!target->IsEntity()) {
  10328. lua_interface->LogError("%s: LUA CastCustomSpell command error: target (%s) is not an entity", lua_interface->GetScriptName(state), target->GetName());
  10329. return 0;
  10330. }
  10331. if (!spell) {
  10332. lua_interface->LogError("%s: LUA CastCustomSpell command error: spell is not valid", lua_interface->GetScriptName(state));
  10333. return 0;
  10334. }
  10335. if (caster && !caster->IsEntity()) {
  10336. lua_interface->LogError("%s: LUA CastSpell command error: caster (%s) is not an entity", lua_interface->GetScriptName(state), caster->GetName());
  10337. return 0;
  10338. }
  10339. target->GetZone()->ProcessSpell(NULL, (Entity*)caster, (Entity*)target, true, false, spell, 0);
  10340. return 0;
  10341. }
  10342. int EQ2Emu_lua_InWater(lua_State* state) {
  10343. if (!lua_interface)
  10344. return 0;
  10345. Spawn* spawn = lua_interface->GetSpawn(state);
  10346. lua_interface->ResetFunctionStack(state);
  10347. if (spawn) {
  10348. lua_interface->SetBooleanValue(state, spawn->InWater());
  10349. return 1;
  10350. }
  10351. return 0;
  10352. }
  10353. int EQ2Emu_lua_InLava(lua_State* state) {
  10354. if (!lua_interface)
  10355. return 0;
  10356. Spawn* spawn = lua_interface->GetSpawn(state);
  10357. lua_interface->ResetFunctionStack(state);
  10358. if (spawn) {
  10359. lua_interface->SetBooleanValue(state, spawn->InLava());
  10360. return 1;
  10361. }
  10362. return 0;
  10363. }
  10364. int EQ2Emu_lua_DamageSpawn(lua_State* state) {
  10365. if (!lua_interface)
  10366. return 0;
  10367. Spawn* attacker = lua_interface->GetSpawn(state);
  10368. Spawn* victim = lua_interface->GetSpawn(state, 2);
  10369. int8 type = lua_interface->GetInt8Value(state, 3);
  10370. int8 dmg_type = lua_interface->GetInt8Value(state, 4);
  10371. int32 low_damage = lua_interface->GetInt32Value(state, 5);
  10372. int32 high_damage = lua_interface->GetInt32Value(state, 6);
  10373. string spell_name = lua_interface->GetStringValue(state, 7);
  10374. int8 crit_mod = lua_interface->GetInt8Value(state, 8);
  10375. bool is_tick = (lua_interface->GetInt8Value(state, 9) == 1);
  10376. bool no_calcs = (lua_interface->GetInt8Value(state, 10) == 1);
  10377. bool ignore_attacker = (lua_interface->GetInt8Value(state, 11) == 1);
  10378. lua_interface->ResetFunctionStack(state);
  10379. if (!attacker) {
  10380. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not a valid spawn", lua_interface->GetScriptName(state));
  10381. return 0;
  10382. }
  10383. if (!attacker->IsEntity()) {
  10384. lua_interface->LogError("%s: LUA ProcDamage command error: caster is not an entity", lua_interface->GetScriptName(state));
  10385. return 0;
  10386. }
  10387. if (!victim) {
  10388. lua_interface->LogError("%s: LUA ProcDamage command error: target is not a valid spawn", lua_interface->GetScriptName(state));
  10389. return 0;
  10390. }
  10391. if (!victim->IsEntity()) {
  10392. lua_interface->LogError("%s: LUA ProcDamage command error: target is not an entity", lua_interface->GetScriptName(state));
  10393. return 0;
  10394. }
  10395. ((Entity*)attacker)->DamageSpawn((Entity*)victim, type, dmg_type, low_damage, high_damage, spell_name.c_str(), crit_mod, is_tick, no_calcs, ignore_attacker);
  10396. return 0;
  10397. }
  10398. int EQ2Emu_lua_IsInvulnerable(lua_State* state) {
  10399. if (!lua_interface)
  10400. return 0;
  10401. Spawn* spawn = lua_interface->GetSpawn(state);
  10402. lua_interface->ResetFunctionStack(state);
  10403. if (spawn) {
  10404. lua_interface->SetBooleanValue(state, spawn->GetInvulnerable());
  10405. return 1;
  10406. }
  10407. return 0;
  10408. }
  10409. int EQ2Emu_lua_SetInvulnerable(lua_State* state) {
  10410. if (!lua_interface)
  10411. return 0;
  10412. Spawn* spawn = lua_interface->GetSpawn(state);
  10413. bool invul = lua_interface->GetBooleanValue(state, 2);
  10414. lua_interface->ResetFunctionStack(state);
  10415. if (spawn) {
  10416. spawn->SetInvulnerable(invul);
  10417. }
  10418. return 0;
  10419. }
  10420. int EQ2Emu_lua_GetRuleFlagBool(lua_State* state) {
  10421. if (!lua_interface)
  10422. return 0;
  10423. string category = lua_interface->GetStringValue(state);
  10424. string name = lua_interface->GetStringValue(state, 2);
  10425. lua_interface->ResetFunctionStack(state);
  10426. Rule *ret = 0;
  10427. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10428. lua_interface->SetBooleanValue(state, ret->GetBool());
  10429. return 1;
  10430. }
  10431. lua_interface->LogError("%s: LUA GetRuleFlagBool Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10432. return 0;
  10433. }
  10434. int EQ2Emu_lua_GetRuleFlagInt32(lua_State* state) {
  10435. if (!lua_interface)
  10436. return 0;
  10437. string category = lua_interface->GetStringValue(state);
  10438. string name = lua_interface->GetStringValue(state, 2);
  10439. lua_interface->ResetFunctionStack(state);
  10440. Rule *ret = 0;
  10441. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10442. lua_interface->SetInt32Value(state, ret->GetInt32());
  10443. return 1;
  10444. }
  10445. lua_interface->LogError("%s: LUA GetRuleFlagInt32 Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10446. return 0;
  10447. }
  10448. int EQ2Emu_lua_GetRuleFlagFloat(lua_State* state) {
  10449. if (!lua_interface)
  10450. return 0;
  10451. string category = lua_interface->GetStringValue(state);
  10452. string name = lua_interface->GetStringValue(state, 2);
  10453. lua_interface->ResetFunctionStack(state);
  10454. Rule *ret = 0;
  10455. if ((ret = rule_manager.GetGlobalRule(category.c_str(), name.c_str()))) {
  10456. lua_interface->SetFloatValue(state, ret->GetFloat());
  10457. return 1;
  10458. }
  10459. lua_interface->LogError("%s: LUA GetRuleFlagFloat Unknown rule with category '%s' and type '%s'", lua_interface->GetScriptName(state), category.c_str(), name.c_str());
  10460. return 0;
  10461. }
  10462. int EQ2Emu_lua_GetAAInfo(lua_State* state) {
  10463. if (!lua_interface)
  10464. return 0;
  10465. Spawn* spawn = lua_interface->GetSpawn(state);
  10466. string type = lua_interface->GetStringValue(state, 2);
  10467. lua_interface->ResetFunctionStack(state);
  10468. if (spawn) {
  10469. int res = 1;
  10470. boost::to_lower(type);
  10471. if(type == "assigned_aa")
  10472. lua_interface->SetSInt32Value(state, spawn->GetAssignedAA());
  10473. else if ( type == "unassigned_aa")
  10474. lua_interface->SetSInt32Value(state, spawn->GetUnassignedAA());
  10475. else if ( type == "assigned_tradeskill_aa")
  10476. lua_interface->SetSInt32Value(state, spawn->GetTradeskillAA());
  10477. else if ( type == "unassigned_tradeskill_aa")
  10478. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillAA());
  10479. else if ( type == "assigned_prestige_aa")
  10480. lua_interface->SetSInt32Value(state, spawn->GetPrestigeAA());
  10481. else if ( type == "unassigned_prestige_aa")
  10482. lua_interface->SetSInt32Value(state, spawn->GetUnassignedPretigeAA());
  10483. else if ( type == "assigned_tradeskill_prestige_aa")
  10484. lua_interface->SetSInt32Value(state, spawn->GetTradeskillPrestigeAA());
  10485. else if ( type == "unassigned_tradeskill_prestige_aa")
  10486. lua_interface->SetSInt32Value(state, spawn->GetUnassignedTradeskillPrestigeAA());
  10487. else
  10488. res = 0;
  10489. return res;
  10490. }
  10491. lua_interface->LogError("%s: LUA GetAAInfo spawn does not exist", lua_interface->GetScriptName(state));
  10492. return 0;
  10493. }
  10494. int EQ2Emu_lua_SetAAInfo(lua_State* state) {
  10495. if (!lua_interface)
  10496. return 0;
  10497. Spawn* spawn = lua_interface->GetSpawn(state);
  10498. string type = lua_interface->GetStringValue(state, 2);
  10499. sint32 value = lua_interface->GetSInt32Value(state, 3);
  10500. lua_interface->ResetFunctionStack(state);
  10501. if (spawn) {
  10502. boost::to_lower(type);
  10503. if(type == "assigned_aa")
  10504. spawn->SetAssignedAA((sint16)value);
  10505. else if ( type == "unassigned_aa")
  10506. spawn->SetUnassignedAA((sint16)value);
  10507. else if ( type == "assigned_tradeskill_aa")
  10508. spawn->SetTradeskillAA((sint16)value);
  10509. else if ( type == "unassigned_tradeskill_aa")
  10510. spawn->SetUnassignedTradeskillAA((sint16)value);
  10511. else if ( type == "assigned_prestige_aa")
  10512. spawn->SetPrestigeAA((sint16)value);
  10513. else if ( type == "unassigned_prestige_aa")
  10514. spawn->SetUnassignedPrestigeAA((sint16)value);
  10515. else if ( type == "assigned_tradeskill_prestige_aa")
  10516. spawn->SetTradeskillPrestigeAA((sint16)value);
  10517. else if ( type == "unassigned_tradeskill_prestige_aa")
  10518. spawn->SetUnassignedTradeskillPrestigeAA((sint16)value);
  10519. if(spawn->IsPlayer())
  10520. ((Player*)spawn)->SetCharSheetChanged(true);
  10521. }
  10522. return 0;
  10523. }
  10524. int EQ2Emu_lua_AddMasterTitle(lua_State* state) {
  10525. if (!lua_interface)
  10526. return 0;
  10527. string titleName = lua_interface->GetStringValue(state);
  10528. int8 isPrefix = lua_interface->GetInt8Value(state, 2);
  10529. lua_interface->ResetFunctionStack(state);
  10530. sint32 index = database.AddMasterTitle(titleName.c_str(), isPrefix);
  10531. lua_interface->SetSInt32Value(state, index);
  10532. return 1;
  10533. }
  10534. int EQ2Emu_lua_AddCharacterTitle(lua_State* state) {
  10535. if (!lua_interface)
  10536. return 0;
  10537. Spawn* spawn = lua_interface->GetSpawn(state);
  10538. string titleName = lua_interface->GetStringValue(state, 2);
  10539. lua_interface->ResetFunctionStack(state);
  10540. if(!spawn->IsPlayer())
  10541. {
  10542. lua_interface->LogError("%s: LUA AddCharacterTitle command error: player is not valid", lua_interface->GetScriptName(state));
  10543. lua_interface->SetSInt32Value(state, -1);
  10544. return 1;
  10545. }
  10546. Player* player = (Player*)spawn;
  10547. // check if player already has the title, don't need to add twice
  10548. Title* playerHasTitle = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10549. if ( playerHasTitle)
  10550. {
  10551. lua_interface->SetSInt32Value(state, playerHasTitle->GetID());
  10552. return 1;
  10553. }
  10554. Title* title = master_titles_list.GetTitleByName(titleName.c_str());
  10555. if(!title)
  10556. {
  10557. lua_interface->LogError("%s: LUA AddCharacterTitle command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10558. lua_interface->SetSInt32Value(state, -1);
  10559. return 1;
  10560. }
  10561. sint32 returnIdx = database.AddCharacterTitle(title->GetID(), player->GetCharacterID(), player);
  10562. if(returnIdx < 0)
  10563. {
  10564. lua_interface->LogError("%s: LUA AddCharacterTitle command error: got invalid index (-1) returned for database.AddCharacterTitle '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10565. }
  10566. lua_interface->SetSInt32Value(state, returnIdx);
  10567. player->GetClient()->SendTitleUpdate();
  10568. return 1;
  10569. }
  10570. int EQ2Emu_lua_SetCharacterTitleSuffix(lua_State* state) {
  10571. if (!lua_interface)
  10572. return 0;
  10573. Spawn* spawn = lua_interface->GetSpawn(state);
  10574. string titleName = lua_interface->GetStringValue(state, 2);
  10575. lua_interface->ResetFunctionStack(state);
  10576. if(!spawn->IsPlayer())
  10577. {
  10578. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10579. return 0;
  10580. }
  10581. Player* player = (Player*)spawn;
  10582. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10583. if(!title)
  10584. {
  10585. lua_interface->LogError("%s: LUA SetCharacterTitleSuffix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10586. return 0;
  10587. }
  10588. if(title->GetPrefix())
  10589. {
  10590. 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());
  10591. return 0;
  10592. }
  10593. database.SaveCharSuffixIndex(title->GetID(), player->GetCharacterID());
  10594. player->GetClient()->SendTitleUpdate();
  10595. return 1;
  10596. }
  10597. int EQ2Emu_lua_SetCharacterTitlePrefix(lua_State* state) {
  10598. if (!lua_interface)
  10599. return 0;
  10600. Spawn* spawn = lua_interface->GetSpawn(state);
  10601. string titleName = lua_interface->GetStringValue(state, 2);
  10602. lua_interface->ResetFunctionStack(state);
  10603. if(!spawn->IsPlayer())
  10604. {
  10605. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10606. return 0;
  10607. }
  10608. Player* player = (Player*)spawn;
  10609. Title* title = player->GetPlayerTitles()->GetTitleByName(titleName.c_str());
  10610. if(!title)
  10611. {
  10612. lua_interface->LogError("%s: LUA SetCharacterTitlePrefix command error: title is not valid with name '%s'", lua_interface->GetScriptName(state), titleName.c_str());
  10613. return 0;
  10614. }
  10615. if(!title->GetPrefix())
  10616. {
  10617. 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());
  10618. return 0;
  10619. }
  10620. database.SaveCharPrefixIndex(title->GetID(), player->GetCharacterID());
  10621. player->GetClient()->SendTitleUpdate();
  10622. return 1;
  10623. }
  10624. int EQ2Emu_lua_ResetCharacterTitleSuffix(lua_State* state) {
  10625. if (!lua_interface)
  10626. return 0;
  10627. Spawn* spawn = lua_interface->GetSpawn(state);
  10628. lua_interface->ResetFunctionStack(state);
  10629. if(!spawn->IsPlayer())
  10630. {
  10631. lua_interface->LogError("%s: LUA ResetCharacterTitleSuffix command error: player is not valid", lua_interface->GetScriptName(state));
  10632. return 0;
  10633. }
  10634. Player* player = (Player*)spawn;
  10635. database.SaveCharSuffixIndex(-1, player->GetCharacterID());
  10636. player->GetClient()->SendTitleUpdate();
  10637. return 1;
  10638. }
  10639. int EQ2Emu_lua_ResetCharacterTitlePrefix(lua_State* state) {
  10640. if (!lua_interface)
  10641. return 0;
  10642. Spawn* spawn = lua_interface->GetSpawn(state);
  10643. lua_interface->ResetFunctionStack(state);
  10644. if(!spawn->IsPlayer())
  10645. {
  10646. lua_interface->LogError("%s: LUA ResetCharacterTitlePrefix command error: player is not valid", lua_interface->GetScriptName(state));
  10647. return 0;
  10648. }
  10649. Player* player = (Player*)spawn;
  10650. database.SaveCharPrefixIndex(-1, player->GetCharacterID());
  10651. player->GetClient()->SendTitleUpdate();
  10652. return 1;
  10653. }
  10654. int EQ2Emu_lua_GetInfoStructString(lua_State* state) {
  10655. if (!lua_interface)
  10656. return 0;
  10657. Spawn* spawn = lua_interface->GetSpawn(state);
  10658. string field = lua_interface->GetStringValue(state, 2);
  10659. lua_interface->ResetFunctionStack(state);
  10660. if(!spawn || !spawn->IsEntity())
  10661. {
  10662. 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));
  10663. return 0;
  10664. }
  10665. Entity* ent = (Entity*)spawn;
  10666. lua_interface->SetStringValue(state, ent->GetInfoStructString(field).c_str());
  10667. return 1;
  10668. }
  10669. int EQ2Emu_lua_GetInfoStructUInt(lua_State* state) {
  10670. if (!lua_interface)
  10671. return 0;
  10672. Spawn* spawn = lua_interface->GetSpawn(state);
  10673. string field = lua_interface->GetStringValue(state, 2);
  10674. lua_interface->ResetFunctionStack(state);
  10675. if(!spawn || !spawn->IsEntity())
  10676. {
  10677. 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));
  10678. return 0;
  10679. }
  10680. Entity* ent = (Entity*)spawn;
  10681. lua_interface->SetInt64Value(state, ent->GetInfoStructUInt(field));
  10682. return 1;
  10683. }
  10684. int EQ2Emu_lua_GetInfoStructSInt(lua_State* state) {
  10685. if (!lua_interface)
  10686. return 0;
  10687. Spawn* spawn = lua_interface->GetSpawn(state);
  10688. string field = lua_interface->GetStringValue(state, 2);
  10689. lua_interface->ResetFunctionStack(state);
  10690. if(!spawn || !spawn->IsEntity())
  10691. {
  10692. 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));
  10693. return 0;
  10694. }
  10695. Entity* ent = (Entity*)spawn;
  10696. lua_interface->SetSInt64Value(state, ent->GetInfoStructSInt(field));
  10697. return 1;
  10698. }
  10699. int EQ2Emu_lua_GetInfoStructFloat(lua_State* state) {
  10700. if (!lua_interface)
  10701. return 0;
  10702. Spawn* spawn = lua_interface->GetSpawn(state);
  10703. string field = lua_interface->GetStringValue(state, 2);
  10704. lua_interface->ResetFunctionStack(state);
  10705. if(!spawn || !spawn->IsEntity())
  10706. {
  10707. 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));
  10708. return 0;
  10709. }
  10710. Entity* ent = (Entity*)spawn;
  10711. lua_interface->SetFloatValue(state, ent->GetInfoStructFloat(field));
  10712. return 1;
  10713. }
  10714. int EQ2Emu_lua_SetInfoStructString(lua_State* state) {
  10715. if (!lua_interface)
  10716. return 0;
  10717. Spawn* spawn = lua_interface->GetSpawn(state);
  10718. string field = lua_interface->GetStringValue(state, 2);
  10719. string value = lua_interface->GetStringValue(state, 3);
  10720. lua_interface->ResetFunctionStack(state);
  10721. if(!spawn || !spawn->IsEntity())
  10722. {
  10723. 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));
  10724. return 0;
  10725. }
  10726. Entity* ent = (Entity*)spawn;
  10727. bool set_ = ent->SetInfoStructString(field, value);
  10728. lua_interface->SetBooleanValue(state, set_);
  10729. return 1;
  10730. }
  10731. int EQ2Emu_lua_SetInfoStructUInt(lua_State* state) {
  10732. if (!lua_interface)
  10733. return 0;
  10734. Spawn* spawn = lua_interface->GetSpawn(state);
  10735. string field = lua_interface->GetStringValue(state, 2);
  10736. int64 value = lua_interface->GetInt64Value(state, 3);
  10737. lua_interface->ResetFunctionStack(state);
  10738. if(!spawn || !spawn->IsEntity())
  10739. {
  10740. 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));
  10741. return 0;
  10742. }
  10743. Entity* ent = (Entity*)spawn;
  10744. bool set_ = ent->SetInfoStructUInt(field, value);
  10745. lua_interface->SetBooleanValue(state, set_);
  10746. return 1;
  10747. }
  10748. int EQ2Emu_lua_SetInfoStructSInt(lua_State* state) {
  10749. if (!lua_interface)
  10750. return 0;
  10751. Spawn* spawn = lua_interface->GetSpawn(state);
  10752. string field = lua_interface->GetStringValue(state, 2);
  10753. sint64 value = lua_interface->GetSInt64Value(state, 3);
  10754. lua_interface->ResetFunctionStack(state);
  10755. if(!spawn || !spawn->IsEntity())
  10756. {
  10757. 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));
  10758. return 0;
  10759. }
  10760. Entity* ent = (Entity*)spawn;
  10761. bool set_ = ent->SetInfoStructSInt(field, value);
  10762. lua_interface->SetBooleanValue(state, set_);
  10763. return 1;
  10764. }
  10765. int EQ2Emu_lua_SetInfoStructFloat(lua_State* state) {
  10766. if (!lua_interface)
  10767. return 0;
  10768. Spawn* spawn = lua_interface->GetSpawn(state);
  10769. string field = lua_interface->GetStringValue(state, 2);
  10770. float value = lua_interface->GetFloatValue(state, 3);
  10771. lua_interface->ResetFunctionStack(state);
  10772. if(!spawn || !spawn->IsEntity())
  10773. {
  10774. 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));
  10775. return 0;
  10776. }
  10777. Entity* ent = (Entity*)spawn;
  10778. bool set_ = ent->SetInfoStructFloat(field, value);
  10779. lua_interface->SetBooleanValue(state, set_);
  10780. return 1;
  10781. }
  10782. int EQ2Emu_lua_SetCharSheetChanged(lua_State* state) {
  10783. if (!lua_interface)
  10784. return 0;
  10785. Spawn* spawn = lua_interface->GetSpawn(state);
  10786. bool value = lua_interface->GetBooleanValue(state, 2);
  10787. lua_interface->ResetFunctionStack(state);
  10788. if(!spawn || !spawn->IsPlayer())
  10789. {
  10790. 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));
  10791. return 0;
  10792. }
  10793. ((Player*)spawn)->SetCharSheetChanged(value);
  10794. return 0;
  10795. }
  10796. int EQ2Emu_lua_AddPlayerMail(lua_State* state) {
  10797. if (!lua_interface)
  10798. return 0;
  10799. Spawn* spawn = lua_interface->GetSpawn(state);
  10800. std::string fromName = lua_interface->GetStringValue(state, 2);
  10801. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10802. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10803. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10804. int32 copper = lua_interface->GetInt32Value(state, 6);
  10805. int32 silver = lua_interface->GetInt32Value(state, 7);
  10806. int32 gold = lua_interface->GetInt32Value(state, 8);
  10807. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10808. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10809. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10810. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10811. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10812. lua_interface->ResetFunctionStack(state);
  10813. if(!spawn || !spawn->IsPlayer())
  10814. {
  10815. 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));
  10816. lua_interface->SetBooleanValue(state, false);
  10817. return 1;
  10818. }
  10819. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10820. ((Player*)spawn)->GetClient()->CreateAndUpdateMail(fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10821. lua_interface->SetBooleanValue(state, true);
  10822. return 1;
  10823. }
  10824. int EQ2Emu_lua_AddPlayerMailByCharID(lua_State* state) {
  10825. if (!lua_interface)
  10826. return 0;
  10827. int32 char_id = lua_interface->GetInt32Value(state);
  10828. std::string fromName = lua_interface->GetStringValue(state, 2);
  10829. std::string subjectName = lua_interface->GetStringValue(state, 3);
  10830. std::string mailBody = lua_interface->GetStringValue(state, 4);
  10831. int8 mailType = lua_interface->GetInt8Value(state, 5);
  10832. int32 copper = lua_interface->GetInt32Value(state, 6);
  10833. int32 silver = lua_interface->GetInt32Value(state, 7);
  10834. int32 gold = lua_interface->GetInt32Value(state, 8);
  10835. int32 platinum = lua_interface->GetInt32Value(state, 9);
  10836. int32 item_id = lua_interface->GetInt32Value(state, 10);
  10837. int16 stack_size = lua_interface->GetInt32Value(state, 11);
  10838. int32 expire_time = lua_interface->GetInt32Value(state, 12);
  10839. int32 sent_time = lua_interface->GetInt32Value(state, 13);
  10840. lua_interface->ResetFunctionStack(state);
  10841. int32 time_sent = sent_time > 0 ? sent_time : Timer::GetUnixTimeStamp();
  10842. Client::CreateMail(char_id, fromName, subjectName, mailBody, mailType, copper, silver, gold, platinum, item_id, stack_size, time_sent, expire_time);
  10843. lua_interface->SetBooleanValue(state, true);
  10844. return 1;
  10845. }
  10846. int EQ2Emu_lua_OpenDoor(lua_State* state) {
  10847. Spawn* widget;
  10848. if (lua_interface) {
  10849. widget = lua_interface->GetSpawn(state);
  10850. bool disable_open_sound = lua_interface->GetBooleanValue(state, 2);
  10851. lua_interface->ResetFunctionStack(state);
  10852. if (widget && widget->IsWidget())
  10853. {
  10854. ((Widget*)widget)->OpenDoor();
  10855. if(!disable_open_sound && ((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetOpenSound())
  10856. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetOpenSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10857. }
  10858. else
  10859. 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));
  10860. }
  10861. return 0;
  10862. }
  10863. int EQ2Emu_lua_CloseDoor(lua_State* state) {
  10864. Spawn* widget;
  10865. if (lua_interface) {
  10866. widget = lua_interface->GetSpawn(state);
  10867. bool disable_close_sound = lua_interface->GetBooleanValue(state, 2);
  10868. lua_interface->ResetFunctionStack(state);
  10869. if (widget && widget->IsWidget())
  10870. {
  10871. ((Widget*)widget)->CloseDoor();
  10872. if(!disable_close_sound && !((Widget*)widget)->IsOpen() && ((Widget*)widget)->GetCloseSound())
  10873. widget->GetZone()->PlaySoundFile(0, ((Widget*)widget)->GetCloseSound(), ((Widget*)widget)->GetX(), ((Widget*)widget)->GetY(), ((Widget*)widget)->GetZ());
  10874. }
  10875. else
  10876. 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));
  10877. }
  10878. return 0;
  10879. }
  10880. int EQ2Emu_lua_IsOpen(lua_State* state) {
  10881. if (!lua_interface)
  10882. return 0;
  10883. Spawn* widget = lua_interface->GetSpawn(state);
  10884. lua_interface->ResetFunctionStack(state);
  10885. if (widget && widget->IsWidget())
  10886. {
  10887. lua_interface->SetBooleanValue(state, ((Widget*)widget)->IsOpen());
  10888. return 1;
  10889. }
  10890. return 0;
  10891. }
  10892. int EQ2Emu_lua_MakeRandomInt(lua_State* state) {
  10893. if (!lua_interface)
  10894. return 0;
  10895. sint32 min = lua_interface->GetSInt32Value(state);
  10896. sint32 max = lua_interface->GetSInt32Value(state, 2);
  10897. lua_interface->ResetFunctionStack(state);
  10898. sint32 result = MakeRandomInt(min, max);
  10899. lua_interface->SetSInt32Value(state, result);
  10900. return 1;
  10901. }
  10902. int EQ2Emu_lua_MakeRandomFloat(lua_State* state) {
  10903. if (!lua_interface)
  10904. return 0;
  10905. float min = lua_interface->GetFloatValue(state);
  10906. float max = lua_interface->GetFloatValue(state, 2);
  10907. lua_interface->ResetFunctionStack(state);
  10908. float result = MakeRandomFloat(min, max);
  10909. lua_interface->SetFloatValue(state, result);
  10910. return 1;
  10911. }
  10912. int EQ2Emu_lua_AddIconValue(lua_State* state) {
  10913. if (!lua_interface)
  10914. return 0;
  10915. Spawn* spawn = lua_interface->GetSpawn(state);
  10916. int32 value = lua_interface->GetInt32Value(state, 2);
  10917. lua_interface->ResetFunctionStack(state);
  10918. if(!spawn)
  10919. {
  10920. lua_interface->LogError("%s: LUA AddIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10921. lua_interface->SetBooleanValue(state, false);
  10922. return 1;
  10923. }
  10924. spawn->AddIconValue(value);
  10925. lua_interface->SetBooleanValue(state, true);
  10926. return 1;
  10927. }
  10928. int EQ2Emu_lua_RemoveIconValue(lua_State* state) {
  10929. if (!lua_interface)
  10930. return 0;
  10931. Spawn* spawn = lua_interface->GetSpawn(state);
  10932. int32 value = lua_interface->GetInt32Value(state, 2);
  10933. lua_interface->ResetFunctionStack(state);
  10934. if(!spawn)
  10935. {
  10936. lua_interface->LogError("%s: LUA RemoveIconValue command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  10937. lua_interface->SetBooleanValue(state, false);
  10938. return 1;
  10939. }
  10940. spawn->RemoveIconValue(value);
  10941. lua_interface->SetBooleanValue(state, true);
  10942. return 1;
  10943. }
  10944. int EQ2Emu_lua_GetShardID(lua_State* state) {
  10945. Spawn* npc = lua_interface->GetSpawn(state);
  10946. lua_interface->ResetFunctionStack(state);
  10947. if (npc && npc->IsNPC()) {
  10948. NPC* shard = (NPC*)npc;
  10949. int32 shardid = shard->GetShardID();
  10950. lua_interface->SetInt32Value(state, shardid);
  10951. return 1;
  10952. }
  10953. lua_interface->SetInt32Value(state, 0);
  10954. return 1;
  10955. }
  10956. int EQ2Emu_lua_GetShardCharID(lua_State* state) {
  10957. Spawn* npc = lua_interface->GetSpawn(state);
  10958. lua_interface->ResetFunctionStack(state);
  10959. if (npc && npc->IsNPC()) {
  10960. NPC* shard = (NPC*)npc;
  10961. int32 charid = shard->GetShardCharID();
  10962. lua_interface->SetInt32Value(state, charid);
  10963. return 1;
  10964. }
  10965. lua_interface->SetInt32Value(state, 0);
  10966. return 1;
  10967. }
  10968. int EQ2Emu_lua_GetShardCreatedTimestamp(lua_State* state) {
  10969. Spawn* npc = lua_interface->GetSpawn(state);
  10970. lua_interface->ResetFunctionStack(state);
  10971. if (npc && npc->IsNPC()) {
  10972. NPC* shard = (NPC*)npc;
  10973. int64 timestamp = shard->GetShardCreatedTimestamp();
  10974. lua_interface->SetSInt64Value(state, timestamp);
  10975. return 1;
  10976. }
  10977. lua_interface->SetSInt64Value(state, 0);
  10978. return 1;
  10979. }
  10980. int EQ2Emu_lua_DeleteDBShardID(lua_State* state) {
  10981. if (!lua_interface)
  10982. return 0;
  10983. int32 shardid = lua_interface->GetInt32Value(state);
  10984. lua_interface->ResetFunctionStack(state);
  10985. if(shardid < 1)
  10986. lua_interface->SetBooleanValue(state, false);
  10987. else
  10988. lua_interface->SetBooleanValue(state, database.DeleteSpiritShard(shardid));
  10989. return 1;
  10990. }
  10991. int EQ2Emu_lua_PauseMovement(lua_State* state) {
  10992. if (!lua_interface)
  10993. return 0;
  10994. Spawn* spawn = lua_interface->GetSpawn(state);
  10995. int32 delay_in_ms = lua_interface->GetInt32Value(state, 2);
  10996. if (spawn) {
  10997. spawn->PauseMovement(delay_in_ms);
  10998. }
  10999. lua_interface->ResetFunctionStack(state);
  11000. return 0;
  11001. }
  11002. int EQ2Emu_lua_StopMovement(lua_State* state) {
  11003. if (!lua_interface)
  11004. return 0;
  11005. Spawn* spawn = lua_interface->GetSpawn(state);
  11006. if (spawn) {
  11007. spawn->StopMovement();
  11008. }
  11009. lua_interface->ResetFunctionStack(state);
  11010. return 0;
  11011. }
  11012. int EQ2Emu_lua_GetArrowColor(lua_State* state) {
  11013. Player* player = (Player*)lua_interface->GetSpawn(state);
  11014. int8 level = lua_interface->GetInt8Value(state, 2);
  11015. lua_interface->ResetFunctionStack(state);
  11016. if (player && player->IsPlayer() && level > 0) {
  11017. lua_interface->SetInt32Value(state, player->GetArrowColor(level));
  11018. return 1;
  11019. }
  11020. return 0;
  11021. }
  11022. int EQ2Emu_lua_GetTSArrowColor(lua_State* state) {
  11023. Player* player = (Player*)lua_interface->GetSpawn(state);
  11024. int8 level = lua_interface->GetInt8Value(state, 2);
  11025. lua_interface->ResetFunctionStack(state);
  11026. if (player && player->IsPlayer() && level > 0) {
  11027. lua_interface->SetInt32Value(state, player->GetTSArrowColor(level));
  11028. return 1;
  11029. }
  11030. return 0;
  11031. }
  11032. int EQ2Emu_lua_GetSpawnByRailID(lua_State* state) {
  11033. ZoneServer* zone = lua_interface->GetZone(state);
  11034. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11035. lua_interface->ResetFunctionStack(state);
  11036. if (zone) {
  11037. Spawn* spawn = zone->GetTransportByRailID(rail_id);
  11038. if (spawn) {
  11039. lua_interface->SetSpawnValue(state, spawn);
  11040. return 1;
  11041. }
  11042. }
  11043. return 0;
  11044. }
  11045. int EQ2Emu_lua_SetRailID(lua_State* state) {
  11046. if (!lua_interface)
  11047. return 0;
  11048. Spawn* spawn = lua_interface->GetSpawn(state);
  11049. sint64 rail_id = lua_interface->GetSInt64Value(state, 2);
  11050. lua_interface->ResetFunctionStack(state);
  11051. bool res = false;
  11052. if(spawn && spawn->IsTransportSpawn())
  11053. {
  11054. //printf("Set rail id %i for %s\n",rail_id,spawn->GetName());
  11055. spawn->SetRailID(rail_id);
  11056. res = true;
  11057. }
  11058. else if (!spawn) {
  11059. lua_interface->LogError("%s: LUA SetRailID command error: spawn is not valid, does not exist", lua_interface->GetScriptName(state));
  11060. }
  11061. else if(!spawn->IsTransportSpawn()) {
  11062. 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());
  11063. }
  11064. lua_interface->SetBooleanValue(state, res);
  11065. return 1;
  11066. }
  11067. int EQ2Emu_lua_IsZoneLoading(lua_State* state) {
  11068. if (!lua_interface)
  11069. return 0;
  11070. ZoneServer* zone = lua_interface->GetZone(state);
  11071. lua_interface->ResetFunctionStack(state);
  11072. if (zone) {
  11073. lua_interface->SetBooleanValue(state, zone->IsLoading());
  11074. return 1;
  11075. }
  11076. return 0;
  11077. }
  11078. int EQ2Emu_lua_IsRunning(lua_State* state) {
  11079. if (!lua_interface)
  11080. return 0;
  11081. Spawn* spawn = lua_interface->GetSpawn(state);
  11082. lua_interface->ResetFunctionStack(state);
  11083. if (spawn) {
  11084. lua_interface->SetBooleanValue(state, spawn->IsRunning());
  11085. return 1;
  11086. }
  11087. return 0;
  11088. }
  11089. int EQ2Emu_lua_GetZoneLockoutTimer(lua_State* state) {
  11090. if (!lua_interface)
  11091. return 0;
  11092. Spawn* player = lua_interface->GetSpawn(state);
  11093. int32 zoneID = lua_interface->GetInt32Value(state, 2);
  11094. bool displayClient = lua_interface->GetInt32Value(state, 3);
  11095. lua_interface->ResetFunctionStack(state);
  11096. if (!player || !player->IsPlayer() || !player->GetClient()) {
  11097. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: player is not valid, does not exist", lua_interface->GetScriptName(state));
  11098. }
  11099. else if(!zoneID) {
  11100. lua_interface->LogError("%s: LUA GetZoneLockoutTimer command error: zoneID is not set.");
  11101. }
  11102. else
  11103. {
  11104. lua_interface->SetStringValue(state, player->GetClient()->IdentifyInstanceLockout(zoneID, displayClient).c_str());
  11105. return 1;
  11106. }
  11107. return 0;
  11108. }
  11109. int EQ2Emu_lua_SetWorldTime(lua_State* state) {
  11110. if (!lua_interface)
  11111. return 0;
  11112. int16 newYear = lua_interface->GetInt16Value(state, 1);
  11113. sint32 newMonth = lua_interface->GetInt16Value(state, 2);
  11114. int16 newHour = lua_interface->GetInt16Value(state, 3);
  11115. int16 newMinute = lua_interface->GetInt16Value(state, 4);
  11116. lua_interface->ResetFunctionStack(state);
  11117. world.MWorldTime.writelock(__FUNCTION__, __LINE__);
  11118. world.GetWorldTimeStruct()->year = newYear;
  11119. world.GetWorldTimeStruct()->month = newMonth;
  11120. world.GetWorldTimeStruct()->hour = newHour;
  11121. world.GetWorldTimeStruct()->minute = newMinute;
  11122. world.MWorldTime.releasewritelock(__FUNCTION__, __LINE__);
  11123. return 0;
  11124. }
  11125. int EQ2Emu_lua_GetWorldTimeYear(lua_State* state) {
  11126. if (!lua_interface)
  11127. return 0;
  11128. lua_interface->ResetFunctionStack(state);
  11129. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11130. lua_interface->SetInt32Value(state, world.GetWorldTimeStruct()->year);
  11131. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11132. return 1;
  11133. }
  11134. int EQ2Emu_lua_GetWorldTimeMonth(lua_State* state) {
  11135. if (!lua_interface)
  11136. return 0;
  11137. lua_interface->ResetFunctionStack(state);
  11138. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11139. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->month);
  11140. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11141. return 1;
  11142. }
  11143. int EQ2Emu_lua_GetWorldTimeHour(lua_State* state) {
  11144. if (!lua_interface)
  11145. return 0;
  11146. lua_interface->ResetFunctionStack(state);
  11147. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11148. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->hour);
  11149. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11150. return 1;
  11151. }
  11152. int EQ2Emu_lua_GetWorldTimeMinute(lua_State* state) {
  11153. if (!lua_interface)
  11154. return 0;
  11155. lua_interface->ResetFunctionStack(state);
  11156. world.MWorldTime.readlock(__FUNCTION__, __LINE__);
  11157. lua_interface->SetSInt32Value(state, world.GetWorldTimeStruct()->minute);
  11158. world.MWorldTime.releasereadlock(__FUNCTION__, __LINE__);
  11159. return 1;
  11160. }
  11161. int EQ2Emu_lua_SendTimeUpdate(lua_State* state) {
  11162. if (!lua_interface)
  11163. return 0;
  11164. lua_interface->ResetFunctionStack(state);
  11165. world.SendTimeUpdate();
  11166. return 0;
  11167. }
  11168. int EQ2Emu_lua_ChangeFaction(lua_State* state) {
  11169. bool update_result = false;
  11170. Faction* faction = 0;
  11171. Player* player = (Player*)lua_interface->GetSpawn(state);
  11172. Client* client = player->GetZone()->GetClientBySpawn(player);
  11173. int32 faction_id = lua_interface->GetInt32Value(state, 2);
  11174. sint32 increase = lua_interface->GetInt32Value(state, 3);
  11175. lua_interface->ResetFunctionStack(state);
  11176. if (player && player->IsPlayer() && faction_id > 0) {
  11177. bool hasfaction = database.VerifyFactionID(player->GetCharacterID(),faction_id);
  11178. if(hasfaction == 0) {
  11179. //they do not have the faction. Lets get the default value and feed it in.
  11180. sint32 defaultfaction = master_faction_list.GetDefaultFactionValue(faction_id);
  11181. //add the default faction for the player.
  11182. player->SetFactionValue(faction_id, defaultfaction);
  11183. }
  11184. if(increase >= 0) {
  11185. update_result = player->GetFactions()->IncreaseFaction(faction_id,increase);
  11186. faction = master_faction_list.GetFaction(faction_id);
  11187. if(faction && update_result)
  11188. client->Message(CHANNEL_FACTION, "Your faction standing with %s got better.", faction->name.c_str());
  11189. else if(faction)
  11190. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any better.", faction->name.c_str());
  11191. lua_interface->SetBooleanValue(state, true);
  11192. return 1;
  11193. }
  11194. if(increase < 0){
  11195. //change the negative to a positive, since thats how decreasefaction() likes it.
  11196. increase *= -1;
  11197. update_result = player->GetFactions()->DecreaseFaction(faction_id,increase);
  11198. faction = master_faction_list.GetFaction(faction_id);
  11199. if(faction && update_result)
  11200. client->Message(CHANNEL_FACTION, "Your faction standing with %s got worse.", faction->name.c_str());
  11201. else if(faction)
  11202. client->Message(CHANNEL_FACTION, "Your faction standing with %s could not possibly get any worse.", faction->name.c_str());
  11203. lua_interface->SetBooleanValue(state, true);
  11204. return 1;
  11205. }
  11206. }
  11207. lua_interface->SetBooleanValue(state, false);
  11208. return 1;
  11209. }
  11210. int EQ2Emu_lua_HasCoin(lua_State* state) {
  11211. bool hascoin = 0;
  11212. Player* player = (Player*)lua_interface->GetSpawn(state);
  11213. int32 coins = lua_interface->GetInt32Value(state, 2);
  11214. lua_interface->ResetFunctionStack(state);
  11215. if (player && player->IsPlayer()) {
  11216. hascoin = player->HasCoins(coins);
  11217. if(hascoin == 0) {
  11218. lua_interface->SetBooleanValue(state, false);
  11219. return 1;
  11220. }
  11221. if(hascoin == 1) {
  11222. lua_interface->SetBooleanValue(state, true);
  11223. return 1;
  11224. }
  11225. }
  11226. return 0;
  11227. }
  11228. int EQ2Emu_lua_GetLootTier(lua_State* state) {
  11229. int32 loot_tier = 0;
  11230. Spawn* spawn = lua_interface->GetSpawn(state);
  11231. lua_interface->ResetFunctionStack(state);
  11232. if (spawn) {
  11233. loot_tier = spawn->GetLootTier();
  11234. lua_interface->SetInt32Value(state, loot_tier);
  11235. return 1;
  11236. }
  11237. return 0;
  11238. }
  11239. int EQ2Emu_lua_SetLootTier(lua_State* state) {
  11240. if (!lua_interface)
  11241. return 0;
  11242. Spawn* spawn = lua_interface->GetSpawn(state);
  11243. int32 loot_tier = lua_interface->GetInt32Value(state, 2);
  11244. lua_interface->ResetFunctionStack(state);
  11245. if (spawn) {
  11246. spawn->SetLootTier(loot_tier);
  11247. lua_interface->SetBooleanValue(state, true);
  11248. return 1;
  11249. }
  11250. lua_interface->SetBooleanValue(state, false);
  11251. return 1;
  11252. }
  11253. int EQ2Emu_lua_GetLootDropType(lua_State* state) {
  11254. int32 loot_drop_type = 0;
  11255. Spawn* spawn = lua_interface->GetSpawn(state);
  11256. lua_interface->ResetFunctionStack(state);
  11257. if (spawn) {
  11258. loot_drop_type = spawn->GetLootDropType();
  11259. lua_interface->SetInt32Value(state, loot_drop_type);
  11260. return 1;
  11261. }
  11262. return 0;
  11263. }
  11264. int EQ2Emu_lua_SetLootDropType(lua_State* state) {
  11265. if (!lua_interface)
  11266. return 0;
  11267. Spawn* spawn = lua_interface->GetSpawn(state);
  11268. int32 loot_drop_type = lua_interface->GetInt32Value(state, 2);
  11269. lua_interface->ResetFunctionStack(state);
  11270. if (spawn) {
  11271. spawn->SetLootDropType(loot_drop_type);
  11272. lua_interface->SetBooleanValue(state, true);
  11273. return 1;
  11274. }
  11275. lua_interface->SetBooleanValue(state, false);
  11276. return 1;
  11277. }